Forráskód Böngészése

OP导入超支名称修改, 添加导游超时费用,修改餐费匹配方式

yuanrf 10 hónapja%!(EXTRA string=óta)
szülő
commit
069d28cc6b

+ 109 - 19
OASystem/OASystem.Infrastructure/Repositories/Groups/CarTouristGuideGroundRepository.cs

@@ -25,14 +25,16 @@ namespace OASystem.Infrastructure.Repositories.Groups
         private readonly CheckBoxsRepository _checkRep;
         private readonly SetDataRepository _setDataRep;
         private readonly DailyFeePaymentRepository _daiRep;    //日付申请仓库
+        private readonly GroupCostParameterRepository _groupCostParameterRepository;
 
-        public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper, CheckBoxsRepository checkRep, SetDataRepository setDataRep, DailyFeePaymentRepository daiRep)
+        public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper, CheckBoxsRepository checkRep, SetDataRepository setDataRep, DailyFeePaymentRepository daiRep, GroupCostParameterRepository groupCostParameterRepository)
             : base(sqlSugar)
         {
             _mapper = mapper;
             _checkRep = checkRep;
             _setDataRep = setDataRep;
             _daiRep = daiRep;
+            _groupCostParameterRepository = groupCostParameterRepository;
         }
 
         public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
@@ -731,6 +733,8 @@ namespace OASystem.Infrastructure.Repositories.Groups
 
                     //车超时费
                     //餐费和三公经费那个表做完匹配后也放进超支表里
+                    //添加导游超时费用
+
                     DataTable tb = new DataTable();
                     tb.Columns.Add("日期", typeof(DateTime));
                     tb.Columns.Add("费用", typeof(decimal));
@@ -738,6 +742,46 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     var addsTourClientList = new List<Grp_TourClientList>();
                     var carExtraList = carTouristList.Where(x => x.SId == 982 && x.Price != 0).ToList();
                     var mealPriceList = carTouristList.Where(x => (x.SId == 93 || x.SId == 988 || x.SId == 989) && x.Price != 0).GroupBy(x => x.DatePrice).ToList();
+                    var tgOvertime = carExtraList.Where(x => x.SId == 1059 && x.Price != 0 ).ToList();
+
+                    //成本数据
+                    List<Grp_GroupCost> _GroupCosts = new List<Grp_GroupCost>();
+
+                    var _GroupCostParameters = _groupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.DiId);
+
+                    if (_GroupCostParameters != null && _GroupCostParameters.IsShare == 1)
+                    {
+                        _GroupCosts = _sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
+                    }
+
+                    //处理date为空问题
+                    if (_GroupCosts.Count > 0)
+                    {
+                        for (int i = 0; i < _GroupCosts.Count; i++)
+                        {
+                            if (string.IsNullOrEmpty(_GroupCosts[i].Date))
+                            {
+                                if (i > 0)
+                                {
+                                    _GroupCosts[i].Date = _GroupCosts[i - 1].Date;
+                                }
+                            }
+                        }
+
+                        var CostSoure = _GroupCosts.GroupBy(x => x.Date).ToList();
+
+                        _GroupCosts.Clear();
+
+                        foreach (var costSoure in CostSoure)
+                        {
+                            var cost = costSoure.ToList();
+                            cost[0].D = cost.Sum(x => x.D);
+                            cost[0].B = cost.Sum(x => x.B);
+                            cost[0].L = cost.Sum(x => x.L);
+                            _GroupCosts.Add(cost[0]);
+                        }
+                    }
+
                     mealPriceList.ForEach(x =>
                     {
                         var row = tb.NewRow();
@@ -792,7 +836,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                                 Coefficient = 1,
                                 DiId = dto.DiId,
                                 PriceCurrency = item.Currency,
-                                PriceName = di.TeamName + priceCity + "车超时费(地接导入)",
+                                PriceName = di.TeamName +"-"+ priceCity + "-" + "车超时费(地接导入)",
                                 PriceType = 1028,
                                 PriceDt = item.DatePrice.ObjToDate(),
                                 PriceSum = item.Price * item.Count,
@@ -803,33 +847,80 @@ namespace OASystem.Infrastructure.Repositories.Groups
                         }
                     }
 
-                    if (cityPrice != null)
+                    //导游超时费用
+                    if (tgOvertime.Count > 0)
+                    {
+                        foreach (var item in tgOvertime)
+                        {
+                            groupExtraCostsArr.Add(new Fin_GroupExtraCost
+                            {
+                                Price = item.Price,
+                                CreateTime = DateTime.Now,
+                                CreateUserId = dto.CreateUserId,
+                                Coefficient = 1,
+                                DiId = dto.DiId,
+                                PriceCurrency = item.Currency,
+                                PriceName = di.TeamName + "-" + priceCity + "-" + "导游超时费(地接导入)",
+                                PriceType = 1028,
+                                PriceDt = item.DatePrice.ObjToDate(),
+                                PriceSum = item.Price * item.Count,
+                                PriceCount = item.Count,
+                                FilePath = string.Empty,
+                                PriceDetailType = 1072,
+                            });
+                        }
+                    }
+
+                    if (_GroupCostParameters != null)
                     {
                         //币种
                         var currOpResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, carTouristList[0].Currency);
                         var currOp = currOpResult.Code == 0 ? (currOpResult.Data as CurrencyInfo) == null ? 1 : (currOpResult.Data as CurrencyInfo)!.Rate : 1;
-                        var cityCurrResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, cityPrice.Currency);
-                        var cityCurr = cityCurrResult.Code == 0 ? (cityCurrResult.Data as CurrencyInfo) == null ? 1 : (cityCurrResult.Data as CurrencyInfo)!.Rate : 1;
+
+                        //三公费用汇率 (修改为对比成本)
+                        //var cityCurrResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, cityPrice.Currency);
+                        //var cityCurr = cityCurrResult.Code == 0 ? (cityCurrResult.Data as CurrencyInfo) == null ? 1 : (cityCurrResult.Data as CurrencyInfo)!.Rate : 1;
+
+                        //成本汇率
+                        var costCurr = _GroupCostParameters.Rate;
 
                         if (tb.Rows.Count > 0)
                         {
                             foreach (DataRow item in tb.Rows)
                             {
-                                decimal foodCost = 1;
-                                if (!decimal.TryParse(cityPrice.FoodCost, out foodCost))
-                                {
-                                    //三公费用 ( 城市餐费用有问题! )
-                                }
+                                var listTime =  Convert.ToDateTime(item["日期"]);
+                                var costFliterArr = _GroupCosts.Where(x => DateTime.TryParse(x.Date, out DateTime costData) 
+                                && costData.ToString("yyyy-MM-dd") == listTime.ToString("yyyy-MM-dd")).ToList();
+
+                                //成本日期费用
+                                decimal foodCost = (costFliterArr.Sum(x=>x.D) + costFliterArr.Sum(x => x.L) + costFliterArr.Sum(x => x.B)) * di.VisitPNumber;
 
                                 var price = Convert.ToDecimal(item["费用"]);
-                                if (item["币种"].ToString() != cityPrice.Currency.ToString()) //币种不相同
+                                if (item["币种"].ToString() != _GroupCostParameters.Currency.ToString().Trim()) //币种不相同
                                 {
-                                    //全部转换为rmb;
-                                    item["费用"] = price * currOp;
-                                    foodCost = (foodCost * cityCurr);
+                                    var a = item["币种"].ToString();
+                                    var b = _GroupCostParameters.Currency.ToString().Trim();
 
-                                    item["币种"] = "836";
-                                    cityPrice.Currency = 836;
+                                    //币种str匹配不上在匹配Name
+                                    if (int.TryParse(a,out int a1))
+                                    {
+                                        a = _sqlSugar.Queryable<Sys_SetData>().First(x=>x.IsDel ==0 && x.Id == a1).Name; 
+                                    }
+
+                                    if (int.TryParse(b, out int b1))
+                                    {
+                                        b = _sqlSugar.Queryable<Sys_SetData>().First(x => x.IsDel == 0 && x.Id == b1).Name;
+                                    }
+
+                                    if (a != b) 
+                                    {
+                                        //全部转换为rmb;
+                                        item["费用"] = price * currOp;
+                                        foodCost = (foodCost * costCurr);
+
+                                        item["币种"] = "836";
+                                        //cityPrice.Currency = 836;
+                                    }
                                 }
 
                                 if (price > foodCost)
@@ -842,8 +933,8 @@ namespace OASystem.Infrastructure.Repositories.Groups
                                         CreateUserId = dto.CreateUserId,
                                         Coefficient = 1,
                                         DiId = dto.DiId,
-                                        PriceCurrency = cityPrice.Currency,
-                                        PriceName = di.TeamName + priceCity + "餐费(地接导入)",
+                                        PriceCurrency = Convert.ToInt32(item["币种"]),
+                                        PriceName = di.TeamName + "-" + priceCity + "-" + "餐费(地接导入)",
                                         PriceType = 1028,
                                         PriceDt = Convert.ToDateTime(item["日期"]),
                                         PriceSum = price - foodCost,
@@ -851,7 +942,6 @@ namespace OASystem.Infrastructure.Repositories.Groups
                                         FilePath = string.Empty,
                                         PriceDetailType = 1049,
                                     });
-
                                 }
                             }
                         }