dev
嵇文龙 2 weeks ago
parent 43921c871d
commit c6478e8dab

@ -283,12 +283,29 @@ namespace DS.WMS.Core.Invoice.Dtos
public string? Checker { get; set; }
/// <summary>
/// 是否被冲红
/// </summary>
public bool IsSetRed { get; set; }
/// <summary>
/// 红票发票号
/// </summary>
public string? RedNO { get; set; }
/// <summary>
/// 红票代码
/// </summary>
public string? RedCode { get; set; }
/// <summary>
/// 冲红原因
/// </summary>
public string? RedReason { get; set; }
/// <summary>
/// 红票ID
/// </summary>
public long? RedId { get; set; }
/// <summary>
@ -306,6 +323,9 @@ namespace DS.WMS.Core.Invoice.Dtos
public string? Email { get; set; }
/// <summary>
/// 备注
/// </summary>
public string? Note { get; set; }
/// <summary>

@ -1,46 +0,0 @@
using System.Security;
using DS.Module.Core;
using DS.Module.Core.Extensions;
using Microsoft.Extensions.Configuration;
namespace DS.WMS.Core.Invoice.Method
{
/// <summary>
/// 提供对HTTP请求的低级别访问
/// </summary>
internal sealed class InvoiceApiFox : ApiFox
{
/// <summary>
/// 用户Key
/// </summary>
public string? UserKey { get; set; }
/// <summary>
/// 用户密钥
/// </summary>
public SecureString? UserSecret { get; private set; }
public InvoiceApiFox(IConfiguration config)
{
BaseUri = new Uri(config.GetValue<string>("InvoiceApi:BaseUrl"));
UserKey = config.GetValue<string>("InvoiceApi:UserKey");
var us = config.GetValue<string>("InvoiceApi:UserSecret");
if (!us.IsNullOrEmpty())
{
UserSecret = new SecureString();
for (int i = 0; i < us.Length; i++)
UserSecret.AppendChar(us[i]);
UserSecret.MakeReadOnly();
}
us = null;
DefaultHeaders.Add("USER_KEY", UserKey ?? string.Empty);
DefaultHeaders.Add("USER_SECRET", UserSecret?.ToString());
}
}
}

@ -28,7 +28,7 @@ namespace DS.WMS.Core.Invoice.Method
}
readonly Lazy<ICommonService> CommonService;
IGeneralInvoiceService InvoiceService;
readonly Lazy<IGeneralInvoiceService> InvoiceService;
/// <summary>
/// 初始化并加载配置
@ -38,7 +38,7 @@ namespace DS.WMS.Core.Invoice.Method
{
var config = provider.GetRequiredService<IConfiguration>();
CommonService = new Lazy<ICommonService>(provider.GetRequiredService<ICommonService>());
InvoiceService = provider.GetRequiredService<IGeneralInvoiceService>();
InvoiceService = new Lazy<IGeneralInvoiceService>(provider.GetRequiredService<IGeneralInvoiceService>());
}
/// <summary>
@ -247,12 +247,12 @@ namespace DS.WMS.Core.Invoice.Method
//获取发票费用明细ID
var ids = await TenantDb.Queryable<Entity.Invoice>()
.InnerJoin<ApplicationDetail>((i, d) => i.Id == d.ApplicationId)
.Where((i, d) => billNumbers.Contains(i.BillNO) && i.Type == InvoiceType.Red)
.Where((i, d) => billNumbers.Contains(i.BillNO) && i.Type == InvoiceType.Blue)
.Select((i, d) => d.Id).ToArrayAsync();
if (ids.Length > 0)
{
//删除蓝票费用明细
await InvoiceService.DeleteDetailAsync(ids);
await InvoiceService.Value.DeleteDetailAsync(ids);
}
await TenantDb.Updateable(invoices).WhereColumns(x => x.BillNO)
@ -300,12 +300,12 @@ namespace DS.WMS.Core.Invoice.Method
/// <returns></returns>
public async Task<DataResult> ReverseAsync(InvoiceReversalRequest request)
{
var blueInvoice = await TenantDb.Queryable<Entity.Invoice>().Includes(x => x.Details)
var blueInvoice = await TenantDb.Queryable<Entity.Invoice>()
.WhereIF(request.InvoiceId.HasValue, x => x.Id == request.InvoiceId)
.WhereIF(!request.orderNo.IsNullOrEmpty(), x => x.BillNO == request.orderNo)
.FirstAsync();
if (blueInvoice == null)
return DataResult.FailedWithDesc("发票ID或业务编号无效");
return DataResult.FailedWithDesc("传入的发票ID或编号无效");
if (blueInvoice.Type == InvoiceType.Red)
return DataResult.FailedWithDesc("红票无法被冲红");
if (blueInvoice.IsSettled)
@ -313,23 +313,69 @@ namespace DS.WMS.Core.Invoice.Method
var redInvoice = blueInvoice.DeepClone();
var sequence = CommonService.Value.GetSequenceNext<Entity.Invoice>();
redInvoice.Id = 0;
redInvoice.BillNO = sequence.Data;
redInvoice.SN = request.senid;
redInvoice.Type = InvoiceType.Red;
redInvoice.Details ??= [];
if (redInvoice.Details.Count == 0)
redInvoice.Details.AddRange(blueInvoice.Details);
redInvoice.InvoiceAmount = 0 - redInvoice.InvoiceAmount;
redInvoice.ApiCode = redInvoice.ApiStatus = redInvoice.PDFUrl = null;
redInvoice.CreateBy = long.Parse(User.UserId);
redInvoice.CreateTime = DateTime.Now;
redInvoice.UpdateBy = null;
redInvoice.UpdateTime = null;
redInvoice.Details = await TenantDb.Queryable<ApplicationDetail>().Where(x => x.ApplicationId == blueInvoice.Id).ToListAsync();
foreach (var detail in redInvoice.Details)
{
detail.Id = detail.ApplicationId = 0;
detail.ApplyAmount = 0 - detail.ApplyAmount;
detail.OriginalAmount = 0 - detail.OriginalAmount;
detail.OriginalProcessedAmount = detail.ProcessedAmount = 0;
}
redInvoice.InvoiceDetails = await TenantDb.Queryable<InvoiceDetail>().Where(x => x.ApplicationId == blueInvoice.Id).ToListAsync();
if (redInvoice.InvoiceDetails.Count == 0)
redInvoice.InvoiceDetails.AddRange(blueInvoice.InvoiceDetails);
foreach (var detail in redInvoice.InvoiceDetails)
{
detail.Id = detail.ApplicationId = 0;
detail.Amount = 0 - detail.Amount;
detail.TaxUnitPrice = 0 - detail.TaxUnitPrice;
detail.UnitPrice = 0 - detail.UnitPrice;
}
await TenantDb.Ado.BeginTranAsync();
try
{
await TenantDb.InsertNav(redInvoice).Include(x => x.Details).Include(x => x.InvoiceDetails).ExecuteCommandAsync();
blueInvoice.RedId = redInvoice.Id;
blueInvoice.IsSetRed = true;
blueInvoice.RedCode = request.chyyDm;
if (string.IsNullOrEmpty(request.Reason))
{
switch (request.chyyDm)
{
case "01":
request.Reason = "开票有误";
break;
case "02":
request.Reason = "销货退回";
break;
case "03":
request.Reason = "服务中止";
break;
case "04":
request.Reason = "销售折让";
break;
default:
request.Reason = "直接冲红";
break;
}
}
blueInvoice.RedReason = request.Reason;
await TenantDb.Updateable(blueInvoice).UpdateColumns(x => new { x.IsSetRed, x.RedId, x.RedCode, x.RedReason }).ExecuteCommandAsync();
//如果开票中所属机构为空,则取用户的orgId
var userOrgId = (blueInvoice.SaleDeptId != null && blueInvoice.SaleDeptId > 0) ? blueInvoice.SaleDeptId : User.OrgId;
//接口请求key密钥
@ -347,14 +393,7 @@ namespace DS.WMS.Core.Invoice.Method
if (result.Data == null || !result.Data.success)
return DataResult.Failed(result.Data == null ? "请求失败" : result.Data.msg);
await TenantDb.Insertable(redInvoice).ExecuteCommandAsync();
blueInvoice.RedCode = redInvoice.SN;
blueInvoice.RedId = redInvoice.Id;
blueInvoice.IsSetRed = true;
blueInvoice.RedReason = request.Reason;
await TenantDb.Updateable(blueInvoice).UpdateColumns(x => new { x.IsSetRed, x.RedId, x.RedReason }).ExecuteCommandAsync();
await TenantDb.Ado.CommitTranAsync();
var result2 = DataResult.Success;
result2.Data = redInvoice;
return result2;

@ -109,7 +109,12 @@ namespace DS.WMS.Core.Invoice.Method
/// <returns></returns>
public async Task<DataResult<InvoiceDto>> GetAsync(long id)
{
var invoice = await TenantDb.Queryable<Entity.Invoice>().Select<InvoiceDto>().FirstAsync(x => x.Id == id);
var invoice = await TenantDb.Queryable<Entity.Invoice>()
.LeftJoin<Entity.Invoice>((x, y) => x.RedId == y.Id)
.Select((x, y) => new InvoiceDto
{
RedNO = y.InvoiceNO
}, true).FirstAsync(x => x.Id == id);
if (invoice != null)
{
if (!string.IsNullOrEmpty(invoice.PushMode))
@ -476,7 +481,7 @@ namespace DS.WMS.Core.Invoice.Method
invoice.Note += Environment.NewLine + invRemark;
invoice.InvoiceRemark += Environment.NewLine + invRemark;
}
}
//筛选出新增的费用明细
@ -625,7 +630,7 @@ namespace DS.WMS.Core.Invoice.Method
}
else
{
foreach (var detail in details)
foreach (var detail in details)
{
if (detail.Currency == FeeCurrency.RMB_CODE)
detail.ApplyAmount = detail.OriginalAmount;

@ -103,8 +103,8 @@ namespace DS.WMS.FeeApi.Controllers
if (recordSubmit.Items == null)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
if (recordSubmit.Items.Any(x => x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission))
return DataResult.Failed("只能提交状态为‘录入’或‘驳回提交’的费用", MultiLanguageConst.IllegalRequest);
//if (recordSubmit.Items.Any(x => x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission))
// return DataResult.Failed("只能提交状态为‘录入’或‘驳回提交’的费用", MultiLanguageConst.IllegalRequest);
foreach (var item in recordSubmit.Items)
{

Loading…
Cancel
Save