|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
using System.Text;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.WMS.Core.Application.Dtos;
|
|
|
|
|
using DS.WMS.Core.Application.Entity;
|
|
|
|
|
using DS.WMS.Core.Application.Interface;
|
|
|
|
@ -8,9 +7,11 @@ using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Method;
|
|
|
|
|
using DS.WMS.Core.Info.Entity;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Application.Method
|
|
|
|
|
{
|
|
|
|
@ -19,7 +20,7 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class InvoiceTemplateService : FeeServiceBase, IInvoiceTemplateService
|
|
|
|
|
{
|
|
|
|
|
const int MAX_NUM = 3;//每个用户的最大模板数量
|
|
|
|
|
const int MAX_NUM = 2;//每个用户的最大模板数量
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
@ -58,10 +59,8 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
if (list.Count == 0 && createIfEmpty)
|
|
|
|
|
{
|
|
|
|
|
var arr = new InvoiceTemplate[MAX_NUM];
|
|
|
|
|
for (int i = 0; i < MAX_NUM; i++)
|
|
|
|
|
{
|
|
|
|
|
arr[i] = new InvoiceTemplate { Content = string.Empty, Name = $"{MultiLanguageConst.DefaultTemplateName}{i + 1}" };
|
|
|
|
|
}
|
|
|
|
|
arr[0] = new InvoiceTemplate { Currency = FeeCurrency.RMB_CODE, Name = $"发票备注模板-{FeeCurrency.RMB_CODE}" };
|
|
|
|
|
arr[1] = new InvoiceTemplate { Currency = FeeCurrency.USD_CODE, Name = $"发票备注模板-{FeeCurrency.USD_CODE}" };
|
|
|
|
|
|
|
|
|
|
return Save(arr);
|
|
|
|
|
}
|
|
|
|
@ -77,7 +76,7 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
{
|
|
|
|
|
int rows = TenantDb.Storageable(templates).DefaultAddElseUpdate().ExecuteCommand();
|
|
|
|
|
return rows > 0 ?
|
|
|
|
|
DataResult<List<InvoiceTemplate>>.Success(new List<InvoiceTemplate>(templates)) :
|
|
|
|
|
DataResult<List<InvoiceTemplate>>.Success([.. templates]) :
|
|
|
|
|
DataResult<List<InvoiceTemplate>>.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -85,12 +84,21 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
/// 渲染模板
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">发票申请ID</param>
|
|
|
|
|
/// <param name="templateText">模板文本</param>
|
|
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
|
|
/// <param name="environment"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<string>> RenderTemplateAsync(long id, string templateText, IHostEnvironment environment)
|
|
|
|
|
public async Task<DataResult<string>> RenderTemplateAsync(long id, long templateId, IHostEnvironment environment)
|
|
|
|
|
{
|
|
|
|
|
var dto = await GetTemplateFormAsync(id);
|
|
|
|
|
var template = await TenantDb.Queryable<InvoiceTemplate>().Where(x => x.Id == templateId).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.Content,
|
|
|
|
|
x.Currency
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
if (template == null)
|
|
|
|
|
return DataResult<string>.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
|
|
|
|
|
|
|
|
|
|
var dto = await GetTemplateFormAsync(id, template.Currency);
|
|
|
|
|
if (dto == null)
|
|
|
|
|
return DataResult<string>.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
|
|
|
|
|
|
|
|
|
@ -98,13 +106,16 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
var jObj = JObject.Parse(json);
|
|
|
|
|
var jArray = jObj[nameof(InvoiceTemplateForm.Details)] as JArray;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new(templateText);
|
|
|
|
|
StringBuilder sb2 = new();
|
|
|
|
|
var fields = GetFields(environment).Data;
|
|
|
|
|
if (fields == null)
|
|
|
|
|
return DataResult<string>.Success(string.Empty);
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new(template.Content);
|
|
|
|
|
StringBuilder sb2 = new();
|
|
|
|
|
foreach (var field in fields)
|
|
|
|
|
{
|
|
|
|
|
//循环输出
|
|
|
|
|
if (templateText.Contains($"<{field.DisplayName}>"))
|
|
|
|
|
if (template.Content.Contains($"<{field.DisplayName}>"))
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in jArray)
|
|
|
|
|
{
|
|
|
|
@ -120,44 +131,53 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//单次输出
|
|
|
|
|
else if (templateText.Contains($"[{field.DisplayName}]"))
|
|
|
|
|
else if (template.Content.Contains($"[{field.DisplayName}]"))
|
|
|
|
|
{
|
|
|
|
|
string val = string.Empty;
|
|
|
|
|
string? val = string.Empty;
|
|
|
|
|
if (field.IsSumValue)
|
|
|
|
|
{
|
|
|
|
|
val = jObj[field.FieldName]?.Value<string>();
|
|
|
|
|
}
|
|
|
|
|
else if (jArray.Count > 0)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var item1 = jArray[0];
|
|
|
|
|
val = item1[field.FieldName]?.Value<string>();
|
|
|
|
|
var token = jObj[field.FieldName];
|
|
|
|
|
if (token == null && jArray?.Count > 0)
|
|
|
|
|
token = jArray[0][field.FieldName];
|
|
|
|
|
|
|
|
|
|
if (token != null && token.Type != JTokenType.Null)
|
|
|
|
|
{
|
|
|
|
|
if (token.Type == JTokenType.Date)
|
|
|
|
|
val = token.Value<DateTime>().ToString("yyyy-MM-dd");
|
|
|
|
|
else if (token.Type == JTokenType.Array && token.HasValues)
|
|
|
|
|
val = string.Join(",", token.Values<string>());
|
|
|
|
|
else
|
|
|
|
|
val = token.Value<string>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!val.IsNullOrEmpty())
|
|
|
|
|
sb = sb.Replace($"[{field.DisplayName}]", val);
|
|
|
|
|
sb = sb.Replace($"[{field.DisplayName}]", val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(sb.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取发票模板所需数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">发票申请ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
internal async Task<InvoiceTemplateForm> GetTemplateFormAsync(long id)
|
|
|
|
|
//获取发票模板所需数据
|
|
|
|
|
internal async Task<InvoiceTemplateForm> GetTemplateFormAsync(long id, string currency)
|
|
|
|
|
{
|
|
|
|
|
var dto = await TenantDb.Queryable<InvoiceApplication>()
|
|
|
|
|
.LeftJoin<InfoClientBank>((a, b) => a.CustomerBankId == b.Id)
|
|
|
|
|
.Where((a, b) => a.Id == id).Select((a, b) => new InvoiceTemplateForm
|
|
|
|
|
{
|
|
|
|
|
CustomerId = a.CustomerId,
|
|
|
|
|
CustomerName = a.CustomerName,
|
|
|
|
|
CustomerBankId = a.CustomerBankId,
|
|
|
|
|
ClientAccount = b.Account,
|
|
|
|
|
ClientBankName = b.BankName
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
.LeftJoin<InfoClientBank>((a, b1) => a.CustomerBankId == b1.Id && b1.Currency == currency)
|
|
|
|
|
.LeftJoin<InfoClientBank>((a, b1, b2) => a.USDCustomerBankId == b2.Id && b2.Currency == currency)
|
|
|
|
|
.LeftJoin<SysBank>((a, b1, b2, sb) => sb.LinkId == SqlFunc.IsNull(a.SaleDeptId, a.OrgId), "shippingweb8_dev.sys_bank")
|
|
|
|
|
.Where((a, b1, b2, sb) => a.Id == id && sb.IsDefault).Select((a, b1, b2, sb) => new InvoiceTemplateForm
|
|
|
|
|
{
|
|
|
|
|
CustomerId = a.CustomerId,
|
|
|
|
|
CustomerName = a.CustomerName,
|
|
|
|
|
CustomerBankId = a.CustomerBankId,
|
|
|
|
|
ClientAccount = currency == FeeCurrency.USD_CODE ? b2.BankAccountNo : b1.BankAccountNo,
|
|
|
|
|
ClientBankName = currency == FeeCurrency.USD_CODE ? b2.BankName : b1.BankName,
|
|
|
|
|
BankName = sb.BankName
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
|
|
|
|
|
if (dto != null)
|
|
|
|
|
{
|
|
|
|
@ -191,7 +211,6 @@ namespace DS.WMS.Core.Application.Method
|
|
|
|
|
x.ETD,
|
|
|
|
|
x.CntrTotal,
|
|
|
|
|
x.AccountDate,
|
|
|
|
|
x.OperatorCode,
|
|
|
|
|
x.Vessel,
|
|
|
|
|
x.Voyno,
|
|
|
|
|
x.LoadPort,
|
|
|
|
|