|
|
|
@ -3,6 +3,7 @@ using DS.WMS.Core.Application.Method;
|
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
{
|
|
|
|
@ -26,52 +27,59 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 发起开票请求
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="invoices">开票的发票信息</param>
|
|
|
|
|
/// <param name="ids">开票的发票ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<string>> InitiateAsync(params Entity.Invoice[] invoices)
|
|
|
|
|
public async Task<DataResult<string>> InitiateAsync(params long[] ids)
|
|
|
|
|
{
|
|
|
|
|
ArgumentNullException.ThrowIfNull(ids, nameof(ids));
|
|
|
|
|
|
|
|
|
|
//请求参数设置
|
|
|
|
|
InvoiceIssuanceRequest request = new();
|
|
|
|
|
request.order = invoices.Select(x => new InvoiceInfo
|
|
|
|
|
InvoiceIssuanceRequest request = new()
|
|
|
|
|
{
|
|
|
|
|
invoiceType = ((int)x.Type).ToString(),
|
|
|
|
|
orderNo = x.BillNO,
|
|
|
|
|
email = x.Email,
|
|
|
|
|
buyerTaxNum = x.TaxID,
|
|
|
|
|
buyerName = x.InvoiceHeader,
|
|
|
|
|
buyerAddress = x.CustomerAddress,
|
|
|
|
|
buyerTel = x.CustomerPhone,
|
|
|
|
|
gmfkhh = x.CustomerBankName,
|
|
|
|
|
gmfzh = x.CustomerAccount,
|
|
|
|
|
skyhmc = x.BankName,
|
|
|
|
|
skyhzh = x.Account,
|
|
|
|
|
checker = x.Checker,
|
|
|
|
|
payee = x.Payee,
|
|
|
|
|
//---------金额项---------
|
|
|
|
|
hjse = x.InvoiceAmount * x.TaxRate,
|
|
|
|
|
hjje = x.InvoiceAmount - x.InvoiceAmount * x.TaxRate,
|
|
|
|
|
jshj = x.InvoiceAmount,
|
|
|
|
|
clerk = x.CreateUserName, //开票人
|
|
|
|
|
kprzjhm = "", //证件号
|
|
|
|
|
kprzjlx = "201", //身份证,
|
|
|
|
|
//---------发票明细---------
|
|
|
|
|
invoiceDetail = x.InvoiceDetails.Select(y => new InvoiceDetailInfo
|
|
|
|
|
order = await TenantDb.Queryable<Entity.Invoice>().Where(x => ids.Contains(x.Id)).Select(x => new InvoiceInfo
|
|
|
|
|
{
|
|
|
|
|
mxxh = x.InvoiceDetails.IndexOf(y) + 1,
|
|
|
|
|
xmmc = y.Name,
|
|
|
|
|
spfwjc = string.Empty,
|
|
|
|
|
specType = y.Specification,
|
|
|
|
|
unit = y.Unit,
|
|
|
|
|
num = y.Quantity.ToString(),
|
|
|
|
|
taxExcludedAmount = y.UnitPrice,
|
|
|
|
|
taxRate = y.TaxRate.ToString(),
|
|
|
|
|
tax = y.TaxAmount,
|
|
|
|
|
taxIncludedAmount = y.TaxUnitPrice,
|
|
|
|
|
goodsCode = "", //商品和服务税收分类合并编码
|
|
|
|
|
invoiceLineProperty = "00"
|
|
|
|
|
}).ToList()
|
|
|
|
|
invoiceType = ((int)x.Type).ToString(),
|
|
|
|
|
orderNo = x.BillNO,
|
|
|
|
|
email = x.Email,
|
|
|
|
|
buyerTaxNum = x.TaxID,
|
|
|
|
|
buyerName = x.InvoiceHeader,
|
|
|
|
|
buyerAddress = x.CustomerAddress,
|
|
|
|
|
buyerTel = x.CustomerPhone,
|
|
|
|
|
gmfkhh = x.CustomerBankName,
|
|
|
|
|
gmfzh = x.CustomerAccount,
|
|
|
|
|
skyhmc = x.BankName,
|
|
|
|
|
skyhzh = x.Account,
|
|
|
|
|
checker = x.Checker,
|
|
|
|
|
payee = x.Payee,
|
|
|
|
|
//---------金额项---------
|
|
|
|
|
hjse = x.InvoiceAmount * x.TaxRate,
|
|
|
|
|
hjje = x.InvoiceAmount - x.InvoiceAmount * x.TaxRate,
|
|
|
|
|
jshj = x.InvoiceAmount,
|
|
|
|
|
clerk = x.CreateUserName, //开票人
|
|
|
|
|
kprzjhm = "", //证件号
|
|
|
|
|
kprzjlx = "201", //身份证,
|
|
|
|
|
//---------发票明细---------
|
|
|
|
|
invoiceDetail = x.InvoiceDetails.Select(y => new InvoiceDetailInfo
|
|
|
|
|
{
|
|
|
|
|
mxxh = SqlFunc.RowNumber(y.Id), //x.InvoiceDetails.IndexOf(y) + 1,
|
|
|
|
|
xmmc = y.Name,
|
|
|
|
|
spfwjc = string.Empty,
|
|
|
|
|
specType = y.Specification,
|
|
|
|
|
unit = y.Unit,
|
|
|
|
|
num = y.Quantity.ToString(),
|
|
|
|
|
taxExcludedAmount = y.UnitPrice,
|
|
|
|
|
taxRate = y.TaxRate.ToString(),
|
|
|
|
|
tax = y.TaxAmount,
|
|
|
|
|
taxIncludedAmount = y.TaxUnitPrice,
|
|
|
|
|
goodsCode = "", //商品和服务税收分类合并编码
|
|
|
|
|
invoiceLineProperty = "00"
|
|
|
|
|
}).ToList()
|
|
|
|
|
|
|
|
|
|
}).ToListAsync()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
if (request.order.Count == 0 || request.order.Any(x => x.invoiceDetail.Count == 0))
|
|
|
|
|
return DataResult<string>.FailedWithDesc(MultiLanguageConst.InvoiceIncomplete);
|
|
|
|
|
|
|
|
|
|
var result = await api.PostAsync<InvoiceIssuanceResult<string>>("/api/Invoice/services", request);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
@ -80,14 +88,12 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
|
var invResult = result.Data;
|
|
|
|
|
if (invResult.Success)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(invResult.Data);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (invResult.Code == 1)
|
|
|
|
|
return await InitiateAsync(invoices);
|
|
|
|
|
return await InitiateAsync(ids);
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed(invResult.Message);
|
|
|
|
|
}
|
|
|
|
|