StatisticsController.cs 110 KB

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