Browse Source

团组报表 --> excel下载代码编写(70%)

LEIYI 1 month ago
parent
commit
2d2616c8a6

+ 220 - 11
OASystem/OASystem.Api/Controllers/StatisticsController.cs

@@ -581,7 +581,6 @@ ORDER BY
                                           是否由地接支付:{isFeeMark4} <br/>";
                         }
 
-
                         if (!string.IsNullOrEmpty(paymentStr))
                         {
                             item.IsPay = 2;
@@ -1360,7 +1359,6 @@ ORDER BY
                     .Select(x => new Crm_DeleClient { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Sex = x.Sex })
                     .ToList();
 
-
             //获取模板
             string tempPath = (AppSettingsHelper.Get("ExcelBasePath") + "Template/团组费用统计模板.xls");
             var designer = new WorkbookDesigner();
@@ -1369,6 +1367,11 @@ ORDER BY
             var worksheets = designer.Workbook.Worksheets;
 
             #region 获取sheet,定义datatable,局部变量
+            //酒店费用相关 
+            var hotelFeeSheet = worksheets["酒店费用"];
+            var hotelFeeDt = new DataTable($"HotelFeeView");
+            decimal hotelCNYTotalCost = 0.00M;
+
             //签证费用相关 
             var visaFeeSheet = worksheets["签证费用"];
             var visaFeeDt = new DataTable($"VisaFeeView"); 
@@ -1396,6 +1399,188 @@ ORDER BY
 
             #endregion
 
+            #region 酒店费用
+
+            if (hotelFeeSheet != null)
+            {
+                var _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
+
+                string hotelFeeSql = string.Format(@"
+SELECT
+  hr.Id AS HrId,
+  hr.DiId AS HrDiId,
+  hr.City,
+  hr.HotelName,
+  hr.CheckInDate,
+  hr.CheckOutDate,
+  hr.CardPrice AS RoomPrice,
+  sd1.Name AS PaymentCurrency,
+  hr.SingleRoomPrice,
+  hr.SingleRoomCount,
+  hr.DoubleRoomPrice,
+  hr.DoubleRoomCount,
+  hr.SuiteRoomPrice,
+  hr.SuiteRoomCount,
+  hr.OtherRoomPrice,
+  hr.OtherRoomCount,
+  hr.BreakfastPrice,
+  sd4.Name AS BreakfastCurrency,
+  hr.Isoppay,
+  hr.GovernmentRent,
+  sd5.Name AS GovernmentRentCurrency,
+  hr.CityTax,
+  sd6.Name AS CityTaxCurrency,
+  ccp.PayMoney,
+  (
+    ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
+  ) AS CNYPrice,
+  ccp.PayPercentage,
+  ccp.DayRate,
+  ccp.Payee,
+  ccp.OrbitalPrivateTransfer,
+  sd2.Name AS PayWay,
+  sd3.Name AS CardType,
+  ccp.IsPay,
+  u.CnName AS Applicant,
+  hr.Remark
+FROM
+  Grp_HotelReservations hr
+  INNER JOIN Grp_CreditCardPayment ccp ON hr.Id = ccp.CId
+  LEFT JOIN Sys_SetData sd1 ON ccp.PaymentCurrency = sd1.Id
+  LEFT JOIN Sys_SetData sd2 ON ccp.PayDId = sd2.Id
+  LEFT JOIN Sys_SetData sd3 ON ccp.CTDId = sd3.Id
+  LEFT JOIN Sys_Users u ON ccp.CreateUserId = u.Id
+  LEFT JOIN Sys_SetData sd4 ON hr.BreakfastCurrency = sd4.Id
+  LEFT JOIN Sys_SetData sd5 ON hr.GovernmentRentCurrency = sd5.Id
+  LEFT JOIN Sys_SetData sd6 ON hr.CityTaxCurrency = sd6.Id
+WHERE
+  hr.IsDel = 0
+  AND ccp.IsDel = 0
+  AND ccp.CTable = 76 {1}
+  AND ccp.PayMoney <> 0
+  AND hr.DiId = {0}
+ORDER BY
+  CheckInDate Asc", _dto.DiId, _dto.isAudit ? "AND (ccp.IsAuditGM = 1 Or ccp.IsAuditGM = 3)" : " ");
+
+                var groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
+
+                var hotelSubIds = groupHotelFeeViews.Select(it => it.HrId).ToList();
+
+                var groupHotelContentFeeViews = await _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => hotelSubIds.Contains(it.HrId)).ToListAsync();
+
+                var teamRateData = await _teamRateRep.PostGroupRateInfoByDiId(_dto.DiId);
+                foreach (var item in groupHotelFeeViews)
+                {
+                    if (groupHotelContentFeeViews.Count > 0)
+                    {
+
+                        string paymentStr = string.Empty;
+
+                        var roomData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 1); //房费 
+
+                        item.RoomPrice = roomData?.Price ?? 0.00M;
+                        if (item.RoomPrice != 0)
+                        {
+                            if (roomData.IsPay == 0) paymentStr += $"房费:未付款<br/>";
+
+                            item.RoomPriceCurrency = _setDatas.Find(it => it.Id == roomData?.Currency)?.Name;
+                            string feeMark1 = roomData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
+                            string isFeeMark1 = roomData?.IsOppay == 1 ? "是" : "否";
+                            item.RoomInfoTips = @$"当时汇率:{roomData?.Rate.ToString("#0.0000")} <br/>
+                                           收款方:{roomData?.Payee}<br/>
+                                           费用标识:{feeMark1} <br/>
+                                           支付方式:{_setDatas.Find(it => it.Id == roomData?.PayDId)?.Name} <br/>
+                                           卡类型:{_setDatas.Find(it => it.Id == roomData?.CTDId)?.Name}<br/>
+                                           是否由地接支付:{isFeeMark1} <br/>";
+                        }
+
+                        var breakfastData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 2); //早餐 
+
+                        item.BreakfastPrice = breakfastData?.Price ?? 0.00M;
+
+                        if (item.BreakfastPrice != 0)
+                        {
+                            if (breakfastData.IsPay == 0) paymentStr += $"早餐:未付款<br/>";
+
+                            item.BreakfastCurrency = _setDatas.Find(it => it.Id == breakfastData?.Currency)?.Name;
+                            string feeMark2 = breakfastData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
+                            string isFeeMark2 = breakfastData?.IsOppay == 1 ? "是" : "否";
+                            item.BreakfastInfoTips = @$"当时汇率:{breakfastData?.Rate.ToString("#0.0000")} <br/>
+                                                收款方:{breakfastData?.Payee}<br/>
+                                                费用标识:{feeMark2} <br/>
+                                                支付方式:{_setDatas.Find(it => it.Id == roomData?.PayDId)?.Name} <br/>
+                                                卡类型:{_setDatas.Find(it => it.Id == roomData?.CTDId)?.Name} <br/>
+                                                是否由地接支付:{isFeeMark2} <br/>";
+                        }
+
+                        var landTaxData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 3); //地税
+
+                        item.GovernmentRent = landTaxData?.Price ?? 0.00M;
+
+                        if (item.GovernmentRent != 0)
+                        {
+                            if (landTaxData.IsPay == 0) paymentStr += $"地税:未付款<br/>";
+
+                            item.GovernmentRentCurrency = _setDatas.Find(it => it.Id == landTaxData?.Currency)?.Name;
+                            string feeMark3 = landTaxData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
+                            string isFeeMark3 = landTaxData?.IsOppay == 1 ? "是" : "否";
+                            item.GovernmentRentTips = @$"当时汇率:{landTaxData?.Rate.ToString("#0.0000")} <br/>
+                                                 收款方:{landTaxData?.Payee}<br/>
+                                                 费用标识:{feeMark3} <br/>
+                                                 支付方式:{_setDatas.Find(it => it.Id == landTaxData?.PayDId)?.Name} <br/>
+                                                 卡类型:{_setDatas.Find(it => it.Id == landTaxData?.CTDId)?.Name} <br/>
+                                                 是否由地接支付:{isFeeMark3} <br/>";
+                        }
+
+                        var cityTaxData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 4); //城市税 
+
+                        item.CityTax = cityTaxData?.Price ?? 0.00M;
+
+                        if (item.CityTax != 0)
+                        {
+                            if (cityTaxData.IsPay == 0) paymentStr += $"城市税:未付款<br/>";
+                            item.CityTaxCurrency = _setDatas.Find(it => it.Id == cityTaxData?.Currency)?.Name;
+                            string feeMark4 = cityTaxData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
+                            string isFeeMark4 = landTaxData?.IsOppay == 1 ? "是" : "否";
+                            item.CityTaxTips = @$"当时汇率:{cityTaxData?.Rate.ToString("#0.0000")} <br/>
+                                          收款方:{cityTaxData?.Payee}<br/>
+                                          费用标识:{feeMark4} <br/>
+                                          支付方式:{_setDatas.Find(it => it.Id == cityTaxData?.PayDId)?.Name} <br/>
+                                          卡类型:{_setDatas.Find(it => it.Id == cityTaxData?.CTDId)?.Name} <br/>
+                                          是否由地接支付:{isFeeMark4} <br/>";
+                        }
+
+                        if (!string.IsNullOrEmpty(paymentStr))
+                        {
+                            item.IsPay = 2;
+                            item.PayTips = paymentStr;
+                        }
+                        //item.CNYPrice = roomData?.Price ?? 0.00M * roomData?.Rate ?? 0.00M +
+                        //                breakfastData?.Price ?? 0.00M * breakfastData?.Rate ?? 0.00M +
+                        //                landTaxData?.Price ?? 0.00M * landTaxData?.Rate ?? 0.00M +
+                        //                cityTaxData?.Price ?? 0.00M * cityTaxData?.Rate ?? 0.00M;
+                    }
+                    else
+                    {
+                        decimal roomPrice = (item.SingleRoomCount * item.SingleRoomPrice) +
+                                            (item.DoubleRoomCount * item.DoubleRoomPrice) +
+                                            (item.SuiteRoomCount * item.SuiteRoomPrice) +
+                                            (item.OtherRoomCount * item.OtherRoomPrice);
+                        //item.RoomPrice = item.CardPrice;
+                        item.RoomPriceCurrency = item.PaymentCurrency;
+                    }
+
+                    item.PayMoney = item.PayMoney.ConvertToDecimal1();
+                    item.CNYPrice = item.CNYPrice.ConvertToDecimal1();
+                }
+
+                hotelCNYTotalCost = groupHotelFeeViews.Sum(x => x.CNYPrice);
+                hotelFeeDt = CommonFun.ToDataTableArray(groupHotelFeeViews);
+                hotelFeeDt.TableName = $"HotelFeeView";
+            }
+
+            #endregion
+
             #region 签证费用
             if (visaFeeSheet != null)
             {
@@ -1450,7 +1635,6 @@ ORDER BY
                 }
 
                 visaCNYTotalCost = groupVisaFeeViews.Sum(x => x.CNYPrice);
-
                 visaFeeDt = CommonFun.ToDataTableArray(groupVisaFeeViews);
                 visaFeeDt.TableName = $"VisaFeeView";
 
@@ -1612,6 +1796,10 @@ ORDER BY
             designer.SetDataSource("GroupName", groupName);
             designer.SetDataSource("Lister", lister);
 
+            //酒店
+            designer.SetDataSource(hotelFeeDt);
+            designer.SetDataSource("HotelCNYTotalCost", $"{hotelCNYTotalCost.ToString("#0.00")} CNY");
+
             //签证
             designer.SetDataSource(visaFeeDt);
             designer.SetDataSource("VisaCNYTotalCost", $"{visaCNYTotalCost.ToString("#0.00")} CNY");
@@ -1630,24 +1818,45 @@ ORDER BY
 
             designer.Process();
 
+            #endregion
+
             #region 单元格样式设置  未付款设置为红色
             /*
             * 设置单元格样式
             */
             //背景颜色
             Style style = designer.Workbook.CreateStyle();
-            style.ForegroundColor = System.Drawing.Color.Red;
+            style.ForegroundColor = Color.FromArgb(255, 182, 193);
             style.Pattern = BackgroundType.Solid;
             //字体
             style.Font.Name = "微软雅黑";                   // 字体名称
             style.Font.Size = 10;                           // 字体大小
-            style.Font.Color = System.Drawing.Color.White;  // 字体颜色
+            style.Font.Color = System.Drawing.Color.Black;  // 字体颜色
+
+            #region 酒店费用单元格
+            for (int i = 0; i < hotelFeeDt.Rows.Count; i++)
+            {
+                var isPayStr = hotelFeeDt.Rows[i]["IsPayLable"].ToString();
+                if (string.IsNullOrEmpty(isPayStr)) continue;
+
+                if (isPayStr.Contains("未付款"))
+                {
+                    var excelIndex = 8 + i;
+
+                    if (hotelFeeSheet != null)
+                    {
+                        Aspose.Cells.Range range = hotelFeeSheet.Cells.CreateRange($"A{excelIndex}", $"V{excelIndex}");
+                        range.ApplyStyle(style, new StyleFlag() { CellShading = true, Font = true });
+                    }
+                }
+            }
+            #endregion
 
             #region 签证费用单元格
             for (int i = 0; i < visaFeeDt.Rows.Count; i++)
             {
                 var isPayStr = visaFeeDt.Rows[i]["IsPay"].ToString();
-                if (string.IsNullOrEmpty(isPayStr)) break;
+                if (string.IsNullOrEmpty(isPayStr)) continue;
 
                 if (isPayStr.Equals("未付款"))
                 {
@@ -1666,7 +1875,7 @@ ORDER BY
             for (int i = 0; i < OAFeeDt.Rows.Count; i++)
             {
                 var isPayStr = OAFeeDt.Rows[i]["IsPay"].ToString();
-                if (string.IsNullOrEmpty(isPayStr)) break;
+                if (string.IsNullOrEmpty(isPayStr)) continue;
                 if (isPayStr.Equals("未付款"))
                 {
                     var excelIndex = 6 + i;
@@ -1684,7 +1893,7 @@ ORDER BY
             for (int i = 0; i < airTicketFeeDt.Rows.Count; i++)
             {
                 var isPayStr = airTicketFeeDt.Rows[i]["IsPay"].ToString();
-                if (string.IsNullOrEmpty(isPayStr)) break;
+                if (string.IsNullOrEmpty(isPayStr)) continue;
 
                 if (isPayStr.Equals("未付款"))
                 {
@@ -1702,7 +1911,7 @@ ORDER BY
             for (int i = 0; i < insureFeeDt.Rows.Count; i++)
             {
                 var isPayStr = insureFeeDt.Rows[i]["IsPay"].ToString();
-                if (string.IsNullOrEmpty(isPayStr)) break;
+                if (string.IsNullOrEmpty(isPayStr)) continue;
 
                 if (isPayStr.Equals("未付款"))
                 {
@@ -1720,7 +1929,7 @@ ORDER BY
             for (int i = 0; i < otherFeeDt.Rows.Count; i++)
             {
                 var isPayStr = otherFeeDt.Rows[i]["IsPay"].ToString();
-                if (string.IsNullOrEmpty(isPayStr)) break;
+                if (string.IsNullOrEmpty(isPayStr)) continue;
 
                 if (isPayStr.Equals("未付款"))
                 {
@@ -1733,7 +1942,7 @@ ORDER BY
                 }
             }
             #endregion
-            #endregion
+
             #endregion
 
             //文件名

+ 57 - 5
OASystem/OASystem.Domain/ViewModels/Statistics/GroupStatementView.cs

@@ -682,6 +682,11 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// </summary>
         public string RoomInfoTips { get; set; }
 
+        /// <summary>
+        /// excel Label
+        /// </summary>
+        public string RoomFeeLabel { get { return $"{RoomPrice.ToString("#0.00")} {RoomPriceCurrency}"; } }
+
         /// <summary>
         /// 早餐费用
         /// </summary>
@@ -697,6 +702,11 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// </summary>
         public string BreakfastInfoTips { get; set; }
 
+        /// <summary>
+        /// excel Label
+        /// </summary>
+        public string BreakfastFeeLabel { get { return $"{BreakfastPrice.ToString("#0.00")} {BreakfastCurrency}"; } }
+
         ///// <summary>
         ///// 由地接支付
         ///// 0 是 1否
@@ -718,6 +728,12 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// </summary>
         public string GovernmentRentTips { get; set; }
 
+
+        /// <summary>
+        /// excel Label
+        /// </summary>
+        public string GovernmentRentFeeLabel { get { return $"{GovernmentRent.ToString("#0.00")} {GovernmentRentCurrency}"; } }
+
         /// <summary>
         /// 城市价格
         /// </summary>
@@ -733,6 +749,11 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// </summary>
         public string? CityTaxTips { get; set; }
 
+        /// <summary>
+        /// excel Label
+        /// </summary>
+        public string CityTaxFeeLabel { get { return $"{CityTax.ToString("#0.00")} {CityTaxCurrency}"; } }
+
         /// <summary>
         /// 信用卡金额
         /// </summary>
@@ -748,6 +769,11 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// </summary>
         public decimal CNYPrice { get; set; } = 0.00M;
 
+        /// <summary>
+        /// 人民币金额
+        /// </summary>
+        public string CNYPriceLabel { get { return $"{CNYPrice.ToString("#0.00")} CNY"; } }
+
         ///// <summary>
         ///// 当天汇率
         ///// </summary>
@@ -767,12 +793,24 @@ namespace OASystem.Domain.ViewModels.Statistics
         ///// 费用标识
         ///// -1 未选择 0 公转 1 私转
         ///// </summary>
-        //public int OrbitalPrivateTransfer { get; set; }
+        public int OrbitalPrivateTransfer { get; set; }
 
-        ///// <summary>
-        ///// 支付方式
-        ///// </summary>
-        //public string? PayWay { get; set; }
+        public string CostMark
+        {
+            get
+            {
+                var label = string.Empty;
+
+                if (OrbitalPrivateTransfer == 0) label = "公转";
+                else if (OrbitalPrivateTransfer == 1) label = "私转";
+                return label;
+            }
+        }
+
+        /// <summary>
+        /// 支付方式
+        /// </summary>
+        public string? PayWay { get; set; }
 
         ///// <summary>
         ///// 卡类型
@@ -785,6 +823,18 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// </summary>
         public int IsPay { get; set; }
 
+        public string IsPayLable
+        {
+            get
+            {
+                var label = string.Empty;
+                if (IsPay == 1) label = "未付款";
+                else if (IsPay == 2) label = "已付款";
+                else if (IsPay == 3) label = "其它费用子项未付款";
+                return label;
+            }
+        }
+
         /// <summary>
         /// 
         /// </summary>
@@ -794,6 +844,8 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// 操作人
         /// </summary>
         public string? Applicant { get; set; }
+
+        public string Remark { get; set; }
     }
 
     /// <summary>