StatisticsController.cs 110 KB

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