StatisticsController.cs 54 KB

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