StatisticsController.cs 37 KB

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