|
|
@ -1,4 +1,5 @@
|
|
|
|
using DS.Module.Core;
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
|
|
|
using DS.Module.Core.Enums;
|
|
|
|
using DS.WMS.Core.Application.Entity;
|
|
|
|
using DS.WMS.Core.Application.Entity;
|
|
|
|
using DS.WMS.Core.Application.Method;
|
|
|
|
using DS.WMS.Core.Application.Method;
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
@ -35,7 +36,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="ids">发票ID</param>
|
|
|
|
/// <param name="ids">发票ID</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<DataResult<JObject>> InitiateAsync(params long[] ids)
|
|
|
|
public async Task<DataResult> InitiateAsync(params long[] ids)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ArgumentNullException.ThrowIfNull(ids, nameof(ids));
|
|
|
|
ArgumentNullException.ThrowIfNull(ids, nameof(ids));
|
|
|
|
|
|
|
|
|
|
|
@ -47,7 +48,7 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
}).FirstAsync();
|
|
|
|
}).FirstAsync();
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(userInfo.IdCardNo))
|
|
|
|
if (string.IsNullOrEmpty(userInfo.IdCardNo))
|
|
|
|
return DataResult<JObject>.FailedWithDesc(MultiLanguageConst.DrawerIDNumberIsNull);
|
|
|
|
return DataResult.FailedWithDesc(MultiLanguageConst.DrawerIDNumberIsNull);
|
|
|
|
|
|
|
|
|
|
|
|
//请求参数设置
|
|
|
|
//请求参数设置
|
|
|
|
InvoiceIssuanceRequest request = new()
|
|
|
|
InvoiceIssuanceRequest request = new()
|
|
|
@ -98,55 +99,122 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (request.order.Count == 0 || request.order.Any(x => x.invoiceDetail.Count == 0))
|
|
|
|
if (request.order.Count == 0 || request.order.Any(x => x.invoiceDetail.Count == 0))
|
|
|
|
return DataResult<JObject>.FailedWithDesc(MultiLanguageConst.InvoiceIncomplete);
|
|
|
|
return DataResult.FailedWithDesc(MultiLanguageConst.InvoiceIncomplete);
|
|
|
|
|
|
|
|
|
|
|
|
var result = await api.PostAsync<InvoiceResult<string>>("/api/Invoice/services", request);
|
|
|
|
var result = await api.PostAsync<InvoiceResult<string>>("/api/Invoice/services", request);
|
|
|
|
if (!result.Succeeded)
|
|
|
|
if (!result.Succeeded)
|
|
|
|
return DataResult<JObject>.Failed(result.Message, result.MultiCode);
|
|
|
|
return DataResult.Failed(result.Message, result.MultiCode);
|
|
|
|
|
|
|
|
|
|
|
|
var invResult = result.Data;
|
|
|
|
var invResult = result.Data;
|
|
|
|
JObject? jObj = JObject.Parse(invResult.Data);
|
|
|
|
|
|
|
|
if (invResult.Success)
|
|
|
|
if (invResult.Success)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return DataResult<JObject>.Success(jObj);
|
|
|
|
string sn = invResult.Data; //开票成功返回流水号
|
|
|
|
|
|
|
|
var invoices = ids.Select(x => new Entity.Invoice { Id = x, SN = sn, ApiType = InvoiceApiType.Default }).ToList();
|
|
|
|
|
|
|
|
await TenantDb.Updateable(invoices).UpdateColumns(x => new { x.SN, x.ApiType }).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdateInvoiceNumberAsync(sn);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (invResult.Code == 1)
|
|
|
|
if (invResult.Code == 1)
|
|
|
|
return await InitiateAsync(ids);
|
|
|
|
return await InitiateAsync(ids);
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<JObject>.FailedData(jObj, invResult.Message);
|
|
|
|
return DataResult.Failed(invResult.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 更新发票号码
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="sn">开票流水号</param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public async Task<DataResult> UpdateInvoiceNumberAsync(string sn)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//调用查询API获取发票号
|
|
|
|
|
|
|
|
var result = await api.PostAsync<InvoiceResult<InvoiceQuery>>("/api/Invoice/GetInvoiceState", new { guid = sn });
|
|
|
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
|
|
|
return DataResult.Failed(result.Message, result.MultiCode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var queryResult = result.Data;
|
|
|
|
|
|
|
|
if (queryResult == null || !queryResult.Success)
|
|
|
|
|
|
|
|
return DataResult.Failed(queryResult?.Message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (queryResult.Data.Order?.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
List<Entity.Invoice> invoices = [];
|
|
|
|
|
|
|
|
foreach (var item in queryResult.Data.Order)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var inv = new Entity.Invoice
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SN = sn,
|
|
|
|
|
|
|
|
BillNO = item.orderNo,
|
|
|
|
|
|
|
|
InvoiceNO = item.fphm,
|
|
|
|
|
|
|
|
ApiCode = item.State.ToString(),
|
|
|
|
|
|
|
|
ApiStatus = item.UpMessage,
|
|
|
|
|
|
|
|
PDFUrl = item.FileUrl
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
invoices.Add(inv);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(inv.ApiStatus))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (item.State)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
inv.ApiStatus = "已提交待上传";
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
inv.ApiStatus = "已上传待开票";
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
inv.ApiStatus = "开票成功";
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(invoices).WhereColumns(x => x.BillNO)
|
|
|
|
|
|
|
|
.UpdateColumns(x => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
x.InvoiceNO,
|
|
|
|
|
|
|
|
x.ApiCode,
|
|
|
|
|
|
|
|
x.ApiStatus,
|
|
|
|
|
|
|
|
x.PDFUrl
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 发票冲红
|
|
|
|
/// 发票冲红
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<DataResult<JObject>> ReverseAsync(InvoiceReversalRequest request)
|
|
|
|
public async Task<DataResult> ReverseAsync(InvoiceReversalRequest request)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var invoice = await TenantDb.Queryable<Entity.Invoice>()
|
|
|
|
var invoice = await TenantDb.Queryable<Entity.Invoice>()
|
|
|
|
.WhereIF(request.InvoiceId.HasValue, x => x.Id == request.InvoiceId)
|
|
|
|
.WhereIF(request.InvoiceId.HasValue, x => x.Id == request.InvoiceId)
|
|
|
|
.WhereIF(!request.orderNo.IsNullOrEmpty(), x => x.BillNO == request.orderNo)
|
|
|
|
.WhereIF(!request.orderNo.IsNullOrEmpty(), x => x.BillNO == request.orderNo)
|
|
|
|
.FirstAsync();
|
|
|
|
.FirstAsync();
|
|
|
|
if (invoice == null)
|
|
|
|
if (invoice == null)
|
|
|
|
return DataResult<JObject>.FailedWithDesc(MultiLanguageConst.EmptyData);
|
|
|
|
return DataResult.FailedWithDesc(MultiLanguageConst.EmptyData);
|
|
|
|
|
|
|
|
|
|
|
|
var req = new InvoiceReversalRequest { orderNo = invoice.BillNO };
|
|
|
|
var req = new InvoiceReversalRequest { orderNo = invoice.BillNO };
|
|
|
|
var result = await api.PostAsync<InvoiceResult<string>>("/api/Invoice/RedInvoicing", req);
|
|
|
|
var result = await api.PostAsync<InvoiceResult<string>>("/api/Invoice/RedInvoicing", req);
|
|
|
|
if (!result.Succeeded)
|
|
|
|
if (!result.Succeeded)
|
|
|
|
return DataResult<JObject>.Failed(result.Message, result.MultiCode);
|
|
|
|
return DataResult.Failed(result.Message, result.MultiCode);
|
|
|
|
|
|
|
|
|
|
|
|
var invResult = result.Data;
|
|
|
|
var invResult = result.Data;
|
|
|
|
JObject? jObj = JObject.Parse(invResult.Data);
|
|
|
|
JObject? jObj = JObject.Parse(invResult.Data);
|
|
|
|
if (invResult.Success)
|
|
|
|
if (invResult.Success)
|
|
|
|
return DataResult<JObject>.FailedData(jObj, invResult.Message);
|
|
|
|
return DataResult.Failed(invResult.Message);
|
|
|
|
|
|
|
|
|
|
|
|
invoice.IsSetRed = true;
|
|
|
|
invoice.IsSetRed = true;
|
|
|
|
invoice.RedReason = request.Reason;
|
|
|
|
invoice.RedReason = request.Reason;
|
|
|
|
await TenantDb.Updateable(invoice).UpdateColumns(x => new { x.IsSetRed, x.RedReason }).ExecuteCommandAsync();
|
|
|
|
await TenantDb.Updateable(invoice).UpdateColumns(x => new { x.IsSetRed, x.RedReason }).ExecuteCommandAsync();
|
|
|
|
return DataResult<JObject>.Success(jObj);
|
|
|
|
return DataResult.Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|