StatisticsController.cs 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  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
  364. And hr.DiId = {0}", _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.*,ccp.PayMoney,
  388. sd2.name As PaymentCurrency,ccp.PayPercentage,(ccp.PayMoney * ccp.PayPercentage / 100) As AmountPaid,
  389. (ccp.PayMoney -(ccp.PayMoney * ccp.PayPercentage / 100)) As BalancePayment,ccp.DayRate,
  390. ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  391. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  392. From Grp_CarTouristGuideGroundReservations ctggr
  393. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price,sd2.Name As PriceCurrency,
  394. cggrc.PriceContent
  395. From Grp_CarTouristGuideGroundReservationsContent cggrc
  396. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  397. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  398. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  399. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  400. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  401. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  402. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  403. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  404. Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ctggr.DiId = {0} Order By CreateTime", _dto.DiId);
  405. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  406. string CTGGRFeeStr = "";
  407. decimal CTGGRCNYTotalPrice = 0.00M;
  408. foreach (var item in groupCTGGRFeeViews)
  409. {
  410. if (!string.IsNullOrEmpty(item.AuditGMDate))
  411. {
  412. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  413. }
  414. CTGGRFeeStr += string.Format(@"{0} 总费用:{1} {2}(人民币:{3} CNY 当时支付汇率:{4})\r\n",
  415. item.Area, item.AmountPaid.ConvertToDecimal1().ToString("#0.00"), item.PaymentCurrency, item.CNYPrice.ToString("#0.0000"), item.DayRate.ToString("#0.0000"));
  416. CTGGRCNYTotalPrice += item.CNYPrice;
  417. }
  418. _geView.GroupCTGGRFeeViews = groupCTGGRFeeViews;
  419. _geView.GroupCTGGRFeeStr = string.Format(@"{0}人民币总费用:{1} CNY", CTGGRFeeStr,CTGGRCNYTotalPrice.ToString("#0.00"));
  420. #endregion
  421. #region 机票预订费用
  422. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  423. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  424. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  425. sd1.Name As PayMoneyCurrency,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  426. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,atr.CreateTime
  427. From Grp_AirTicketReservations atr
  428. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  429. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  430. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  431. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  432. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  433. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  434. Where atr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And atr.DiId = {0} Order By CreateTime", _dto.DiId);
  435. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  436. string str = "";
  437. List<dynamic> airClientPris = new List<dynamic>();
  438. decimal AirCNYTotalPrice = 0.00M;
  439. decimal JJCCNYTotalPrice = 0.00M, JJCPeopleNum = 0.00M, JJCAveragePrice = 0.00M;
  440. decimal GWCCNYTotalPrice = 0.00M, GWCPeopleNum = 0.00M, GWCAveragePrice = 0.00M;
  441. //if (groupAirFeeViews.Count > 0)
  442. //{
  443. // JJCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.CNYPrice);
  444. // JJCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.ClientNum);
  445. // JJCAveragePrice = (JJCCNYTotalPrice / JJCPeopleNum).ConvertToDecimal1();
  446. // GWCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.CNYPrice);
  447. // GWCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.ClientNum);
  448. // GWCAveragePrice = (GWCCNYTotalPrice / GWCPeopleNum).ConvertToDecimal1();
  449. //}
  450. int Index = 0;
  451. foreach (var item in groupAirFeeViews)
  452. {
  453. if (item.AirId > 2924)
  454. {
  455. string itemClientName = "";
  456. if (!string.IsNullOrEmpty(item.ClientName))
  457. {
  458. string[] clientIds = new string[] { };
  459. if (item.ClientName.Contains(','))
  460. {
  461. clientIds = item.ClientName.Split(',');
  462. }
  463. else
  464. {
  465. clientIds = new string[] { item.ClientName };
  466. }
  467. if (clientIds.Length > 0)
  468. {
  469. int[] output = Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
  470. if (output.Contains(-1))
  471. {
  472. itemClientName += $@"行程单";
  473. output = output.Where(val => val != -1).ToArray();
  474. }
  475. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  476. decimal unitCost = 0.00M;
  477. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  478. int clienIndex = 1;
  479. foreach (var client in clients)
  480. {
  481. airClientPris.Add(new {
  482. CnName = client.LastName+client.FirstName,
  483. EnName = client.Pinyin,
  484. Price = unitCost,
  485. AirType = item.AirTypeName
  486. });
  487. string six = "";
  488. if (client.Sex == 0) six = "Mr";
  489. else if (client.Sex == 1) six = "Ms";
  490. itemClientName += string.Format(@"{0}.{1} {2};", clienIndex, client.LastName + client.FirstName, six);
  491. clienIndex++;
  492. }
  493. }
  494. }
  495. item.ClientName = itemClientName;
  496. }
  497. else
  498. {
  499. string clientPinYinName = "";
  500. decimal unitCost = 0.00M;
  501. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  502. string[] clientNames = item.ClientName.Split('.');
  503. for (int i = 0; i < item.ClientNum; i++)
  504. {
  505. string name = "";
  506. if (clientNames.Length > 0)
  507. {
  508. int index = i + 1;
  509. if (index < clientNames.Length)
  510. {
  511. name = clientNames[index].Replace("MR","").Replace("MS","");
  512. }
  513. }
  514. clientPinYinName += string.Format(@"{0}.{1}出票价为:{2} CNY;", Index, name, unitCost);
  515. }
  516. }
  517. if (!string.IsNullOrEmpty(item.AuditGMDate))
  518. {
  519. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  520. }
  521. AirCNYTotalPrice += item.CNYPrice;
  522. }
  523. _geView.GroupAirFeeViews = groupAirFeeViews;
  524. if (airClientPris.Count > 0)
  525. {
  526. var peoplePriStr = "";
  527. var airClientPris1 = airClientPris.GroupBy(item => item.CnName)
  528. .Select(group => group.First())
  529. .ToList();
  530. int airClientPrisIndex = 1;
  531. foreach (var item in airClientPris1)
  532. {
  533. decimal price = 0.00M;
  534. var prices = airClientPris.Where(it => it.CnName == item.CnName).ToList();
  535. foreach (var pri in prices)
  536. {
  537. price += pri.Price;
  538. }
  539. peoplePriStr += $@"{airClientPrisIndex}.{item.EnName}出票价为: { price.ToString("#0.00")} CNY;";
  540. airClientPrisIndex++;
  541. }
  542. if (!string.IsNullOrEmpty(peoplePriStr))
  543. {
  544. str = $@"其中:{peoplePriStr}";
  545. }
  546. //经济舱均价
  547. var airJJCPris = airClientPris.Where(it => it.AirType == "经济舱").ToList();
  548. if (airJJCPris.Count > 0)
  549. {
  550. decimal jjcTotalPrice = 0.00M;
  551. foreach (var item in airJJCPris)
  552. {
  553. jjcTotalPrice += item.Price;
  554. }
  555. decimal jjcPeopleNum = airJJCPris.GroupBy(item => item.CnName)
  556. .Select(group => group.First())
  557. .ToList().Count();;
  558. JJCAveragePrice = jjcTotalPrice / jjcPeopleNum;
  559. }
  560. //公务舱均价
  561. var airGWCPris = airClientPris.Where(it => it.AirType == "公务舱").ToList();
  562. if (airGWCPris.Count > 0)
  563. {
  564. decimal gwcTotalPrice = 0.00M;
  565. foreach (var item in airGWCPris)
  566. {
  567. gwcTotalPrice += item.Price;
  568. }
  569. decimal gwcPeopleNum = airGWCPris.GroupBy(item => item.CnName)
  570. .Select(group => group.First())
  571. .ToList().Count();
  572. GWCAveragePrice = gwcTotalPrice / gwcPeopleNum;
  573. }
  574. }
  575. _geView.GroupAirFeeStr = $@"人民币总费用:{AirCNYTotalPrice.ToString("#0.00")} CNY\r\n{str}\r\n经济舱均价为:{JJCAveragePrice.ToString("#0.00")}CNY/人;公务舱均价为:{GWCAveragePrice.ToString("#0.00")}CNY/人;";
  576. #endregion
  577. #region 签证费用
  578. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  579. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  580. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  581. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant,vi.CreateTime
  582. From Grp_VisaInfo vi
  583. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  584. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  585. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  586. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  587. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  588. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And vi.DIId = {0} Order By CreateTime", _dto.DiId);
  589. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  590. decimal VisaCNYTotalPirce = 0.00M;
  591. foreach (var item in groupVisaFeeViews)
  592. {
  593. string itemClientName = "";
  594. string visaClients = item.VisaClient;
  595. if (!string.IsNullOrEmpty(visaClients))
  596. {
  597. string[] clientIds = new string[] { };
  598. if (visaClients.Contains(','))
  599. {
  600. clientIds = visaClients.Split(',');
  601. }
  602. else
  603. {
  604. clientIds = new string[] { visaClients };
  605. }
  606. if (clientIds.Length > 0)
  607. {
  608. List<int> clientIds1 = new List<int>() { };
  609. foreach (var clientIdStr in clientIds)
  610. {
  611. if (clientIdStr.IsNumeric())
  612. {
  613. clientIds1.Add(int.Parse(clientIdStr));
  614. }
  615. }
  616. if (clientIds1.Count > 0)
  617. {
  618. var clients = _clientDatas.Where(it => clientIds1.Contains(it.Id)).ToList();
  619. foreach (var client in clients)
  620. {
  621. itemClientName += $"{client.LastName + client.FirstName},";
  622. }
  623. }
  624. else {
  625. itemClientName = visaClients;
  626. }
  627. }
  628. }
  629. if (itemClientName.Length > 0 )
  630. {
  631. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  632. }
  633. item.VisaClient = itemClientName;
  634. VisaCNYTotalPirce += item.PayMoney;
  635. if (!string.IsNullOrEmpty(item.AuditGMDate))
  636. {
  637. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  638. }
  639. }
  640. _geView.GroupVisaFeeViews = groupVisaFeeViews;
  641. _geView.GroupVisaFeeStr = string.Format(@"人民币总费用:{0} CNY", VisaCNYTotalPirce.ConvertToDecimal1());
  642. #endregion
  643. #region 邀请/公务活动 CTable = 81
  644. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  645. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  646. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  647. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  648. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  649. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ioa.CreateTime
  650. From Grp_InvitationOfficialActivities ioa
  651. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  652. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  653. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  654. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  655. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  656. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  657. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  658. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  659. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  660. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ioa.Diid = {0} Order By CreateTime", _dto.DiId);
  661. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  662. #region 邀请/公务活动 - 模拟数据
  663. //if (groupInvitationalFeeViews.Count < 1)
  664. //{
  665. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  666. // {
  667. // IOAId = 0,
  668. // IOADiId = 2334,
  669. // InviterArea = "模拟数据-邀请方地区",
  670. // Inviter = "模拟数据-邀请方",
  671. // InviteTime = "2023-10-10",
  672. // InviteCost = 100.00M,
  673. // InviteCurrency = "EUR",
  674. // SendCost = 100.00M,
  675. // SendCurrency = "EUR",
  676. // EventsCost = 10000.00M,
  677. // EventsCurrency = "EUR",
  678. // TranslateCost = 300.00M,
  679. // TranslateCurrency = "EUR",
  680. // PayMoney = 10500.00M,
  681. // PaymentCurrency = "EUR",
  682. // CNYPrice = 76765.50M,
  683. // Payee = "模拟数据-收款方",
  684. // AuditGMDate = "2023-12-05",
  685. // OrbitalPrivateTransfer = 1,
  686. // PayWay = "刷卡",
  687. // IsPay = 1,
  688. // Applicant = "刘华举"
  689. // });
  690. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  691. // {
  692. // IOAId = 0,
  693. // IOADiId = 2334,
  694. // InviterArea = "模拟数据-邀请方地区",
  695. // Inviter = "模拟数据-邀请方",
  696. // InviteTime = "2023-10-10",
  697. // InviteCost = 100.00M,
  698. // InviteCurrency = "EUR",
  699. // SendCost = 100.00M,
  700. // SendCurrency = "EUR",
  701. // EventsCost = 10000.00M,
  702. // EventsCurrency = "EUR",
  703. // TranslateCost = 300.00M,
  704. // TranslateCurrency = "EUR",
  705. // PayMoney = 10500.00M,
  706. // PaymentCurrency = "EUR",
  707. // CNYPrice = 76765.50M,
  708. // Payee = "模拟数据-收款方",
  709. // AuditGMDate = "2023-12-05",
  710. // OrbitalPrivateTransfer = 1,
  711. // PayWay = "刷卡",
  712. // IsPay = 1,
  713. // Applicant = "刘华举"
  714. // });
  715. //}
  716. #endregion
  717. decimal InvitationalCNYTotalPrice = 0.00M;
  718. foreach (var item in groupInvitationalFeeViews)
  719. {
  720. InvitationalCNYTotalPrice += item.CNYPrice;
  721. if (!string.IsNullOrEmpty(item.AuditGMDate))
  722. {
  723. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  724. }
  725. string currencyRateStr = "";
  726. List<string> currencys = new List<string>();
  727. if (!string.IsNullOrEmpty(item.InviteCurrency)) currencys.Add(item.InviteCurrency);
  728. if (!string.IsNullOrEmpty(item.SendCurrency)) currencys.Add(item.SendCurrency);
  729. if (!string.IsNullOrEmpty(item.EventsCurrency)) currencys.Add(item.EventsCurrency);
  730. if (!string.IsNullOrEmpty(item.TranslateCurrency)) currencys.Add(item.TranslateCurrency);
  731. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  732. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 81, currencys);
  733. item.CurrencyRateStr = currencyRateStr;
  734. }
  735. _geView.GroupInvitationalFeeViews = groupInvitationalFeeViews;
  736. _geView.GroupInvitationalFeeStr = string.Format(@"人民币总费用:{0} CNY", InvitationalCNYTotalPrice);
  737. #endregion
  738. #region 保险费用
  739. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  740. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  741. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  742. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ic.CreateTime
  743. From Grp_Customers ic
  744. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  745. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  746. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  747. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  748. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ic.DiId = {0} Order By CreateTime", _dto.DiId);
  749. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  750. decimal InsuranceCNYTotalPrice = 0.00M;
  751. foreach (var item in groupInsuranceFeeViews)
  752. {
  753. InsuranceCNYTotalPrice += item.CNYPrice;
  754. string itemClientName = "";
  755. string insClients = item.ClientName;
  756. if (!string.IsNullOrEmpty(insClients))
  757. {
  758. string[] clientIds = new string[] { };
  759. if (insClients.Contains(','))
  760. {
  761. clientIds = insClients.Split(',');
  762. }
  763. else
  764. {
  765. clientIds = new string[] { insClients };
  766. }
  767. if (clientIds.Length > 0)
  768. {
  769. List<int> output = new List<int>();
  770. foreach (var clientId in clientIds)
  771. {
  772. if (clientId.IsNumeric())
  773. {
  774. output.Add(int.Parse(clientId));
  775. }
  776. }
  777. if (output.Count > 0)
  778. {
  779. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  780. foreach (var client in clients)
  781. {
  782. itemClientName += $"{client.LastName + client.FirstName},";
  783. }
  784. if (itemClientName.Length > 0)
  785. {
  786. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  787. }
  788. }
  789. else
  790. {
  791. itemClientName = insClients;
  792. }
  793. }
  794. }
  795. item.ClientName = itemClientName;
  796. if (!string.IsNullOrEmpty(item.AuditGMDate))
  797. {
  798. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  799. }
  800. }
  801. _geView.GroupInsuranceFeeViews = groupInsuranceFeeViews;
  802. _geView.GroupInsuranceFeeStr = string.Format(@"人民币总费用:{0} CNY", InsuranceCNYTotalPrice.ToString("#0.00"));
  803. #endregion
  804. #region 其他款项费用 98
  805. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  806. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  807. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,
  808. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  809. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,dp.CreateTime
  810. From Grp_DecreasePayments dp
  811. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  812. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  813. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  814. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  815. Where dp.IsDel = 0 And ccp.Ctable = 98 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And dp.Diid = {0}
  816. Order By CreateTime", _dto.DiId);
  817. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  818. #region 保险费用 - 模拟数据
  819. //if (groupDecreaseFeeViews.Count < 1)
  820. //{
  821. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  822. // {
  823. // DPId = 0,
  824. // DPDiId = 2334,
  825. // PriceName = "模拟数据-费用名称",
  826. // PayMoney = 1000.00M,
  827. // PayMoneyCurrency = "CNY",
  828. // DayRate = 1.0000M,
  829. // CNYPrice = 1.0000M,
  830. // AuditGMDate = "2023-12-10 12:13:00",
  831. // Payee = "模拟数据-付款方",
  832. // OrbitalPrivateTransfer = 1,
  833. // PayWay = "现金",
  834. // IsPay = 1,
  835. // Applicant = "刘华举"
  836. // });
  837. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  838. // {
  839. // DPId = 0,
  840. // DPDiId = 2334,
  841. // PriceName = "模拟数据-费用名称",
  842. // PayMoney = 1000.00M,
  843. // PayMoneyCurrency = "CNY",
  844. // DayRate = 1.0000M,
  845. // CNYPrice = 1.0000M,
  846. // AuditGMDate = "2023-12-10 12:13:00",
  847. // Payee = "模拟数据-付款方",
  848. // OrbitalPrivateTransfer = 1,
  849. // PayWay = "现金",
  850. // IsPay = 1,
  851. // Applicant = "刘华举"
  852. // });
  853. //}
  854. #endregion
  855. decimal DecreaseCNYTotalPrice = 0.00M;
  856. foreach (var item in groupDecreaseFeeViews)
  857. {
  858. item.CNYPrice = Convert.ToDecimal(item.CNYPrice.ToString("#0.00"));
  859. DecreaseCNYTotalPrice += item.CNYPrice;
  860. if (!string.IsNullOrEmpty(item.AuditGMDate))
  861. {
  862. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  863. }
  864. }
  865. _geView.GroupDecreaseFeeViews = groupDecreaseFeeViews;
  866. _geView.GroupDecreaseFeeStr = string.Format(@"人民币总费用:{0} CNY", DecreaseCNYTotalPrice.ToString("#0.00"));
  867. #endregion
  868. _view.GroupExpenditure = _geView;
  869. #endregion
  870. /*
  871. * 团组报表计算方式
  872. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  873. * 应收金额 = 应收表.Sum()
  874. * 已收金额 = 已收表.Sum()
  875. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  876. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  877. *
  878. */
  879. decimal _totalExpenditure = 0.00M; //总支出
  880. decimal _amountReceivable = 0.00M; //应收金额
  881. decimal _amountReceived = 0.00M; //已收金额
  882. decimal _receivableProfit = 0.00M; //应收利润
  883. decimal _receivedProfit = 0.00M; //已收利润
  884. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  885. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  886. _amountReceivable = frTotalAmount;
  887. _amountReceived = prTotalAmount;
  888. _receivableProfit = _amountReceivable - promTotalAmount - _totalExpenditure;
  889. _receivedProfit = _amountReceived - promTotalAmount - _totalExpenditure;
  890. _view.FeeTotalStr = string.Format(@$"<span>
  891. <span>当前总支出:{_totalExpenditure.ToString("#0.00")} CNY</span>
  892. <span style='padding-left:10px;color: Green;'>应收金额:{_amountReceivable.ToString("#0.00")} CNY</span>
  893. <span style='padding-left:10px;color: Green;'>已收金额:{_amountReceived.ToString("#0.00")} CNY</span>
  894. <span style='padding-left:10px;color: Green;'>应收利润(应收-支出):{_receivableProfit.ToString("#0.00")} CNY</span>
  895. <span style='padding-left:10px;color: Green;'>已收利润(已收-支出):{_receivedProfit.ToString("#0.00")} CNY</span>
  896. </span>");
  897. return Ok(JsonView(true, "查询成功!", _view));
  898. }
  899. else
  900. {
  901. return Ok(JsonView(false, "查询成功"));
  902. }
  903. }
  904. #endregion
  905. }
  906. }