StatisticsController.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  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. #region 参数验证
  130. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  131. if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  132. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  133. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  134. #region 页面操作权限验证
  135. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  136. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  137. #endregion
  138. #endregion
  139. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  140. {
  141. GroupStatementDetailsView _view = new GroupStatementDetailsView();
  142. #region 费用类型 币种,转账,客户信息
  143. List<Sys_SetData> _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  144. var _clientDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync();
  145. #endregion
  146. #region 团组收入
  147. GroupIncomeView _giView = new GroupIncomeView();
  148. /*
  149. * 应收报表
  150. */
  151. decimal frTotalAmount = 0.00M;//应收总金额
  152. string _frSql = string.Format(@"Select fr.Id,fr.Diid,fr.PriceName,fr.Price,fr.Count,fr.Unit,fr.Currency,
  153. sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice
  154. From Fin_ForeignReceivables fr
  155. Left Join Sys_SetData sd On fr.Currency = sd.Id
  156. Where fr.IsDel = 0 And fr.Diid = {0}",_dto.DiId);
  157. List<Gsd_ForeignReceivablesView> _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
  158. frTotalAmount = _frViews.Sum(it => it.ItemSumPrice);
  159. _giView.Receivables = _frViews;
  160. _giView.ReceivableStr = string.Format(@"应收款合计:{0} CNY(人民币)", frTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  161. /*
  162. * 已收报表
  163. */
  164. decimal prTotalAmount = 0.00M;//已收总金额
  165. string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime,pr.Price,pr.Currency,
  166. sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
  167. pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark
  168. From Fin_ProceedsReceived pr
  169. Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
  170. Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
  171. Where pr.IsDel = 0 and pr.Diid = {0}", _dto.DiId);
  172. List<Gsd_ProceedsReceivedView> _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
  173. prTotalAmount = _prViews.Sum(it => it.Price);
  174. _giView.ProceedsReceivedViews = _prViews;
  175. _giView.ProceedsReceivedStr = string.Format(@"已收款合计:{0} CNY(人民币)", prTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  176. /*
  177. * 超支费用
  178. */
  179. decimal exTotalAmount = 0.00M;
  180. string _ecSql = string.Format(@"Select gec.Id As GECId,gec.DiId As GECDiId,gec.PriceName,ccp.PayMoney,sd1.Name As PaymentCurrency,
  181. ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  182. sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  183. From Fin_GroupExtraCost gec
  184. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 1015 And gec.Id = ccp.CId
  185. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  186. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  187. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  188. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  189. Where gec.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And gec.DiId = {0}",_dto.DiId);
  190. List<Gsd_ExtraCostsView> _ExtraCostsViews = await _sqlSugar.SqlQueryable<Gsd_ExtraCostsView>(_ecSql).ToListAsync();
  191. #region 模拟数据
  192. //if (_ExtraCostsViews.Count < 1)
  193. //{
  194. // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  195. // {
  196. // GECId = 0,
  197. // GECDiId = 2334,
  198. // PriceName = "模拟数据-超支费用名称",
  199. // PayMoney = 1000.00M,
  200. // PaymentCurrency = "CNY",
  201. // DayRate = 1.0000M,
  202. // CNYPrice = 1000.00M,
  203. // Payee = "模拟数据-超支费用收款方",
  204. // OrbitalPrivateTransfer = 1,
  205. // PayWay = "刷卡",
  206. // CardType = "招行卡",
  207. // IsPay = 1,
  208. // Applicant = "刘华举"
  209. // });
  210. // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  211. // {
  212. // GECId = 0,
  213. // GECDiId = 2334,
  214. // PriceName = "模拟数据-超支费用名称",
  215. // PayMoney = 1000.00M,
  216. // PaymentCurrency = "CNY",
  217. // DayRate = 1.0000M,
  218. // CNYPrice = 1000.00M,
  219. // Payee = "模拟数据-超支费用收款方",
  220. // OrbitalPrivateTransfer = 1,
  221. // PayWay = "刷卡",
  222. // CardType = "招行卡",
  223. // IsPay = 1,
  224. // Applicant = "刘华举"
  225. // });
  226. //}
  227. #endregion
  228. exTotalAmount = _ExtraCostsViews.Sum(it => it.CNYPrice);
  229. _giView.ExtraCostsViews = _ExtraCostsViews;
  230. _giView.ExtraCostsStr = string.Format(@"人民币总费用:{0} CNY", exTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  231. /*
  232. * 收款退还
  233. */
  234. decimal promTotalAmount = 0.00M;// 收款退还总金额
  235. List<Gsd_PaymentRefundAndOtherMoneyView> _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
  236. //删除了 And prom.PriceType = 1
  237. string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
  238. prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
  239. prom.PayType As PrPayType,prom.PriceType As PrPriceType,ccp.*
  240. From Fin_PaymentRefundAndOtherMoney prom
  241. Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
  242. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  243. Where prom.IsDel = 0 And prom.PayType = 1 And ccp.CTable = 285
  244. And ccp.IsAuditGM = 1 And ccp.IsPay = 1
  245. And prom.DiId = {0}", _dto.DiId);
  246. var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
  247. foreach (var ropItem in _promDatas)
  248. {
  249. string thisCueencyCode = "Unknown";
  250. string thisCueencyName = "Unknown";
  251. var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
  252. if (currency != null)
  253. {
  254. thisCueencyCode = currency.Name;
  255. thisCueencyName = currency.Remark;
  256. }
  257. string orbitalPrivateTransferStr = "Unknown";
  258. var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
  259. if (orbitalPrivateTransfer != null)
  260. {
  261. orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
  262. }
  263. string payStr = "Unknown";
  264. var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
  265. if (pay != null)
  266. {
  267. payStr = pay.Name;
  268. }
  269. Gsd_PaymentRefundAndOtherMoneyView gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
  270. {
  271. Id = ropItem.Id,
  272. DiId = ropItem.DIId,
  273. PriceName = ropItem.PrPriceName,
  274. PayCurrencyCode = thisCueencyCode,
  275. PayCurrencyName = thisCueencyName,
  276. Price = ropItem.PrPrice,
  277. CNYPrice = ropItem.RMBPrice,
  278. ThisRate = ropItem.DayRate,
  279. Payee = ropItem.Payee,
  280. PayTime = ropItem.AuditGMDate,
  281. OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
  282. PayType = payStr,
  283. IsPay = ropItem.IsPay,
  284. Applicant = ropItem.Appliction
  285. };
  286. _promView.Add(gsd_PaymentRefund);
  287. }
  288. #region 模拟数据
  289. //if (_promView.Count < 1)
  290. //{
  291. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  292. // {
  293. // Id = 0,
  294. // DiId = 2334,
  295. // PriceName = "模拟数据-费用名称",
  296. // PayCurrencyCode = "CNY",
  297. // PayCurrencyName = "人民币",
  298. // Price = 1000.00M,
  299. // CNYPrice = 1000.00M,
  300. // ThisRate = 1.00M,
  301. // Payee = "模拟数据-收款方",
  302. // PayTime = "2023-01-01 15:20:01",
  303. // OrbitalPrivateTransfer = 1,
  304. // PayType = "刷卡",
  305. // IsPay = 1,
  306. // Applicant = "刘华举"
  307. // });
  308. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  309. // {
  310. // Id = 0,
  311. // DiId = 2334,
  312. // PriceName = "模拟数据-费用名称",
  313. // PayCurrencyCode = "CNY",
  314. // PayCurrencyName = "人民币",
  315. // Price = 1000.00M,
  316. // CNYPrice = 1000.00M,
  317. // ThisRate = 1.00M,
  318. // Payee = "模拟数据-收款方",
  319. // PayTime = "2023-01-01 15:20:01",
  320. // OrbitalPrivateTransfer = 1,
  321. // PayType = "刷卡",
  322. // IsPay = 1,
  323. // Applicant = "刘华举"
  324. // });
  325. //}
  326. #endregion
  327. promTotalAmount = _promView.Sum(it => it.CNYPrice);
  328. _giView.PaymentRefundAndOtherMoneyViews = _promView;
  329. _giView.PaymentRefundAndOtherMoneyStr = string.Format(@"人民币总费用:{0} CNY", promTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  330. decimal BalancePayment = frTotalAmount - prTotalAmount + promTotalAmount;
  331. _view.GroupIncome = _giView;
  332. _view.GroupIncomeStr = string.Format(@"<span style='color:red;'>剩余尾款:{0} CNY(包含了收款退还费用数据)</span>", BalancePayment.ConvertToDecimal1().ToString("#0.00"));
  333. #endregion
  334. #region 团组支出
  335. GroupExpenditureView _geView = new GroupExpenditureView();
  336. #region 酒店预定费用
  337. List<GroupHotelFeeView> groupHotelFeeViews = new List<GroupHotelFeeView>();
  338. string hotelFeeSql = string.Format(@"Select hr.Id As HrId,hr.DiId As HrDiId,hr.City,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,
  339. sd1.Name As PaymentCurrency,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  340. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,
  341. hr.BreakfastPrice,sd4.Name As BreakfastCurrency,hr.Isoppay,hr.GovernmentRent,
  342. sd5.Name As GovernmentRentCurrency,hr.CityTax,sd6.Name As CityTaxCurrency,
  343. ccp.PayMoney,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,
  344. sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  345. From Grp_HotelReservations hr
  346. Left Join Grp_CreditCardPayment ccp On hr.Id = ccp.CId
  347. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  348. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  349. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  350. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  351. Left Join Sys_SetData sd4 On hr.BreakfastCurrency = sd4.Id
  352. Left Join Sys_SetData sd5 On hr.GovernmentRentCurrency = sd5.Id
  353. Left Join Sys_SetData sd6 On hr.CityTaxCurrency = sd6.Id
  354. Where hr.IsDel = 0 And ccp.IsDel = 0 And ccp.CTable = 76 And ccp.IsAuditGM = 1 And ccp.IsPay = 1
  355. And hr.DiId = {0}", _dto.DiId);
  356. groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
  357. decimal HotelCNYTotalPrice = 0.00M;
  358. var teamRateData = await _teamRateRep.PostGroupRateInfoByDiId(_dto.DiId);
  359. foreach (var item in groupHotelFeeViews)
  360. {
  361. HotelCNYTotalPrice += item.CNYPrice;
  362. item.PayMoney = item.PayMoney.ConvertToDecimal1();
  363. item.CNYPrice = item.CNYPrice.ConvertToDecimal1();
  364. string currencyRateStr = "";
  365. List<string> currencys = new List<string>();
  366. if (!string.IsNullOrEmpty(item.BreakfastCurrency)) currencys.Add(item.BreakfastCurrency);
  367. if (!string.IsNullOrEmpty(item.GovernmentRentCurrency)) currencys.Add(item.GovernmentRentCurrency);
  368. if (!string.IsNullOrEmpty(item.CityTaxCurrency)) currencys.Add(item.CityTaxCurrency);
  369. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  370. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 76, currencys);
  371. item.CurrencyRateStr = currencyRateStr;
  372. }
  373. _geView.GroupHotelFeeViews = groupHotelFeeViews;
  374. _geView.GroupHotelFeeStr = string.Format(@"人民币总费用:{0} CNY", HotelCNYTotalPrice.ToString("#0.00"));
  375. #endregion
  376. #region 地接费用
  377. List<GroupCTGGRFeeView> groupCTGGRFeeViews = new List<GroupCTGGRFeeView>();
  378. string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.Area,ctggrc.*,ccp.PayMoney,
  379. sd2.name As PaymentCurrency,ccp.PayPercentage,(ccp.PayMoney * ccp.PayPercentage / 100) As AmountPaid,
  380. (ccp.PayMoney -(ccp.PayMoney * ccp.PayPercentage / 100)) As BalancePayment,ccp.DayRate,
  381. ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  382. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant
  383. From Grp_CarTouristGuideGroundReservations ctggr
  384. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price,sd2.Name As PriceCurrency,
  385. cggrc.PriceContent
  386. From Grp_CarTouristGuideGroundReservationsContent cggrc
  387. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  388. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  389. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  390. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  391. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  392. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  393. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  394. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  395. Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ctggr.DiId = {0} ",_dto.DiId);
  396. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  397. string CTGGRFeeStr = "";
  398. decimal CTGGRCNYTotalPrice = 0.00M;
  399. foreach (var item in groupCTGGRFeeViews)
  400. {
  401. if (!string.IsNullOrEmpty(item.AuditGMDate))
  402. {
  403. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  404. }
  405. CTGGRFeeStr += string.Format(@"{0} 总费用:{1} {2}(人民币:{3} CNY 当时支付汇率:{4})\r\n",
  406. item.Area, item.AmountPaid.ConvertToDecimal1().ToString("#0.00"), item.PaymentCurrency, item.CNYPrice.ToString("#0.0000"), item.DayRate.ToString("#0.0000"));
  407. CTGGRCNYTotalPrice += item.CNYPrice;
  408. }
  409. _geView.GroupCTGGRFeeViews = groupCTGGRFeeViews;
  410. _geView.GroupCTGGRFeeStr = string.Format(@"{0}人民币总费用:{1} CNY", CTGGRFeeStr,CTGGRCNYTotalPrice.ToString("#0.00"));
  411. #endregion
  412. #region 机票预订费用
  413. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  414. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  415. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  416. sd1.Name As PayMoneyCurrency,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  417. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  418. From Grp_AirTicketReservations atr
  419. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  420. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  421. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  422. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  423. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  424. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  425. Where atr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And atr.DiId = {0} ", _dto.DiId);
  426. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  427. string str = "";
  428. List<dynamic> airClientPris = new List<dynamic>();
  429. decimal AirCNYTotalPrice = 0.00M;
  430. decimal JJCCNYTotalPrice = 0.00M, JJCPeopleNum = 0.00M, JJCAveragePrice = 0.00M;
  431. decimal GWCCNYTotalPrice = 0.00M, GWCPeopleNum = 0.00M, GWCAveragePrice = 0.00M;
  432. //if (groupAirFeeViews.Count > 0)
  433. //{
  434. // JJCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.CNYPrice);
  435. // JJCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.ClientNum);
  436. // JJCAveragePrice = (JJCCNYTotalPrice / JJCPeopleNum).ConvertToDecimal1();
  437. // GWCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.CNYPrice);
  438. // GWCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.ClientNum);
  439. // GWCAveragePrice = (GWCCNYTotalPrice / GWCPeopleNum).ConvertToDecimal1();
  440. //}
  441. int Index = 0;
  442. foreach (var item in groupAirFeeViews)
  443. {
  444. if (item.AirId > 2924)
  445. {
  446. string itemClientName = "";
  447. if (!string.IsNullOrEmpty(item.ClientName))
  448. {
  449. string[] clientIds = new string[] { };
  450. if (item.ClientName.Contains(','))
  451. {
  452. clientIds = item.ClientName.Split(',');
  453. }
  454. else
  455. {
  456. clientIds = new string[] { item.ClientName };
  457. }
  458. if (clientIds.Length > 0)
  459. {
  460. int[] output = Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
  461. if (output.Contains(-1))
  462. {
  463. itemClientName += $@"行程单";
  464. output = output.Where(val => val != -1).ToArray();
  465. }
  466. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  467. decimal unitCost = 0.00M;
  468. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  469. int clienIndex = 1;
  470. foreach (var client in clients)
  471. {
  472. airClientPris.Add(new {
  473. CnName = client.LastName+client.FirstName,
  474. EnName = client.Pinyin,
  475. Price = unitCost,
  476. AirType = item.AirTypeName
  477. });
  478. string six = "";
  479. if (client.Sex == 0) six = "Mr";
  480. else if (client.Sex == 1) six = "Ms";
  481. itemClientName += string.Format(@"{0}.{1} {2};", clienIndex, client.LastName + client.FirstName, six);
  482. clienIndex++;
  483. }
  484. }
  485. }
  486. item.ClientName = itemClientName;
  487. }
  488. else
  489. {
  490. string clientPinYinName = "";
  491. decimal unitCost = 0.00M;
  492. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  493. string[] clientNames = item.ClientName.Split('.');
  494. for (int i = 0; i < item.ClientNum; i++)
  495. {
  496. string name = "";
  497. if (clientNames.Length > 0)
  498. {
  499. int index = i + 1;
  500. if (index < clientNames.Length)
  501. {
  502. name = clientNames[index].Replace("MR","").Replace("MS","");
  503. }
  504. }
  505. clientPinYinName += string.Format(@"{0}.{1}出票价为:{2} CNY;", Index, name, unitCost);
  506. }
  507. }
  508. if (!string.IsNullOrEmpty(item.AuditGMDate))
  509. {
  510. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  511. }
  512. AirCNYTotalPrice += item.CNYPrice;
  513. }
  514. _geView.GroupAirFeeViews = groupAirFeeViews;
  515. if (airClientPris.Count > 0)
  516. {
  517. var peoplePriStr = "";
  518. var airClientPris1 = airClientPris.GroupBy(item => item.CnName)
  519. .Select(group => group.First())
  520. .ToList();
  521. int airClientPrisIndex = 1;
  522. foreach (var item in airClientPris1)
  523. {
  524. decimal price = 0.00M;
  525. var prices = airClientPris.Where(it => it.CnName == item.CnName).ToList();
  526. foreach (var pri in prices)
  527. {
  528. price += pri.Price;
  529. }
  530. peoplePriStr += $@"{airClientPrisIndex}.{item.EnName}出票价为: { price.ToString("#0.00")} CNY;";
  531. airClientPrisIndex++;
  532. }
  533. if (!string.IsNullOrEmpty(peoplePriStr))
  534. {
  535. str = $@"其中:{peoplePriStr}";
  536. }
  537. //经济舱均价
  538. var airJJCPris = airClientPris.Where(it => it.AirType == "经济舱").ToList();
  539. if (airJJCPris.Count > 0)
  540. {
  541. decimal jjcTotalPrice = 0.00M;
  542. foreach (var item in airJJCPris)
  543. {
  544. jjcTotalPrice += item.Price;
  545. }
  546. decimal jjcPeopleNum = airJJCPris.GroupBy(item => item.CnName)
  547. .Select(group => group.First())
  548. .ToList().Count();;
  549. JJCAveragePrice = jjcTotalPrice / jjcPeopleNum;
  550. }
  551. //公务舱均价
  552. var airGWCPris = airClientPris.Where(it => it.AirType == "公务舱").ToList();
  553. if (airGWCPris.Count > 0)
  554. {
  555. decimal gwcTotalPrice = 0.00M;
  556. foreach (var item in airGWCPris)
  557. {
  558. gwcTotalPrice += item.Price;
  559. }
  560. decimal gwcPeopleNum = airGWCPris.GroupBy(item => item.CnName)
  561. .Select(group => group.First())
  562. .ToList().Count();
  563. GWCAveragePrice = gwcTotalPrice / gwcPeopleNum;
  564. }
  565. }
  566. _geView.GroupAirFeeStr = $@"人民币总费用:{AirCNYTotalPrice.ToString("#0.00")} CNY\r\n{str}\r\n经济舱均价为:{JJCAveragePrice.ToString("#0.00")}CNY/人;公务舱均价为:{GWCAveragePrice.ToString("#0.00")}CNY/人;";
  567. #endregion
  568. #region 签证费用
  569. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  570. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  571. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  572. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant
  573. From Grp_VisaInfo vi
  574. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  575. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  576. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  577. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  578. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  579. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And vi.DIId = {0}",_dto.DiId);
  580. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  581. decimal VisaCNYTotalPirce = 0.00M;
  582. foreach (var item in groupVisaFeeViews)
  583. {
  584. string itemClientName = "";
  585. string visaClients = item.VisaClient;
  586. if (!string.IsNullOrEmpty(visaClients))
  587. {
  588. string[] clientIds = new string[] { };
  589. if (visaClients.Contains(','))
  590. {
  591. clientIds = visaClients.Split(',');
  592. }
  593. else
  594. {
  595. clientIds = new string[] { visaClients };
  596. }
  597. if (clientIds.Length > 0)
  598. {
  599. List<int> clientIds1 = new List<int>() { };
  600. foreach (var clientIdStr in clientIds)
  601. {
  602. if (clientIdStr.IsNumeric())
  603. {
  604. clientIds1.Add(int.Parse(clientIdStr));
  605. }
  606. }
  607. if (clientIds1.Count > 0)
  608. {
  609. var clients = _clientDatas.Where(it => clientIds1.Contains(it.Id)).ToList();
  610. foreach (var client in clients)
  611. {
  612. itemClientName += $"{client.LastName + client.FirstName},";
  613. }
  614. }
  615. else {
  616. itemClientName = visaClients;
  617. }
  618. }
  619. }
  620. if (itemClientName.Length > 0 )
  621. {
  622. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  623. }
  624. item.VisaClient = itemClientName;
  625. VisaCNYTotalPirce += item.PayMoney;
  626. if (!string.IsNullOrEmpty(item.AuditGMDate))
  627. {
  628. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  629. }
  630. }
  631. _geView.GroupVisaFeeViews = groupVisaFeeViews;
  632. _geView.GroupVisaFeeStr = string.Format(@"人民币总费用:{0} CNY", VisaCNYTotalPirce.ConvertToDecimal1());
  633. #endregion
  634. #region 邀请/公务活动费用 CTable = 81
  635. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  636. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  637. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  638. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  639. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  640. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant
  641. From Grp_InvitationOfficialActivities ioa
  642. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  643. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  644. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  645. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  646. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  647. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  648. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  649. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  650. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  651. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ioa.Diid = {0}",_dto.DiId);
  652. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  653. #region 模拟数据
  654. //if (groupInvitationalFeeViews.Count < 1)
  655. //{
  656. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  657. // {
  658. // IOAId = 0,
  659. // IOADiId = 2334,
  660. // InviterArea = "模拟数据-邀请方地区",
  661. // Inviter = "模拟数据-邀请方",
  662. // InviteTime = "2023-10-10",
  663. // InviteCost = 100.00M,
  664. // InviteCurrency = "EUR",
  665. // SendCost = 100.00M,
  666. // SendCurrency = "EUR",
  667. // EventsCost = 10000.00M,
  668. // EventsCurrency = "EUR",
  669. // TranslateCost = 300.00M,
  670. // TranslateCurrency = "EUR",
  671. // PayMoney = 10500.00M,
  672. // PaymentCurrency = "EUR",
  673. // CNYPrice = 76765.50M,
  674. // Payee = "模拟数据-收款方",
  675. // AuditGMDate = "2023-12-05",
  676. // OrbitalPrivateTransfer = 1,
  677. // PayWay = "刷卡",
  678. // IsPay = 1,
  679. // Applicant = "刘华举"
  680. // });
  681. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  682. // {
  683. // IOAId = 0,
  684. // IOADiId = 2334,
  685. // InviterArea = "模拟数据-邀请方地区",
  686. // Inviter = "模拟数据-邀请方",
  687. // InviteTime = "2023-10-10",
  688. // InviteCost = 100.00M,
  689. // InviteCurrency = "EUR",
  690. // SendCost = 100.00M,
  691. // SendCurrency = "EUR",
  692. // EventsCost = 10000.00M,
  693. // EventsCurrency = "EUR",
  694. // TranslateCost = 300.00M,
  695. // TranslateCurrency = "EUR",
  696. // PayMoney = 10500.00M,
  697. // PaymentCurrency = "EUR",
  698. // CNYPrice = 76765.50M,
  699. // Payee = "模拟数据-收款方",
  700. // AuditGMDate = "2023-12-05",
  701. // OrbitalPrivateTransfer = 1,
  702. // PayWay = "刷卡",
  703. // IsPay = 1,
  704. // Applicant = "刘华举"
  705. // });
  706. //}
  707. #endregion
  708. decimal InvitationalCNYTotalPrice = 0.00M;
  709. foreach (var item in groupInvitationalFeeViews)
  710. {
  711. InvitationalCNYTotalPrice += item.CNYPrice;
  712. if (!string.IsNullOrEmpty(item.AuditGMDate))
  713. {
  714. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  715. }
  716. string currencyRateStr = "";
  717. List<string> currencys = new List<string>();
  718. if (!string.IsNullOrEmpty(item.InviteCurrency)) currencys.Add(item.InviteCurrency);
  719. if (!string.IsNullOrEmpty(item.SendCurrency)) currencys.Add(item.SendCurrency);
  720. if (!string.IsNullOrEmpty(item.EventsCurrency)) currencys.Add(item.EventsCurrency);
  721. if (!string.IsNullOrEmpty(item.TranslateCurrency)) currencys.Add(item.TranslateCurrency);
  722. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  723. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 81, currencys);
  724. item.CurrencyRateStr = currencyRateStr;
  725. }
  726. _geView.GroupInvitationalFeeViews = groupInvitationalFeeViews;
  727. _geView.GroupInvitationalFeeStr = string.Format(@"人民币总费用:{0} CNY", InvitationalCNYTotalPrice);
  728. #endregion
  729. #region 保险费用
  730. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  731. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  732. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  733. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant
  734. From Grp_Customers ic
  735. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  736. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  737. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  738. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  739. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ic.DiId = {0}", _dto.DiId);
  740. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  741. decimal InsuranceCNYTotalPrice = 0.00M;
  742. foreach (var item in groupInsuranceFeeViews)
  743. {
  744. InsuranceCNYTotalPrice += item.CNYPrice;
  745. string itemClientName = "";
  746. string insClients = item.ClientName;
  747. if (!string.IsNullOrEmpty(insClients))
  748. {
  749. string[] clientIds = new string[] { };
  750. if (insClients.Contains(','))
  751. {
  752. clientIds = insClients.Split(',');
  753. }
  754. else
  755. {
  756. clientIds = new string[] { insClients };
  757. }
  758. if (clientIds.Length > 0)
  759. {
  760. List<int> output = new List<int>();
  761. foreach (var clientId in clientIds)
  762. {
  763. if (clientId.IsNumeric())
  764. {
  765. output.Add(int.Parse(clientId));
  766. }
  767. }
  768. if (output.Count > 0)
  769. {
  770. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  771. foreach (var client in clients)
  772. {
  773. itemClientName += $"{client.LastName + client.FirstName},";
  774. }
  775. if (itemClientName.Length > 0)
  776. {
  777. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  778. }
  779. }
  780. else
  781. {
  782. itemClientName = insClients;
  783. }
  784. }
  785. }
  786. item.ClientName = itemClientName;
  787. if (!string.IsNullOrEmpty(item.AuditGMDate))
  788. {
  789. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  790. }
  791. }
  792. _geView.GroupInsuranceFeeViews = groupInsuranceFeeViews;
  793. _geView.GroupInsuranceFeeStr = string.Format(@"人民币总费用:{0} CNY", InsuranceCNYTotalPrice.ToString("#0.00"));
  794. #endregion
  795. #region 其他款项费用
  796. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  797. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  798. ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  799. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant
  800. From Grp_DecreasePayments dp
  801. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  802. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  803. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  804. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  805. Where dp.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And dp.Diid = {0}",_dto.DiId);
  806. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  807. #region 模拟数据
  808. //if (groupDecreaseFeeViews.Count < 1)
  809. //{
  810. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  811. // {
  812. // DPId = 0,
  813. // DPDiId = 2334,
  814. // PriceName = "模拟数据-费用名称",
  815. // PayMoney = 1000.00M,
  816. // PayMoneyCurrency = "CNY",
  817. // DayRate = 1.0000M,
  818. // CNYPrice = 1.0000M,
  819. // AuditGMDate = "2023-12-10 12:13:00",
  820. // Payee = "模拟数据-付款方",
  821. // OrbitalPrivateTransfer = 1,
  822. // PayWay = "现金",
  823. // IsPay = 1,
  824. // Applicant = "刘华举"
  825. // });
  826. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  827. // {
  828. // DPId = 0,
  829. // DPDiId = 2334,
  830. // PriceName = "模拟数据-费用名称",
  831. // PayMoney = 1000.00M,
  832. // PayMoneyCurrency = "CNY",
  833. // DayRate = 1.0000M,
  834. // CNYPrice = 1.0000M,
  835. // AuditGMDate = "2023-12-10 12:13:00",
  836. // Payee = "模拟数据-付款方",
  837. // OrbitalPrivateTransfer = 1,
  838. // PayWay = "现金",
  839. // IsPay = 1,
  840. // Applicant = "刘华举"
  841. // });
  842. //}
  843. #endregion
  844. decimal DecreaseCNYTotalPrice = 0.00M;
  845. foreach (var item in groupDecreaseFeeViews)
  846. {
  847. DecreaseCNYTotalPrice += item.CNYPrice;
  848. if (!string.IsNullOrEmpty(item.AuditGMDate))
  849. {
  850. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  851. }
  852. }
  853. _geView.GroupDecreaseFeeViews = groupDecreaseFeeViews;
  854. _geView.GroupDecreaseFeeStr = string.Format(@"人民币总费用:{0} CNY", DecreaseCNYTotalPrice.ToString("#0.00"));
  855. #endregion
  856. _view.GroupExpenditure = _geView;
  857. #endregion
  858. decimal _totalExpenditure = 0.00M; //总支出
  859. decimal _amountReceivable = 0.00M; //应收金额
  860. decimal _amountReceived = 0.00M; //已收金额
  861. decimal _profit = 0.00M; //利润
  862. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  863. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  864. _amountReceivable = frTotalAmount;
  865. _amountReceived = prTotalAmount;
  866. _profit = _amountReceived - _totalExpenditure;
  867. _view.FeeTotalStr = string.Format(@"<span>
  868. <span>当前总支出:{0} CNY</span>
  869. <span style='padding-left:10px;color: Green;'>应收金额:{1} CNY</span>
  870. <span style='padding-left:10px;color: Green;'>已收金额:{2} CNY</span>
  871. <span style='padding-left:10px;color: Green;'>利润(收入-支出):{3} CNY</span>
  872. </span>", _totalExpenditure, _amountReceivable, _amountReceived, _profit);
  873. return Ok(JsonView(true, "查询成功!", _view));
  874. }
  875. else
  876. {
  877. return Ok(JsonView(false, "查询成功"));
  878. }
  879. }
  880. #endregion
  881. }
  882. }