You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.7 KiB
C#
124 lines
4.7 KiB
C#
using DS.Module.Core;
|
|
using DS.WMS.Core.Application.Method;
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
using DS.WMS.Core.Sys.Entity;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.Invoice.Method
|
|
{
|
|
/// <summary>
|
|
/// 发票开具服务
|
|
/// </summary>
|
|
public sealed class InvoiceIssuanceService : ApplicationServiceBase
|
|
{
|
|
readonly InvoiceApiFox api;
|
|
|
|
/// <summary>
|
|
/// 初始化并加载配置
|
|
/// </summary>
|
|
/// <param name="provider"></param>
|
|
public InvoiceIssuanceService(IServiceProvider provider) : base(provider)
|
|
{
|
|
var config = provider.GetRequiredService<IConfiguration>();
|
|
api = new InvoiceApiFox(config);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发起开票请求
|
|
/// </summary>
|
|
/// <param name="ids">开票的发票ID</param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult<string>> InitiateAsync(params long[] ids)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(ids, nameof(ids));
|
|
|
|
long userId = long.Parse(User.UserId);
|
|
var userInfo = await Db.Queryable<SysUser>().Where(x => x.Id == userId).Select(x => new
|
|
{
|
|
x.Id,
|
|
}).FirstAsync();
|
|
|
|
//请求参数设置
|
|
InvoiceIssuanceRequest request = new()
|
|
{
|
|
order = await TenantDb.Queryable<Entity.Invoice>().Where(x => ids.Contains(x.Id)).Select(x => new InvoiceInfo
|
|
{
|
|
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()
|
|
};
|
|
|
|
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)
|
|
return DataResult<string>.Failed(result.Message, result.MultiCode);
|
|
|
|
var invResult = result.Data;
|
|
if (invResult.Success)
|
|
{
|
|
return DataResult<string>.Success(invResult.Data);
|
|
}
|
|
else
|
|
{
|
|
if (invResult.Code == 1)
|
|
return await InitiateAsync(ids);
|
|
|
|
return DataResult<string>.Failed(invResult.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加租户信息
|
|
/// </summary>
|
|
/// <param name="tenant">租户信息</param>
|
|
/// <returns></returns>
|
|
/// <exception cref="ArgumentNullException">当<paramref name="tenant"/>为null时引发。</exception>
|
|
public async Task<string> AddTenantAsync(Tenant tenant)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(tenant, nameof(tenant));
|
|
|
|
var result = await api.PostAsync<string>("/api/Login/AddTenant", tenant);
|
|
return result.Data;
|
|
}
|
|
}
|
|
}
|