StatisticsController.cs 46 KB

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