|
|
|
@ -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;
|
|
|
|
|