StatisticsController.cs 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  1. using Microsoft.AspNetCore.Mvc;
  2. using NPOI.POIFS.Properties;
  3. using NPOI.SS.Formula.Functions;
  4. using OASystem.API.OAMethodLib;
  5. using OASystem.Domain.Dtos.Groups;
  6. using OASystem.Domain.Dtos.Statistics;
  7. using OASystem.Domain.Entities.Financial;
  8. using OASystem.Domain.ViewModels.Financial;
  9. using OASystem.Domain.ViewModels.Groups;
  10. using OASystem.Domain.ViewModels.Statistics;
  11. using OASystem.Infrastructure.Repositories.Groups;
  12. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  13. using System;
  14. using OASystem.Domain.Entities.Customer;
  15. using System.Collections.Generic;
  16. using Microsoft.AspNetCore.Mvc.RazorPages;
  17. using Microsoft.VisualBasic;
  18. using OASystem.Domain.Entities.Groups;
  19. using Microsoft.Extensions.DependencyInjection;
  20. using Aspose.Words.Lists;
  21. using static OASystem.API.OAMethodLib.GeneralMethod;
  22. using TypeInfo = OASystem.Domain.ViewModels.Statistics.TypeInfo;
  23. namespace OASystem.API.Controllers
  24. {
  25. /// <summary>
  26. /// 统计模块
  27. /// </summary>
  28. [Route("api/[controller]")]
  29. [ApiController]
  30. public class StatisticsController : ControllerBase
  31. {
  32. private readonly int _decimalPlaces;
  33. private readonly IMapper _mapper;
  34. private readonly SqlSugarClient _sqlSugar;
  35. private readonly DelegationInfoRepository _groupRep;
  36. private readonly SetDataRepository _setDataRep;
  37. private readonly TeamRateRepository _teamRateRep;
  38. /// <summary>
  39. /// Init
  40. /// </summary>
  41. /// <param name="mapper"></param>
  42. /// <param name="sqlSugar"></param>
  43. /// <param name="groupRep"></param>
  44. /// <param name="setDataRep"></param>
  45. public StatisticsController(IMapper mapper, SqlSugarClient sqlSugar, DelegationInfoRepository groupRep, SetDataRepository setDataRep, TeamRateRepository teamRate)
  46. {
  47. _mapper = mapper;
  48. _groupRep = groupRep;
  49. _setDataRep = setDataRep;
  50. _sqlSugar = sqlSugar;
  51. _teamRateRep = teamRate;
  52. }
  53. #region 团组报表
  54. /// <summary>
  55. /// 团组报表
  56. /// Items
  57. /// </summary>
  58. /// <param name="_dto">团组列表请求dto</param>
  59. /// <returns></returns>
  60. [HttpPost("PostGroupStatementItems")]
  61. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  62. public async Task<IActionResult> PostGroupStatementItems(GroupStatementItemsDto _dto)
  63. {
  64. #region 参数验证
  65. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  66. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  67. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  68. #region 页面操作权限验证
  69. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  70. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  71. #endregion
  72. #endregion
  73. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  74. {
  75. string sqlWhere = string.Empty;
  76. if (_dto.IsSure == 0) //未完成
  77. {
  78. sqlWhere += string.Format(@" And IsSure = 0");
  79. }
  80. else if (_dto.IsSure == 1) //已完成
  81. {
  82. sqlWhere += string.Format(@" And IsSure = 1");
  83. }
  84. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  85. {
  86. string tj = _dto.SearchCriteria;
  87. 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}%')",
  88. tj, tj, tj, tj, tj);
  89. }
  90. string sql = string.Format(@"Select row_number() over(order by gdi.VisitDate Desc) as Row_Number,
  91. gdi.Id,TourCode,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,
  92. ClientName,ClientUnit,VisitDate,ssd.Id TeamTypeId, ssd.Name TeamType,
  93. VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure,gdi.CreateTime,
  94. pr.LastCollectionTime
  95. From Grp_DelegationInfo gdi
  96. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  97. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  98. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  99. Left Join (
  100. SELECT Diid, MAX(CreateTime) LastCollectionTime
  101. FROM Fin_ProceedsReceived
  102. Where IsDel = 0
  103. GROUP BY Diid
  104. ) pr On gdi.Id = pr.Diid
  105. Where gdi.IsDel = 0 {0} ", sqlWhere);
  106. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  107. var _DelegationList = await _sqlSugar.SqlQueryable<GroupStatementItemView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);//ToPageAsync
  108. var _view = new
  109. {
  110. PageFuncAuth = pageFunAuthView,
  111. Data = _DelegationList
  112. };
  113. return Ok(JsonView(true, "查询成功!", _view, total));
  114. }
  115. else
  116. {
  117. return Ok(JsonView(false, "查询失败"));
  118. }
  119. }
  120. /// <summary>
  121. /// 团组报表
  122. /// Details
  123. /// </summary>
  124. /// <param name="_dto">团组列表请求dto</param>
  125. /// <returns></returns>
  126. [HttpPost("PostGroupStatementDetails")]
  127. //[JsonConverter(typeof(DecimalConverter), 2)]
  128. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  129. public async Task<IActionResult> PostGroupStatementDetails(GroupStatementDetailsDto _dto)
  130. {
  131. /*
  132. * 团组报表计算方式
  133. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  134. * 应收金额 = 应收表.Sum()
  135. * 已收金额 = 已收表.Sum()
  136. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  137. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  138. *
  139. */
  140. #region 参数验证
  141. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  142. if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  143. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  144. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  145. #region 页面操作权限验证
  146. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  147. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  148. #endregion
  149. #endregion
  150. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  151. {
  152. GroupStatementDetailsView _view = new GroupStatementDetailsView();
  153. #region 费用类型 币种,转账,客户信息
  154. List<Sys_SetData> _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  155. var _clientDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync();
  156. #endregion
  157. #region 团组收入
  158. GroupIncomeView _giView = new GroupIncomeView();
  159. /*
  160. * 应收报表
  161. */
  162. decimal frTotalAmount = 0.00M;//应收总金额
  163. string _frSql = string.Format(@"Select fr.Id,fr.Diid,fr.PriceName,fr.Price,fr.Count,fr.Unit,fr.Currency,
  164. sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice,fr.CreateTime
  165. From Fin_ForeignReceivables fr
  166. Left Join Sys_SetData sd On fr.Currency = sd.Id
  167. Where fr.IsDel = 0 And fr.Diid = {0} Order By CreateTime", _dto.DiId);
  168. List<Gsd_ForeignReceivablesView> _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
  169. frTotalAmount = _frViews.Sum(it => it.ItemSumPrice);
  170. _giView.Receivables = _frViews;
  171. _giView.ReceivableStr = string.Format(@"应收款合计:{0} CNY(人民币)", frTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  172. /*
  173. * 已收报表
  174. */
  175. decimal prTotalAmount = 0.00M;//已收总金额
  176. string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime As SectionTimeDt,pr.Price,pr.Currency,
  177. sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
  178. pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark,pr.CreateTime
  179. From Fin_ProceedsReceived pr
  180. Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
  181. Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
  182. Where pr.IsDel = 0 and pr.Diid = {0} Order By CreateTime", _dto.DiId);
  183. List<Gsd_ProceedsReceivedView> _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
  184. prTotalAmount = _prViews.Sum(it => it.Price);
  185. _giView.ProceedsReceivedViews = _prViews;
  186. _giView.ProceedsReceivedStr = string.Format(@$"应收合计:{frTotalAmount.ToString("#0.00")} CNY 已收款合计:{prTotalAmount.ConvertToDecimal1().ToString("#0.00")} CNY" );
  187. /*
  188. * 超支费用
  189. */
  190. decimal exTotalAmount = 0.00M;
  191. string _ecSql = string.Format(@"Select gec.Id As GECId,gec.DiId As GECDiId,gec.PriceName,ccp.PayMoney,sd1.Name As PaymentCurrency,
  192. ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  193. sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,gec.CreateTime
  194. From OA2023DB.dbo.Fin_GroupExtraCost gec
  195. Left Join Grp_CreditCardPayment ccp On gec.Id = ccp.CId
  196. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  197. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  198. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  199. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  200. Where ccp.IsDel = 0 And ccp.CTable = 1015 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ccp.DiId = {0} Order By CreateTime", _dto.DiId);
  201. List<Gsd_ExtraCostsView> _ExtraCostsViews = await _sqlSugar.SqlQueryable<Gsd_ExtraCostsView>(_ecSql).ToListAsync();
  202. #region 超支费用 - 模拟数据
  203. //if (_ExtraCostsViews.Count < 1)
  204. //{
  205. // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  206. // {
  207. // GECId = 0,
  208. // GECDiId = 2334,
  209. // PriceName = "模拟数据-超支费用名称",
  210. // PayMoney = 1000.00M,
  211. // PaymentCurrency = "CNY",
  212. // DayRate = 1.0000M,
  213. // CNYPrice = 1000.00M,
  214. // Payee = "模拟数据-超支费用收款方",
  215. // OrbitalPrivateTransfer = 1,
  216. // PayWay = "刷卡",
  217. // CardType = "招行卡",
  218. // IsPay = 1,
  219. // Applicant = "刘华举"
  220. // });
  221. // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  222. // {
  223. // GECId = 0,
  224. // GECDiId = 2334,
  225. // PriceName = "模拟数据-超支费用名称",
  226. // PayMoney = 1000.00M,
  227. // PaymentCurrency = "CNY",
  228. // DayRate = 1.0000M,
  229. // CNYPrice = 1000.00M,
  230. // Payee = "模拟数据-超支费用收款方",
  231. // OrbitalPrivateTransfer = 1,
  232. // PayWay = "刷卡",
  233. // CardType = "招行卡",
  234. // IsPay = 1,
  235. // Applicant = "刘华举"
  236. // });
  237. //}
  238. #endregion
  239. exTotalAmount = _ExtraCostsViews.Sum(it => it.CNYPrice);
  240. _giView.ExtraCostsViews = _ExtraCostsViews;
  241. _giView.ExtraCostsStr = string.Format(@"人民币总费用:{0} CNY", exTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  242. /*
  243. * 收款退还
  244. */
  245. decimal promTotalAmount = 0.00M;// 收款退还总金额
  246. List<Gsd_PaymentRefundAndOtherMoneyView> _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
  247. //删除了 And prom.PriceType = 1
  248. string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
  249. prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
  250. prom.PayType As PrPayType,prom.PriceType As PrPriceType,ccp.*,prom.CreateTime As PrCreateTime
  251. From Fin_PaymentRefundAndOtherMoney prom
  252. Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
  253. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  254. Where prom.IsDel = 0 And prom.PayType = 1 And ccp.CTable = 285
  255. And ccp.IsAuditGM = 1 And ccp.IsPay = 1
  256. And prom.DiId = {0} Order By PrCreateTime", _dto.DiId);
  257. var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
  258. foreach (var ropItem in _promDatas)
  259. {
  260. string thisCueencyCode = "Unknown";
  261. string thisCueencyName = "Unknown";
  262. var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
  263. if (currency != null)
  264. {
  265. thisCueencyCode = currency.Name;
  266. thisCueencyName = currency.Remark;
  267. }
  268. string orbitalPrivateTransferStr = "Unknown";
  269. var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
  270. if (orbitalPrivateTransfer != null)
  271. {
  272. orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
  273. }
  274. string payStr = "Unknown";
  275. var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
  276. if (pay != null)
  277. {
  278. payStr = pay.Name;
  279. }
  280. Gsd_PaymentRefundAndOtherMoneyView gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
  281. {
  282. Id = ropItem.Id,
  283. DiId = ropItem.DIId,
  284. PriceName = ropItem.PrPriceName,
  285. PayCurrencyCode = thisCueencyCode,
  286. PayCurrencyName = thisCueencyName,
  287. Price = ropItem.PrPrice,
  288. CNYPrice = ropItem.RMBPrice,
  289. ThisRate = ropItem.DayRate,
  290. Payee = ropItem.Payee,
  291. PayTime = ropItem.AuditGMDate,
  292. OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
  293. PayType = payStr,
  294. IsPay = ropItem.IsPay,
  295. Applicant = ropItem.Appliction
  296. };
  297. _promView.Add(gsd_PaymentRefund);
  298. }
  299. #region 收款退还 - 模拟数据
  300. //if (_promView.Count < 1)
  301. //{
  302. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  303. // {
  304. // Id = 0,
  305. // DiId = 2334,
  306. // PriceName = "模拟数据-费用名称",
  307. // PayCurrencyCode = "CNY",
  308. // PayCurrencyName = "人民币",
  309. // Price = 1000.00M,
  310. // CNYPrice = 1000.00M,
  311. // ThisRate = 1.00M,
  312. // Payee = "模拟数据-收款方",
  313. // PayTime = "2023-01-01 15:20:01",
  314. // OrbitalPrivateTransfer = 1,
  315. // PayType = "刷卡",
  316. // IsPay = 1,
  317. // Applicant = "刘华举"
  318. // });
  319. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  320. // {
  321. // Id = 0,
  322. // DiId = 2334,
  323. // PriceName = "模拟数据-费用名称",
  324. // PayCurrencyCode = "CNY",
  325. // PayCurrencyName = "人民币",
  326. // Price = 1000.00M,
  327. // CNYPrice = 1000.00M,
  328. // ThisRate = 1.00M,
  329. // Payee = "模拟数据-收款方",
  330. // PayTime = "2023-01-01 15:20:01",
  331. // OrbitalPrivateTransfer = 1,
  332. // PayType = "刷卡",
  333. // IsPay = 1,
  334. // Applicant = "刘华举"
  335. // });
  336. //}
  337. #endregion
  338. promTotalAmount = _promView.Sum(it => it.CNYPrice);
  339. _giView.PaymentRefundAndOtherMoneyViews = _promView;
  340. _giView.PaymentRefundAndOtherMoneyStr = string.Format(@"人民币总费用:{0} CNY", promTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  341. decimal BalancePayment = frTotalAmount - prTotalAmount + promTotalAmount;
  342. _view.GroupIncome = _giView;
  343. _view.GroupIncomeStr = string.Format(@"<span style='color:red;'>剩余尾款:{0} CNY(包含了收款退还费用数据)</span>", BalancePayment.ConvertToDecimal1().ToString("#0.00"));
  344. #endregion
  345. #region 团组支出
  346. GroupExpenditureView _geView = new GroupExpenditureView();
  347. #region 酒店预定费用
  348. List<GroupHotelFeeView> groupHotelFeeViews = new List<GroupHotelFeeView>();
  349. string hotelFeeSql = string.Format(@"Select hr.Id As HrId,hr.DiId As HrDiId,hr.City,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,
  350. sd1.Name As PaymentCurrency,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  351. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,
  352. hr.BreakfastPrice,sd4.Name As BreakfastCurrency,hr.Isoppay,hr.GovernmentRent,
  353. sd5.Name As GovernmentRentCurrency,hr.CityTax,sd6.Name As CityTaxCurrency,
  354. ccp.PayMoney,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,
  355. sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  356. From Grp_HotelReservations hr
  357. Left Join Grp_CreditCardPayment ccp On hr.Id = ccp.CId
  358. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  359. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  360. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  361. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  362. Left Join Sys_SetData sd4 On hr.BreakfastCurrency = sd4.Id
  363. Left Join Sys_SetData sd5 On hr.GovernmentRentCurrency = sd5.Id
  364. Left Join Sys_SetData sd6 On hr.CityTaxCurrency = sd6.Id
  365. Where hr.IsDel = 0 And ccp.IsDel = 0 And ccp.CTable = 76 And ccp.IsAuditGM = 1 And ccp.PayMoney<> 0 And hr.DiId = {0}
  366. Order By CheckInDate Asc", _dto.DiId);
  367. groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
  368. decimal HotelCNYTotalPrice = 0.00M;
  369. var teamRateData = await _teamRateRep.PostGroupRateInfoByDiId(_dto.DiId);
  370. foreach (var item in groupHotelFeeViews)
  371. {
  372. HotelCNYTotalPrice += item.CNYPrice;
  373. item.PayMoney = item.PayMoney.ConvertToDecimal1();
  374. item.CNYPrice = item.CNYPrice.ConvertToDecimal1();
  375. string currencyRateStr = "";
  376. List<string> currencys = new List<string>();
  377. if (!string.IsNullOrEmpty(item.BreakfastCurrency)) currencys.Add(item.BreakfastCurrency);
  378. if (!string.IsNullOrEmpty(item.GovernmentRentCurrency)) currencys.Add(item.GovernmentRentCurrency);
  379. if (!string.IsNullOrEmpty(item.CityTaxCurrency)) currencys.Add(item.CityTaxCurrency);
  380. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  381. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 76, currencys);
  382. item.CurrencyRateStr = currencyRateStr;
  383. }
  384. _geView.GroupHotelFeeViews = groupHotelFeeViews;
  385. _geView.GroupHotelFeeStr = string.Format(@"人民币总费用:{0} CNY", HotelCNYTotalPrice.ToString("#0.00"));
  386. #endregion
  387. #region 地接费用
  388. List<GroupCTGGRFeeView> groupCTGGRFeeViews = new List<GroupCTGGRFeeView>();
  389. string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.Area,ctggrc.*,ctggrc.Price As PayMoney,
  390. sd2.name As PaymentCurrency,ccp.PayPercentage,
  391. (ctggrc.Price / (ccp.PayPercentage / 100)) As AmountPaid,
  392. (ctggrc.Price / (ccp.PayPercentage / 100) - ctggrc.Price) As BalancePayment,
  393. ccp.DayRate,(ctggrc.Price * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  394. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  395. From Grp_CarTouristGuideGroundReservations ctggr
  396. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price,sd2.Name As PriceCurrency,
  397. cggrc.PriceContent
  398. From Grp_CarTouristGuideGroundReservationsContent cggrc
  399. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  400. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  401. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  402. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  403. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  404. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  405. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  406. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  407. Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ctggr.DiId = {0}
  408. Order By CreateTime", _dto.DiId);
  409. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  410. string CTGGRFeeStr = "";
  411. decimal CTGGRCNYTotalPrice = 0.00M;
  412. //按1 地区,2 币种,3 汇率 分组计算
  413. var groupCTGGRFeeDatas = groupCTGGRFeeViews.GroupBy(it => it.Area);
  414. foreach (var ctggfr in groupCTGGRFeeDatas)
  415. {
  416. var ctggfr_curr = ctggfr.GroupBy(it => it.PaymentCurrency);
  417. if (ctggfr_curr.Count() > 0)
  418. {
  419. foreach (var curr in ctggfr_curr)
  420. {
  421. var ctggfr_rate = curr.GroupBy(it => it.DayRate);
  422. if (ctggfr_rate.Count() > 0)
  423. {
  424. foreach (var rate in ctggfr_rate)
  425. {
  426. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{rate.Sum(it => it.AmountPaid).ToString("#0.00")}
  427. {rate.FirstOrDefault()?.PaymentCurrency}(人民币:
  428. {rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  429. {rate.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  430. CTGGRCNYTotalPrice += rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  431. }
  432. }
  433. else
  434. {
  435. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{curr.Sum(it => it.AmountPaid).ToString("#0.00")}
  436. {curr.FirstOrDefault()?.PaymentCurrency}(人民币:
  437. {curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  438. {curr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  439. CTGGRCNYTotalPrice += curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  440. }
  441. }
  442. }
  443. else
  444. {
  445. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{ctggfr.Sum(it => it.AmountPaid).ToString("#0.00")}
  446. {ctggfr.FirstOrDefault()?.PaymentCurrency}(人民币:
  447. {ctggfr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  448. {ctggfr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  449. CTGGRCNYTotalPrice += ctggfr.Sum(it => Convert.ToDecimal( it.CNYPrice.ToString("#0.00")));
  450. }
  451. }
  452. foreach (var item in groupCTGGRFeeViews)
  453. {
  454. if (!string.IsNullOrEmpty(item.AuditGMDate))
  455. {
  456. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  457. }
  458. //CTGGRFeeStr += string.Format(@"{0} 总费用:{1} {2}(人民币:{3} CNY 当时支付汇率:{4})\r\n",
  459. // item.Area, item.AmountPaid.ConvertToDecimal1().ToString("#0.00"), item.PaymentCurrency, item.CNYPrice.ToString("#0.0000"), item.DayRate.ToString("#0.0000"));
  460. //CTGGRCNYTotalPrice += item.CNYPrice;
  461. }
  462. _geView.GroupCTGGRFeeViews = groupCTGGRFeeViews;
  463. _geView.GroupCTGGRFeeStr = string.Format(@"{0}人民币总费用:{1} CNY", CTGGRFeeStr,CTGGRCNYTotalPrice.ToString("#0.00"));
  464. #endregion
  465. #region 机票预订费用
  466. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  467. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  468. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  469. sd1.Name As PayMoneyCurrency,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  470. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,atr.CreateTime
  471. From Grp_AirTicketReservations atr
  472. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  473. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  474. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  475. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  476. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  477. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  478. Where atr.IsDel = 0 And ccp.IsAuditGM = 1 And atr.DiId = {0} Order By CreateTime", _dto.DiId);
  479. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  480. string str = "";
  481. List<dynamic> airClientPris = new List<dynamic>();
  482. decimal AirCNYTotalPrice = 0.00M;
  483. decimal JJCCNYTotalPrice = 0.00M, JJCPeopleNum = 0.00M, JJCAveragePrice = 0.00M;
  484. decimal GWCCNYTotalPrice = 0.00M, GWCPeopleNum = 0.00M, GWCAveragePrice = 0.00M;
  485. //if (groupAirFeeViews.Count > 0)
  486. //{
  487. // JJCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.CNYPrice);
  488. // JJCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.ClientNum);
  489. // JJCAveragePrice = (JJCCNYTotalPrice / JJCPeopleNum).ConvertToDecimal1();
  490. // GWCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.CNYPrice);
  491. // GWCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.ClientNum);
  492. // GWCAveragePrice = (GWCCNYTotalPrice / GWCPeopleNum).ConvertToDecimal1();
  493. //}
  494. int Index = 0;
  495. foreach (var item in groupAirFeeViews)
  496. {
  497. if (item.AirId > 2924)
  498. {
  499. string itemClientName = "";
  500. if (!string.IsNullOrEmpty(item.ClientName))
  501. {
  502. string[] clientIds = new string[] { };
  503. if (item.ClientName.Contains(','))
  504. {
  505. clientIds = item.ClientName.Split(',');
  506. }
  507. else
  508. {
  509. clientIds = new string[] { item.ClientName };
  510. }
  511. if (clientIds.Length > 0)
  512. {
  513. int[] output = Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
  514. if (output.Contains(-1))
  515. {
  516. itemClientName += $@"行程单";
  517. output = output.Where(val => val != -1).ToArray();
  518. }
  519. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  520. decimal unitCost = 0.00M;
  521. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  522. int clienIndex = 1;
  523. foreach (var client in clients)
  524. {
  525. airClientPris.Add(new {
  526. CnName = client.LastName+client.FirstName,
  527. EnName = client.Pinyin,
  528. Price = unitCost,
  529. AirType = item.AirTypeName
  530. });
  531. string six = "";
  532. if (client.Sex == 0) six = "Mr";
  533. else if (client.Sex == 1) six = "Ms";
  534. itemClientName += string.Format(@"{0}.{1} {2};", clienIndex, client.LastName + client.FirstName, six);
  535. clienIndex++;
  536. }
  537. }
  538. }
  539. item.ClientName = itemClientName;
  540. }
  541. else
  542. {
  543. string clientPinYinName = "";
  544. decimal unitCost = 0.00M;
  545. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  546. Regex r = new Regex("[0-9]");
  547. string name1 = item.ClientName;
  548. name1 = r.Replace(name1, "");
  549. string[] clientNames = name1.Split('.');
  550. for (int i = 0; i < item.ClientNum; i++)
  551. {
  552. string name = "";
  553. if (clientNames.Length > 0)
  554. {
  555. int index = i + 1;
  556. if (index < clientNames.Length)
  557. {
  558. name = clientNames[index].Replace("MR","").Replace("MS","").Trim();
  559. if (!string.IsNullOrEmpty(name))
  560. {
  561. airClientPris.Add(new
  562. {
  563. CnName = name,
  564. EnName = name,
  565. Price = unitCost,
  566. AirType = item.AirTypeName
  567. });
  568. }
  569. //if (name.Length > 0)
  570. //{
  571. // string nameLastStr = name[name.Length - 1].ToString();
  572. // if (nameLastStr.IsNumeric())
  573. // {
  574. // name = name.Substring(0, name.Length - 1).Trim();
  575. // }
  576. //}
  577. }
  578. }
  579. clientPinYinName += string.Format(@"{0}.{1}出票价为:{2} CNY;", Index+1, name, unitCost.ToString("#0.00"));
  580. }
  581. }
  582. if (!string.IsNullOrEmpty(item.AuditGMDate))
  583. {
  584. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  585. }
  586. AirCNYTotalPrice += item.CNYPrice;
  587. }
  588. _geView.GroupAirFeeViews = groupAirFeeViews;
  589. if (airClientPris.Count > 0)
  590. {
  591. var peoplePriStr = "";
  592. var airClientPris1 = airClientPris.GroupBy(item => item.CnName)
  593. .Select(group => group.First())
  594. .ToList();
  595. int airClientPrisIndex = 1;
  596. foreach (var item in airClientPris1)
  597. {
  598. decimal price = 0.00M;
  599. var prices = airClientPris.Where(it => it.CnName == item.CnName).ToList();
  600. foreach (var pri in prices)
  601. {
  602. price += pri.Price;
  603. }
  604. peoplePriStr += $@"{airClientPrisIndex}.{item.EnName}出票价为: { price.ToString("#0.00")} CNY;";
  605. airClientPrisIndex++;
  606. }
  607. if (!string.IsNullOrEmpty(peoplePriStr))
  608. {
  609. str = $@"其中:{peoplePriStr}";
  610. }
  611. //经济舱均价
  612. var airJJCPris = airClientPris.Where(it => it.AirType == "经济舱").ToList();
  613. if (airJJCPris.Count > 0)
  614. {
  615. decimal jjcTotalPrice = 0.00M;
  616. foreach (var item in airJJCPris)
  617. {
  618. jjcTotalPrice += item.Price;
  619. }
  620. decimal jjcPeopleNum = airJJCPris.GroupBy(item => item.CnName)
  621. .Select(group => group.First())
  622. .ToList().Count();;
  623. JJCAveragePrice = jjcTotalPrice / jjcPeopleNum;
  624. }
  625. //公务舱均价
  626. var airGWCPris = airClientPris.Where(it => it.AirType == "公务舱").ToList();
  627. if (airGWCPris.Count > 0)
  628. {
  629. decimal gwcTotalPrice = 0.00M;
  630. foreach (var item in airGWCPris)
  631. {
  632. gwcTotalPrice += item.Price;
  633. }
  634. decimal gwcPeopleNum = airGWCPris.GroupBy(item => item.CnName)
  635. .Select(group => group.First())
  636. .ToList().Count();
  637. GWCAveragePrice = gwcTotalPrice / gwcPeopleNum;
  638. }
  639. }
  640. _geView.GroupAirFeeStr = $@"人民币总费用:{AirCNYTotalPrice.ToString("#0.00")} CNY\r\n{str}\r\n经济舱均价为:{JJCAveragePrice.ToString("#0.00")}CNY/人;公务舱均价为:{GWCAveragePrice.ToString("#0.00")}CNY/人;";
  641. #endregion
  642. #region 签证费用
  643. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  644. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  645. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  646. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant,vi.CreateTime
  647. From Grp_VisaInfo vi
  648. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  649. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  650. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  651. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  652. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  653. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And vi.DIId = {0} Order By CreateTime", _dto.DiId);
  654. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  655. decimal VisaCNYTotalPirce = 0.00M;
  656. foreach (var item in groupVisaFeeViews)
  657. {
  658. string itemClientName = "";
  659. string visaClients = item.VisaClient;
  660. if (!string.IsNullOrEmpty(visaClients))
  661. {
  662. string[] clientIds = new string[] { };
  663. if (visaClients.Contains(','))
  664. {
  665. clientIds = visaClients.Split(',');
  666. }
  667. else
  668. {
  669. clientIds = new string[] { visaClients };
  670. }
  671. if (clientIds.Length > 0)
  672. {
  673. List<int> clientIds1 = new List<int>() { };
  674. foreach (var clientIdStr in clientIds)
  675. {
  676. if (clientIdStr.IsNumeric())
  677. {
  678. clientIds1.Add(int.Parse(clientIdStr));
  679. }
  680. }
  681. if (clientIds1.Count > 0)
  682. {
  683. var clients = _clientDatas.Where(it => clientIds1.Contains(it.Id)).ToList();
  684. foreach (var client in clients)
  685. {
  686. itemClientName += $"{client.LastName + client.FirstName},";
  687. }
  688. }
  689. else {
  690. itemClientName = visaClients;
  691. }
  692. }
  693. }
  694. if (itemClientName.Length > 0 )
  695. {
  696. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  697. }
  698. item.VisaClient = itemClientName;
  699. VisaCNYTotalPirce += item.PayMoney;
  700. if (!string.IsNullOrEmpty(item.AuditGMDate))
  701. {
  702. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  703. }
  704. }
  705. _geView.GroupVisaFeeViews = groupVisaFeeViews;
  706. _geView.GroupVisaFeeStr = string.Format(@"人民币总费用:{0} CNY", VisaCNYTotalPirce.ConvertToDecimal1());
  707. #endregion
  708. #region 邀请/公务活动 CTable = 81
  709. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  710. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  711. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  712. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  713. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  714. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ioa.CreateTime
  715. From Grp_InvitationOfficialActivities ioa
  716. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  717. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  718. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  719. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  720. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  721. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  722. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  723. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  724. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  725. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ioa.Diid = {0} Order By CreateTime", _dto.DiId);
  726. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  727. #region 邀请/公务活动 - 模拟数据
  728. //if (groupInvitationalFeeViews.Count < 1)
  729. //{
  730. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  731. // {
  732. // IOAId = 0,
  733. // IOADiId = 2334,
  734. // InviterArea = "模拟数据-邀请方地区",
  735. // Inviter = "模拟数据-邀请方",
  736. // InviteTime = "2023-10-10",
  737. // InviteCost = 100.00M,
  738. // InviteCurrency = "EUR",
  739. // SendCost = 100.00M,
  740. // SendCurrency = "EUR",
  741. // EventsCost = 10000.00M,
  742. // EventsCurrency = "EUR",
  743. // TranslateCost = 300.00M,
  744. // TranslateCurrency = "EUR",
  745. // PayMoney = 10500.00M,
  746. // PaymentCurrency = "EUR",
  747. // CNYPrice = 76765.50M,
  748. // Payee = "模拟数据-收款方",
  749. // AuditGMDate = "2023-12-05",
  750. // OrbitalPrivateTransfer = 1,
  751. // PayWay = "刷卡",
  752. // IsPay = 1,
  753. // Applicant = "刘华举"
  754. // });
  755. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  756. // {
  757. // IOAId = 0,
  758. // IOADiId = 2334,
  759. // InviterArea = "模拟数据-邀请方地区",
  760. // Inviter = "模拟数据-邀请方",
  761. // InviteTime = "2023-10-10",
  762. // InviteCost = 100.00M,
  763. // InviteCurrency = "EUR",
  764. // SendCost = 100.00M,
  765. // SendCurrency = "EUR",
  766. // EventsCost = 10000.00M,
  767. // EventsCurrency = "EUR",
  768. // TranslateCost = 300.00M,
  769. // TranslateCurrency = "EUR",
  770. // PayMoney = 10500.00M,
  771. // PaymentCurrency = "EUR",
  772. // CNYPrice = 76765.50M,
  773. // Payee = "模拟数据-收款方",
  774. // AuditGMDate = "2023-12-05",
  775. // OrbitalPrivateTransfer = 1,
  776. // PayWay = "刷卡",
  777. // IsPay = 1,
  778. // Applicant = "刘华举"
  779. // });
  780. //}
  781. #endregion
  782. decimal InvitationalCNYTotalPrice = 0.00M;
  783. foreach (var item in groupInvitationalFeeViews)
  784. {
  785. InvitationalCNYTotalPrice += item.CNYPrice;
  786. if (!string.IsNullOrEmpty(item.AuditGMDate))
  787. {
  788. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  789. }
  790. string currencyRateStr = "";
  791. List<string> currencys = new List<string>();
  792. if (!string.IsNullOrEmpty(item.InviteCurrency)) currencys.Add(item.InviteCurrency);
  793. if (!string.IsNullOrEmpty(item.SendCurrency)) currencys.Add(item.SendCurrency);
  794. if (!string.IsNullOrEmpty(item.EventsCurrency)) currencys.Add(item.EventsCurrency);
  795. if (!string.IsNullOrEmpty(item.TranslateCurrency)) currencys.Add(item.TranslateCurrency);
  796. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  797. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 81, currencys);
  798. item.CurrencyRateStr = currencyRateStr;
  799. }
  800. _geView.GroupInvitationalFeeViews = groupInvitationalFeeViews;
  801. _geView.GroupInvitationalFeeStr = string.Format(@"人民币总费用:{0} CNY", InvitationalCNYTotalPrice);
  802. #endregion
  803. #region 保险费用
  804. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  805. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  806. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  807. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ic.CreateTime
  808. From Grp_Customers ic
  809. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  810. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  811. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  812. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  813. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ic.DiId = {0} Order By CreateTime", _dto.DiId);
  814. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  815. decimal InsuranceCNYTotalPrice = 0.00M;
  816. foreach (var item in groupInsuranceFeeViews)
  817. {
  818. InsuranceCNYTotalPrice += item.CNYPrice;
  819. string itemClientName = "";
  820. string insClients = item.ClientName;
  821. if (!string.IsNullOrEmpty(insClients))
  822. {
  823. string[] clientIds = new string[] { };
  824. if (insClients.Contains(','))
  825. {
  826. clientIds = insClients.Split(',');
  827. }
  828. else
  829. {
  830. clientIds = new string[] { insClients };
  831. }
  832. if (clientIds.Length > 0)
  833. {
  834. List<int> output = new List<int>();
  835. foreach (var clientId in clientIds)
  836. {
  837. if (clientId.IsNumeric())
  838. {
  839. output.Add(int.Parse(clientId));
  840. }
  841. }
  842. if (output.Count > 0)
  843. {
  844. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  845. foreach (var client in clients)
  846. {
  847. itemClientName += $"{client.LastName + client.FirstName},";
  848. }
  849. if (itemClientName.Length > 0)
  850. {
  851. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  852. }
  853. }
  854. else
  855. {
  856. itemClientName = insClients;
  857. }
  858. }
  859. }
  860. item.ClientName = itemClientName;
  861. if (!string.IsNullOrEmpty(item.AuditGMDate))
  862. {
  863. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  864. }
  865. }
  866. _geView.GroupInsuranceFeeViews = groupInsuranceFeeViews;
  867. _geView.GroupInsuranceFeeStr = string.Format(@"人民币总费用:{0} CNY", InsuranceCNYTotalPrice.ToString("#0.00"));
  868. #endregion
  869. #region 其他款项费用 98
  870. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  871. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  872. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,
  873. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  874. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,dp.CreateTime
  875. From Grp_DecreasePayments dp
  876. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  877. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  878. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  879. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  880. Where dp.IsDel = 0 And ccp.Ctable = 98 And ccp.IsAuditGM = 1 And dp.Diid = {0}
  881. Order By CreateTime", _dto.DiId);
  882. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  883. #region 保险费用 - 模拟数据
  884. //if (groupDecreaseFeeViews.Count < 1)
  885. //{
  886. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  887. // {
  888. // DPId = 0,
  889. // DPDiId = 2334,
  890. // PriceName = "模拟数据-费用名称",
  891. // PayMoney = 1000.00M,
  892. // PayMoneyCurrency = "CNY",
  893. // DayRate = 1.0000M,
  894. // CNYPrice = 1.0000M,
  895. // AuditGMDate = "2023-12-10 12:13:00",
  896. // Payee = "模拟数据-付款方",
  897. // OrbitalPrivateTransfer = 1,
  898. // PayWay = "现金",
  899. // IsPay = 1,
  900. // Applicant = "刘华举"
  901. // });
  902. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  903. // {
  904. // DPId = 0,
  905. // DPDiId = 2334,
  906. // PriceName = "模拟数据-费用名称",
  907. // PayMoney = 1000.00M,
  908. // PayMoneyCurrency = "CNY",
  909. // DayRate = 1.0000M,
  910. // CNYPrice = 1.0000M,
  911. // AuditGMDate = "2023-12-10 12:13:00",
  912. // Payee = "模拟数据-付款方",
  913. // OrbitalPrivateTransfer = 1,
  914. // PayWay = "现金",
  915. // IsPay = 1,
  916. // Applicant = "刘华举"
  917. // });
  918. //}
  919. #endregion
  920. decimal DecreaseCNYTotalPrice = 0.00M;
  921. foreach (var item in groupDecreaseFeeViews)
  922. {
  923. item.CNYPrice = Convert.ToDecimal(item.CNYPrice.ToString("#0.00"));
  924. DecreaseCNYTotalPrice += item.CNYPrice;
  925. if (!string.IsNullOrEmpty(item.AuditGMDate))
  926. {
  927. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  928. }
  929. }
  930. _geView.GroupDecreaseFeeViews = groupDecreaseFeeViews;
  931. _geView.GroupDecreaseFeeStr = string.Format(@"人民币总费用:{0} CNY", DecreaseCNYTotalPrice.ToString("#0.00"));
  932. #endregion
  933. _view.GroupExpenditure = _geView;
  934. #endregion
  935. /*
  936. * 团组报表计算方式
  937. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  938. * 应收金额 = 应收表.Sum()
  939. * 已收金额 = 已收表.Sum()
  940. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  941. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  942. *
  943. */
  944. decimal _totalExpenditure = 0.00M; //总支出
  945. decimal _amountReceivable = 0.00M; //应收金额
  946. decimal _amountReceived = 0.00M; //已收金额
  947. decimal _receivableProfit = 0.00M; //应收利润
  948. decimal _receivedProfit = 0.00M; //已收利润
  949. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  950. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  951. _amountReceivable = frTotalAmount;
  952. _amountReceived = prTotalAmount;
  953. _receivableProfit = _amountReceivable - promTotalAmount - _totalExpenditure;
  954. _receivedProfit = _amountReceived - promTotalAmount - _totalExpenditure;
  955. _view.FeeTotalStr = string.Format(@$"<span>
  956. <span>当前总支出:{_totalExpenditure.ToString("#0.00")} CNY</span>
  957. <span style='padding-left:10px;color: Green;'>应收金额:{_amountReceivable.ToString("#0.00")} CNY</span>
  958. <span style='padding-left:10px;color: Green;'>已收金额:{_amountReceived.ToString("#0.00")} CNY</span>
  959. <span style='padding-left:10px;color: Green;'>应收利润(应收-支出):{_receivableProfit.ToString("#0.00")} CNY</span>
  960. <span style='padding-left:10px;color: Green;'>已收利润(已收-支出):{_receivedProfit.ToString("#0.00")} CNY</span>
  961. </span>");
  962. return Ok(JsonView(true, "查询成功!", _view));
  963. }
  964. else
  965. {
  966. return Ok(JsonView(false, "查询成功"));
  967. }
  968. }
  969. #endregion
  970. #region 报表/折线图统计
  971. //企业利润-团组利润
  972. //企业利润-会务利润
  973. /// <summary>
  974. /// 企业利润
  975. /// Details
  976. /// 待添加权限验证
  977. /// </summary>
  978. /// <param name="_dto">团组列表请求dto</param>
  979. /// <returns></returns>
  980. [HttpPost("PostCorporateProfit")]
  981. //[JsonConverter(typeof(DecimalConverter), 2)]
  982. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  983. public async Task<IActionResult> PostCorporateProfit(PostCorporateProfitDto _dto)
  984. {
  985. #region 参数验证
  986. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  987. if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  988. if (_dto.Year < 1) return Ok(JsonView(false, "请输入有效的Year参数!"));
  989. if (_dto.StatisticsType > 2 && _dto.StatisticsType < 1) return Ok(JsonView(false, "请输入有效的StatisticsType参数,1 月份 2 季度"));
  990. if (_dto.BusinessType > 3 && _dto.BusinessType < 1) return Ok(JsonView(false, "请输入有效的BusinessType参数,1 所有 2 团组 3 会务"));
  991. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  992. #region 页面操作权限验证
  993. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  994. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  995. #endregion
  996. string sqlWhere = string.Empty;
  997. //起止时间
  998. DateTime beginDt = Convert.ToDateTime( $"{_dto.Year}-01-01 00:00:00");
  999. DateTime endDt = Convert.ToDateTime($"{_dto.Year}-12-31 23:59:59");
  1000. sqlWhere = string.Format(@$" Where Isdel = 0 ");
  1001. //业务类型
  1002. List<int> groupTypeId = new List<int>();
  1003. if (_dto.BusinessType == 2) //团组
  1004. {
  1005. groupTypeId.AddRange(new List<int>() {
  1006. 38, // 政府团
  1007. 39, // 企业团
  1008. 40, // 散客团
  1009. 1048 // 高校团
  1010. });
  1011. }
  1012. else if (_dto.BusinessType == 3) //会务
  1013. {
  1014. groupTypeId.AddRange(new List<int>() {
  1015. 102, // 未知
  1016. 248, // 非团组
  1017. 302, // 成都-会务活动
  1018. 691, // 四川-会务活动
  1019. 762, // 四川-赛事项目收入
  1020. 1047 // 成都-赛事项目收入
  1021. });
  1022. }
  1023. if (groupTypeId.Count > 0 )
  1024. {
  1025. sqlWhere += string.Format(@$" And TeamDid In ({string.Join(',', groupTypeId)})");
  1026. }
  1027. string sql = string.Format(@$"Select * From Grp_DelegationInfo {sqlWhere}");
  1028. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).Where(it => it.CreateTime >= beginDt && it.CreateTime <= endDt).ToListAsync();
  1029. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无相关团组!"));
  1030. List<int> diIds = groupInfos.Select(it => it.Id).ToList();
  1031. List<CorporateProfit> corporateProfits = await CorporateProfit(diIds);
  1032. List<MonthInfo> months = new List<MonthInfo>();
  1033. if (_dto.StatisticsType == 1) //月份
  1034. {
  1035. months = GeneralMethod.GetMonthInfos(Convert.ToInt32(_dto.Year));
  1036. }
  1037. else if (_dto.StatisticsType == 1) //季度
  1038. {
  1039. months = GeneralMethod.GetQuarter(Convert.ToInt32(_dto.Year));
  1040. }
  1041. List<CorporateProfitMonthView> _view = new List<CorporateProfitMonthView>();
  1042. foreach (var item in months)
  1043. {
  1044. DateTime monthBeginDt = Convert.ToDateTime($"{_dto.Year}-{item.Month}-{item.Days.BeginDays} 00:00:00");
  1045. DateTime monthEndDt = Convert.ToDateTime($"{_dto.Year}-{item.Month}-{item.Days.EndDays} 23:59:59");
  1046. var corporateProfit = corporateProfits.Where(it => it.CreateDt >= monthBeginDt && it.CreateDt <= monthEndDt).ToList();
  1047. _view.Add(new CorporateProfitMonthView()
  1048. {
  1049. Month = item.Month,
  1050. Profit = corporateProfit.Sum(it => it.ReceivedProfit),
  1051. GroupInfos = corporateProfit.OrderBy(it => it.CreateDt).ToList()
  1052. });
  1053. }
  1054. return Ok(JsonView(true,"操作成功!",_view));
  1055. #endregion
  1056. }
  1057. /// <summary>
  1058. /// 计算团组利润
  1059. /// </summary>
  1060. /// <param name="diIds"></param>
  1061. /// <returns></returns>
  1062. private async Task<List<CorporateProfit>> CorporateProfit(List<int> diIds)
  1063. {
  1064. List<CorporateProfit> corporateProfits = new List<CorporateProfit>();
  1065. if (diIds.Count < 1)
  1066. {
  1067. return corporateProfits;
  1068. }
  1069. #region 计算团组利润
  1070. /*
  1071. * 团组报表计算方式
  1072. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1073. * 应收金额 = 应收表.Sum()
  1074. * 已收金额 = 已收表.Sum()
  1075. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1076. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1077. *
  1078. */
  1079. string diIdStr = string.Join(",", diIds);
  1080. string sql = string.Format(@$"Select * From Grp_DelegationInfo Where Isdel = 0 And Id In ({diIdStr})");
  1081. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToListAsync();
  1082. #region 费用类型 币种,转账,客户信息
  1083. List<Sys_SetData> _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  1084. var _clientDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync();
  1085. #endregion
  1086. foreach (var _diId in diIds)
  1087. {
  1088. List<ExpenditureInfo> expenditureInfos = new List<ExpenditureInfo>();
  1089. #region 团组收入
  1090. /*
  1091. * 应收报表
  1092. */
  1093. decimal frTotalAmount = 0.00M;//应收总金额
  1094. string _frSql = string.Format(@"Select fr.Id,fr.Diid,fr.PriceName,fr.Price,fr.Count,fr.Unit,fr.Currency,
  1095. sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice,fr.CreateTime
  1096. From Fin_ForeignReceivables fr
  1097. Left Join Sys_SetData sd On fr.Currency = sd.Id
  1098. Where fr.IsDel = 0 And fr.Diid = {0} Order By CreateTime", _diId);
  1099. List<Gsd_ForeignReceivablesView> _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
  1100. frTotalAmount = _frViews.Sum(it => it.ItemSumPrice);
  1101. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "应收项", Amount = frTotalAmount });
  1102. /*
  1103. * 已收报表
  1104. */
  1105. decimal prTotalAmount = 0.00M;//已收总金额
  1106. string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime As SectionTimeDt,pr.Price,pr.Currency,
  1107. sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
  1108. pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark,pr.CreateTime
  1109. From Fin_ProceedsReceived pr
  1110. Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
  1111. Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
  1112. Where pr.IsDel = 0 and pr.Diid = {0} Order By CreateTime", _diId);
  1113. List<Gsd_ProceedsReceivedView> _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
  1114. prTotalAmount = _prViews.Sum(it => it.Price);
  1115. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "已收项", Amount = prTotalAmount });
  1116. /*
  1117. * 超支费用
  1118. */
  1119. decimal exTotalAmount = 0.00M;
  1120. string _ecSql = string.Format(@"Select gec.Id As GECId,gec.DiId As GECDiId,gec.PriceName,ccp.PayMoney,sd1.Name As PaymentCurrency,
  1121. ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  1122. sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,gec.CreateTime
  1123. From OA2023DB.dbo.Fin_GroupExtraCost gec
  1124. Left Join Grp_CreditCardPayment ccp On gec.Id = ccp.CId
  1125. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1126. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1127. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1128. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1129. Where ccp.IsDel = 0 And ccp.CTable = 1015 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ccp.DiId = {0} Order By CreateTime", _diId);
  1130. List<Gsd_ExtraCostsView> _ExtraCostsViews = await _sqlSugar.SqlQueryable<Gsd_ExtraCostsView>(_ecSql).ToListAsync();
  1131. exTotalAmount = _ExtraCostsViews.Sum(it => it.CNYPrice);
  1132. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "超支费用", Amount = exTotalAmount });
  1133. /*
  1134. * 收款退还
  1135. */
  1136. decimal promTotalAmount = 0.00M;// 收款退还总金额
  1137. List<Gsd_PaymentRefundAndOtherMoneyView> _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
  1138. //删除了 And prom.PriceType = 1
  1139. string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
  1140. prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
  1141. prom.PayType As PrPayType,prom.PriceType As PrPriceType,ccp.*,prom.CreateTime As PrCreateTime
  1142. From Fin_PaymentRefundAndOtherMoney prom
  1143. Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
  1144. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1145. Where prom.IsDel = 0 And prom.PayType = 1 And ccp.CTable = 285
  1146. And ccp.IsAuditGM = 1 And ccp.IsPay = 1
  1147. And prom.DiId = {0} Order By PrCreateTime", _diId);
  1148. var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
  1149. foreach (var ropItem in _promDatas)
  1150. {
  1151. string thisCueencyCode = "Unknown";
  1152. string thisCueencyName = "Unknown";
  1153. var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
  1154. if (currency != null)
  1155. {
  1156. thisCueencyCode = currency.Name;
  1157. thisCueencyName = currency.Remark;
  1158. }
  1159. string orbitalPrivateTransferStr = "Unknown";
  1160. var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
  1161. if (orbitalPrivateTransfer != null)
  1162. {
  1163. orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
  1164. }
  1165. string payStr = "Unknown";
  1166. var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
  1167. if (pay != null)
  1168. {
  1169. payStr = pay.Name;
  1170. }
  1171. Gsd_PaymentRefundAndOtherMoneyView gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
  1172. {
  1173. Id = ropItem.Id,
  1174. DiId = ropItem.DIId,
  1175. PriceName = ropItem.PrPriceName,
  1176. PayCurrencyCode = thisCueencyCode,
  1177. PayCurrencyName = thisCueencyName,
  1178. Price = ropItem.PrPrice,
  1179. CNYPrice = ropItem.RMBPrice,
  1180. ThisRate = ropItem.DayRate,
  1181. Payee = ropItem.Payee,
  1182. PayTime = ropItem.AuditGMDate,
  1183. OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
  1184. PayType = payStr,
  1185. IsPay = ropItem.IsPay,
  1186. Applicant = ropItem.Appliction
  1187. };
  1188. _promView.Add(gsd_PaymentRefund);
  1189. }
  1190. promTotalAmount = _promView.Sum(it => it.CNYPrice);
  1191. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "收款退还", Amount = promTotalAmount });
  1192. #endregion
  1193. #region 团组支出
  1194. GroupExpenditureView _geView = new GroupExpenditureView();
  1195. #region 酒店预定费用
  1196. List<GroupHotelFeeView> groupHotelFeeViews = new List<GroupHotelFeeView>();
  1197. string hotelFeeSql = string.Format(@"Select hr.Id As HrId,hr.DiId As HrDiId,hr.City,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,
  1198. sd1.Name As PaymentCurrency,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  1199. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,
  1200. hr.BreakfastPrice,sd4.Name As BreakfastCurrency,hr.Isoppay,hr.GovernmentRent,
  1201. sd5.Name As GovernmentRentCurrency,hr.CityTax,sd6.Name As CityTaxCurrency,
  1202. ccp.PayMoney,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,
  1203. sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  1204. From Grp_HotelReservations hr
  1205. Left Join Grp_CreditCardPayment ccp On hr.Id = ccp.CId
  1206. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1207. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1208. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1209. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1210. Left Join Sys_SetData sd4 On hr.BreakfastCurrency = sd4.Id
  1211. Left Join Sys_SetData sd5 On hr.GovernmentRentCurrency = sd5.Id
  1212. Left Join Sys_SetData sd6 On hr.CityTaxCurrency = sd6.Id
  1213. Where hr.IsDel = 0 And ccp.IsDel = 0 And ccp.CTable = 76 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And hr.DiId = {0}
  1214. Order By CheckInDate Asc", _diId);
  1215. groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
  1216. decimal HotelCNYTotalPrice = groupHotelFeeViews.Sum(it => it.CNYPrice);
  1217. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "酒店预定", Amount = HotelCNYTotalPrice });
  1218. #endregion
  1219. #region 地接费用
  1220. List<GroupCTGGRFeeView> groupCTGGRFeeViews = new List<GroupCTGGRFeeView>();
  1221. string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.Area,ctggrc.*,ctggrc.Price As PayMoney,
  1222. sd2.name As PaymentCurrency,ccp.PayPercentage,
  1223. (ctggrc.Price / (ccp.PayPercentage / 100)) As AmountPaid,
  1224. (ctggrc.Price / (ccp.PayPercentage / 100) - ctggrc.Price) As BalancePayment,
  1225. ccp.DayRate,(ctggrc.Price * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  1226. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  1227. From Grp_CarTouristGuideGroundReservations ctggr
  1228. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price,sd2.Name As PriceCurrency,
  1229. cggrc.PriceContent
  1230. From Grp_CarTouristGuideGroundReservationsContent cggrc
  1231. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  1232. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  1233. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  1234. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  1235. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  1236. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  1237. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  1238. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1239. Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ctggr.DiId = {0}
  1240. Order By CreateTime", _diId);
  1241. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  1242. decimal CTGGRCNYTotalPrice = groupCTGGRFeeViews.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  1243. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "地接", Amount = CTGGRCNYTotalPrice });
  1244. #endregion
  1245. #region 机票预订费用
  1246. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  1247. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  1248. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  1249. sd1.Name As PayMoneyCurrency,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  1250. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,atr.CreateTime
  1251. From Grp_AirTicketReservations atr
  1252. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  1253. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1254. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1255. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1256. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  1257. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1258. Where atr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And atr.DiId = {0} Order By CreateTime", _diId);
  1259. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  1260. decimal AirCNYTotalPrice = groupAirFeeViews.Sum(it => it.CNYPrice);
  1261. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "机票预订", Amount = AirCNYTotalPrice });
  1262. #endregion
  1263. #region 签证费用
  1264. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  1265. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  1266. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  1267. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant,vi.CreateTime
  1268. From Grp_VisaInfo vi
  1269. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  1270. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1271. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1272. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1273. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1274. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And vi.DIId = {0} Order By CreateTime", _diId);
  1275. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  1276. decimal VisaCNYTotalPirce = groupVisaFeeViews.Sum(it => it.PayMoney);
  1277. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "签证", Amount = VisaCNYTotalPirce });
  1278. #endregion
  1279. #region 邀请/公务活动 CTable = 81
  1280. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  1281. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  1282. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  1283. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  1284. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  1285. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ioa.CreateTime
  1286. From Grp_InvitationOfficialActivities ioa
  1287. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  1288. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1289. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1290. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  1291. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  1292. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  1293. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  1294. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  1295. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1296. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ioa.Diid = {0} Order By CreateTime", _diId);
  1297. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  1298. decimal InvitationalCNYTotalPrice = groupInvitationalFeeViews.Sum(it => it.CNYPrice);
  1299. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "邀请/公务活动", Amount = InvitationalCNYTotalPrice });
  1300. #endregion
  1301. #region 保险费用
  1302. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  1303. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  1304. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  1305. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ic.CreateTime
  1306. From Grp_Customers ic
  1307. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  1308. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1309. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1310. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1311. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ic.DiId = {0} Order By CreateTime", _diId);
  1312. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  1313. decimal InsuranceCNYTotalPrice = groupInsuranceFeeViews.Sum(it => it.CNYPrice);
  1314. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "保险费用", Amount = InsuranceCNYTotalPrice });
  1315. #endregion
  1316. #region 其他款项费用 98
  1317. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  1318. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  1319. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,
  1320. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  1321. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,dp.CreateTime
  1322. From Grp_DecreasePayments dp
  1323. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  1324. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1325. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1326. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1327. Where dp.IsDel = 0 And ccp.Ctable = 98 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And dp.Diid = {0}
  1328. Order By CreateTime", _diId);
  1329. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  1330. decimal DecreaseCNYTotalPrice = groupDecreaseFeeViews.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  1331. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "其他款项", Amount = DecreaseCNYTotalPrice });
  1332. #endregion
  1333. #endregion
  1334. /*
  1335. * 团组报表计算方式
  1336. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1337. * 应收金额 = 应收表.Sum()
  1338. * 已收金额 = 已收表.Sum()
  1339. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1340. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1341. *
  1342. */
  1343. decimal _totalExpenditure = 0.00M; //总支出
  1344. decimal _amountReceivable = 0.00M; //应收金额
  1345. decimal _amountReceived = 0.00M; //已收金额
  1346. decimal _receivableProfit = 0.00M; //应收利润
  1347. decimal _receivedProfit = 0.00M; //已收利润
  1348. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  1349. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  1350. _amountReceivable = frTotalAmount;
  1351. _amountReceived = prTotalAmount;
  1352. _receivableProfit = _amountReceivable - promTotalAmount - _totalExpenditure;
  1353. _receivedProfit = _amountReceived - promTotalAmount - _totalExpenditure;
  1354. var groupInfo = groupInfos.Find(it => it.Id == _diId);
  1355. corporateProfits.Add(new CorporateProfit()
  1356. {
  1357. DiId = _diId,
  1358. TeamName = groupInfo?.TeamName ?? "Unkwnon",
  1359. CreateDt = Convert.ToDateTime(groupInfo?.CreateTime),
  1360. TotalExpenditure = _totalExpenditure,
  1361. ExpenditureItem = expenditureInfos,
  1362. AmountReceivable = _amountReceivable,
  1363. AmountReceived = _amountReceived,
  1364. ReceivableProfit = _receivableProfit,
  1365. ReceivedProfit = _receivedProfit,
  1366. });
  1367. }
  1368. #endregion
  1369. return corporateProfits;
  1370. }
  1371. //未来预测-地区接团/出团量
  1372. //未来预测-地区酒店预订量
  1373. //未来预测-地区机票预订量
  1374. //未来预测-地区车辆预订量
  1375. /// <summary>
  1376. /// (国家/城市)地区预订数量(团,酒店,机票,车辆)
  1377. /// Details
  1378. /// 待添加权限验证
  1379. /// </summary>
  1380. /// <param name="_dto">团组列表请求dto</param>
  1381. /// <returns></returns>
  1382. [HttpPost("PostRegionalBookingsNumber")]
  1383. //[JsonConverter(typeof(DecimalConverter), 2)]
  1384. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1385. public async Task<IActionResult> PostRegionalBookingsNumber(PostRegionalBookingsNumberDto _dto)
  1386. {
  1387. #region 参数验证
  1388. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1389. //if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  1390. if (_dto.Type > 1 && _dto.Type > 5) return Ok(JsonView(false, "请输入有效的Type参数,1 团 2 酒店 3 机票 4 车辆"));
  1391. if (_dto.Year < 1) return Ok(JsonView(false, "请输入有效的Year参数!"));
  1392. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1393. #region 页面操作权限验证
  1394. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1395. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1396. #endregion
  1397. string sqlWhere = string.Empty;
  1398. //起止时间
  1399. DateTime beginDt = Convert.ToDateTime($"{_dto.Year}-01-01 00:00:00");
  1400. DateTime endDt = Convert.ToDateTime($"{_dto.Year}-12-31 23:59:59");
  1401. sqlWhere = string.Format(@$" Where Isdel = 0 ");
  1402. string sql = string.Format(@$"Select * From Grp_DelegationInfo {sqlWhere}");
  1403. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).Where(it => it.CreateTime >= beginDt && it.CreateTime <= endDt).ToListAsync();
  1404. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无相关团组!"));
  1405. List<GroupTypeNumberInfo> datas = new List<GroupTypeNumberInfo>();
  1406. foreach (var item in groupInfos)
  1407. {
  1408. var data = await GroupBookingsNumber(_dto.Type,item);
  1409. if (data.TypeItem.Count > 0)
  1410. {
  1411. datas.Add(data);
  1412. }
  1413. }
  1414. //类型处理
  1415. if (_dto.Type == 1)//接团
  1416. {
  1417. List<GroupBookingNumberView> views = new List<GroupBookingNumberView>();
  1418. dynamic groupData = null;
  1419. foreach (var item in datas)
  1420. {
  1421. if (item.TypeItem.Count > 0)
  1422. {
  1423. foreach (var item1 in item.TypeItem)
  1424. {
  1425. if (item1.RegionItem.Count > 0)
  1426. {
  1427. GroupInfo groupInfo = new GroupInfo()
  1428. {
  1429. DiId=item.DiId,
  1430. TeamName = item.GroupName,
  1431. CreateTime = groupInfos.Find(it => it.Id == item.DiId)?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") ?? "Unknown",
  1432. ClientUnit = groupInfos.Find(it => it.Id == item.DiId)?.ClientUnit ?? "Unknown",
  1433. Principal = groupInfos.Find(it => it.Id == item.DiId)?.ClientName ?? "Unknown",
  1434. };
  1435. views.Add(new GroupBookingNumberView() { Name = item1.RegionItem[0].Name, Number = item1.RegionItem[0].Number, GroupItem = new List<GroupInfo>() { groupInfo } });
  1436. }
  1437. }
  1438. }
  1439. }
  1440. var viewsGroup = views.GroupBy(it => it.Name);
  1441. List<GroupBookingNumberView> _view = new List<GroupBookingNumberView>();
  1442. foreach (var item in viewsGroup)
  1443. {
  1444. List<GroupInfo> infos = new List<GroupInfo>();
  1445. foreach (var item1 in item)
  1446. {
  1447. infos.AddRange(item1.GroupItem);
  1448. }
  1449. infos = infos.OrderByDescending(it => it.CreateTime).ToList(); //
  1450. _view.Add(new GroupBookingNumberView() { Name = item.Key, Number = item.Count(),GroupItem = infos });
  1451. }
  1452. _view = _view.OrderByDescending(it => it.Number).Take(10).ToList();
  1453. return Ok(JsonView(true, "操作成功!", _view, _view.Count));
  1454. }
  1455. else if (_dto.Type == 2)
  1456. {
  1457. List<HotelBookingNumberView> views = new List<HotelBookingNumberView>();
  1458. foreach (var item in datas)
  1459. {
  1460. if (item.TypeItem.Count > 0)
  1461. {
  1462. foreach (var item1 in item.TypeItem)
  1463. {
  1464. if (item1.RegionItem.Count > 0)
  1465. {
  1466. foreach (var item2 in item1.RegionItem)
  1467. {
  1468. GroupInfo groupInfo = new GroupInfo()
  1469. {
  1470. DiId = item.DiId,
  1471. TeamName = item.GroupName,
  1472. CreateTime = groupInfos.Find(it => it.Id == item.DiId)?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") ?? "Unknown",
  1473. ClientUnit = groupInfos.Find(it => it.Id == item.DiId)?.ClientUnit ?? "Unknown",
  1474. Principal = groupInfos.Find(it => it.Id == item.DiId)?.ClientName ?? "Unknown",
  1475. };
  1476. List<HotelInfo> hotels = new List<HotelInfo>();
  1477. foreach (var item3 in item2.Data)
  1478. {
  1479. StatisticsHotelInfo statisticsHotelInfos = JsonConvert.DeserializeObject<StatisticsHotelInfo>(JsonConvert.SerializeObject( item3));
  1480. HotelInfo hotelInfo = new HotelInfo()
  1481. {
  1482. HotelName = statisticsHotelInfos.HotelName,
  1483. SingleRoomNum = statisticsHotelInfos.SingleRoomNum,
  1484. DoubleRoomNum = statisticsHotelInfos.DoubleRoomNum,
  1485. SuiteRoomNum = statisticsHotelInfos.SuiteRoomNum,
  1486. OtherRoomNum = statisticsHotelInfos.OtherRoomNum,
  1487. GroupInfo = groupInfo
  1488. };
  1489. hotels.Add(hotelInfo);
  1490. }
  1491. views.Add(new HotelBookingNumberView() { Name = item1.RegionItem[0].Name, Number = item1.RegionItem[0].Number, HotelItem = hotels });
  1492. }
  1493. }
  1494. }
  1495. }
  1496. }
  1497. var viewsGroup = views.GroupBy(it => it.Name);
  1498. List<HotelBookingNumberView> _view = new List<HotelBookingNumberView>();
  1499. foreach (var item in viewsGroup)
  1500. {
  1501. List<HotelInfo> infos = new List<HotelInfo>();
  1502. foreach (var item1 in item)
  1503. {
  1504. infos.AddRange(item1.HotelItem);
  1505. }
  1506. _view.Add(new HotelBookingNumberView() { Name = item.Key, Number = item.Count(), HotelItem = infos });
  1507. }
  1508. _view = _view.OrderByDescending(it => it.Number).Take(10).ToList();
  1509. return Ok(JsonView(true, "操作成功!", views, views.Count));
  1510. }
  1511. return Ok(JsonView(false, "操作失败!"));
  1512. #endregion
  1513. }
  1514. /// <summary>
  1515. /// 计算团组ALLType预订数量
  1516. /// </summary>
  1517. /// <param name="diIds"></param>
  1518. /// <returns></returns>
  1519. private async Task<GroupTypeNumberInfo> GroupBookingsNumber(int type, Grp_DelegationInfo info)
  1520. {
  1521. GroupTypeNumberInfo _view = new GroupTypeNumberInfo();
  1522. if (info == null)
  1523. {
  1524. return _view;
  1525. }
  1526. _view.DiId = info.Id;
  1527. _view.GroupName = info.TeamName;
  1528. List<TypeInfo> _types = new List<TypeInfo>();
  1529. #region 计算团组ALLType预订数量
  1530. if (type == 1)
  1531. {
  1532. //接团 客户集团所在地区
  1533. string group_region = string.Empty;
  1534. int group_number = 0;
  1535. if (!string.IsNullOrEmpty(info.ClientUnit))
  1536. {
  1537. var _NewClientData = await _sqlSugar.Queryable<Crm_NewClientData>().Where(it => it.IsDel == 0 && it.Client.Equals(info.ClientUnit)).FirstAsync();
  1538. if (_NewClientData != null)
  1539. {
  1540. var regionInfo = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == _NewClientData.Lvlid).FirstAsync();
  1541. if (regionInfo != null)
  1542. {
  1543. group_region = regionInfo.Name.Replace("级", "");
  1544. group_number++;
  1545. }
  1546. }
  1547. }
  1548. if (group_number > 0)
  1549. {
  1550. _types.Add(new TypeInfo() { Id = 1, RegionItem = new List<RegionInfo>() { new RegionInfo() { Name = group_region, Number = group_number } } });
  1551. }
  1552. }
  1553. else if (type == 2)
  1554. {
  1555. //酒店
  1556. var hotelInfos = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1557. if (hotelInfos.Count > 0)
  1558. {
  1559. List<RegionInfo> hotelRegions = new List<RegionInfo>();
  1560. foreach (var item in hotelInfos)
  1561. {
  1562. var hotelNumberInfo = new StatisticsHotelInfo()
  1563. {
  1564. HotelName = item.HotelName,
  1565. SingleRoomNum = item.SingleRoomCount,
  1566. DoubleRoomNum = item.DoubleRoomCount,
  1567. SuiteRoomNum = item.SuiteRoomCount,
  1568. OtherRoomNum = item.OtherRoomCount,
  1569. };
  1570. int hotelRoomTotal = item.SingleRoomCount + item.DoubleRoomCount + item.SuiteRoomCount + item.OtherRoomCount;
  1571. if (hotelRegions.Select(it => it.Name).ToList().Contains(item.City))
  1572. {
  1573. RegionInfo hotelRegion = hotelRegions.Find(it => it.Name.Equals(item.City));
  1574. if (hotelRegion != null)
  1575. {
  1576. hotelRegions.Remove(hotelRegion);
  1577. if (hotelRegion.Data.Count > 0)
  1578. {
  1579. hotelRegion.Data.Add(hotelNumberInfo);
  1580. }
  1581. hotelRegion.Number += hotelRoomTotal;
  1582. hotelRegions.Add(hotelRegion);
  1583. }
  1584. }
  1585. else
  1586. {
  1587. hotelRegions.Add(new RegionInfo() { Name = item.City, Number = hotelRoomTotal, Data = new List<dynamic>() { hotelNumberInfo } });
  1588. }
  1589. }
  1590. _types.Add(new TypeInfo() { Id = 2, RegionItem = hotelRegions });
  1591. }
  1592. }
  1593. else if (type == 3)
  1594. {
  1595. //机票
  1596. var airTicketInfos = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1597. .LeftJoin<Grp_CreditCardPayment>((atr, ccp) => atr.Id == ccp.CId && ccp.IsPay == 1)
  1598. .LeftJoin<Sys_SetData>((atr, ccp, sd) => atr.CType == sd.Id)
  1599. .Where((atr, ccp, sd) => atr.IsDel == 0 && atr.DIId == info.Id)
  1600. .Select((atr, ccp, sd) => new { atr.ClientNum, atr.CType, ccp.Payee, AirType = sd.Name })
  1601. .ToListAsync();
  1602. if (airTicketInfos.Count > 0)
  1603. {
  1604. List<RegionInfo> airTicketRegions = new List<RegionInfo>();
  1605. foreach (var item in airTicketInfos)
  1606. {
  1607. var ticketClass = new
  1608. {
  1609. TiketClass = item.AirType,
  1610. Number = item.ClientNum
  1611. };
  1612. if (airTicketRegions.Select(it => it.Name).ToList().Contains(item.Payee))
  1613. {
  1614. RegionInfo airTicketRegion = airTicketRegions.Find(it => it.Name.Equals(item.Payee));
  1615. if (airTicketRegion != null)
  1616. {
  1617. airTicketRegions.Remove(airTicketRegion);
  1618. if (airTicketRegion.Data.Count > 0)
  1619. {
  1620. airTicketRegion.Data.Add(ticketClass);
  1621. }
  1622. airTicketRegion.Number += item.ClientNum;
  1623. airTicketRegions.Add(airTicketRegion);
  1624. }
  1625. }
  1626. else
  1627. {
  1628. airTicketRegions.Add(new RegionInfo() { Name = item.Payee, Number = item.ClientNum, Data = new List<dynamic>() { ticketClass } });
  1629. }
  1630. }
  1631. _types.Add(new TypeInfo() { Id = 3, RegionItem = airTicketRegions });
  1632. }
  1633. }
  1634. else if (type == 4)
  1635. {
  1636. //车辆
  1637. var opInfos = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1638. var opContentInfos = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1639. if (opInfos.Count > 0)
  1640. {
  1641. List<RegionInfo> opRegions = new List<RegionInfo>();
  1642. foreach (var item in opInfos)
  1643. {
  1644. int carNum = 0;
  1645. var opContentInfo = opContentInfos.Where(it => it.CTGGRId == item.Id && it.SId == 91).ToList();
  1646. if (opContentInfo.Count > 0)
  1647. {
  1648. foreach (var item1 in opContentInfo)
  1649. {
  1650. if (item1.Price > 0 && item1.Count > 0)
  1651. {
  1652. carNum += item1.Count;
  1653. }
  1654. }
  1655. }
  1656. if (carNum > 0)
  1657. {
  1658. var opData = new
  1659. {
  1660. ServiceCompany = item.ServiceCompany,
  1661. BusName = item.BusName,
  1662. Numbuer = carNum
  1663. };
  1664. if (opRegions.Select(it => it.Name).ToList().Contains(item.Area))
  1665. {
  1666. RegionInfo opRegion = opRegions.Find(it => it.Name.Equals(item.Area));
  1667. if (opRegion != null)
  1668. {
  1669. opRegions.Remove(opRegion);
  1670. if (opRegion.Data.Count > 0)
  1671. {
  1672. opRegion.Data.Add(opData);
  1673. }
  1674. opRegion.Number += carNum;
  1675. opRegions.Add(opRegion);
  1676. }
  1677. }
  1678. else
  1679. {
  1680. opRegions.Add(new RegionInfo() { Name = item.Area, Number = carNum, Data = new List<dynamic>() { opData } });
  1681. }
  1682. }
  1683. }
  1684. _types.Add(new TypeInfo() { Id = 4, RegionItem = opRegions });
  1685. }
  1686. }
  1687. #endregion
  1688. _view.TypeItem = _types;
  1689. return _view;
  1690. }
  1691. #endregion
  1692. }
  1693. }