StatisticsController.cs 90 KB

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