Просмотр исходного кода

团组报表 -- Excel 下载 完善

LEIYI 1 месяц назад
Родитель
Сommit
a9a72e2bda

+ 447 - 177
OASystem/OASystem.Api/Controllers/StatisticsController.cs

@@ -1,6 +1,10 @@
 using Aspose.Cells;
+using Aspose.Words.Tables;
+using Microsoft.AspNetCore.Mvc.ViewEngines;
 using Microsoft.EntityFrameworkCore.Metadata.Internal;
+using MySqlX.XDevAPI.Relational;
 using NetUV.Core.Handles;
+using NPOI.POIFS.Properties;
 using NPOI.SS.Formula.Functions;
 using NPOI.SS.Formula.PTG;
 using OASystem.API.OAMethodLib;
@@ -656,8 +660,6 @@ ORDER BY
                                                      Order By CreateTime", _dto.DiId, _dto.isAudit ? "And (ccp.IsAuditGM = 1 OR ccp.IsAuditGM = 3)" : " ");
                 }
 
-
-
                 groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
 
                 string CTGGRFeeStr = "";
@@ -1372,6 +1374,12 @@ ORDER BY
             var hotelFeeDt = new DataTable($"HotelFeeView");
             decimal hotelCNYTotalCost = 0.00M;
 
+            //地接费用相关 
+            var OPFeeSheet = worksheets["地接费用"];
+            var OPFeeDt = new DataTable($"OPFeeView");
+            var OPFeeLabel = string.Empty;
+            decimal OPCNYTotalCost = 0.00M;
+
             //签证费用相关 
             var visaFeeSheet = worksheets["签证费用"];
             var visaFeeDt = new DataTable($"VisaFeeView"); 
@@ -1397,14 +1405,35 @@ ORDER BY
             var otherFeeDt = new DataTable($"OtherFeeView");
             decimal otherCNYTotalCost = 0.00M;
 
+            //收款退还相关 
+            var SKTHFeeSheet = worksheets["收款退还"];
+            var SKTHFeeDt = new DataTable($"SKTHFeeView");
+            decimal SKTHCNYTotalCost = 0.00M;
+
+            var totalAmount = 0.00M;     //支出成本合计
+            var accountsAmount = 0.00M;  //应收金额合计
+            var receivedAmount = 0.00M;  //已收金额合计
+            var accountsProfit = 0.00M;  //应收利润合计
+            var receiveProfit = 0.00M;   //已收利润合计
+            var profitMargin = 0.00M;    //利润差合计
+
+            //应收合计相关
+            var receivableFeeSheet = worksheets["团组收入(未收)"];
+            var receivableFeeDt = new DataTable($"ReceivableFeeView");
+
+            //已收合计相关
+            var receivedFeeSheet = worksheets["团组收入(已收)"];
+            var receivedFeeDt = new DataTable($"ReceivedFeeView");
+
+            //团组收入支出利润
+            var groupIEProfitDt = new DataTable($"IEProfitFeeView");
+            
             #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,
@@ -1464,119 +1493,233 @@ ORDER BY
 
                 var groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
 
-                var hotelSubIds = groupHotelFeeViews.Select(it => it.HrId).ToList();
+                if (groupHotelFeeViews.Any())
+                {
+                    var _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
 
-                var groupHotelContentFeeViews = await _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => hotelSubIds.Contains(it.HrId)).ToListAsync();
+                    var hotelSubIds = groupHotelFeeViews.Select(it => it.HrId).ToList();
 
-                var teamRateData = await _teamRateRep.PostGroupRateInfoByDiId(_dto.DiId);
-                foreach (var item in groupHotelFeeViews)
-                {
-                    if (groupHotelContentFeeViews.Count > 0)
+                    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;
+                            string paymentStr = string.Empty;
 
-                        var roomData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 1); //房费 
+                            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.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/>
+                                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); //早餐 
+                            var breakfastData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 2); //早餐 
 
-                        item.BreakfastPrice = breakfastData?.Price ?? 0.00M;
+                            item.BreakfastPrice = breakfastData?.Price ?? 0.00M;
 
-                        if (item.BreakfastPrice != 0)
-                        {
-                            if (breakfastData.IsPay == 0) paymentStr += $"早餐:未付款<br/>";
+                            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/>
+                                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); //地税
+                            var landTaxData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 3); //地税
 
-                        item.GovernmentRent = landTaxData?.Price ?? 0.00M;
+                            item.GovernmentRent = landTaxData?.Price ?? 0.00M;
 
-                        if (item.GovernmentRent != 0)
-                        {
-                            if (landTaxData.IsPay == 0) paymentStr += $"地税:未付款<br/>";
+                            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/>
+                                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); //城市税 
+                            var cityTaxData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 4); //城市税 
 
-                        item.CityTax = cityTaxData?.Price ?? 0.00M;
+                            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/>
+                            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;
                         }
 
-                        if (!string.IsNullOrEmpty(paymentStr))
+                        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 (OPFeeSheet != null)
+            {
+                string CTGGRFeeSql = string.Empty;
+                if (groupInfo.VisitDate > Convert.ToDateTime("2024-04-17"))
+                {
+                    CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.PriceName As Area,ctggrc.*,ctggrc.Price As PayMoney,
+                                                     sd2.name As PaymentCurrency,ccp.PayPercentage,
+                                                     (ctggrc.Price * (ccp.PayPercentage / 100)) As AmountPaid,
+                                                     (ctggrc.Price - ctggrc.Price * (ccp.PayPercentage / 100)) As BalancePayment,
+                                                     ccp.DayRate,(ctggrc.Price * (ccp.PayPercentage / 100) * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
+                                                     ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
+                                                     From Grp_CarTouristGuideGroundReservations ctggr
+                                                     Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price*cggrc.Count As Price,sd2.Name As PriceCurrency,
+                                                                        cggrc.DatePrice,cggrc.PriceContent
+                                                             From Grp_CarTouristGuideGroundReservationsContent cggrc
+                                                             Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
+                                                             Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
+                                                             Where cggrc.ISdel = 0 And cggrc.Price != 0.00 
+                                                             ) ctggrc On ctggr.Id = ctggrc.CTGGRId 
+                                                     Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0  And ccp.CTable = 79 And ctggr.Id = ccp.CId
+                                                     Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
+                                                     Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
+                                                     Left Join Sys_Users u On ccp.CreateUserId = u.Id
+                                                     Where ctggr.IsDel = 0 {1} And ctggr.DiId = {0}
+                                                     Order By CreateTime", _dto.DiId, _dto.isAudit ? "And (ccp.IsAuditGM = 1 OR ccp.IsAuditGM = 3)" : " ");
+                }
+                else
+                {
+                    CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.PriceName As Area,
+													 ccp.PayMoney,sd2.name As PaymentCurrency,ccp.PayPercentage,
+													 (ccp.PayMoney * (ccp.PayPercentage / 100)) As AmountPaid,
+													 (ccp.PayMoney -ccp.PayMoney * (ccp.PayPercentage / 100)) As BalancePayment,
+                                                     ccp.DayRate,(ccp.PayMoney * (ccp.PayPercentage / 100) * ccp.DayRate) As CNYPrice,
+													 ccp.Payee,ccp.AuditGMDate,
+                                                     ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
+                                                     From Grp_CarTouristGuideGroundReservations ctggr
+                                                     Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0  And ccp.CTable = 79 And ctggr.Id = ccp.CId
+                                                     Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
+                                                     Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
+                                                     Left Join Sys_Users u On ccp.CreateUserId = u.Id
+                                                     Where ctggr.IsDel = 0 {1} And ctggr.DiId = {0}
+                                                     Order By CreateTime", _dto.DiId, _dto.isAudit ? "And (ccp.IsAuditGM = 1 OR ccp.IsAuditGM = 3)" : " ");
+                }
+
+                var groupOPFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
+                string CTGGRFeeStr = "";
+                var OPToDataTableViews = groupOPFeeViews;
+                
+                decimal CTGGRCNYTotalPrice = 0.00M;
+
+                //按1 地区,2 币种,3 汇率 分组计算
+                var groupCTGGRFeeDatas = groupOPFeeViews.GroupBy(it => it.Area);
+
+                foreach (var ctggfr in groupCTGGRFeeDatas)
+                {
+                    var ctggfr_curr = ctggfr.GroupBy(it => it.PaymentCurrency);
+
+                    if (ctggfr_curr.Count() > 0)
+                    {
+                        foreach (var curr in ctggfr_curr)
                         {
-                            item.IsPay = 2;
-                            item.PayTips = paymentStr;
+
+                            var ctggfr_rate = curr.GroupBy(it => it.DayRate);
+
+                            if (ctggfr_rate.Count() > 0)
+                            {
+                                foreach (var rate in ctggfr_rate)
+                                {
+                                    CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{rate.Sum(it => it.AmountPaid).ToString("#0.00")} {rate.FirstOrDefault()?.PaymentCurrency}(人民币:{rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:{rate.FirstOrDefault()?.DayRate.ToString("#0.0000")})\n");
+                                    CTGGRCNYTotalPrice += rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
+                                }
+                            }
+                            else
+                            {
+                                CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{curr.Sum(it => it.AmountPaid).ToString("#0.00")} {curr.FirstOrDefault()?.PaymentCurrency}(人民币:{curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:{curr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\n");
+                                CTGGRCNYTotalPrice += curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
+                            }
                         }
-                        //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;
+                        CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{ctggfr.Sum(it => it.AmountPaid).ToString("#0.00")} {ctggfr.FirstOrDefault()?.PaymentCurrency}(人民币:{ctggfr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:{ctggfr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\n");
+                        CTGGRCNYTotalPrice += ctggfr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
                     }
+                }
 
-                    item.PayMoney = item.PayMoney.ConvertToDecimal1();
-                    item.CNYPrice = item.CNYPrice.ConvertToDecimal1();
+                foreach (var item in groupOPFeeViews)
+                {
+                    if (!string.IsNullOrEmpty(item.AuditGMDate))
+                    {
+                        item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
+                    }
+
+                    if (item.DatePrice != null)
+                    {
+                        item.PriceName = $"{item.PriceName}({Convert.ToDateTime(item.DatePrice).ToString("yyyy-MM-dd")})";
+                    }
                 }
 
-                hotelCNYTotalCost = groupHotelFeeViews.Sum(x => x.CNYPrice);
-                hotelFeeDt = CommonFun.ToDataTableArray(groupHotelFeeViews);
-                hotelFeeDt.TableName = $"HotelFeeView";
+                OPCNYTotalCost = CTGGRCNYTotalPrice;
+                OPFeeDt = CommonFun.ToDataTableArray(OPToDataTableViews);
+                OPFeeLabel = CTGGRFeeStr;
+                OPFeeDt.TableName = $"OPFeeView";
             }
 
             #endregion
@@ -1791,6 +1934,160 @@ ORDER BY
 
             #endregion
 
+            #region 收款退还
+
+            if (SKTHFeeSheet != null)
+            {
+                //删除了  And prom.PriceType = 1
+                string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
+										         prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
+										         prom.PayType As PrPayType,prom.PriceType As PrPriceType,
+												 ccp.RMBPrice * ccp.DayRate As RMBPrice,ccp.*,prom.CreateTime As PrCreateTime,prom.Remark AS SKTHRemark
+										         From Fin_PaymentRefundAndOtherMoney prom
+										         Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
+										         Left Join Sys_Users u On ccp.CreateUserId = u.Id
+										         Where prom.IsDel = 0  
+                                                 And prom.PayType = 1 
+                                                 And ccp.CTable = 285
+										         {1} 
+										         And prom.DiId = {0} Order By PrCreateTime", _dto.DiId, _dto.isAudit ? "And ccp.IsAuditGM = 1" : " ");
+                var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
+
+                if (_promDatas.Any())
+                {
+                    var _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
+                    var _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
+
+                    foreach (var ropItem in _promDatas)
+                    {
+                        string thisCueencyCode = "Unknown";
+                        string thisCueencyName = "Unknown";
+                        var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
+                        if (currency != null)
+                        {
+                            thisCueencyCode = currency.Name;
+                            thisCueencyName = currency.Remark;
+                        }
+
+                        string orbitalPrivateTransferStr = "Unknown";
+                        var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
+                        if (orbitalPrivateTransfer != null)
+                        {
+                            orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
+                        }
+
+                        string payStr = "Unknown";
+                        var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
+                        if (pay != null)
+                        {
+                            payStr = pay.Name;
+                        }
+
+                        var gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
+                        {
+                            Id = ropItem.Id,
+                            DiId = ropItem.DIId,
+                            PriceName = ropItem.PrPriceName,
+                            PayCurrencyCode = thisCueencyCode,
+                            PayCurrencyName = thisCueencyName,
+                            Price = ropItem.PrPrice,
+                            CNYPrice = ropItem.PayMoney * ropItem.DayRate,
+                            ThisRate = ropItem.DayRate,
+                            Payee = ropItem.Payee,
+                            PayTime = ropItem.AuditGMDate,
+                            OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
+                            PayType = payStr,
+                            IsPay = ropItem.IsPay,
+                            Applicant = ropItem.Appliction,
+                            Remark = ropItem.SKTHRemark
+                        };
+
+                        _promView.Add(gsd_PaymentRefund);
+                    }
+
+                    SKTHCNYTotalCost = _promView.Sum(x => x.CNYPrice);
+                    SKTHFeeDt = CommonFun.ToDataTableArray(_promView);
+                    SKTHFeeDt.TableName = $"SKTHFeeView";
+                }
+
+            }
+
+            #endregion
+
+            #region 应收金额(增加方式=实际报价时 费用必须审核才能进入团组报表)
+            decimal frTotalAmount = 0.00M;//应收总金额
+            string _frSql = string.Format(@"  Select fr.Id,fr.AddingWay,fr.Status,u.CnName As Auditor,fr.AuditTime,fr.Diid,fr.PriceName,fr.Price,fr.Count,fr.Unit,fr.Currency,
+										        sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice,fr.CreateTime,fr.Remark
+										        From Fin_ForeignReceivables fr
+										        Left Join Sys_SetData sd On fr.Currency = sd.Id
+												Left Join Sys_Users u On fr.Auditor = u.Id
+										        Where fr.IsDel = 0 And fr.Diid = {0} Order By CreateTime", _dto.DiId);
+           var _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
+
+            _frViews.ForEach(x =>
+            {
+                string namePrefix = string.Empty;
+                if (x.AddingWay == 0) namePrefix = $"账单模块-";
+                else if (x.AddingWay == 1) namePrefix = $"成本预算模块-";
+                else if (x.AddingWay == 2) namePrefix = $"实际报价-";
+                x.PriceName = $"{namePrefix}{x.PriceName}";
+            });
+
+            if (_frViews.Any())
+            {
+                accountsAmount = _frViews.Sum(it => it.ItemSumPrice);
+                receivableFeeDt = CommonFun.ToDataTableArray(_frViews);
+                receivableFeeDt.TableName = $"ReceivedFeeView";
+            }
+
+            #endregion
+
+            #region 已收金额
+            decimal prTotalAmount = 0.00M;//已收总金额
+            string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime As SectionTimeDt,pr.Price,pr.Currency,
+										        sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
+										        pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark,pr.CreateTime
+										        From Fin_ProceedsReceived  pr
+										        Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
+										        Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
+										        Where pr.IsDel = 0 and pr.Diid = {0} Order By CreateTime", _dto.DiId);
+            var _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
+            
+            if (_prViews.Any())
+            {
+                receivedAmount = _prViews.Sum(it => it.Price);
+                receivedFeeDt = CommonFun.ToDataTableArray(_prViews);
+                receivedFeeDt.TableName = $"ReceivableFeeView";
+            }
+
+            #endregion
+
+            #region 团组收入支出利润
+            groupIEProfitDt.Columns.AddRange(new DataColumn[] {
+                            new DataColumn(){ ColumnName = "ModuleName"},
+                            new DataColumn(){ ColumnName = "FeeTotal",DataType = typeof(decimal)},
+                            new DataColumn(){ ColumnName = "FeeCurrency"},
+                        });
+
+            var groupIEProfitDt_rows = new[] {
+                new object[] { $"签证费用", visaCNYTotalCost, $"CNY" },
+                new object[] { $"酒店费用", hotelCNYTotalCost, $"CNY" },
+                new object[] { $"地接费用", OPCNYTotalCost, $"CNY" },
+                new object[] { $"商邀费用", OACNYTotalCost, $"CNY" },
+                new object[] { $"机票费用", airTicketCNYTotalCost, $"CNY" },
+                new object[] { $"保险费用", insureCNYTotalCost, $"CNY" },
+                new object[] { $"其他费用", otherCNYTotalCost, $"CNY" },
+                new object[] { $"收款退还费用", SKTHCNYTotalCost, $"CNY" },
+            };
+
+            // 批量添加
+            foreach (var rowData in groupIEProfitDt_rows)
+            {
+                groupIEProfitDt.Rows.Add(rowData);
+            }
+
+            #endregion
+
             #region 统一填充数据源
             designer.SetDataSource("GroupNo", groupNo);
             designer.SetDataSource("GroupName", groupName);
@@ -1800,156 +2097,129 @@ ORDER BY
             designer.SetDataSource(hotelFeeDt);
             designer.SetDataSource("HotelCNYTotalCost", $"{hotelCNYTotalCost.ToString("#0.00")} CNY");
 
+            //地接
+            designer.SetDataSource(OPFeeDt);
+            designer.SetDataSource("OPFeeLabel", OPFeeLabel);
+            designer.SetDataSource("OPCNYTotalCost", $"{OPCNYTotalCost.ToString("#0.00")} CNY");
+
             //签证
             designer.SetDataSource(visaFeeDt);
             designer.SetDataSource("VisaCNYTotalCost", $"{visaCNYTotalCost.ToString("#0.00")} CNY");
+
             //商邀
             designer.SetDataSource(OAFeeDt);
             designer.SetDataSource("OACNYTotalCost", $"{OACNYTotalCost.ToString("#0.00")} CNY");
+
             //机票
             designer.SetDataSource(airTicketFeeDt);
             designer.SetDataSource("AirTicketCNYTotalCost", $"{airTicketCNYTotalCost.ToString("#0.00")} CNY");
+
             //保险
             designer.SetDataSource(insureFeeDt);
             designer.SetDataSource("InsureCNYTotalCost", $"{insureCNYTotalCost.ToString("#0.00")} CNY");
+
             //其他费用
             designer.SetDataSource(otherFeeDt);
             designer.SetDataSource("OtherCNYTotalCost", $"{otherCNYTotalCost.ToString("#0.00")} CNY");
 
+            //收款退还
+            designer.SetDataSource(SKTHFeeDt);
+            designer.SetDataSource("SKTHCNYTotalCost", $"{SKTHCNYTotalCost.ToString("#0.00")}");
+
+            //已收金额
+            designer.SetDataSource(receivedFeeDt);
+            designer.SetDataSource("ReceivedAmount", $"{receivedAmount.ToString("#0.00")}");
+
+            //应收金额
+            designer.SetDataSource(receivableFeeDt);
+            designer.SetDataSource("AccountsAmount", $"{accountsAmount.ToString("#0.00")}");
+
+            //应收已收 -- 尾款
+            var balancePayment = accountsAmount - SKTHCNYTotalCost - receivedAmount;
+            designer.SetDataSource("BalancePayment", $"{balancePayment.ToString("#0.00")}");
+
+            //团组收入支出利润
+            designer.SetDataSource(groupIEProfitDt);
+            #region 各项费用计算
+            /* 
+             * 团组报表计算方式
+             * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
+             * 应收金额 = 应收表.Sum() - 收款退还
+             * 已收金额 = 已收表.Sum() - 收款退还
+             * 应收利润(应收-支出) = 应收金额 - 当前总支出
+             * 已收利润(已收-支出) = 已收金额 - 当前总支出
+             * 利润差 = 应收利润 - 已收利润
+             */
+
+            totalAmount = visaCNYTotalCost + hotelCNYTotalCost + OPCNYTotalCost + OACNYTotalCost + airTicketCNYTotalCost + insureCNYTotalCost + otherCNYTotalCost;//合计金额
+            accountsProfit = accountsAmount - totalAmount - SKTHCNYTotalCost;   //应收利润
+            receiveProfit = receivedAmount - totalAmount - SKTHCNYTotalCost; //已收利润
+            profitMargin = accountsProfit - receiveProfit;   //利润差
+
+            designer.SetDataSource("TotalAmount", $"{totalAmount.ToString("#0.00")}");
+            designer.SetDataSource("AccountsProfit", $"{accountsProfit.ToString("#0.00")}");
+            designer.SetDataSource("ReceiveProfit", $"{receiveProfit.ToString("#0.00")}");
+            designer.SetDataSource("ProfitMargin", $"{profitMargin.ToString("#0.00")}");
+            #endregion
+
             designer.Process();
 
             #endregion
 
             #region 单元格样式设置  未付款设置为红色
+
             /*
-            * 设置单元格样式
-            */
+             * 设置单元格样式
+             */
             //背景颜色
             Style style = designer.Workbook.CreateStyle();
-            style.ForegroundColor = Color.FromArgb(255, 182, 193);
+            style.ForegroundColor = Color.FromArgb(254, 242, 203);
             style.Pattern = BackgroundType.Solid;
             //字体
             style.Font.Name = "微软雅黑";                   // 字体名称
             style.Font.Size = 10;                           // 字体大小
             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)) continue;
-
-                if (isPayStr.Equals("未付款"))
-                {
-                    var excelIndex = 6 + i;
-
-                    if (visaFeeSheet != null)
-                    {
-                        Aspose.Cells.Range range = visaFeeSheet.Cells.CreateRange($"A{excelIndex}", $"I{excelIndex}");
-                        range.ApplyStyle(style, new StyleFlag() { CellShading = true, Font = true });
-                    }
-                }
-            }
-            #endregion
-
-            #region 商邀费用单元格
-            for (int i = 0; i < OAFeeDt.Rows.Count; i++)
-            {
-                var isPayStr = OAFeeDt.Rows[i]["IsPay"].ToString();
-                if (string.IsNullOrEmpty(isPayStr)) continue;
-                if (isPayStr.Equals("未付款"))
-                {
-                    var excelIndex = 6 + i;
-
-                    if (OAFeeSheet != null)
-                    {
-                        Aspose.Cells.Range range = OAFeeSheet.Cells.CreateRange($"A{excelIndex}", $"R{excelIndex}");
-                        range.ApplyStyle(style, new StyleFlag() { CellShading = true, Font = true });
-                    }
-                }
-            }
+            StatementExportExcelSetCell(designer, hotelFeeSheet, hotelFeeDt, style, "IsPayLable", 8, "A", "V");    //酒店
+            StatementExportExcelSetCell(designer, OPFeeSheet, OPFeeDt, style, "IsPayLabel", 6, "A", "M");          //OP
+            StatementExportExcelSetCell(designer, visaFeeSheet, visaFeeDt, style, "IsPay", 6, "A", "I");           //签证
+            StatementExportExcelSetCell(designer, OAFeeSheet, OAFeeDt, style, "IsPay", 6, "A", "R");               //商邀
+            StatementExportExcelSetCell(designer, airTicketFeeSheet, airTicketFeeDt, style, "IsPay", 6, "A", "M"); //机票
+            StatementExportExcelSetCell(designer, insureFeeSheet, insureFeeDt, style, "IsPay", 6, "A", "I");       //保险
+            StatementExportExcelSetCell(designer, otherFeeSheet, otherFeeDt, style, "IsPay", 6, "A", "J");         //其他
+            StatementExportExcelSetCell(designer, SKTHFeeSheet, SKTHFeeDt, style, "IsPayLable", 6, "A", "K");      //首款退还
             #endregion
 
-            #region 机票费用单元格
-            for (int i = 0; i < airTicketFeeDt.Rows.Count; i++)
-            {
-                var isPayStr = airTicketFeeDt.Rows[i]["IsPay"].ToString();
-                if (string.IsNullOrEmpty(isPayStr)) continue;
-
-                if (isPayStr.Equals("未付款"))
-                {
-                    var excelIndex = 6 + i;
-                    if (airTicketFeeSheet != null)
-                    {
-                        Aspose.Cells.Range range = airTicketFeeSheet.Cells.CreateRange($"A{excelIndex}", $"M{excelIndex}");
-                        range.ApplyStyle(style, new StyleFlag() { CellShading = true, Font = true });
-                    }
-                }
-            }
-            #endregion
-
-            #region 保险费用单元格
-            for (int i = 0; i < insureFeeDt.Rows.Count; i++)
-            {
-                var isPayStr = insureFeeDt.Rows[i]["IsPay"].ToString();
-                if (string.IsNullOrEmpty(isPayStr)) continue;
+            //文件名
+            string fileName = $"{groupName}[{groupNo}]_团组费用清单{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
+            designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "GroupStatement/" + fileName);
+            string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/GroupStatement/" + fileName;
+            return Ok(JsonView(true, "成功", url));
+        }
 
-                if (isPayStr.Equals("未付款"))
-                {
-                    var excelIndex = 6 + i;
-                    if (insureFeeSheet != null)
-                    {
-                        Aspose.Cells.Range range = insureFeeSheet.Cells.CreateRange($"A{excelIndex}", $"I{excelIndex}");
-                        range.ApplyStyle(style, new StyleFlag() { CellShading = true, Font = true });
-                    }
-                }
-            }
-            #endregion
 
-            #region 其他费用单元格
-            for (int i = 0; i < otherFeeDt.Rows.Count; i++)
+        private void StatementExportExcelSetCell(WorkbookDesigner designer, Worksheet sheet,DataTable dt, Style style,string judgeLable,  int startIndex, string startRange,string endRange)
+        {
+            if (designer == null) return;
+            if (sheet == null) return;
+            if (style == null) return;
+            if (dt == null) return;
+            if (string.IsNullOrEmpty(startRange)) return;
+            if (string.IsNullOrEmpty(endRange)) return;
+
+            for (int i = 0; i < dt.Rows.Count; i++)
             {
-                var isPayStr = otherFeeDt.Rows[i]["IsPay"].ToString();
+                var isPayStr = dt.Rows[i][$"{judgeLable}"].ToString();
                 if (string.IsNullOrEmpty(isPayStr)) continue;
 
-                if (isPayStr.Equals("未付款"))
+                if (isPayStr.Contains("未付款"))
                 {
-                    var excelIndex = 6 + i;
-                    if (otherFeeSheet != null)
-                    {
-                        Aspose.Cells.Range range = otherFeeSheet.Cells.CreateRange($"A{excelIndex}", $"J{excelIndex}");
-                        range.ApplyStyle(style, new StyleFlag() { CellShading = true, Font = true });
-                    }
+                    var excelIndex = startIndex + i;
+                    Aspose.Cells.Range range = sheet.Cells.CreateRange($"{startRange}{excelIndex}", $"{endRange}{excelIndex}");
+                    range.ApplyStyle(style, new StyleFlag() { CellShading = true, Font = true });
                 }
             }
-            #endregion
-
-            #endregion
 
-            //文件名
-            string fileName = $"{groupName}[{groupNo}]_团组费用清单{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
-            designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "GroupStatement/" + fileName);
-            string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/GroupStatement/" + fileName;
-            return Ok(JsonView(true, "成功", url));
         }
 
         #endregion

+ 49 - 6
OASystem/OASystem.Domain/ViewModels/Statistics/GroupStatementView.cs

@@ -280,6 +280,8 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// 应收金额
         /// </summary>
         public decimal ItemSumPrice { get; set; } = 0.00M;
+
+        public string Remark { get; set; }
     }
 
     /// <summary>
@@ -474,7 +476,15 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// 费用标识
         /// -1 未选择 0 公转 1 私转
         /// </summary>
-        public int? OrbitalPrivateTransfer { get; set; }
+        public int OrbitalPrivateTransfer { get; set; }
+
+        public string CostMark
+        {
+            get
+            {
+                return OrbitalPrivateTransfer == 0 ? "公转" : OrbitalPrivateTransfer == 1 ? "私转" : "-";
+            }
+        }
 
         /// <summary>
         /// 支付方式
@@ -487,10 +497,21 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// </summary>
         public int IsPay { get; set; }
 
+        public string IsPayLable
+        {
+            get
+            {
+                return IsPay == 0 ? "未付款" : IsPay == 1 ? "已付款" : "-";
+            }
+        }
+
+
         /// <summary>
         /// 申请人
         /// </summary>
         public string? Applicant { get; set; }
+
+        public string Remark { get; set; }
     }
 
     #region 收款退还 View
@@ -509,6 +530,7 @@ namespace OASystem.Domain.ViewModels.Statistics
         public int PrCurrencyId { get; set; }
         public int PrPayType { get; set; }
         public int PrPriceType { get; set; }
+        public string SKTHRemark { get; set; }
     };
 
     #endregion
@@ -827,10 +849,10 @@ namespace OASystem.Domain.ViewModels.Statistics
         {
             get
             {
-                var label = string.Empty;
-                if (IsPay == 1) label = "未付款";
-                else if (IsPay == 2) label = "已付款";
-                else if (IsPay == 3) label = "其它费用子项未付款";
+                var label = $"未选择";
+                if (IsPay == 0) label = "未付款";
+                else if (IsPay == 1) label = "已付款";
+                else if (IsPay == 2) label = "其它费用子项未付款";
                 return label;
             }
         }
@@ -899,7 +921,7 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// <summary>
         /// 消费日期
         /// </summary>
-        public DateTime? DatePrice { get; set; }
+        public DateTime DatePrice { get; set; }
 
         /// <summary>
         /// 当时汇率
@@ -927,6 +949,17 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// </summary>
         public int OrbitalPrivateTransfer { get; set; }
 
+        /// <summary>
+        /// 费用标识Text
+        /// </summary>
+        public string CostMark
+        {
+            get
+            {
+                return OrbitalPrivateTransfer == 0 ? "公转" : OrbitalPrivateTransfer == 1 ? "私转" : "-";
+            }
+        }
+
         /// <summary>
         /// 支付方式
         /// </summary>
@@ -938,6 +971,16 @@ namespace OASystem.Domain.ViewModels.Statistics
         /// </summary>
         public int IsPay { get; set; }
 
+
+        public string IsPayLabel
+        {
+            get
+            {
+                return IsPay == 0 ? "未付款" : IsPay == 1 ? "已付款" : "-";
+            }
+        }
+
+
         /// <summary>
         /// 操作人
         /// </summary>