From 5b292efc82a8ac5e86f0382998a9b7ab044779c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Tue, 16 Jul 2024 15:12:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E5=87=86=E5=BC=80=E7=A5=A8=E7=B1=BB?= =?UTF-8?q?=E7=AD=BE=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DS.Module.Core/Enums/ApplicationStatus.cs | 2 +- .../DS.Module.Core/Enums/Invoice.cs | 10 +- .../Application/Dtos/InvoiceApplicationDto.cs | 9 +- .../DS.WMS.Core/Invoice/Dtos/InvoiceDto.cs | 5 + .../DS.WMS.Core/Invoice/Entity/Invoice.cs | 2 +- .../Invoice/Interface/IFreeInvoiceService.cs | 8 +- .../Interface/IGeneralInvoiceService.cs | 10 ++ .../Invoice/Interface/IInvoiceService`1.cs | 15 +++ .../Invoice/Method/FreeInvoiceService.cs | 8 ++ .../Invoice/Method/GeneralInvoiceService.cs | 82 ++++++++++++++++ .../Invoice/Method/InvoiceService`1.cs | 23 +++++ .../Controllers/FreeInvoiceController.cs | 44 --------- .../Controllers/GeneralInvoiceController.cs | 95 +++++++++++++++++++ .../DS.WMS.FeeApi/Logs/internal-nlog.txt | 7 ++ 14 files changed, 264 insertions(+), 56 deletions(-) create mode 100644 ds-wms-service/DS.WMS.Core/Invoice/Interface/IGeneralInvoiceService.cs create mode 100644 ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs create mode 100644 ds-wms-service/DS.WMS.FeeApi/Controllers/GeneralInvoiceController.cs diff --git a/ds-wms-service/DS.Module.Core/Enums/ApplicationStatus.cs b/ds-wms-service/DS.Module.Core/Enums/ApplicationStatus.cs index 52c08372..dec39293 100644 --- a/ds-wms-service/DS.Module.Core/Enums/ApplicationStatus.cs +++ b/ds-wms-service/DS.Module.Core/Enums/ApplicationStatus.cs @@ -80,7 +80,7 @@ namespace DS.Module.Core.Enums Invoiced = 4, /// - /// 已开出 + /// 部分开出 /// [Description("部分开出")] PartialInvoiced = 5 diff --git a/ds-wms-service/DS.Module.Core/Enums/Invoice.cs b/ds-wms-service/DS.Module.Core/Enums/Invoice.cs index a1144d71..47235e4f 100644 --- a/ds-wms-service/DS.Module.Core/Enums/Invoice.cs +++ b/ds-wms-service/DS.Module.Core/Enums/Invoice.cs @@ -7,17 +7,23 @@ namespace DS.Module.Core.Enums /// public enum InvoiceCategory { + /// + /// 普通发票 + /// + [Description("普通发票")] + General = 0, + /// /// 电子发票 /// [Description("电子发票")] - Electronic = 0, + Electronic = 1, /// /// 纸质发票 /// [Description("纸质发票")] - Paper = 1 + Paper = 2 } /// diff --git a/ds-wms-service/DS.WMS.Core/Application/Dtos/InvoiceApplicationDto.cs b/ds-wms-service/DS.WMS.Core/Application/Dtos/InvoiceApplicationDto.cs index e803dd7c..184f1469 100644 --- a/ds-wms-service/DS.WMS.Core/Application/Dtos/InvoiceApplicationDto.cs +++ b/ds-wms-service/DS.WMS.Core/Application/Dtos/InvoiceApplicationDto.cs @@ -45,10 +45,17 @@ namespace DS.WMS.Core.Application.Dtos public string? AmountUppercase { get; set; } /// - /// 所属机构(公司) + /// 所属机构(公司)ID /// + [IgnoreDataMember] public long? OrgId { get; set; } + /// + /// 所属机构(公司) + /// + [IgnoreDataMember] + public string? OrgName { get; set; } + /// /// 客户地址电话 /// diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Dtos/InvoiceDto.cs b/ds-wms-service/DS.WMS.Core/Invoice/Dtos/InvoiceDto.cs index 2b5937bb..c32883ef 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Dtos/InvoiceDto.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Dtos/InvoiceDto.cs @@ -253,5 +253,10 @@ namespace DS.WMS.Core.Invoice.Dto /// 发票明细 /// public List? InvoiceDetails { get; set; } + + /// + /// 费用明细汇总 + /// + public List? Summary { get; set; } } } diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Entity/Invoice.cs b/ds-wms-service/DS.WMS.Core/Invoice/Entity/Invoice.cs index 8305b329..f62c277c 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Entity/Invoice.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Entity/Invoice.cs @@ -317,7 +317,7 @@ namespace DS.WMS.Core.Invoice.Entity /// 作废时间 /// [SugarColumn(ColumnDescription = "作废时间")] - public DateTime CancelTime { get; set; } + public DateTime? CancelTime { get; set; } /// /// 费用明细 diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Interface/IFreeInvoiceService.cs b/ds-wms-service/DS.WMS.Core/Invoice/Interface/IFreeInvoiceService.cs index b869ff81..8453dbff 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Interface/IFreeInvoiceService.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Interface/IFreeInvoiceService.cs @@ -1,7 +1,6 @@ using DS.Module.Core; using DS.WMS.Core.Application.Dtos; using DS.WMS.Core.Fee.Dtos; -using DS.WMS.Core.Invoice.Dto; namespace DS.WMS.Core.Invoice.Interface { @@ -24,11 +23,6 @@ namespace DS.WMS.Core.Invoice.Interface /// Task> GetFeesAsync(params BizItem[] items); - /// - /// 获取发票详情 - /// - /// 发票ID - /// - Task> GetAsync(long id); + } } diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Interface/IGeneralInvoiceService.cs b/ds-wms-service/DS.WMS.Core/Invoice/Interface/IGeneralInvoiceService.cs new file mode 100644 index 00000000..0d108cbc --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Invoice/Interface/IGeneralInvoiceService.cs @@ -0,0 +1,10 @@ +namespace DS.WMS.Core.Invoice.Interface +{ + /// + /// 标准开票 + /// + public interface IGeneralInvoiceService : IInvoiceService + { + + } +} diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Interface/IInvoiceService`1.cs b/ds-wms-service/DS.WMS.Core/Invoice/Interface/IInvoiceService`1.cs index 2ec062cb..054972b6 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Interface/IInvoiceService`1.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Interface/IInvoiceService`1.cs @@ -17,6 +17,13 @@ namespace DS.WMS.Core.Invoice.Interface /// Task>> GetListAsync(PageRequest request); + /// + /// 获取发票详情 + /// + /// 发票ID + /// + Task> GetAsync(long id); + /// /// 提交发票开票 /// @@ -45,5 +52,13 @@ namespace DS.WMS.Core.Invoice.Interface /// 发票ID /// Task SetLockAsync(bool isLocked, params long[] ids); + + /// + /// 设置发票的作废状态 + /// + /// 是否锁定 + /// 发票ID + /// + Task SetCancelAsync(bool isCancelled, params long[] ids); } } diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/FreeInvoiceService.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/FreeInvoiceService.cs index 2ee80b26..fc2c90f5 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/FreeInvoiceService.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/FreeInvoiceService.cs @@ -52,6 +52,7 @@ namespace DS.WMS.Core.Invoice.Method FeeType = x.FeeType, ApplyAmount = x.ApplyAmount, ExchangeRate = x.ExchangeRate, + Currency = x.Currency, OriginalAmount = x.OriginalAmount, OriginalCurrency = x.OriginalCurrency, OriginalRate = x.OriginalRate, @@ -66,6 +67,13 @@ namespace DS.WMS.Core.Invoice.Method Voyage = x.Voyage, }).ToListAsync(); + invoice.Summary = invoice.Details.GroupBy(x => new { x.FeeType, x.Currency }).Select(x => new SummaryItem + { + FeeType = x.Key.FeeType, + Currency = x.Key.Currency, + Amount = x.Sum(y => y.ApplyAmount) + }).ToList(); + invoice.InvoiceDetails = await TenantDb.Queryable().Where( x => x.ApplicationId == id && x.Category == DetailCategory.InvoiceIssuance).ToListAsync(); } diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs new file mode 100644 index 00000000..38aea391 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/GeneralInvoiceService.cs @@ -0,0 +1,82 @@ +using DS.Module.Core; +using DS.Module.Core.Enums; +using DS.Module.Core.Extensions; +using DS.WMS.Core.Application.Dtos; +using DS.WMS.Core.Application.Entity; +using DS.WMS.Core.Invoice.Interface; +using DS.WMS.Core.Sys.Entity; +using SqlSugar; + +namespace DS.WMS.Core.Invoice.Method +{ + /// + /// 标准(按申请)开票实现 + /// + public class GeneralInvoiceService : InvoiceService, IGeneralInvoiceService + { + /// + /// 初始化 + /// + /// + public GeneralInvoiceService(IServiceProvider provider) : base(provider) + { + } + + /// + /// 获取付费申请分页列表 + /// + /// + /// + public async Task>> GetApplicationListAsync(PageRequest request) + { + var query = TenantDb.Queryable().Where(x => x.Status == InvoiceApplicationStatus.AuditPassed || x.Status == InvoiceApplicationStatus.PartialInvoiced) + .InnerJoin((a, d) => a.Id == d.ApplicationId && (d.OriginalAmount - d.OriginalProcessedAmount) != 0) + .Select(a => new InvoiceApplicationDto + { + Id = a.Id, + ApplicationNO = a.ApplicationNO, + Status = a.Status, + CustomerId = a.CustomerId, + CustomerName = a.CustomerName, //结算单位 + InvoiceHeader = a.InvoiceHeader, + ApplyAmount = a.ApplyAmount, + InvoiceAmount = a.InvoiceAmount, + Currency = a.Currency, + Category = a.Category, + OrgId = a.OrgId, //所属部门 + SaleDeptId = a.SaleDeptId, //所属分部 + CreateBy = a.CreateBy, //申请人 + CreateTime = a.CreateTime, //申请日期 + InvoiceRemark = a.InvoiceRemark, //开票要求 + Note = a.Note, + //原币金额 + OriginalAmountList = SqlFunc.Subqueryable().Where(y => a.Id == y.ApplicationId) + .GroupBy(y => y.OriginalCurrency).ToList(y => new CurrencyAmount { Currency = y.OriginalCurrency, Amount = y.OriginalAmount }) + }); + + var whereList = request.GetConditionalModels(Db); + var result = await query.Where(whereList).ToQueryPageAsync(request.PageCondition); + + if (result.Data.Count > 0) + { + var userIds = result.Data.Select(x => x.CreateBy).Distinct(); + var users = await Db.Queryable().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync(); + + var orgIds = result.Data.Where(x => x.SaleDeptId.HasValue).Select(x => x.SaleDeptId) + .Union(result.Data.Where(x => x.OrgId.HasValue).Select(x => x.OrgId)) + .Distinct(); + var orgs = await Db.Queryable().Where(x => orgIds.Contains(x.Id)).Select(x => new { x.Id, x.OrgName }).ToListAsync(); + + foreach (var item in result.Data) + { + item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName; + + item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName; + item.OrgName = orgs.Find(x => x.Id == item.OrgId)?.OrgName; + } + } + + return result; + } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs index c2dfffb1..2246a39b 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs @@ -518,5 +518,28 @@ namespace DS.WMS.Core.Invoice.Method return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); } + + /// + /// 设置发票的作废状态 + /// + /// 是否锁定 + /// 发票ID + /// + public async Task SetCancelAsync(bool isCancelled, params long[] ids) + { + var dt = DateTime.Now; + var userId = long.Parse(User.UserId); + var list = ids.Select(x => new TEntity + { + Id = x, + IsCancelled = isCancelled, + CancelTime = isCancelled ? dt : null, + CancelUserId = isCancelled ? userId : null + }).ToList(); + int rows = await TenantDb.Updateable(list) + .UpdateColumns(x => new { x.IsCancelled, x.CancelTime, x.CancelUserId }).ExecuteCommandAsync(); + + return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); + } } } diff --git a/ds-wms-service/DS.WMS.FeeApi/Controllers/FreeInvoiceController.cs b/ds-wms-service/DS.WMS.FeeApi/Controllers/FreeInvoiceController.cs index 60f17693..2dbca283 100644 --- a/ds-wms-service/DS.WMS.FeeApi/Controllers/FreeInvoiceController.cs +++ b/ds-wms-service/DS.WMS.FeeApi/Controllers/FreeInvoiceController.cs @@ -1,5 +1,4 @@ using DS.Module.Core; -using DS.Module.Core.Data; using DS.WMS.Core.Application.Dtos; using DS.WMS.Core.Fee.Dtos; using DS.WMS.Core.Invoice.Dto; @@ -72,48 +71,5 @@ namespace DS.WMS.FeeApi.Controllers return await _service.SaveAsync(request); } - - /// - /// 删除发票明细 - /// - /// 发票明细ID - /// - [HttpPost, Route("DeleteDetail")] - public async Task DeleteDetailAsync([FromBody] IdModel model) - { - if (!ModelState.IsValid) - return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); - - return await _service.DeleteDetailAsync(model.Ids); - } - - /// - /// 删除发票 - /// - /// 发票ID - /// - [HttpPost, Route("Delete")] - public async Task DeleteAsync([FromBody] IdModel model) - { - if (!ModelState.IsValid) - return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); - - return await _service.DeleteAsync(model.Ids); - } - - /// - /// 设置发票的锁定状态 - /// - /// 发票ID - /// - [HttpPost, Route("SetLock")] - public async Task SetLockAsync([FromBody] IdModel model) - { - if (!ModelState.IsValid) - return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); - - bool isLocked = Convert.ToBoolean(model.Value); - return await _service.SetLockAsync(isLocked, model.Ids); - } } } diff --git a/ds-wms-service/DS.WMS.FeeApi/Controllers/GeneralInvoiceController.cs b/ds-wms-service/DS.WMS.FeeApi/Controllers/GeneralInvoiceController.cs new file mode 100644 index 00000000..79265a00 --- /dev/null +++ b/ds-wms-service/DS.WMS.FeeApi/Controllers/GeneralInvoiceController.cs @@ -0,0 +1,95 @@ +using DS.Module.Core; +using DS.Module.Core.Data; +using DS.WMS.Core.Invoice.Dto; +using DS.WMS.Core.Invoice.Dtos; +using DS.WMS.Core.Invoice.Entity; +using DS.WMS.Core.Invoice.Interface; +using Microsoft.AspNetCore.Mvc; + +namespace DS.WMS.FeeApi.Controllers +{ + /// + /// 标准(按申请)开票API + /// + public class GeneralInvoiceController : ApiController + { + readonly IGeneralInvoiceService _service; + + /// + /// 初始化 + /// + /// + public GeneralInvoiceController(IGeneralInvoiceService service) + { + _service = service; + } + + /// + /// 获取发票详情 + /// + /// 发票ID + /// + [HttpGet, Route("Get")] + public async Task> GetAsync(long id) + { + return await _service.GetAsync(id); + } + + /// + /// 提交发票开票 + /// + /// 请求参数 + /// + [HttpPost, Route("Save")] + public async Task> SaveAsync(InvoiceRequest request) + { + if (!ModelState.IsValid) + return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); + + return await _service.SaveAsync(request); + } + + /// + /// 删除发票明细 + /// + /// 发票明细ID + /// + [HttpPost, Route("DeleteDetail")] + public async Task DeleteDetailAsync([FromBody] IdModel model) + { + if (!ModelState.IsValid) + return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); + + return await _service.DeleteDetailAsync(model.Ids); + } + + /// + /// 删除发票 + /// + /// 发票ID + /// + [HttpPost, Route("Delete")] + public async Task DeleteAsync([FromBody] IdModel model) + { + if (!ModelState.IsValid) + return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); + + return await _service.DeleteAsync(model.Ids); + } + + /// + /// 设置发票的锁定状态 + /// + /// 发票ID + /// + [HttpPost, Route("SetLock")] + public async Task SetLockAsync([FromBody] IdModel model) + { + if (!ModelState.IsValid) + return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); + + bool isLocked = Convert.ToBoolean(model.Value); + return await _service.SetLockAsync(isLocked, model.Ids); + } + } +} diff --git a/ds-wms-service/DS.WMS.FeeApi/Logs/internal-nlog.txt b/ds-wms-service/DS.WMS.FeeApi/Logs/internal-nlog.txt index d3de5fe8..eacf544c 100644 --- a/ds-wms-service/DS.WMS.FeeApi/Logs/internal-nlog.txt +++ b/ds-wms-service/DS.WMS.FeeApi/Logs/internal-nlog.txt @@ -2798,3 +2798,10 @@ 2024-07-16 11:28:24.8156 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Source\Repos\DS8\ds-wms-service\DS.WMS.FeeApi\bin\Debug\net8.0\nlog.config 2024-07-16 11:28:24.8156 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile 2024-07-16 11:28:24.8313 Info Configuration initialized. +2024-07-16 14:04:36.2569 Info Registered target NLog.Targets.FileTarget(Name=allfile) +2024-07-16 14:04:36.2882 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web) +2024-07-16 14:04:36.2985 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console) +2024-07-16 14:04:36.3120 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False +2024-07-16 14:04:36.3120 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Source\Repos\DS8\ds-wms-service\DS.WMS.FeeApi\bin\Debug\net8.0\nlog.config +2024-07-16 14:04:36.3120 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile +2024-07-16 14:04:36.3280 Info Configuration initialized.