Bladeren bron

地接导入超支部分完善

yuanrf 8 maanden geleden
bovenliggende
commit
ef0c003063

+ 101 - 12
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -25,6 +25,7 @@ using OASystem.Domain.ViewModels.Groups;
 using OASystem.Infrastructure.Repositories.Financial;
 using OASystem.Infrastructure.Repositories.Groups;
 using OfficeOpenXml;
+using Org.BouncyCastle.Math;
 using SqlSugar.Extensions;
 using System.Collections;
 using System.Data;
@@ -59,7 +60,7 @@ namespace OASystem.API.Controllers
         /// </summary>
         public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
             TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
-            PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient, DelegationInfoRepository delegationInfoRep)
+            PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient, DelegationInfoRepository delegationInfoRep, SetDataRepository setDataRep)
         {
             _mapper = mapper;
             _config = configuration;
@@ -72,6 +73,7 @@ namespace OASystem.API.Controllers
             _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
             _httpClient = httpClient;
             _delegationInfoRep = delegationInfoRep;
+            _setDataRep = setDataRep;
         }
 
         #region 日付申请
@@ -3768,13 +3770,33 @@ Group by PriceType ", dto.diId);
                 return Ok(JsonView(false, "团组信息有误!"));
             }
 
-            var joinTable = _sqlSugar.Queryable<Fin_GroupExtraCost, Grp_CreditCardPayment,Sys_SetData , Grp_NationalTravelFee>((f, c, s, g) => new JoinQueryInfos(
-                    JoinType.Left,f.Id == c.CId && c.CTable == 1015 && c.IsDel == 0 ,
-                    JoinType.Left,c.PaymentCurrency == s.Id && s.IsDel == 0,
-                    JoinType.Left,g.IsDel == 0 && g.Id == f.Area
+            Dictionary<int, int> dicSoure = new
+                 Dictionary<int, int>()
+            {
+                {1077,1074 },
+                {1078,1075 },
+                {1079,1076 }
+            };
+
+            Dictionary<int, int> mealsDic = new Dictionary<int, int>()
+                    {
+                        {988,1074},
+                        {93,1075},
+                        {989,1076},
+                    };
+
+            var joinTable =  _sqlSugar.Queryable<Fin_GroupExtraCost, Grp_CreditCardPayment, Sys_SetData, Grp_NationalTravelFee ,
+                Fin_LocalGuideRelevancyOverspend , Grp_CarTouristGuideGroundReservations, Sys_SetData,Grp_DelegationInfo>((f, c, s, g, r ,l, s1,i) => new JoinQueryInfos(
+                    JoinType.Left, f.Id == c.CId && c.CTable == 1015 && c.IsDel == 0,
+                    JoinType.Left, c.PaymentCurrency == s.Id && s.IsDel == 0,
+                    JoinType.Left, g.IsDel == 0 && g.Id == f.Area,
+                    JoinType.Left, f.Id == r.OverspendId && r.IsDel == 0,
+                    JoinType.Left, l.Id == r.LocalGuideId && l.IsDel == 0,
+                    JoinType.Left, s1.Id == l.toCurr && s1.IsDel == 0,
+                    JoinType.Left, i.Id == l.DiId && i.IsDel == 0
                 ))
-                .Where((f,c,s, g) => f.IsDel == 0 && f.DiId == dto.diId)
-                .Select((f,c,s,g)=> new
+                .Where((f, c, s, g) => f.IsDel == 0 && f.DiId == dto.diId)
+                .Select((f, c, s, g, r, l,s1,i) => new
                 {
                     c.PaymentCurrency,
                     c.DayRate,
@@ -3782,14 +3804,81 @@ Group by PriceType ", dto.diId);
                     f.PriceName,
                     f.Remark,
                     f.PriceCount,
-                    f.Price,
+                    Price = f.Price * f.Coefficient,
                     c.PayMoney,
-                    RMBPrice = c.RMBPrice * f.PriceCount,
+                    RMBPrice = c.RMBPrice * f.Coefficient,
                     Offer = c.RMBPrice * f.PriceCount * f.Coefficient,
                     c.CTable,
                     f.PriceDetailType,
-                    Area = g.Country ?? "未选择地区!"
-                }).ToList();
+                    Area = g.Country ?? "未选择地区!",
+                    l.toCurr,
+                    l.Rate,
+                    toCurrStr = s1.Name,
+                    g.FoodCost,
+                    CarParentId = l.Id,
+                    f.PriceDt,
+                    i.VisitPNumber,
+                    f.DiId,
+                    f.PriceCurrency
+                })
+                .ToList()
+                .Select(x =>
+                {
+                    var costPirce = x.Price;
+
+                    decimal rateValue = x.DayRate;
+                    decimal costRMBPrice = x.RMBPrice;
+                    decimal DayRate = x.DayRate;
+
+                    if (x.VisitPNumber > 0 && x.toCurr != x.PaymentCurrency)
+                    {
+                        decimal.TryParse(x.FoodCost, out decimal cost);
+                        cost /= 2;
+
+                        var rate = _setDataRep.PostCurrencyByDiid(x.DiId, 1015, x.toCurr).Result;
+                        if (rate.Code == 0)
+                        {
+                            var rateData = rate.Data as CurrencyInfo;
+                            if (rateData != null)
+                            {
+                                rateValue = rateData.Rate;
+                            }
+                        }
+
+                        costPirce *= x.Rate;
+                        if (dicSoure.Keys.Contains(x.PriceDetailType))
+                        {
+                            var CarCenter = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(x1 => x1.CTGGRId == x.CarParentId && x1.IsDel == 0
+                            && x1.SId == mealsDic.First(x2 => x2.Value == dicSoure[x.PriceDetailType]).Key ).ToList().First(x1=> (DateTime.Compare(x1.DatePrice.ObjToDate(), x.PriceDt) == 0));
+                            costPirce += (CarCenter.Price * CarCenter.Count);
+                            costPirce = costPirce - x.VisitPNumber * cost;
+                        }
+                        costPirce = Convert.ToInt32(Math.Round(costPirce));
+                        costRMBPrice = Convert.ToInt32(Math.Round(costPirce * rateValue));
+                        DayRate = rateValue;
+                    }
+
+                    return new
+                    {
+                        x.PaymentCurrency,
+                        DayRate,
+                        x.PaymentCurrencyStr,
+                        x.PriceName,
+                        x.Remark,
+                        x.PriceCount,
+                        Price = costPirce,
+                        x.PayMoney,
+                        RMBPrice = costRMBPrice,
+                        Offer = costRMBPrice * x.PriceCount,
+                        x.CTable,
+                        x.PriceDetailType,
+                        x.Area,
+                        x.toCurr,
+                        x.toCurrStr,
+                        ItemPrice = costPirce * x.PriceCount,
+                    };
+                })
+                .ToList();
 
             var PriceDetailTypeArr = new int[] { 1088 , 1074, 1075, 1076 };
             var whereArr = joinTable.Where(x => PriceDetailTypeArr.Contains(x.PriceDetailType)).ToList();
@@ -3806,7 +3895,7 @@ Group by PriceType ", dto.diId);
                 { 2,"Remark" },
                 { 3,"PriceCount" },
                 { 4,"Price" },
-                { 5,"RMBPrice" },
+                { 5,"ItemPrice" },
                 { 6,"DayRate" },
                 { 7,"Offer" },
             };

+ 10 - 0
OASystem/OASystem.Domain/Dtos/Groups/CarTouristGuideGroundDto.cs

@@ -161,6 +161,16 @@ namespace OASystem.Domain.Dtos.Groups
         /// 选中的列
         /// </summary>
         public List<string> SelectCheck { get; set; }
+
+        /// <summary>
+        /// 转换币种
+        /// </summary>
+        public int toCurr { get; set; }
+
+        /// <summary>
+        /// 汇率
+        /// </summary>
+        public decimal Rate { get; set; }
     }
     public class OPContentList
     {

+ 14 - 0
OASystem/OASystem.Domain/Entities/Financial/Fin_LocalGuideRelevancyOverspend.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Entities.Financial
+{
+    public class Fin_LocalGuideRelevancyOverspend:EntityBase
+    {
+        public int LocalGuideId { get; set; }
+        public int OverspendId { get; set; }
+    }
+}

+ 10 - 0
OASystem/OASystem.Domain/Entities/Groups/Grp_CarTouristGuideGroundReservations.cs

@@ -112,5 +112,15 @@ namespace OASystem.Domain.Entities.Groups
         /// 费用名称
         /// </summary>
         public string PriceName { get; set; }
+
+        /// <summary>
+        /// 转换币种
+        /// </summary>
+        public int toCurr { get; set; }
+
+        /// <summary>
+        /// 汇率
+        /// </summary>
+        public decimal Rate { get; set; }
     }
 }

+ 60 - 18
OASystem/OASystem.Infrastructure/Repositories/Groups/CarTouristGuideGroundRepository.cs

@@ -439,6 +439,28 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     _TableInitialization.RemoveAll(x => x.Id == 1070 || x.Id == 1071);
                 }
 
+                //三公费用金额以及币种
+                var boolParse = int.TryParse(grpCarOp.Area, out int natiId);
+                var NationalTravelFee = _sqlSugar.Queryable<Grp_NationalTravelFee>()
+                    .LeftJoin<Sys_SetData>((a, b) => a.Currency == b.Id )
+                    .Where((a, b) => a.IsDel == 0 && b.IsDel == 0)
+                    .Select((a, b) => new
+                    {
+                        a.Id,
+                        a.Currency,
+                        CurrencyStr = b.Name,
+                        a.FoodCost,
+                        a.RoomCost,
+                        a.PublicCost,
+                    })
+                    .First((a) => boolParse == true && a.Id == natiId);
+
+                var rate = new
+                {
+                    grpCarOp.Rate,
+                    grpCarOp.toCurr
+                };
+
                 if (dto.PortType == 1)
                 {
                     var data = new
@@ -452,6 +474,8 @@ namespace OASystem.Infrastructure.Repositories.Groups
                         ssdv,
                         checkedItem,
                         existItem = _TableInitialization.Select(x => x.Name).ToList(),
+                        NationalTravelFee,
+                        rate
                     };
 
                     return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
@@ -818,7 +842,14 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     var setDataCurrArr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToList();
                     var number = 0; //人数
                     var aMeal = cityPrice.FoodCost.ObjToDecimal() / 2; //一顿三公费用
-                    var findSsetDataCurr = setDataCurrArr.Find(q => q.Id == carTouristList[0].Currency);
+                    var findSsetDataCurr = setDataCurrArr.Find(q => q.Id == dto.Currency);
+                    var printRate = 1M;
+
+                    if (cityPrice.Currency != dto.Currency)
+                    {
+                        printRate = dto.Rate;
+                        findSsetDataCurr = setDataCurrArr.Find(q => q.Id == dto.toCurr);
+                    }
 
                     foreach (var item in arr)
                     {
@@ -836,7 +867,6 @@ namespace OASystem.Infrastructure.Repositories.Groups
                                 DateTime.Compare(x.DatePrice.ObjToDate(),q.DatePrice.ObjToDate()) == 0).Sum( q => q.Price) + x.Price;
 
                                 var findSetData = setDataArr.Find(q => q.Id == keyId);
-                                
 
                                 if (di.VisitPNumber > 1 && x.Count == 1)
                                 {
@@ -847,9 +877,9 @@ namespace OASystem.Infrastructure.Repositories.Groups
                                     number = x.Count;
                                 }
 
-                                dayMealPrice = dayMealPrice / number;
-
-                                remake = $"{x.DatePrice?.ToString("M/d")} {findSetData?.Name}{findSsetDataCurr?.Name} {dayMealPrice * number} - 财政{aMeal} * {number}  = {findSsetDataCurr?.Name}{(dayMealPrice * number) - (aMeal * number)}";
+                                dayMealPrice = dayMealPrice / number * printRate;  //转三公币种
+                                var price = (int)Math.Round((dayMealPrice * number) - (aMeal * number));
+                                remake = $"{x.DatePrice?.ToString("M/d")} {findSetData?.Name}{findSsetDataCurr?.Name} {(int)Math.Round(dayMealPrice * number)} - 财政{aMeal} * {number}  = {findSsetDataCurr?.Name}{price}";
                             }
 
                             return new Fin_GroupExtraCost
@@ -869,6 +899,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                                 PriceType = 1028,
                                 PriceDetailType = item.Item3,
                                 Remark = remake,
+                                Area = opSingleCityId
                             };
                         }).ToList();
 
@@ -904,20 +935,19 @@ namespace OASystem.Infrastructure.Repositories.Groups
                         {
                             remake += $"{start.ToString("M/d")}午餐和晚餐,";
                             exitMealCount += 2;
-                            price += (aMeal * 2  * di.VisitPNumber) - (mealPriceWu) - (mealPriceWan);
-
+                            price += (aMeal * 2  * di.VisitPNumber) - (mealPriceWu * printRate) - (mealPriceWan * printRate);
                         }
                         else if (isExistsWu)
                         {
                             remake += $"{start.ToString("M/d")}午餐,";
                             exitMealCount += 1;
-                            price += (aMeal  * di.VisitPNumber) - (mealPriceWu);
+                            price += (aMeal  * di.VisitPNumber) - (mealPriceWu * printRate);
                         }
                         else if (isExistsWan)
                         {
                             remake += $"{start.ToString("M/d")}晚餐,";
                             exitMealCount += 1;
-                            price += (aMeal * di.VisitPNumber)  - (mealPriceWan);
+                            price += (aMeal * di.VisitPNumber)  - (mealPriceWan * printRate);
                         }
 
                         start = start.AddDays(1);
@@ -930,7 +960,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     {
                         remake = remake.TrimEnd(',');
                         remake += $"财政 {findSsetDataCurr?.Name} {aMeal} * {di.VisitPNumber} * {exitMealCount}餐";
-                        price = price / di.VisitPNumber / exitMealCount;
+                        int priceInt = (int)Math.Round(price / di.VisitPNumber / exitMealCount);
                         groupExtraCostsArr.Add(new Fin_GroupExtraCost
                         {
                             Coefficient = 1,
@@ -940,14 +970,15 @@ namespace OASystem.Infrastructure.Repositories.Groups
                             FilePath = string.Empty,
                             IsDel = 0,
                             PriceCount = di.VisitPNumber * exitMealCount * -1 ,
-                            Price = price,
+                            Price = priceInt,
                             PriceDt = opSingle.ServiceStartTime.ObjToDate(),
-                            PriceCurrency = findSsetDataCurr == null ? carTouristList[0].Currency: findSsetDataCurr.Id ,
-                            PriceSum = (di.VisitPNumber * exitMealCount * -1) * price,
+                            PriceCurrency = findSsetDataCurr == null ? dto.toCurr: findSsetDataCurr.Id ,
+                            PriceSum = (di.VisitPNumber * exitMealCount * -1) * priceInt,
                             PriceName = di.TeamName + "-" + priceCity + "-" + $"退餐费(地接导入)",
                             PriceType = 1028,
                             PriceDetailType = 1088,
                             Remark = remake,
+                            Area = opSingleCityId
                         });
                     }
 
@@ -958,9 +989,9 @@ namespace OASystem.Infrastructure.Repositories.Groups
                             var QuerySgin = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(x => x.PriceName == item.PriceName && x.DiId == item.DiId && x.IsDel == 0 && x.PriceDt.ToString("yyyy-MM-dd") == item.PriceDt.ToString("yyyy-MM-dd")).First();
                             if (QuerySgin == null)
                             {
-                                _ = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
+                                var resultId = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
                                 {
-                                    coefficient = 1,
+                                    coefficient = item.Coefficient,
                                     createUser = dto.CreateUserId,
                                     currency = item.PriceCurrency,
                                     diId = item.DiId,
@@ -977,15 +1008,23 @@ namespace OASystem.Infrastructure.Repositories.Groups
                                     PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
                                     payType = dto.PayDId,
                                     costSign = dto.OrbitalPrivateTransfer,
-                                    Area = opSingle.Area.ObjToInt(),
+                                    Area = item.Area
                                 });
+                                _sqlSugar.Insertable<Fin_LocalGuideRelevancyOverspend>(new Fin_LocalGuideRelevancyOverspend
+                                {
+                                    CreateTime = DateTime.Now,
+                                    CreateUserId = dto.CreateUserId,
+                                    IsDel = 0,
+                                    LocalGuideId = opSingle.Id,
+                                    OverspendId = resultId.Data,
+                                }).ExecuteCommand();
                             }
                             else
                             {
                                 item.Id = QuerySgin.Id;
                                 _ = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
                                 {
-                                    coefficient = 1,
+                                    coefficient = item.Coefficient,
                                     createUser = dto.CreateUserId,
                                     currency = item.PriceCurrency,
                                     diId = item.DiId,
@@ -1162,7 +1201,9 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     CId = dto.Currency,
                     ServiceQuotedPrice = c.PayMoney,
                     OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
-                    SelectCheck = string.Join(',', dto.SelectCheck)
+                    SelectCheck = string.Join(',', dto.SelectCheck),
+                    Rate = dto.Rate,
+                    toCurr = dto.toCurr
                 }).ExecuteCommandAsync();
 
                 var data = new { ccpId = noticeCcpId, sign = noticeSign };
@@ -1278,6 +1319,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
             _daiRep.CommitTran();
             rt.Code = 0;
             rt.Msg = "操作成功";
+            rt.Data = dto.Id;
             return rt;
         }