StatisticsController.cs 109 KB

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