Parcourir la source

出国经费报销单导出支持多舱位及模板优化

本次更新实现了报销单导出多舱位(经济舱、公务舱、头等舱)并行填充与Sheet自动管理。增加了团组信息判空、具体线路字段、出国人员姓名判空处理,优化了出国时间与金额显示,修正了字段名拼写,并调整了导出文件名格式。提升了报销单导出的灵活性和准确性。
Lyyyi il y a 1 semaine
Parent
commit
05848736e2
1 fichiers modifiés avec 170 ajouts et 38 suppressions
  1. 170 38
      OASystem/OASystem.Api/Controllers/GroupsController.cs

+ 170 - 38
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -14018,6 +14018,12 @@ FROM
 
                 var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
                 var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
+
+                if (_DelegationInfo == null)
+                {
+                    return Ok(JsonView(400, "团组信息为空!", ""));
+                }
+
                 var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
                     .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
                     .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
@@ -15457,7 +15463,9 @@ FROM
                             Workbook = new Workbook(tempPath)
                         };
                         Workbook workbook = designer.Workbook;
-                        var worksheet = workbook.Worksheets[0];
+                        var worksheet1 = workbook.Worksheets[0];
+                        var worksheet2 = workbook.Worksheets[1];
+                        var worksheet3 = workbook.Worksheets[2];
 
                         // 日期格式化
                         var dateFormat = "yyyy年MM月dd日";
@@ -15469,16 +15477,51 @@ FROM
                         designer.SetDataSource("GroupUnit", _DelegationInfo.ClientUnit); // 组团单位
                         // 出国人员姓名
                         var overseasName = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
+                        if (string.IsNullOrEmpty(overseasName)) overseasName = "-";
                         designer.SetDataSource("OverseasName", overseasName);                   
                         // 国家和地区(含经停) 
                         string countryRegionStops = _groupRepository.FormartTeamName(_DelegationInfo.VisitCountry);
                         designer.SetDataSource("CountryRegionStops", countryRegionStops);
-                        // 国家和地区(含经停) 
-                        string overseasTime = $"{_DelegationInfo.VisitStartDate.ToString(dateFormat)}-{_DelegationInfo.VisitEndDate.ToString(dateFormat)}";
+                        // 具体线路
+                        string specificLine = "";
+                        if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
+                        {
+                            var list = new List<string>();
+                            try
+                            {
+                                var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
+                                foreach (var item in spilitArr)
+                                {
+                                    var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
+                                    var depCode = spDotandEmpty[2].Substring(0, 3);
+                                    var arrCode = spDotandEmpty[2].Substring(3, 3);
+                                    string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City;
+                                    string arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
+
+                                    list.Add(depName);
+                                    list.Add(arrName);
+                                }
+
+                                list = list.Distinct().ToList();
+                                specificLine = string.Join("-", list);
+                            }
+                            catch (Exception)
+                            {
+                                specificLine = "行程录入不正确!";
+                            }
+                        }
+                        else
+                        {
+                            specificLine = "未录入行程!";
+                        }
+                        designer.SetDataSource("SpecRoute", specificLine);
+
+                        // 出国时间
+                        string overseasTime = $"{_DelegationInfo.VisitStartDate.ToString(dateFormat)} - {_DelegationInfo.VisitEndDate.ToString(dateFormat)}";
                         designer.SetDataSource("OverseasTime", overseasTime);
                         // 实际天数
                         TimeSpan overseasActualDays_ts = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
-                        designer.SetDataSource("verseasActualDays", $"{overseasActualDays_ts.Days}天");
+                        designer.SetDataSource("OverseasActualDays", $"{overseasActualDays_ts.Days}天");
 
                         // 数据整理
                         // 住宿费
@@ -15572,15 +15615,6 @@ FROM
                             })
                             .ToList();
 
-                        // 国际旅行费 - 经济舱
-                        var cellLabel4 = new StringBuilder()
-                            .AppendFormat("4.国际旅费(经济舱:{0:#0.00}/人;城市间交通费{1:#0.00}元/人)", _EnterExitCosts.AirJJ,_EnterExitCosts.CityTranffic)
-                            .ToString();
-                        designer.SetDataSource("TotalAirJJCLabel", cellLabel4);
-
-                        decimal totalAirJJC = _EnterExitCosts.AirJJ + _EnterExitCosts.CityTranffic;
-                        designer.SetDataSource("TotalAirJJC", $"{totalAirJJC:#0.00}");
-
                         // 其他费用
                         var otherFeestrs = new List<string>();
                         decimal totalOtherFee = 0.00M;
@@ -15631,12 +15665,42 @@ FROM
 
                         //其他费用合计
                         decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
-                        decimal totalPrice = grandTotalFee + totalAirJJC + totalOtherFee;
-
-                        designer.SetDataSource("TotalFeeLabel", $"大写 :{CommonFun.ToChinese(totalPrice)}"); // 合计金额中文大写
-                        designer.SetDataSource("TotalFee", $"{totalPrice:0.00}");    // 合计金额 
-                        designer.SetDataSource("ActualAmount  ", $"{totalPrice:0.00}元");    // 合计金额 
 
+                        // 国际旅行费 - 经济舱
+                        var cellLabel4_jjc = new StringBuilder()
+                            .AppendFormat($"4.国际旅费(经济舱:{_EnterExitCosts.AirJJ:0.00}/人;城市间交通费:{_EnterExitCosts.CityTranffic:0.00}元/人)")
+                            .ToString();
+                        decimal totalAirJJC = _EnterExitCosts.AirJJ + _EnterExitCosts.CityTranffic;
+                        designer.SetDataSource("TotalAirLabel_JJC", cellLabel4_jjc);
+                        designer.SetDataSource("TotalAir_JJC", $"{totalAirJJC:#0.00}");
+                        decimal totalPrice_jjc = grandTotalFee + totalAirJJC + totalOtherFee;
+                        designer.SetDataSource("TotalFeeLabel_JJC", $"大写 :{CommonFun.ToChinese(totalPrice_jjc)}整"); // 合计金额中文大写
+                        designer.SetDataSource("TotalFee_JJC", $"{totalPrice_jjc:0.00}");          // 合计金额 
+                        designer.SetDataSource("ActualAmount_JJC", $"{totalPrice_jjc:0.00}元");    // 合计金额 
+
+                        // 国际旅行费 - 公务舱
+                        var cellLabel4_gwc = new StringBuilder()
+                            .AppendFormat($"4.国际旅费(公务舱:{_EnterExitCosts.AirGW:0.00}/人;城市间交通费:{_EnterExitCosts.CityTranffic1:0.00}元/人)")
+                            .ToString();
+                        decimal totalAir_gwc = _EnterExitCosts.AirGW + _EnterExitCosts.CityTranffic1;
+                        designer.SetDataSource("TotalAirLabel_GWC", cellLabel4_gwc);
+                        designer.SetDataSource("TotalAir_GWC", $"{totalAir_gwc:#0.00}");
+                        decimal totalPrice_gwc = grandTotalFee + totalAir_gwc + totalOtherFee;
+                        designer.SetDataSource("TotalFeeLabel_GWC", $"大写 :{CommonFun.ToChinese(totalPrice_gwc)}整"); // 合计金额中文大写
+                        designer.SetDataSource("TotalFee_GWC", $"{totalPrice_gwc:0.00}");          // 合计金额 
+                        designer.SetDataSource("ActualAmount_GWC", $"{totalPrice_gwc:0.00}元");    // 合计金额 
+
+                        // 国际旅行费 - 头等舱
+                        var cellLabel4_tdc = new StringBuilder()
+                            .AppendFormat($"4.国际旅费(头等舱:{_EnterExitCosts.AirTD:0.00}/人;城市间交通费:{_EnterExitCosts.CityTranffic2:0.00}元/人)")
+                            .ToString();
+                        decimal totalAir_tdc = _EnterExitCosts.AirTD + _EnterExitCosts.CityTranffic2;
+                        designer.SetDataSource("TotalAirLabel_TDC", cellLabel4_tdc);
+                        designer.SetDataSource("TotalAir_TDC", $"{totalAir_tdc:#0.00}");
+                        decimal totalPrice_tdc = grandTotalFee + totalAir_tdc + totalOtherFee;
+                        designer.SetDataSource("TotalFeeLabel_TDC", $"大写 :{CommonFun.ToChinese(totalPrice_tdc)}整"); // 合计金额中文大写
+                        designer.SetDataSource("TotalFee_TDC", $"{totalPrice_tdc:0.00}");          // 合计金额 
+                        designer.SetDataSource("ActualAmount_TDC", $"{totalPrice_tdc:0.00}元");    // 合计金额 
                         designer.Process();
 
                         #region 设置 住宿费、伙食费和公杂显示值
@@ -15654,18 +15718,38 @@ FROM
                             int startRow1 = startRow + i;
 
                             // 插入数据到对应列
-                            worksheet.Cells[startRow1, startColumn].PutValue(currData.PlaceName);                    // 国家(地区)/城市
-                            worksheet.Cells[startRow1, startColumn + 1].PutValue(currData.CurrencyName);             // 币种
-                            worksheet.Cells[startRow1, startColumn + 2].PutValue($"{currData.Cost:0.00}");           // 标准
-                            worksheet.Cells[startRow1, startColumn + 3].PutValue("1");                               // 人数
-                            worksheet.Cells[startRow1, startColumn + 4].PutValue(currData.TotalDays);                // 天数
-                            worksheet.Cells[startRow1, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}");    // 小计
-                            worksheet.Cells[startRow1, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
-                            worksheet.Cells[startRow1, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}");       // 折合人民币(元)
+                            worksheet1.Cells[startRow1, startColumn].PutValue(currData.PlaceName);                    // 国家(地区)/城市
+                            worksheet1.Cells[startRow1, startColumn + 1].PutValue(currData.CurrencyName);             // 币种
+                            worksheet1.Cells[startRow1, startColumn + 2].PutValue($"{currData.Cost:0.00}");           // 标准
+                            worksheet1.Cells[startRow1, startColumn + 3].PutValue("1");                               // 人数
+                            worksheet1.Cells[startRow1, startColumn + 4].PutValue(currData.TotalDays);                // 天数
+                            worksheet1.Cells[startRow1, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}");    // 小计
+                            worksheet1.Cells[startRow1, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
+                            worksheet1.Cells[startRow1, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}");       // 折合人民币(元)
+
+                            worksheet2.Cells[startRow1, startColumn].PutValue(currData.PlaceName);                    // 国家(地区)/城市
+                            worksheet2.Cells[startRow1, startColumn + 1].PutValue(currData.CurrencyName);             // 币种
+                            worksheet2.Cells[startRow1, startColumn + 2].PutValue($"{currData.Cost:0.00}");           // 标准
+                            worksheet2.Cells[startRow1, startColumn + 3].PutValue("1");                               // 人数
+                            worksheet2.Cells[startRow1, startColumn + 4].PutValue(currData.TotalDays);                // 天数
+                            worksheet2.Cells[startRow1, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}");    // 小计
+                            worksheet2.Cells[startRow1, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
+                            worksheet2.Cells[startRow1, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}");       // 折合人民币(元)
+
+                            worksheet3.Cells[startRow1, startColumn].PutValue(currData.PlaceName);                    // 国家(地区)/城市
+                            worksheet3.Cells[startRow1, startColumn + 1].PutValue(currData.CurrencyName);             // 币种
+                            worksheet3.Cells[startRow1, startColumn + 2].PutValue($"{currData.Cost:0.00}");           // 标准
+                            worksheet3.Cells[startRow1, startColumn + 3].PutValue("1");                               // 人数
+                            worksheet3.Cells[startRow1, startColumn + 4].PutValue(currData.TotalDays);                // 天数
+                            worksheet3.Cells[startRow1, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}");    // 小计
+                            worksheet3.Cells[startRow1, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
+                            worksheet3.Cells[startRow1, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}");       // 折合人民币(元)
                         }
 
                         //设置小计行 合计金额 固定单元格
-                        worksheet.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}");      // 折合人民币(元)
+                        worksheet1.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}");     // 折合人民币(元)
+                        worksheet2.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}");     // 折合人民币(元)
+                        worksheet3.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}");     // 折合人民币(元)
 
                         //  新增小计行
                         if (accomFees.Count == (defualtRow - 1)) startRow += 1;
@@ -15678,24 +15762,72 @@ FROM
                             int startRow2 = startRow + i;
 
                             // 插入数据到对应列
-                            worksheet.Cells[startRow2, startColumn].PutValue(currData.PlaceName);                    // 国家(地区)/城市
-                            worksheet.Cells[startRow2, startColumn + 1].PutValue(currData.CurrencyName);             // 币种
-                            worksheet.Cells[startRow2, startColumn + 2].PutValue($"{currData.Cost:0.00}");           // 标准
-                            worksheet.Cells[startRow2, startColumn + 3].PutValue("1");                               // 人数
-                            worksheet.Cells[startRow2, startColumn + 4].PutValue(currData.TotalDays);                // 天数
-                            worksheet.Cells[startRow2, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}");    // 小计
-                            worksheet.Cells[startRow2, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
-                            worksheet.Cells[startRow2, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}");       // 折合人民币(元)
+                            worksheet1.Cells[startRow2, startColumn].PutValue(currData.PlaceName);                    // 国家(地区)/城市
+                            worksheet1.Cells[startRow2, startColumn + 1].PutValue(currData.CurrencyName);             // 币种
+                            worksheet1.Cells[startRow2, startColumn + 2].PutValue($"{currData.Cost:0.00}");           // 标准
+                            worksheet1.Cells[startRow2, startColumn + 3].PutValue("1");                               // 人数
+                            worksheet1.Cells[startRow2, startColumn + 4].PutValue(currData.TotalDays);                // 天数
+                            worksheet1.Cells[startRow2, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}");    // 小计
+                            worksheet1.Cells[startRow2, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
+                            worksheet1.Cells[startRow2, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}");       // 折合人民币(元)
+
+                            worksheet2.Cells[startRow2, startColumn].PutValue(currData.PlaceName);                    // 国家(地区)/城市
+                            worksheet2.Cells[startRow2, startColumn + 1].PutValue(currData.CurrencyName);             // 币种
+                            worksheet2.Cells[startRow2, startColumn + 2].PutValue($"{currData.Cost:0.00}");           // 标准
+                            worksheet2.Cells[startRow2, startColumn + 3].PutValue("1");                               // 人数
+                            worksheet2.Cells[startRow2, startColumn + 4].PutValue(currData.TotalDays);                // 天数
+                            worksheet2.Cells[startRow2, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}");    // 小计
+                            worksheet2.Cells[startRow2, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
+                            worksheet2.Cells[startRow2, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}");       // 折合人民币(元)
+
+                            worksheet3.Cells[startRow2, startColumn].PutValue(currData.PlaceName);                    // 国家(地区)/城市
+                            worksheet3.Cells[startRow2, startColumn + 1].PutValue(currData.CurrencyName);             // 币种
+                            worksheet3.Cells[startRow2, startColumn + 2].PutValue($"{currData.Cost:0.00}");           // 标准
+                            worksheet3.Cells[startRow2, startColumn + 3].PutValue("1");                               // 人数
+                            worksheet3.Cells[startRow2, startColumn + 4].PutValue(currData.TotalDays);                // 天数
+                            worksheet3.Cells[startRow2, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}");    // 小计
+                            worksheet3.Cells[startRow2, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
+                            worksheet3.Cells[startRow2, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}");       // 折合人民币(元)
                         }
 
                         //设置小计行 合计金额 固定单元格
-                        worksheet.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}");      // 折合人民币(元)
+                        worksheet1.Cells[15, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}");     // 折合人民币(元)
+                        worksheet2.Cells[15, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}");     // 折合人民币(元)
+                        worksheet3.Cells[15, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}");     // 折合人民币(元)
                         #endregion
 
                         workbook.CalculateFormula(true);
 
-                        //模板文件名
-                        string strFileName = $"{_DelegationInfo.TeamName}-省级单位出国经费报销单{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
+                        // 根据舱位选择,删除指定的sheet
+                        if (_EnterExitCosts.SumJJC == 0)
+                        {
+                            var sheetNameToDelete1 = "经济舱";
+                            if (workbook.Worksheets[sheetNameToDelete1] != null) 
+                            {
+                                workbook.Worksheets.RemoveAt(sheetNameToDelete1);
+                            }
+                        }
+
+                        if (_EnterExitCosts.SumGWC == 0)
+                        {
+                            var sheetNameToDelete2 = "公务舱";
+                            if (workbook.Worksheets[sheetNameToDelete2] != null)
+                            {
+                                workbook.Worksheets.RemoveAt(sheetNameToDelete2);
+                            }
+                        }
+
+                        if (_EnterExitCosts.SumTDC == 0)
+                        {
+                            var sheetNameToDelete3 = "头等舱";
+                            if (workbook.Worksheets[sheetNameToDelete3] != null)
+                            {
+                                workbook.Worksheets.RemoveAt(sheetNameToDelete3);
+                            }
+                        }
+
+                        // 模板文件名
+                        string strFileName = $"{_DelegationInfo.TeamName}_省级单位出国经费报销单_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
                         designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
 
                         string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;