StatisticsController.cs 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. using Microsoft.AspNetCore.Mvc;
  2. using NPOI.POIFS.Properties;
  3. using NPOI.SS.Formula.Functions;
  4. using OASystem.API.OAMethodLib;
  5. using OASystem.Domain.Dtos.Groups;
  6. using OASystem.Domain.Dtos.Statistics;
  7. using OASystem.Domain.Entities.Financial;
  8. using OASystem.Domain.ViewModels.Financial;
  9. using OASystem.Domain.ViewModels.Groups;
  10. using OASystem.Domain.ViewModels.Statistics;
  11. using OASystem.Infrastructure.Repositories.Groups;
  12. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  13. using System;
  14. using OASystem.Domain.Entities.Customer;
  15. using System.Collections.Generic;
  16. using Microsoft.AspNetCore.Mvc.RazorPages;
  17. using Microsoft.VisualBasic;
  18. using OASystem.Domain.Entities.Groups;
  19. using Microsoft.Extensions.DependencyInjection;
  20. using Aspose.Words.Lists;
  21. namespace OASystem.API.Controllers
  22. {
  23. /// <summary>
  24. /// 统计模块
  25. /// </summary>
  26. [Route("api/[controller]")]
  27. [ApiController]
  28. public class StatisticsController : ControllerBase
  29. {
  30. private readonly int _decimalPlaces;
  31. private readonly IMapper _mapper;
  32. private readonly SqlSugarClient _sqlSugar;
  33. private readonly DelegationInfoRepository _groupRep;
  34. private readonly SetDataRepository _setDataRep;
  35. private readonly TeamRateRepository _teamRateRep;
  36. /// <summary>
  37. /// Init
  38. /// </summary>
  39. /// <param name="mapper"></param>
  40. /// <param name="sqlSugar"></param>
  41. /// <param name="groupRep"></param>
  42. /// <param name="setDataRep"></param>
  43. public StatisticsController(IMapper mapper, SqlSugarClient sqlSugar, DelegationInfoRepository groupRep, SetDataRepository setDataRep, TeamRateRepository teamRate)
  44. {
  45. _mapper = mapper;
  46. _groupRep = groupRep;
  47. _setDataRep = setDataRep;
  48. _sqlSugar = sqlSugar;
  49. _teamRateRep = teamRate;
  50. }
  51. #region 团组报表
  52. /// <summary>
  53. /// 团组报表
  54. /// Items
  55. /// </summary>
  56. /// <param name="_dto">团组列表请求dto</param>
  57. /// <returns></returns>
  58. [HttpPost("PostGroupStatementItems")]
  59. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  60. public async Task<IActionResult> PostGroupStatementItems(GroupStatementItemsDto _dto)
  61. {
  62. #region 参数验证
  63. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  64. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  65. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  66. #region 页面操作权限验证
  67. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  68. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  69. #endregion
  70. #endregion
  71. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  72. {
  73. string sqlWhere = string.Empty;
  74. if (_dto.IsSure == 0) //未完成
  75. {
  76. sqlWhere += string.Format(@" And IsSure = 0");
  77. }
  78. else if (_dto.IsSure == 1) //已完成
  79. {
  80. sqlWhere += string.Format(@" And IsSure = 1");
  81. }
  82. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  83. {
  84. string tj = _dto.SearchCriteria;
  85. sqlWhere += string.Format(@"And (ssd.Name Like '%{0}%' Or TeamName Like '%{1}%' Or ClientName Like '%{2}%' Or ClientName Like '%{3}%' Or su.CnName Like '%{4}%')",
  86. tj, tj, tj, tj, tj);
  87. }
  88. string sql = string.Format(@"Select row_number() over(order by gdi.VisitDate Desc) as Row_Number,
  89. gdi.Id,TourCode,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,
  90. ClientName,ClientUnit,VisitDate,ssd.Id TeamTypeId, ssd.Name TeamType,
  91. VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure,gdi.CreateTime,
  92. pr.LastCollectionTime
  93. From Grp_DelegationInfo gdi
  94. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  95. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  96. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  97. Left Join (
  98. SELECT Diid, MAX(CreateTime) LastCollectionTime
  99. FROM Fin_ProceedsReceived
  100. Where IsDel = 0
  101. GROUP BY Diid
  102. ) pr On gdi.Id = pr.Diid
  103. Where gdi.IsDel = 0 {0} ", sqlWhere);
  104. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  105. var _DelegationList = await _sqlSugar.SqlQueryable<GroupStatementItemView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);//ToPageAsync
  106. var _view = new
  107. {
  108. PageFuncAuth = pageFunAuthView,
  109. Data = _DelegationList
  110. };
  111. return Ok(JsonView(true, "查询成功!", _view, total));
  112. }
  113. else
  114. {
  115. return Ok(JsonView(false, "查询失败"));
  116. }
  117. }
  118. /// <summary>
  119. /// 团组报表
  120. /// Details
  121. /// </summary>
  122. /// <param name="_dto">团组列表请求dto</param>
  123. /// <returns></returns>
  124. [HttpPost("PostGroupStatementDetails")]
  125. //[JsonConverter(typeof(DecimalConverter), 2)]
  126. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  127. public async Task<IActionResult> PostGroupStatementDetails(GroupStatementDetailsDto _dto)
  128. {
  129. /*
  130. * 团组报表计算方式
  131. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  132. * 应收金额 = 应收表.Sum()
  133. * 已收金额 = 已收表.Sum()
  134. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  135. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  136. *
  137. */
  138. #region 参数验证
  139. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  140. if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  141. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  142. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  143. #region 页面操作权限验证
  144. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  145. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  146. #endregion
  147. #endregion
  148. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  149. {
  150. GroupStatementDetailsView _view = new GroupStatementDetailsView();
  151. #region 费用类型 币种,转账,客户信息
  152. List<Sys_SetData> _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  153. var _clientDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync();
  154. #endregion
  155. #region 团组收入
  156. GroupIncomeView _giView = new GroupIncomeView();
  157. /*
  158. * 应收报表
  159. */
  160. decimal frTotalAmount = 0.00M;//应收总金额
  161. string _frSql = string.Format(@"Select fr.Id,fr.Diid,fr.PriceName,fr.Price,fr.Count,fr.Unit,fr.Currency,
  162. sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice,fr.CreateTime
  163. From Fin_ForeignReceivables fr
  164. Left Join Sys_SetData sd On fr.Currency = sd.Id
  165. Where fr.IsDel = 0 And fr.Diid = {0} Order By CreateTime", _dto.DiId);
  166. List<Gsd_ForeignReceivablesView> _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
  167. frTotalAmount = _frViews.Sum(it => it.ItemSumPrice);
  168. _giView.Receivables = _frViews;
  169. _giView.ReceivableStr = string.Format(@"应收款合计:{0} CNY(人民币)", frTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  170. /*
  171. * 已收报表
  172. */
  173. decimal prTotalAmount = 0.00M;//已收总金额
  174. string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime As SectionTimeDt,pr.Price,pr.Currency,
  175. sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
  176. pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark,pr.CreateTime
  177. From Fin_ProceedsReceived pr
  178. Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
  179. Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
  180. Where pr.IsDel = 0 and pr.Diid = {0} Order By CreateTime", _dto.DiId);
  181. List<Gsd_ProceedsReceivedView> _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
  182. prTotalAmount = _prViews.Sum(it => it.Price);
  183. _giView.ProceedsReceivedViews = _prViews;
  184. _giView.ProceedsReceivedStr = string.Format(@$"应收合计:{frTotalAmount.ToString("#0.00")} CNY 已收款合计:{prTotalAmount.ConvertToDecimal1().ToString("#0.00")} CNY" );
  185. /*
  186. * 超支费用
  187. */
  188. decimal exTotalAmount = 0.00M;
  189. string _ecSql = string.Format(@"Select gec.Id As GECId,gec.DiId As GECDiId,gec.PriceName,ccp.PayMoney,sd1.Name As PaymentCurrency,
  190. ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  191. sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,gec.CreateTime
  192. From OA2023DB.dbo.Fin_GroupExtraCost gec
  193. Left Join Grp_CreditCardPayment ccp On gec.Id = ccp.CId
  194. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  195. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  196. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  197. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  198. Where ccp.IsDel = 0 And ccp.CTable = 1015 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ccp.DiId = {0} Order By CreateTime", _dto.DiId);
  199. List<Gsd_ExtraCostsView> _ExtraCostsViews = await _sqlSugar.SqlQueryable<Gsd_ExtraCostsView>(_ecSql).ToListAsync();
  200. #region 超支费用 - 模拟数据
  201. //if (_ExtraCostsViews.Count < 1)
  202. //{
  203. // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  204. // {
  205. // GECId = 0,
  206. // GECDiId = 2334,
  207. // PriceName = "模拟数据-超支费用名称",
  208. // PayMoney = 1000.00M,
  209. // PaymentCurrency = "CNY",
  210. // DayRate = 1.0000M,
  211. // CNYPrice = 1000.00M,
  212. // Payee = "模拟数据-超支费用收款方",
  213. // OrbitalPrivateTransfer = 1,
  214. // PayWay = "刷卡",
  215. // CardType = "招行卡",
  216. // IsPay = 1,
  217. // Applicant = "刘华举"
  218. // });
  219. // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  220. // {
  221. // GECId = 0,
  222. // GECDiId = 2334,
  223. // PriceName = "模拟数据-超支费用名称",
  224. // PayMoney = 1000.00M,
  225. // PaymentCurrency = "CNY",
  226. // DayRate = 1.0000M,
  227. // CNYPrice = 1000.00M,
  228. // Payee = "模拟数据-超支费用收款方",
  229. // OrbitalPrivateTransfer = 1,
  230. // PayWay = "刷卡",
  231. // CardType = "招行卡",
  232. // IsPay = 1,
  233. // Applicant = "刘华举"
  234. // });
  235. //}
  236. #endregion
  237. exTotalAmount = _ExtraCostsViews.Sum(it => it.CNYPrice);
  238. _giView.ExtraCostsViews = _ExtraCostsViews;
  239. _giView.ExtraCostsStr = string.Format(@"人民币总费用:{0} CNY", exTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  240. /*
  241. * 收款退还
  242. */
  243. decimal promTotalAmount = 0.00M;// 收款退还总金额
  244. List<Gsd_PaymentRefundAndOtherMoneyView> _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
  245. //删除了 And prom.PriceType = 1
  246. string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
  247. prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
  248. prom.PayType As PrPayType,prom.PriceType As PrPriceType,ccp.*,prom.CreateTime As PrCreateTime
  249. From Fin_PaymentRefundAndOtherMoney prom
  250. Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
  251. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  252. Where prom.IsDel = 0 And prom.PayType = 1 And ccp.CTable = 285
  253. And ccp.IsAuditGM = 1 And ccp.IsPay = 1
  254. And prom.DiId = {0} Order By PrCreateTime", _dto.DiId);
  255. var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
  256. foreach (var ropItem in _promDatas)
  257. {
  258. string thisCueencyCode = "Unknown";
  259. string thisCueencyName = "Unknown";
  260. var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
  261. if (currency != null)
  262. {
  263. thisCueencyCode = currency.Name;
  264. thisCueencyName = currency.Remark;
  265. }
  266. string orbitalPrivateTransferStr = "Unknown";
  267. var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
  268. if (orbitalPrivateTransfer != null)
  269. {
  270. orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
  271. }
  272. string payStr = "Unknown";
  273. var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
  274. if (pay != null)
  275. {
  276. payStr = pay.Name;
  277. }
  278. Gsd_PaymentRefundAndOtherMoneyView gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
  279. {
  280. Id = ropItem.Id,
  281. DiId = ropItem.DIId,
  282. PriceName = ropItem.PrPriceName,
  283. PayCurrencyCode = thisCueencyCode,
  284. PayCurrencyName = thisCueencyName,
  285. Price = ropItem.PrPrice,
  286. CNYPrice = ropItem.RMBPrice,
  287. ThisRate = ropItem.DayRate,
  288. Payee = ropItem.Payee,
  289. PayTime = ropItem.AuditGMDate,
  290. OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
  291. PayType = payStr,
  292. IsPay = ropItem.IsPay,
  293. Applicant = ropItem.Appliction
  294. };
  295. _promView.Add(gsd_PaymentRefund);
  296. }
  297. #region 收款退还 - 模拟数据
  298. //if (_promView.Count < 1)
  299. //{
  300. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  301. // {
  302. // Id = 0,
  303. // DiId = 2334,
  304. // PriceName = "模拟数据-费用名称",
  305. // PayCurrencyCode = "CNY",
  306. // PayCurrencyName = "人民币",
  307. // Price = 1000.00M,
  308. // CNYPrice = 1000.00M,
  309. // ThisRate = 1.00M,
  310. // Payee = "模拟数据-收款方",
  311. // PayTime = "2023-01-01 15:20:01",
  312. // OrbitalPrivateTransfer = 1,
  313. // PayType = "刷卡",
  314. // IsPay = 1,
  315. // Applicant = "刘华举"
  316. // });
  317. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  318. // {
  319. // Id = 0,
  320. // DiId = 2334,
  321. // PriceName = "模拟数据-费用名称",
  322. // PayCurrencyCode = "CNY",
  323. // PayCurrencyName = "人民币",
  324. // Price = 1000.00M,
  325. // CNYPrice = 1000.00M,
  326. // ThisRate = 1.00M,
  327. // Payee = "模拟数据-收款方",
  328. // PayTime = "2023-01-01 15:20:01",
  329. // OrbitalPrivateTransfer = 1,
  330. // PayType = "刷卡",
  331. // IsPay = 1,
  332. // Applicant = "刘华举"
  333. // });
  334. //}
  335. #endregion
  336. promTotalAmount = _promView.Sum(it => it.CNYPrice);
  337. _giView.PaymentRefundAndOtherMoneyViews = _promView;
  338. _giView.PaymentRefundAndOtherMoneyStr = string.Format(@"人民币总费用:{0} CNY", promTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  339. decimal BalancePayment = frTotalAmount - prTotalAmount + promTotalAmount;
  340. _view.GroupIncome = _giView;
  341. _view.GroupIncomeStr = string.Format(@"<span style='color:red;'>剩余尾款:{0} CNY(包含了收款退还费用数据)</span>", BalancePayment.ConvertToDecimal1().ToString("#0.00"));
  342. #endregion
  343. #region 团组支出
  344. GroupExpenditureView _geView = new GroupExpenditureView();
  345. #region 酒店预定费用
  346. List<GroupHotelFeeView> groupHotelFeeViews = new List<GroupHotelFeeView>();
  347. string hotelFeeSql = string.Format(@"Select hr.Id As HrId,hr.DiId As HrDiId,hr.City,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,
  348. sd1.Name As PaymentCurrency,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  349. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,
  350. hr.BreakfastPrice,sd4.Name As BreakfastCurrency,hr.Isoppay,hr.GovernmentRent,
  351. sd5.Name As GovernmentRentCurrency,hr.CityTax,sd6.Name As CityTaxCurrency,
  352. ccp.PayMoney,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,
  353. sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  354. From Grp_HotelReservations hr
  355. Left Join Grp_CreditCardPayment ccp On hr.Id = ccp.CId
  356. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  357. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  358. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  359. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  360. Left Join Sys_SetData sd4 On hr.BreakfastCurrency = sd4.Id
  361. Left Join Sys_SetData sd5 On hr.GovernmentRentCurrency = sd5.Id
  362. Left Join Sys_SetData sd6 On hr.CityTaxCurrency = sd6.Id
  363. Where hr.IsDel = 0 And ccp.IsDel = 0 And ccp.CTable = 76 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And hr.DiId = {0}
  364. Order By CheckInDate Asc", _dto.DiId);
  365. groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
  366. decimal HotelCNYTotalPrice = 0.00M;
  367. var teamRateData = await _teamRateRep.PostGroupRateInfoByDiId(_dto.DiId);
  368. foreach (var item in groupHotelFeeViews)
  369. {
  370. HotelCNYTotalPrice += item.CNYPrice;
  371. item.PayMoney = item.PayMoney.ConvertToDecimal1();
  372. item.CNYPrice = item.CNYPrice.ConvertToDecimal1();
  373. string currencyRateStr = "";
  374. List<string> currencys = new List<string>();
  375. if (!string.IsNullOrEmpty(item.BreakfastCurrency)) currencys.Add(item.BreakfastCurrency);
  376. if (!string.IsNullOrEmpty(item.GovernmentRentCurrency)) currencys.Add(item.GovernmentRentCurrency);
  377. if (!string.IsNullOrEmpty(item.CityTaxCurrency)) currencys.Add(item.CityTaxCurrency);
  378. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  379. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 76, currencys);
  380. item.CurrencyRateStr = currencyRateStr;
  381. }
  382. _geView.GroupHotelFeeViews = groupHotelFeeViews;
  383. _geView.GroupHotelFeeStr = string.Format(@"人民币总费用:{0} CNY", HotelCNYTotalPrice.ToString("#0.00"));
  384. #endregion
  385. #region 地接费用
  386. List<GroupCTGGRFeeView> groupCTGGRFeeViews = new List<GroupCTGGRFeeView>();
  387. string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.Area,ctggrc.*,ctggrc.Price As PayMoney,
  388. sd2.name As PaymentCurrency,ccp.PayPercentage,
  389. (ctggrc.Price / (ccp.PayPercentage / 100)) As AmountPaid,
  390. (ctggrc.Price / (ccp.PayPercentage / 100) - ctggrc.Price) As BalancePayment,
  391. ccp.DayRate,(ctggrc.Price * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  392. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  393. From Grp_CarTouristGuideGroundReservations ctggr
  394. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price,sd2.Name As PriceCurrency,
  395. cggrc.PriceContent
  396. From Grp_CarTouristGuideGroundReservationsContent cggrc
  397. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  398. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  399. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  400. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  401. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  402. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  403. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  404. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  405. Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ctggr.DiId = {0}
  406. Order By CreateTime", _dto.DiId);
  407. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  408. string CTGGRFeeStr = "";
  409. decimal CTGGRCNYTotalPrice = 0.00M;
  410. //按1 地区,2 币种,3 汇率 分组计算
  411. var groupCTGGRFeeDatas = groupCTGGRFeeViews.GroupBy(it => it.Area);
  412. foreach (var ctggfr in groupCTGGRFeeDatas)
  413. {
  414. var ctggfr_curr = ctggfr.GroupBy(it => it.PaymentCurrency);
  415. if (ctggfr_curr.Count() > 0)
  416. {
  417. foreach (var curr in ctggfr_curr)
  418. {
  419. var ctggfr_rate = curr.GroupBy(it => it.DayRate);
  420. if (ctggfr_rate.Count() > 0)
  421. {
  422. foreach (var rate in ctggfr_rate)
  423. {
  424. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{rate.Sum(it => it.AmountPaid).ToString("#0.00")}
  425. {rate.FirstOrDefault()?.PaymentCurrency}(人民币:
  426. {rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  427. {rate.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  428. CTGGRCNYTotalPrice += rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  429. }
  430. }
  431. else
  432. {
  433. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{curr.Sum(it => it.AmountPaid).ToString("#0.00")}
  434. {curr.FirstOrDefault()?.PaymentCurrency}(人民币:
  435. {curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  436. {curr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  437. CTGGRCNYTotalPrice += curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  438. }
  439. }
  440. }
  441. else
  442. {
  443. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{ctggfr.Sum(it => it.AmountPaid).ToString("#0.00")}
  444. {ctggfr.FirstOrDefault()?.PaymentCurrency}(人民币:
  445. {ctggfr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  446. {ctggfr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  447. CTGGRCNYTotalPrice += ctggfr.Sum(it => Convert.ToDecimal( it.CNYPrice.ToString("#0.00")));
  448. }
  449. }
  450. foreach (var item in groupCTGGRFeeViews)
  451. {
  452. if (!string.IsNullOrEmpty(item.AuditGMDate))
  453. {
  454. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  455. }
  456. //CTGGRFeeStr += string.Format(@"{0} 总费用:{1} {2}(人民币:{3} CNY 当时支付汇率:{4})\r\n",
  457. // item.Area, item.AmountPaid.ConvertToDecimal1().ToString("#0.00"), item.PaymentCurrency, item.CNYPrice.ToString("#0.0000"), item.DayRate.ToString("#0.0000"));
  458. //CTGGRCNYTotalPrice += item.CNYPrice;
  459. }
  460. _geView.GroupCTGGRFeeViews = groupCTGGRFeeViews;
  461. _geView.GroupCTGGRFeeStr = string.Format(@"{0}人民币总费用:{1} CNY", CTGGRFeeStr,CTGGRCNYTotalPrice.ToString("#0.00"));
  462. #endregion
  463. #region 机票预订费用
  464. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  465. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  466. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  467. sd1.Name As PayMoneyCurrency,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  468. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,atr.CreateTime
  469. From Grp_AirTicketReservations atr
  470. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  471. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  472. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  473. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  474. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  475. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  476. Where atr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And atr.DiId = {0} Order By CreateTime", _dto.DiId);
  477. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  478. string str = "";
  479. List<dynamic> airClientPris = new List<dynamic>();
  480. decimal AirCNYTotalPrice = 0.00M;
  481. decimal JJCCNYTotalPrice = 0.00M, JJCPeopleNum = 0.00M, JJCAveragePrice = 0.00M;
  482. decimal GWCCNYTotalPrice = 0.00M, GWCPeopleNum = 0.00M, GWCAveragePrice = 0.00M;
  483. //if (groupAirFeeViews.Count > 0)
  484. //{
  485. // JJCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.CNYPrice);
  486. // JJCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.ClientNum);
  487. // JJCAveragePrice = (JJCCNYTotalPrice / JJCPeopleNum).ConvertToDecimal1();
  488. // GWCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.CNYPrice);
  489. // GWCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.ClientNum);
  490. // GWCAveragePrice = (GWCCNYTotalPrice / GWCPeopleNum).ConvertToDecimal1();
  491. //}
  492. int Index = 0;
  493. foreach (var item in groupAirFeeViews)
  494. {
  495. if (item.AirId > 2924)
  496. {
  497. string itemClientName = "";
  498. if (!string.IsNullOrEmpty(item.ClientName))
  499. {
  500. string[] clientIds = new string[] { };
  501. if (item.ClientName.Contains(','))
  502. {
  503. clientIds = item.ClientName.Split(',');
  504. }
  505. else
  506. {
  507. clientIds = new string[] { item.ClientName };
  508. }
  509. if (clientIds.Length > 0)
  510. {
  511. int[] output = Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
  512. if (output.Contains(-1))
  513. {
  514. itemClientName += $@"行程单";
  515. output = output.Where(val => val != -1).ToArray();
  516. }
  517. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  518. decimal unitCost = 0.00M;
  519. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  520. int clienIndex = 1;
  521. foreach (var client in clients)
  522. {
  523. airClientPris.Add(new {
  524. CnName = client.LastName+client.FirstName,
  525. EnName = client.Pinyin,
  526. Price = unitCost,
  527. AirType = item.AirTypeName
  528. });
  529. string six = "";
  530. if (client.Sex == 0) six = "Mr";
  531. else if (client.Sex == 1) six = "Ms";
  532. itemClientName += string.Format(@"{0}.{1} {2};", clienIndex, client.LastName + client.FirstName, six);
  533. clienIndex++;
  534. }
  535. }
  536. }
  537. item.ClientName = itemClientName;
  538. }
  539. else
  540. {
  541. string clientPinYinName = "";
  542. decimal unitCost = 0.00M;
  543. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  544. string[] clientNames = item.ClientName.Split('.');
  545. for (int i = 0; i < item.ClientNum; i++)
  546. {
  547. string name = "";
  548. if (clientNames.Length > 0)
  549. {
  550. int index = i + 1;
  551. if (index < clientNames.Length)
  552. {
  553. name = clientNames[index].Replace("MR","").Replace("MS","");
  554. }
  555. }
  556. clientPinYinName += string.Format(@"{0}.{1}出票价为:{2} CNY;", Index, name, unitCost);
  557. }
  558. }
  559. if (!string.IsNullOrEmpty(item.AuditGMDate))
  560. {
  561. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  562. }
  563. AirCNYTotalPrice += item.CNYPrice;
  564. }
  565. _geView.GroupAirFeeViews = groupAirFeeViews;
  566. if (airClientPris.Count > 0)
  567. {
  568. var peoplePriStr = "";
  569. var airClientPris1 = airClientPris.GroupBy(item => item.CnName)
  570. .Select(group => group.First())
  571. .ToList();
  572. int airClientPrisIndex = 1;
  573. foreach (var item in airClientPris1)
  574. {
  575. decimal price = 0.00M;
  576. var prices = airClientPris.Where(it => it.CnName == item.CnName).ToList();
  577. foreach (var pri in prices)
  578. {
  579. price += pri.Price;
  580. }
  581. peoplePriStr += $@"{airClientPrisIndex}.{item.EnName}出票价为: { price.ToString("#0.00")} CNY;";
  582. airClientPrisIndex++;
  583. }
  584. if (!string.IsNullOrEmpty(peoplePriStr))
  585. {
  586. str = $@"其中:{peoplePriStr}";
  587. }
  588. //经济舱均价
  589. var airJJCPris = airClientPris.Where(it => it.AirType == "经济舱").ToList();
  590. if (airJJCPris.Count > 0)
  591. {
  592. decimal jjcTotalPrice = 0.00M;
  593. foreach (var item in airJJCPris)
  594. {
  595. jjcTotalPrice += item.Price;
  596. }
  597. decimal jjcPeopleNum = airJJCPris.GroupBy(item => item.CnName)
  598. .Select(group => group.First())
  599. .ToList().Count();;
  600. JJCAveragePrice = jjcTotalPrice / jjcPeopleNum;
  601. }
  602. //公务舱均价
  603. var airGWCPris = airClientPris.Where(it => it.AirType == "公务舱").ToList();
  604. if (airGWCPris.Count > 0)
  605. {
  606. decimal gwcTotalPrice = 0.00M;
  607. foreach (var item in airGWCPris)
  608. {
  609. gwcTotalPrice += item.Price;
  610. }
  611. decimal gwcPeopleNum = airGWCPris.GroupBy(item => item.CnName)
  612. .Select(group => group.First())
  613. .ToList().Count();
  614. GWCAveragePrice = gwcTotalPrice / gwcPeopleNum;
  615. }
  616. }
  617. _geView.GroupAirFeeStr = $@"人民币总费用:{AirCNYTotalPrice.ToString("#0.00")} CNY\r\n{str}\r\n经济舱均价为:{JJCAveragePrice.ToString("#0.00")}CNY/人;公务舱均价为:{GWCAveragePrice.ToString("#0.00")}CNY/人;";
  618. #endregion
  619. #region 签证费用
  620. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  621. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  622. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  623. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant,vi.CreateTime
  624. From Grp_VisaInfo vi
  625. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  626. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  627. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  628. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  629. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  630. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And vi.DIId = {0} Order By CreateTime", _dto.DiId);
  631. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  632. decimal VisaCNYTotalPirce = 0.00M;
  633. foreach (var item in groupVisaFeeViews)
  634. {
  635. string itemClientName = "";
  636. string visaClients = item.VisaClient;
  637. if (!string.IsNullOrEmpty(visaClients))
  638. {
  639. string[] clientIds = new string[] { };
  640. if (visaClients.Contains(','))
  641. {
  642. clientIds = visaClients.Split(',');
  643. }
  644. else
  645. {
  646. clientIds = new string[] { visaClients };
  647. }
  648. if (clientIds.Length > 0)
  649. {
  650. List<int> clientIds1 = new List<int>() { };
  651. foreach (var clientIdStr in clientIds)
  652. {
  653. if (clientIdStr.IsNumeric())
  654. {
  655. clientIds1.Add(int.Parse(clientIdStr));
  656. }
  657. }
  658. if (clientIds1.Count > 0)
  659. {
  660. var clients = _clientDatas.Where(it => clientIds1.Contains(it.Id)).ToList();
  661. foreach (var client in clients)
  662. {
  663. itemClientName += $"{client.LastName + client.FirstName},";
  664. }
  665. }
  666. else {
  667. itemClientName = visaClients;
  668. }
  669. }
  670. }
  671. if (itemClientName.Length > 0 )
  672. {
  673. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  674. }
  675. item.VisaClient = itemClientName;
  676. VisaCNYTotalPirce += item.PayMoney;
  677. if (!string.IsNullOrEmpty(item.AuditGMDate))
  678. {
  679. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  680. }
  681. }
  682. _geView.GroupVisaFeeViews = groupVisaFeeViews;
  683. _geView.GroupVisaFeeStr = string.Format(@"人民币总费用:{0} CNY", VisaCNYTotalPirce.ConvertToDecimal1());
  684. #endregion
  685. #region 邀请/公务活动 CTable = 81
  686. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  687. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  688. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  689. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  690. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  691. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ioa.CreateTime
  692. From Grp_InvitationOfficialActivities ioa
  693. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  694. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  695. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  696. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  697. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  698. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  699. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  700. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  701. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  702. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ioa.Diid = {0} Order By CreateTime", _dto.DiId);
  703. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  704. #region 邀请/公务活动 - 模拟数据
  705. //if (groupInvitationalFeeViews.Count < 1)
  706. //{
  707. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  708. // {
  709. // IOAId = 0,
  710. // IOADiId = 2334,
  711. // InviterArea = "模拟数据-邀请方地区",
  712. // Inviter = "模拟数据-邀请方",
  713. // InviteTime = "2023-10-10",
  714. // InviteCost = 100.00M,
  715. // InviteCurrency = "EUR",
  716. // SendCost = 100.00M,
  717. // SendCurrency = "EUR",
  718. // EventsCost = 10000.00M,
  719. // EventsCurrency = "EUR",
  720. // TranslateCost = 300.00M,
  721. // TranslateCurrency = "EUR",
  722. // PayMoney = 10500.00M,
  723. // PaymentCurrency = "EUR",
  724. // CNYPrice = 76765.50M,
  725. // Payee = "模拟数据-收款方",
  726. // AuditGMDate = "2023-12-05",
  727. // OrbitalPrivateTransfer = 1,
  728. // PayWay = "刷卡",
  729. // IsPay = 1,
  730. // Applicant = "刘华举"
  731. // });
  732. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  733. // {
  734. // IOAId = 0,
  735. // IOADiId = 2334,
  736. // InviterArea = "模拟数据-邀请方地区",
  737. // Inviter = "模拟数据-邀请方",
  738. // InviteTime = "2023-10-10",
  739. // InviteCost = 100.00M,
  740. // InviteCurrency = "EUR",
  741. // SendCost = 100.00M,
  742. // SendCurrency = "EUR",
  743. // EventsCost = 10000.00M,
  744. // EventsCurrency = "EUR",
  745. // TranslateCost = 300.00M,
  746. // TranslateCurrency = "EUR",
  747. // PayMoney = 10500.00M,
  748. // PaymentCurrency = "EUR",
  749. // CNYPrice = 76765.50M,
  750. // Payee = "模拟数据-收款方",
  751. // AuditGMDate = "2023-12-05",
  752. // OrbitalPrivateTransfer = 1,
  753. // PayWay = "刷卡",
  754. // IsPay = 1,
  755. // Applicant = "刘华举"
  756. // });
  757. //}
  758. #endregion
  759. decimal InvitationalCNYTotalPrice = 0.00M;
  760. foreach (var item in groupInvitationalFeeViews)
  761. {
  762. InvitationalCNYTotalPrice += item.CNYPrice;
  763. if (!string.IsNullOrEmpty(item.AuditGMDate))
  764. {
  765. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  766. }
  767. string currencyRateStr = "";
  768. List<string> currencys = new List<string>();
  769. if (!string.IsNullOrEmpty(item.InviteCurrency)) currencys.Add(item.InviteCurrency);
  770. if (!string.IsNullOrEmpty(item.SendCurrency)) currencys.Add(item.SendCurrency);
  771. if (!string.IsNullOrEmpty(item.EventsCurrency)) currencys.Add(item.EventsCurrency);
  772. if (!string.IsNullOrEmpty(item.TranslateCurrency)) currencys.Add(item.TranslateCurrency);
  773. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  774. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 81, currencys);
  775. item.CurrencyRateStr = currencyRateStr;
  776. }
  777. _geView.GroupInvitationalFeeViews = groupInvitationalFeeViews;
  778. _geView.GroupInvitationalFeeStr = string.Format(@"人民币总费用:{0} CNY", InvitationalCNYTotalPrice);
  779. #endregion
  780. #region 保险费用
  781. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  782. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  783. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  784. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ic.CreateTime
  785. From Grp_Customers ic
  786. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  787. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  788. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  789. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  790. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ic.DiId = {0} Order By CreateTime", _dto.DiId);
  791. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  792. decimal InsuranceCNYTotalPrice = 0.00M;
  793. foreach (var item in groupInsuranceFeeViews)
  794. {
  795. InsuranceCNYTotalPrice += item.CNYPrice;
  796. string itemClientName = "";
  797. string insClients = item.ClientName;
  798. if (!string.IsNullOrEmpty(insClients))
  799. {
  800. string[] clientIds = new string[] { };
  801. if (insClients.Contains(','))
  802. {
  803. clientIds = insClients.Split(',');
  804. }
  805. else
  806. {
  807. clientIds = new string[] { insClients };
  808. }
  809. if (clientIds.Length > 0)
  810. {
  811. List<int> output = new List<int>();
  812. foreach (var clientId in clientIds)
  813. {
  814. if (clientId.IsNumeric())
  815. {
  816. output.Add(int.Parse(clientId));
  817. }
  818. }
  819. if (output.Count > 0)
  820. {
  821. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  822. foreach (var client in clients)
  823. {
  824. itemClientName += $"{client.LastName + client.FirstName},";
  825. }
  826. if (itemClientName.Length > 0)
  827. {
  828. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  829. }
  830. }
  831. else
  832. {
  833. itemClientName = insClients;
  834. }
  835. }
  836. }
  837. item.ClientName = itemClientName;
  838. if (!string.IsNullOrEmpty(item.AuditGMDate))
  839. {
  840. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  841. }
  842. }
  843. _geView.GroupInsuranceFeeViews = groupInsuranceFeeViews;
  844. _geView.GroupInsuranceFeeStr = string.Format(@"人民币总费用:{0} CNY", InsuranceCNYTotalPrice.ToString("#0.00"));
  845. #endregion
  846. #region 其他款项费用 98
  847. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  848. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  849. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,
  850. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  851. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,dp.CreateTime
  852. From Grp_DecreasePayments dp
  853. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  854. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  855. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  856. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  857. Where dp.IsDel = 0 And ccp.Ctable = 98 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And dp.Diid = {0}
  858. Order By CreateTime", _dto.DiId);
  859. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  860. #region 保险费用 - 模拟数据
  861. //if (groupDecreaseFeeViews.Count < 1)
  862. //{
  863. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  864. // {
  865. // DPId = 0,
  866. // DPDiId = 2334,
  867. // PriceName = "模拟数据-费用名称",
  868. // PayMoney = 1000.00M,
  869. // PayMoneyCurrency = "CNY",
  870. // DayRate = 1.0000M,
  871. // CNYPrice = 1.0000M,
  872. // AuditGMDate = "2023-12-10 12:13:00",
  873. // Payee = "模拟数据-付款方",
  874. // OrbitalPrivateTransfer = 1,
  875. // PayWay = "现金",
  876. // IsPay = 1,
  877. // Applicant = "刘华举"
  878. // });
  879. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  880. // {
  881. // DPId = 0,
  882. // DPDiId = 2334,
  883. // PriceName = "模拟数据-费用名称",
  884. // PayMoney = 1000.00M,
  885. // PayMoneyCurrency = "CNY",
  886. // DayRate = 1.0000M,
  887. // CNYPrice = 1.0000M,
  888. // AuditGMDate = "2023-12-10 12:13:00",
  889. // Payee = "模拟数据-付款方",
  890. // OrbitalPrivateTransfer = 1,
  891. // PayWay = "现金",
  892. // IsPay = 1,
  893. // Applicant = "刘华举"
  894. // });
  895. //}
  896. #endregion
  897. decimal DecreaseCNYTotalPrice = 0.00M;
  898. foreach (var item in groupDecreaseFeeViews)
  899. {
  900. item.CNYPrice = Convert.ToDecimal(item.CNYPrice.ToString("#0.00"));
  901. DecreaseCNYTotalPrice += item.CNYPrice;
  902. if (!string.IsNullOrEmpty(item.AuditGMDate))
  903. {
  904. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  905. }
  906. }
  907. _geView.GroupDecreaseFeeViews = groupDecreaseFeeViews;
  908. _geView.GroupDecreaseFeeStr = string.Format(@"人民币总费用:{0} CNY", DecreaseCNYTotalPrice.ToString("#0.00"));
  909. #endregion
  910. _view.GroupExpenditure = _geView;
  911. #endregion
  912. /*
  913. * 团组报表计算方式
  914. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  915. * 应收金额 = 应收表.Sum()
  916. * 已收金额 = 已收表.Sum()
  917. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  918. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  919. *
  920. */
  921. decimal _totalExpenditure = 0.00M; //总支出
  922. decimal _amountReceivable = 0.00M; //应收金额
  923. decimal _amountReceived = 0.00M; //已收金额
  924. decimal _receivableProfit = 0.00M; //应收利润
  925. decimal _receivedProfit = 0.00M; //已收利润
  926. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  927. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  928. _amountReceivable = frTotalAmount;
  929. _amountReceived = prTotalAmount;
  930. _receivableProfit = _amountReceivable - promTotalAmount - _totalExpenditure;
  931. _receivedProfit = _amountReceived - promTotalAmount - _totalExpenditure;
  932. _view.FeeTotalStr = string.Format(@$"<span>
  933. <span>当前总支出:{_totalExpenditure.ToString("#0.00")} CNY</span>
  934. <span style='padding-left:10px;color: Green;'>应收金额:{_amountReceivable.ToString("#0.00")} CNY</span>
  935. <span style='padding-left:10px;color: Green;'>已收金额:{_amountReceived.ToString("#0.00")} CNY</span>
  936. <span style='padding-left:10px;color: Green;'>应收利润(应收-支出):{_receivableProfit.ToString("#0.00")} CNY</span>
  937. <span style='padding-left:10px;color: Green;'>已收利润(已收-支出):{_receivedProfit.ToString("#0.00")} CNY</span>
  938. </span>");
  939. return Ok(JsonView(true, "查询成功!", _view));
  940. }
  941. else
  942. {
  943. return Ok(JsonView(false, "查询成功"));
  944. }
  945. }
  946. #endregion
  947. }
  948. }