StatisticsController.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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. foreach (var client in clients)
  455. {
  456. Index += 1;
  457. int clienIndex = 1;
  458. itemClientName += string.Format(@"{0}.{1} ;", clienIndex, client);
  459. clientPinYinName += string.Format(@"{0}.{1}出票价为:{2} CNY;", Index, client.Pinyin, unitCost);
  460. clienIndex++;
  461. }
  462. }
  463. }
  464. item.ClientName = itemClientName;
  465. }
  466. else
  467. {
  468. string clientPinYinName = "";
  469. decimal unitCost = 0.00M;
  470. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  471. string[] clientNames = item.ClientName.Split('.');
  472. for (int i = 0; i < item.ClientNum; i++)
  473. {
  474. string name = "";
  475. if (clientNames.Length > 0)
  476. {
  477. int index = i + 1;
  478. if (index < clientNames.Length)
  479. {
  480. name = clientNames[index].Replace("MR","").Replace("MS","");
  481. }
  482. }
  483. clientPinYinName += string.Format(@"{0}.{1}出票价为:{2} CNY;", Index, name, unitCost);
  484. }
  485. }
  486. if (!string.IsNullOrEmpty(item.AuditGMDate))
  487. {
  488. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  489. }
  490. }
  491. _geView.GroupAirFeeViews = groupAirFeeViews;
  492. if (!string.IsNullOrEmpty(str))
  493. {
  494. str = string.Format(@"其中:{0}", str);
  495. }
  496. _geView.GroupAirFeeStr = string.Format(@"人名币总费用:{0} CNY\r\n{1}\r\n经济舱均价为:{2}CNY/人;公务舱均价为:{3}CNY/人;", AirCNYTotalPrice, str, JJCAveragePrice, GWCAveragePrice);
  497. #endregion
  498. #region 签证费用
  499. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  500. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  501. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  502. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant
  503. From Grp_VisaInfo vi
  504. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  505. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  506. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  507. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  508. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  509. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And vi.DIId = {0}",_dto.DiId);
  510. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  511. decimal VisaCNYTotalPirce = 0.00M;
  512. foreach (var item in groupVisaFeeViews)
  513. {
  514. VisaCNYTotalPirce += item.PayMoney;
  515. if (!string.IsNullOrEmpty(item.AuditGMDate))
  516. {
  517. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  518. }
  519. }
  520. _geView.GroupVisaFeeViews = groupVisaFeeViews;
  521. _geView.GroupVisaFeeStr = string.Format(@"人名币总费用:{0} CNY", VisaCNYTotalPirce.ConvertToDecimal1());
  522. #endregion
  523. #region 邀请/公务活动费用 CTable = 81
  524. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  525. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  526. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  527. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  528. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  529. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant
  530. From Grp_InvitationOfficialActivities ioa
  531. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  532. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  533. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  534. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  535. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  536. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  537. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  538. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  539. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  540. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ioa.Diid = {0}",_dto.DiId);
  541. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  542. //模拟数据
  543. if (groupInvitationalFeeViews.Count < 1)
  544. {
  545. groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  546. {
  547. IOAId = 0,
  548. IOADiId = 2334,
  549. InviterArea = "模拟数据-邀请方地区",
  550. Inviter = "模拟数据-邀请方",
  551. InviteTime = "2023-10-10",
  552. InviteCost = 100.00M,
  553. InviteCurrency = "EUR",
  554. SendCost = 100.00M,
  555. SendCurrency = "EUR",
  556. EventsCost = 10000.00M,
  557. EventsCurrency = "EUR",
  558. TranslateCost = 300.00M,
  559. TranslateCurrency = "EUR",
  560. PayMoney = 10500.00M,
  561. PaymentCurrency = "EUR",
  562. CNYPrice = 76765.50M,
  563. Payee = "模拟数据-收款方",
  564. AuditGMDate = "2023-12-05",
  565. OrbitalPrivateTransfer = 1,
  566. PayWay = "刷卡",
  567. IsPay = 1,
  568. Applicant = "刘华举"
  569. });
  570. groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  571. {
  572. IOAId = 0,
  573. IOADiId = 2334,
  574. InviterArea = "模拟数据-邀请方地区",
  575. Inviter = "模拟数据-邀请方",
  576. InviteTime = "2023-10-10",
  577. InviteCost = 100.00M,
  578. InviteCurrency = "EUR",
  579. SendCost = 100.00M,
  580. SendCurrency = "EUR",
  581. EventsCost = 10000.00M,
  582. EventsCurrency = "EUR",
  583. TranslateCost = 300.00M,
  584. TranslateCurrency = "EUR",
  585. PayMoney = 10500.00M,
  586. PaymentCurrency = "EUR",
  587. CNYPrice = 76765.50M,
  588. Payee = "模拟数据-收款方",
  589. AuditGMDate = "2023-12-05",
  590. OrbitalPrivateTransfer = 1,
  591. PayWay = "刷卡",
  592. IsPay = 1,
  593. Applicant = "刘华举"
  594. });
  595. }
  596. decimal InvitationalCNYTotalPrice = 0.00M;
  597. foreach (var item in groupInvitationalFeeViews)
  598. {
  599. InvitationalCNYTotalPrice += item.CNYPrice;
  600. if (!string.IsNullOrEmpty(item.AuditGMDate))
  601. {
  602. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  603. }
  604. string currencyRateStr = "";
  605. List<string> currencys = new List<string>();
  606. if (!string.IsNullOrEmpty(item.InviteCurrency)) currencys.Add(item.InviteCurrency);
  607. if (!string.IsNullOrEmpty(item.SendCurrency)) currencys.Add(item.SendCurrency);
  608. if (!string.IsNullOrEmpty(item.EventsCurrency)) currencys.Add(item.EventsCurrency);
  609. if (!string.IsNullOrEmpty(item.TranslateCurrency)) currencys.Add(item.TranslateCurrency);
  610. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  611. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 81, currencys);
  612. item.CurrencyRateStr = currencyRateStr;
  613. }
  614. _geView.GroupInvitationalFeeViews = groupInvitationalFeeViews;
  615. _geView.GroupInvitationalFeeStr = string.Format(@"人民币总费用:{0} CNY", InvitationalCNYTotalPrice);
  616. #endregion
  617. #region 保险费用
  618. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  619. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  620. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  621. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant
  622. From Grp_Customers ic
  623. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  624. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  625. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  626. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  627. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ic.DiId = {0}", _dto.DiId);
  628. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  629. decimal InsuranceCNYTotalPrice = 0.00M;
  630. foreach (var item in groupInsuranceFeeViews)
  631. {
  632. InsuranceCNYTotalPrice += item.CNYPrice;
  633. if (!string.IsNullOrEmpty(item.AuditGMDate))
  634. {
  635. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  636. }
  637. }
  638. _geView.GroupInsuranceFeeViews = groupInsuranceFeeViews;
  639. _geView.GroupInsuranceFeeStr = string.Format(@"人名币总费用:{0} CNY", InsuranceCNYTotalPrice);
  640. #endregion
  641. #region 其他款项费用
  642. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  643. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  644. ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  645. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant
  646. From Grp_DecreasePayments dp
  647. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  648. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  649. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  650. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  651. Where dp.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And dp.Diid = {0}",_dto.DiId);
  652. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  653. decimal DecreaseCNYTotalPrice = 0.00M;
  654. foreach (var item in groupDecreaseFeeViews)
  655. {
  656. DecreaseCNYTotalPrice += item.CNYPrice;
  657. if (!string.IsNullOrEmpty(item.AuditGMDate))
  658. {
  659. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  660. }
  661. }
  662. _geView.GroupDecreaseFeeViews = groupDecreaseFeeViews;
  663. _geView.GroupDecreaseFeeStr = string.Format(@"人名币总费用:{0} CNY", DecreaseCNYTotalPrice);
  664. #endregion
  665. _view.GroupExpenditure = _geView;
  666. #endregion
  667. decimal _totalExpenditure = 0.00M; //总支出
  668. decimal _amountReceivable = 0.00M; //应收金额
  669. decimal _amountReceived = 0.00M; //已收金额
  670. decimal _profit = 0.00M; //利润
  671. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  672. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  673. _amountReceivable = frTotalAmount;
  674. _amountReceived = prTotalAmount;
  675. _profit = _amountReceived - _totalExpenditure;
  676. _view.FeeTotalStr = string.Format(@"<span>
  677. <span>当前总支出:{0} CNY</span>
  678. <span style='padding-left:10px;color: Green;'>应收金额:{1} CNY</span>
  679. <span style='padding-left:10px;color: Green;'>已收金额:{2} CNY</span>
  680. <span style='padding-left:10px;color: Green;'>利润(收入-支出):{3} CNY</span>
  681. </span>", _totalExpenditure, _amountReceivable, _amountReceived, _profit);
  682. return Ok(JsonView(true, "查询成功!", _view));
  683. }
  684. else
  685. {
  686. return Ok(JsonView(false, "查询成功"));
  687. }
  688. }
  689. #endregion
  690. }
  691. }