Explorar el Código

提单成本汇总

立航 饭 hace 4 semanas
padre
commit
931c0f9e6d

+ 51 - 4
2.Data/SMP.Data/Finance/IFinance_Logistics_LadingBillRepository.cs

@@ -7,11 +7,14 @@ using System.Threading.Tasks;
 using XYY.Core.Standard.Data.Infrastructure;
 using Dapper;
 using SMP.Model.Enums;
+using SMP.Model.Report;
 
 namespace SMP.Data.Finance
 {
     public interface IFinance_Logistics_LadingBillRepository : IBaseRepository<Finance_Logistics_LadingBill>
     {
+        [NonTrans]
+        Task<IEnumerable<int>> GetPublics(int month);
         [NonTrans]
         Task<IEnumerable<Finance_Logistics_LadingBill>> GetPortLadingBillsByNumbers(List<string> LadingBillNumbers);
         Task<Finance_Logistics_LadingBill> GetLadingBill(string LadingBillNumber);
@@ -30,6 +33,7 @@ namespace SMP.Data.Finance
         Task ClearIncidentals(int LadingBillId, AmountType amountType = AmountType.应付);
 
         Task<IEnumerable<Finance_Logistics_LadingBill>> QueryByLadingBillNumbers(IEnumerable<string> ladingBillNumbers);
+        Task<IEnumerable<LadingBillCost>> GetLadingBillCost(int month, int publicId);
         #endregion
         #region 订单成本(作废)
         //Task CreateCostTable(string BillTypeCode);
@@ -57,18 +61,18 @@ where rowNum=1 ");
         }
         public async Task<Finance_Logistics_LadingBill> GetLadingBill(string LadingBillNumber)
         {
-            var result =await QueryAsync(x=>x.LadingBillNumber==LadingBillNumber);
+            var result = await QueryAsync(x => x.LadingBillNumber == LadingBillNumber);
             return result.FirstOrDefault();
         }
         #region 帐单费项
         public async Task<IEnumerable<Finance_Incidental>> GetIncidentals(int LadingBillId, AmountType amountType = AmountType.应付)
         {
             string amtTypeCondition = null;
-            if(amountType==AmountType.应付)
+            if (amountType == AmountType.应付)
             {
                 amtTypeCondition = " and (AmountType is null or AmountType=0) ";
             }
-            else 
+            else
             {
                 var amtType = (int)amountType;
                 amtTypeCondition = $" and AmountType={amtType} ";
@@ -76,7 +80,7 @@ where rowNum=1 ");
             string sql = $"select * from Finance_Incidental(nolock) where LadingBillId={LadingBillId} {amtTypeCondition} and IsDeleted=0 ";
             return await _unitOfWork.QueryBySqlAsync<Finance_Incidental>(sql);
         }
-        public async Task ClearIncidentals(int LadingBillId,AmountType amountType=AmountType.应付)
+        public async Task ClearIncidentals(int LadingBillId, AmountType amountType = AmountType.应付)
         {
             string amtTypeCondition = null;
             if (amountType == AmountType.应付)
@@ -99,6 +103,49 @@ where rowNum=1 ");
             return result;
         }
 
+        public async Task<IEnumerable<int>> GetPublics(int month)
+        {
+            DateTime start = new DateTime(DateTime.Now.Year, month, 1);
+            DateTime end = start.AddMonths(1);
+            string sql = @"
+                         select PublicChannelId ,count(0)
+	                        from Logistisc_Order(nolock) where  ReceiveTime between @start and @end
+                            group by PublicChannelId";
+
+            var result = await _unitOfWork.Connection.QueryAsync<int>(sql, new { start, end }, _unitOfWork.Transaction);
+            return result;
+        }
+
+        [NonTrans]
+        public async Task<IEnumerable<LadingBillCost>> GetLadingBillCost(int month,int publicId)
+        {
+            DateTime start = new DateTime(DateTime.Now.Year, month, 1);
+            DateTime end = start.AddMonths(1);
+            string sql = @" with t1 as(
+                         select b.LadingBillNumber,f.Name,sum(c.SettlementAmount)SettlementAmount,CONVERT(nvarchar(7),ReceiveTime,120 ) as [Month]  from 
+                        (select LadingBillNumber 
+	                        from Logistisc_Order(nolock) where PublicChannelId = @publicId and ReceiveTime between @start and @end
+                        group by LadingBillNumber)as a 
+                        join Logistisc_Order(nolock)b on PublicChannelId =@publicId and a.LadingBillNumber=b.LadingBillNumber
+                        join Compute_ExpenseAmount(nolock)c on c.Number = b.SystemNo and c.CostType=1
+                        join Compute_ExpenseAmountBatchOperation(nolock) d on d.BatchNo = c.BatchNo
+                        join Compute_ExpenseItem(nolock)e on c.ExpenseItemId=e.Id
+                        join Compute_ExpenseItemCategory(nolock)f on f.Id=e.CategoryId
+                          group by b.LadingBillNumber,f.Name,CONVERT(nvarchar(7),ReceiveTime,120 ))
+
+                          select * from (
+	                        select 提单=LadingBillNumber,类目=Name,费用=SettlementAmount,月份=[MONTH] from t1
+                          )a
+                          pivot
+                         (
+	                        sum(a.费用) for a.类目 in(空运成本,尾程派送费,海外清关,出口报关,全程派送费用,中转成本)
+                         )p
+                         order by 提单,月份
+                    ";
+            var result = await _unitOfWork.Connection.QueryAsync<LadingBillCost>(sql, new { start, end, publicId }, _unitOfWork.Transaction, null);
+            return result;
+        }
+
         #endregion
         #region  订单成本(作废)
         //public async Task CreateCostTable(string tableName)

+ 31 - 0
2.Data/SMP.Model/Report/LadingBillCost.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SMP.Model.Report
+{
+    public class LadingBillCost
+    {
+        public string 提单 { get; set; }
+
+        public string 月份 { get; set;
+        }
+
+        public string 空运成本 { get; set;
+        }
+
+        public string 尾程派送费 { get; set;
+        }
+
+        public string 海外清关 { get; set;
+        }
+
+        public string 出口报关 { get; set;}
+
+        public string 全程派送费用 { get; set;}
+
+        public string 中转成本 { get; set;}
+    }
+}

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 41 - 25
3.Service/SMP.Service/Report/ICostProfitReportService.cs


+ 18 - 3
4.Api/SMP.Api.Base/Controllers/Report/ReportController.cs

@@ -1,8 +1,10 @@
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using SMP.Model.Dto.Report;
+using SMP.Service.BaseInfo;
 using SMP.Service.Report;
 using SMP.Service.Report.Dto;
+using System.IO;
 using XYY.Common.Standard;
 using XYY.Core.Standard.Mvc;
 
@@ -16,13 +18,14 @@ namespace SMP.Api.Base.Controllers.Report
         IFinancialReportService _financialReportService;
         IGeneralCostReportV2Service _generalCostReportV2Service;
         ICostProfitReportService _costProfitReportService;
+        IBaseInfoService _baseInfoService;
 
-        public ReportController(IGeneralCostReportV2Service generalCostReportV2Service, ICostProfitReportService costProfitReportService, IFinancialReportService financialReportService)
+        public ReportController(IGeneralCostReportV2Service generalCostReportV2Service, ICostProfitReportService costProfitReportService, IFinancialReportService financialReportService, IBaseInfoService baseInfoService)
         {
             _generalCostReportV2Service = generalCostReportV2Service;
             _costProfitReportService = costProfitReportService;
             _financialReportService = financialReportService;
-        
+            _baseInfoService = baseInfoService;
         }
 
 
@@ -83,7 +86,19 @@ namespace SMP.Api.Base.Controllers.Report
 
             return File(content, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
         }
-
+        [AllowAnonymous] 
+        [HttpGet]
+        public async Task<IActionResult> DownLoaddingCostReport(int channelId, int month)
+        {
+            var allPublicChannels = await _baseInfoService.CacheGetAllPublicChannels();
+            var publicChannel = allPublicChannels.FirstOrDefault(i => i.Id == channelId);
+            var ms = await _costProfitReportService.OutLoaddingCost(channelId, month);
+            ms.Seek(0, SeekOrigin.Begin);
+            return new FileStreamResult(ms, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
+            {
+                FileDownloadName = $"{publicChannel.Name} {month}月提单成本.xlsx"
+            };
+        }
 
         /// <summary>
         /// 核对数据下载