瀏覽代碼

应收报表查询与生成Excel

jiangjc 11 月之前
父節點
當前提交
efd75b0ec3

+ 236 - 32
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -1,14 +1,20 @@
-using Microsoft.AspNetCore.Http;
+using Aspose.Cells;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using OASystem.API.OAMethodLib;
 using OASystem.API.OAMethodLib.File;
 using OASystem.Domain;
 using OASystem.Domain.Dtos.Financial;
+using OASystem.Domain.Dtos.Groups;
+using OASystem.Domain.Entities.Financial;
 using OASystem.Domain.Entities.Groups;
 using OASystem.Domain.ViewModels.Financial;
 using OASystem.Domain.ViewModels.Groups;
+using OASystem.Domain.ViewModels.SmallFun;
 using OASystem.Infrastructure.Repositories.Financial;
 using OASystem.Infrastructure.Repositories.Groups;
+using SqlSugar;
+using StackExchange.Redis;
 using System.Data;
 
 namespace OASystem.API.Controllers
@@ -34,8 +40,8 @@ namespace OASystem.API.Controllers
         /// 初始化
         /// </summary>
         public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
-            TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep, 
-            PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep) 
+            TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
+            PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep)
         {
             _mapper = mapper;
             _config = configuration;
@@ -70,7 +76,7 @@ namespace OASystem.API.Controllers
             return Ok(JsonView(data));
         }
 
-        
+
         /// <summary>
         /// 获取日付申请 基础数据源 - 转账表识 
         /// </summary>
@@ -114,7 +120,7 @@ namespace OASystem.API.Controllers
 
             return Ok(JsonView(data));
         }
-        
+
         /// <summary>
         /// 日付申请 Single Search By Id
         /// </summary>
@@ -133,7 +139,7 @@ namespace OASystem.API.Controllers
 
             return Ok(JsonView(result.Data));
         }
-        
+
         /// <summary>
         /// 日付申请 添加
         /// </summary>
@@ -247,28 +253,28 @@ namespace OASystem.API.Controllers
 
                     //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
                     //{
-                        
+
                     //    //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
                     //    //    pairs, datas);
                     //}
                     //else  //日付常规模板
                     //{
-                        pairs.Clear();
-                        pairs.Add("Opertor", userName);
-                        pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")); 
-                        pairs.Add("FAuditStatus", feeData.FAuditDesc); 
-                        pairs.Add("MAuditStatus", feeData.MAuditDesc);
-                        pairs.Add("SumPrice", feeData.SumPrice);
-
-                        DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
-                        datas.Clear();
-                        datas.Add(data);
-                        string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
-                        string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
-
-                        return Ok(JsonView(true, msg));
+                    pairs.Clear();
+                    pairs.Add("Opertor", userName);
+                    pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
+                    pairs.Add("FAuditStatus", feeData.FAuditDesc);
+                    pairs.Add("MAuditStatus", feeData.MAuditDesc);
+                    pairs.Add("SumPrice", feeData.SumPrice);
+
+                    DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
+                    datas.Clear();
+                    datas.Add(data);
+                    string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
+                    string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
+
+                    return Ok(JsonView(true, msg));
                     //}
-                   
+
                 }
                 else
                 {
@@ -276,7 +282,7 @@ namespace OASystem.API.Controllers
                 }
             }
 
-           
+
             return Ok(JsonView(true));
         }
         #endregion
@@ -291,7 +297,7 @@ namespace OASystem.API.Controllers
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
         {
-             var data = await GroupCommission.GetCommissionPageList(dto);
+            var data = await GroupCommission.GetCommissionPageList(dto);
 
             return Ok(JsonView(data.Data));
         }
@@ -754,7 +760,7 @@ namespace OASystem.API.Controllers
                     return Ok(JsonView(false, "参数不能为空!"));
                 }
 
-                Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId );
+                Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
                 dynamic data = null;
                 if (dto.PortType == 1)
                 {
@@ -762,9 +768,9 @@ namespace OASystem.API.Controllers
                     {
                         return Ok(JsonView(false, ffrData.Msg));
                     }
-                    data= ffrData.Data;
+                    data = ffrData.Data;
                 }
-                else if(dto.PortType == 2)
+                else if (dto.PortType == 2)
                 {
                     if (ffrData.Code != 0)
                     {
@@ -785,7 +791,7 @@ namespace OASystem.API.Controllers
                 {
                     return Ok(JsonView(false, "请选择正确的端口号!"));
                 }
-                return Ok(JsonView(true,"操作成功!", data));
+                return Ok(JsonView(true, "操作成功!", data));
             }
             catch (Exception ex)
             {
@@ -895,11 +901,11 @@ namespace OASystem.API.Controllers
         {
             try
             {
-                if (dto == null)  return Ok(JsonView(false, "参数不能为空!"));
-               
+                if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
+
                 if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
-               
-                if (dto.UserId <= 0)  return Ok(JsonView(false, "请传入正确的的员工Id!")); 
+
+                if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
 
                 #region 页面功能权限处理
                 PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
@@ -1100,5 +1106,203 @@ namespace OASystem.API.Controllers
             }
         }
         #endregion
+
+        #region 应收报表
+
+        ///// <summary>
+        ///// 应收报表
+        ///// 查询 根据日期范围
+        ///// </summary>
+        ///// <param name="dto"></param>
+        ///// <returns></returns>
+        //[HttpPost]
+        //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        //public async Task<IActionResult> ExcelSyntheticalReceivable(PostSyntheticalReceivableByDateRangeDto dto)
+        //{
+        //}
+
+        /// <summary>
+        /// 应收报表
+        /// 查询 根据日期范围
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
+        {
+
+            string sqlWhere = " Where di.IsDel=0 ";
+
+            #region 验证
+            if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
+            {
+                return Ok(JsonView(false, "日期参数至少填写一个!"));
+            }
+
+            if (!string.IsNullOrEmpty(dto.beginDt))
+            {
+                if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
+                {
+                    return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
+                }
+                else
+                {
+                    sqlWhere += string.Format(@" And di.VisitDate >= '{0}' ", dto.beginDt);
+                }
+            }
+
+            if (!string.IsNullOrEmpty(dto.endDt))
+            {
+                if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
+                {
+                    return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
+                }
+                else
+                {
+                    sqlWhere += string.Format(@" And di.VisitDate <= '{0}' ", dto.endDt);
+                }
+            }
+
+
+            #endregion
+
+            string sql = string.Format(@" select distinct fr.diid,di.TeamName,di.ClientUnit,di.VisitDate from Fin_ForeignReceivables fr join Grp_DelegationInfo di on fr.DIID = di.id  {0} ", sqlWhere);
+
+            List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
+
+            decimal sumAll_fr = 0M;
+            decimal sumAll_pr = 0M;
+            decimal sumAll_balance = 0M;
+
+            if (list_rst.Count > 0)
+            {
+                int rowNumber = 1;
+                foreach (var item_rst in list_rst)
+                {
+                    item_rst.No = rowNumber;
+                    rowNumber++;
+
+                    int diId = item_rst.diid;
+                    decimal sum_fr = 0M;
+                    decimal sum_pr = 0M;
+                    string str_client = string.Empty;
+                    decimal sum_other = 0M;
+                    decimal balance = 0M;
+                    string str_schedule = string.Empty;
+
+                    //1.
+                    string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
+                    List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
+                    sum_fr = list_fr.Sum(s => s.ItemSumPrice);
+
+                    //2.
+                    string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
+                    List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
+                    foreach (var item_pr in list_pr)
+                    {
+                        sum_pr += item_pr.Price;
+                        str_client += string.Format(@"{0};", item_pr.Client);
+                        str_schedule += string.Format(@"{0};", item_pr.Remark);
+                    }
+                    if (str_schedule.Length > 0)
+                    {
+                        str_schedule = str_schedule.TrimEnd(';');
+                    }
+                    if (str_client.Length > 0)
+                    {
+                        str_client = str_client.TrimEnd(';');
+                    }
+
+                    //3.
+                    string sql_other = string.Format(@" Select * From Fin_OtherPrice where diid = {0} and isdel = 0 and RefundType = 1 and PayType=1 ", diId);
+                    List<Fin_OtherPrice> list_other = _sqlSugar.SqlQueryable<Fin_OtherPrice>(sql_other).ToList();
+                    sum_other = list_other.Sum(s => s.Price);
+
+                    item_rst.frPrice = sum_fr.ToString("#0.00");
+                    item_rst.prPrice = (sum_pr - sum_other).ToString("#0.00");
+                    item_rst.balPrice = (sum_fr - (sum_pr - sum_other)).ToString("#0.00");
+                    item_rst.clientUnit = str_client;
+                    item_rst.schedule = str_schedule;
+
+                    sumAll_fr += sum_fr;
+                    sumAll_pr += (sum_pr - sum_other);
+                    sumAll_balance += (sum_fr - (sum_pr - sum_other));
+
+                }
+
+                PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
+                result.total_fr = sumAll_fr.ToString("#0.00");
+                result.total_pr = sumAll_pr.ToString("#0.00");
+                result.total_balance = sumAll_balance.ToString("#0.00");
+                result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
+
+                if (dto.requestType == 1)
+                {
+                    return Ok(JsonView(true, "请求成功", result, list_rst.Count));
+                }
+                else {
+                    //----------------------------
+                    List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
+                    WorkbookDesigner designer = new WorkbookDesigner();
+                    designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
+
+                    int excNo = 1;
+                    foreach (var item in list_rst)
+                    {
+                        Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
+                        exc.No = excNo.ToString();
+                        excNo++;
+                        exc.TeamName = item.teamName;
+                        exc.ClientUnit = item.clientUnit;
+                        exc.VisitDate = item.visitDate;
+                        exc.Accounts = item.frPrice;
+                        exc.Received = item.prPrice;
+                        exc.Balance = item.balPrice;
+                        exc.Collection = item.schedule;
+                        DateTime time = Convert.ToDateTime(item.visitDate);
+                        TimeSpan ts = DateTime.Now - time;
+                        float SY = float.Parse(item.balPrice);
+                        if (ts.Days >= 365 && SY > 0)
+                        {
+                            exc.Sign = "需收款";
+                        }
+                        else
+                        {
+                            exc.Sign = "";
+                        }
+                        list_Ex.Add(exc);
+                    }
+
+                    var dt = CommonFun.GetDataTableFromIList(list_Ex);
+                    dt.TableName = "Excel_SyntheticalReceivableByDateRange";
+                    if (dt != null)
+                    {
+                        designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB  已收合计:" + result.total_pr + "RMB  余款合计:" + result.total_balance + "RMB");
+
+                        //数据源
+                        designer.SetDataSource(dt);
+
+
+                        //根据数据源处理生成报表内容
+                        designer.Process();
+
+                        string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
+                        designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
+                        string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
+                        return Ok(JsonView(true, "成功", new { url = rst }));
+                    }
+
+
+                }
+                
+            }
+
+
+            return Ok(JsonView(true, "获取成功", "", list_rst.Count));
+
+        }
+
+        #endregion
     }
 }

+ 19 - 0
OASystem/OASystem.Domain/Dtos/Financial/PostSyntheticalReceivableByDateRangeDto.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.Financial
+{
+    public class PostSyntheticalReceivableByDateRangeDto:PortDtoBase
+    {
+        public string beginDt { get; set; }
+        public string endDt { get; set; }
+
+        /// <summary>
+        /// 请求类型:1:查询数据,2:生成Excel
+        /// </summary>
+        public int requestType { get; set; }
+    }
+}

+ 4 - 4
OASystem/OASystem.Domain/Entities/Groups/Grp_HotelReservations.cs

@@ -98,7 +98,7 @@ namespace OASystem.Domain.Entities.Groups
         /// <summary>
         /// 单间数量
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "decimal(18,2)")]
+        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         public int SingleRoomCount { get; set; }
         /// <summary>
         /// 单间单价
@@ -108,7 +108,7 @@ namespace OASystem.Domain.Entities.Groups
         /// <summary>
         /// 双间数量
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "decimal(18,2)")]
+        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         public int DoubleRoomCount { get; set; }
         /// <summary>
         /// 双间单价
@@ -118,7 +118,7 @@ namespace OASystem.Domain.Entities.Groups
         /// <summary>
         /// 套房数量
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "decimal(18,2)")]
+        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         public int SuiteRoomCount { get; set; }
         /// <summary>
         /// 套房单价
@@ -128,7 +128,7 @@ namespace OASystem.Domain.Entities.Groups
         /// <summary>
         /// 其他房型数量
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "decimal(18,2)")]
+        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         public int OtherRoomCount { get; set; }
         /// <summary>
         /// 其他房型单价

+ 106 - 2
OASystem/OASystem.Domain/ViewModels/Financial/Fin_ForeignReceivablesView.cs

@@ -10,14 +10,14 @@ namespace OASystem.Domain.ViewModels.Financial
     /// <summary>
     /// 团组应收款项 View
     /// </summary>
-    public class Fin_ForeignReceivablesView:Fin_ForeignReceivables
+    public class Fin_ForeignReceivablesView : Fin_ForeignReceivables
     {
     }
 
     /// <summary>
     /// 团组应收款项 info View
     /// </summary>
-    public class ForeignReceivablesInfoView 
+    public class ForeignReceivablesInfoView
     {
         /// <summary>
         /// 主键ID
@@ -237,5 +237,109 @@ namespace OASystem.Domain.ViewModels.Financial
 
 
 
+    #endregion
+
+    #region 应收报表
+
+    public class Excel_SyntheticalReceivableByDateRange{
+        public string No { get; set; }
+
+        /// <summary>
+        /// 团组名称
+        /// </summary>
+        public string TeamName { get; set; }
+
+        /// <summary>
+        /// 单位
+        /// </summary>
+        public string ClientUnit { get; set; }
+
+        /// <summary>
+        /// 出访时间
+        /// </summary>
+        public string VisitDate { get; set; }
+
+        /// <summary>
+        /// 应收
+        /// </summary>
+        public string Accounts { get; set; }
+
+        /// <summary>
+        /// 已收
+        /// </summary>
+        public string Received { get; set; }
+
+        /// <summary>
+        /// 余款
+        /// </summary>
+        public string Balance { get; set; }
+
+        /// <summary>
+        /// 收款进度
+        /// </summary>
+        public string Collection { get; set; }
+
+        public string Sign { get; set; }
+    }
+
+    public class PostSyntheticalReceivableByDateRangeResultView
+    {
+        public string total_fr { get; set; }
+        public string total_pr { get; set; }
+        public string total_balance { get; set; }
+
+        public List<PostSyntheticalReceivableByDateRangeView> dataList { get; set; }
+    }
+
+    public class PostSyntheticalReceivableByDateRangeView
+    {
+        public int No { get; set; }
+
+        /// <summary>
+        /// 团组Id
+        /// </summary>
+        public int diid { get; set; }
+
+        /// <summary>
+        /// 团组名称
+        /// </summary>
+        public string teamName { get; set; }
+
+        /// <summary>
+        /// 单位
+        /// </summary>
+        public string clientUnit { get; set; }
+
+        /// <summary>
+        /// 出访时间
+        /// </summary>
+        public string visitDate { get; set; }
+
+        /// <summary>
+        /// 应收
+        /// </summary>
+        public string frPrice { get; set; }
+
+        /// <summary>
+        /// 已收
+        /// </summary>
+        public string prPrice { get; set; }
+
+        /// <summary>
+        /// 余款
+        /// </summary>
+        public string balPrice { get; set; }
+
+        /// <summary>
+        /// 收款单位
+        /// </summary>
+        public string prClient { get; set; }
+
+        /// <summary>
+        /// 收款进度
+        /// </summary>
+        public string schedule { get; set; }
+    }
+
     #endregion
 }

+ 5 - 0
OASystem/OASystem.Domain/ViewModels/Groups/DelegationInfoView.cs

@@ -450,6 +450,11 @@ namespace OASystem.Domain.ViewModels.Groups
         /// 0否1是
         /// </summary>
         public int IsSure { get; set; }
+
+        /// <summary>
+        /// 流程管控Id
+        /// </summary>
+        public int GrpScheduleId { get; set; } = 0;
     }
 
     

+ 26 - 1
OASystem/OASystem.Infrastructure/Repositories/Groups/DelegationInfoRepository.cs

@@ -220,7 +220,31 @@ namespace OASystem.Infrastructure.Repositories.Groups
         {
             Result result = new Result() { Code = -2, Msg = "未知错误" };
 
-            if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
+            if (dto.PortType == 1) {
+                string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
+                  ,gs.Id as GrpScheduleId
+				  From  Grp_DelegationInfo gdi
+                  Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id 
+                  Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
+                  Left Join Sys_Users su On gdi.JietuanOperator = su.Id
+				  left Join Grp_Schedule gs On gdi.Id = gs.DiId
+                  Where gdi.IsDel = 0 
+                  Order By gdi.CreateTime Desc");
+
+                var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
+
+                if (_DelegationList.Count > 0)
+                {
+                    result.Code = 0;
+                    result.Msg = "成功!";
+                    result.Data = _DelegationList;
+                }
+                else
+                {
+                    result.Msg = "暂无该团组信息";
+                }
+            }
+            else if (dto.PortType == 2 || dto.PortType == 3) //web
             {
                 string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
                   From  Grp_DelegationInfo gdi
@@ -231,6 +255,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                   Order By gdi.CreateTime Desc");
 
                 var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
+
                 if (_DelegationList.Count > 0)
                 {
                     result.Code = 0;