ForeignReceivablesRepository.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. using AutoMapper;
  2. using EyeSoft.Extensions;
  3. using MathNet.Numerics.Statistics.Mcmc;
  4. using NPOI.SS.Formula.Functions;
  5. using OASystem.Domain;
  6. using OASystem.Domain.Dtos.Financial;
  7. using OASystem.Domain.Dtos.Groups;
  8. using OASystem.Domain.Entities.Financial;
  9. using OASystem.Domain.Entities.Groups;
  10. using OASystem.Domain.ViewModels.Financial;
  11. using OASystem.Domain.ViewModels.Groups;
  12. using OASystem.Infrastructure.Repositories.Groups;
  13. using OASystem.Infrastructure.Repositories.System;
  14. using SqlSugar;
  15. using SqlSugar.Extensions;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. namespace OASystem.Infrastructure.Repositories.Financial
  22. {
  23. /// <summary>
  24. /// 财务 - 团组应收款项 仓库
  25. /// 雷怡 2023.08.16 15:03
  26. /// </summary>
  27. public class ForeignReceivablesRepository : BaseRepository<Fin_ForeignReceivables, Fin_ForeignReceivablesView>
  28. {
  29. private readonly IMapper _mapper;
  30. private readonly DelegationInfoRepository _delegationRep;
  31. private readonly SetDataRepository _setDataRep;
  32. private readonly List<int> _portTypes = new List<int>() { 1, 2, 3 };
  33. public ForeignReceivablesRepository(SqlSugarClient sqlSugar, IMapper mapper, DelegationInfoRepository delegationRep, SetDataRepository setDataRep)
  34. : base(sqlSugar)
  35. {
  36. _mapper = mapper;
  37. _delegationRep = delegationRep;
  38. _setDataRep = setDataRep;
  39. }
  40. #region 关联已收款项
  41. /// <summary>
  42. /// 收款账单 数据源
  43. /// </summary>
  44. /// <returns></returns>
  45. public async Task<JsonView> GetDataSource(ForeignReceivablesDataSourcesDto dto)
  46. {
  47. JsonView result = new() { Code = StatusCodes.Status204NoContent };
  48. //已收款项 判断如果是市场部的人员进来的话 只显示自己的 其他的都显示全部的
  49. var userInfos = await _sqlSugar.Queryable<Sys_Users>()
  50. .InnerJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  51. .Where((u, d) => u.IsDel == 0 && d.DepName.Contains("市场部") && u.Id == dto.CurrUserId)
  52. .ToListAsync();
  53. string sqlWhere = "";
  54. if (userInfos.Count > 0) sqlWhere = string.Format(@$" And JietuanOperator={dto.CurrUserId} ");
  55. string sql = string.Format(@$"Select Id,TeamName GroupName From Grp_DelegationInfo
  56. Where TeamName != '' And IsDel = 0 {sqlWhere}
  57. Order By Id Desc");
  58. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  59. //var groupNameData = await _delegationRep.GetGroupNameList(new GroupNameDto());
  60. var currencyData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种
  61. var remittanceMethodData = await _setDataRep.GetSetDataBySTId(_setDataRep, 14); //汇款方式
  62. result.Code = StatusCodes.Status200OK;
  63. result.Msg = "成功!";
  64. result.Data = new
  65. {
  66. GroupNameData = _groupNameList,
  67. CurrencyData = currencyData.Data,
  68. RemittanceMethodData = remittanceMethodData.Data
  69. };
  70. return result;
  71. }
  72. /// <summary>
  73. /// 根据diid查询团组应收款项
  74. /// </summary>
  75. /// <param name="diid"></param>
  76. /// <returns></returns>
  77. public async Task<Result> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  78. {
  79. Result result = new() { Code = -2 };
  80. var groupInfoData = await _delegationRep.GetGroupInfo(new GroupInfoDto() { Id = dto.DiId });
  81. //应收款项
  82. string groupReceivedSql = string.Format(@"Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0}", dto.DiId);
  83. var groupReceivedList = await _sqlSugar.SqlQueryable<ForeignReceivablesView>(groupReceivedSql).ToListAsync();
  84. //已收款项
  85. string groupProceedsReceivedSql = string.Format(@"Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0}", dto.DiId);
  86. var groupProceedsReceivedList = await _sqlSugar.SqlQueryable<ProceedsReceivedView>(groupProceedsReceivedSql).ToListAsync();
  87. List<ProceedsReceivedView> NotFIDData = new List<ProceedsReceivedView>();
  88. if (dto.PortType == 1)
  89. {
  90. foreach (var item in groupReceivedList)
  91. {
  92. item._ProceedsReceivedDatas = groupProceedsReceivedList.Where(s => s.FID == item.Id).ToList();
  93. }
  94. NotFIDData = groupProceedsReceivedList.Where(s => !groupReceivedList.Any(e => s.FID == e.Id)).ToList();
  95. }
  96. result.Code = 0;
  97. result.Msg = "查询成功!";
  98. result.Data = new
  99. {
  100. GroupInfo = groupInfoData.Data,
  101. GroupCollectionStatementData = new
  102. {
  103. ReceivedData = groupReceivedList,
  104. UnallocatedData = NotFIDData
  105. }
  106. };
  107. return result;
  108. }
  109. /// <summary>
  110. /// 应收款项 删除
  111. /// </summary>
  112. /// <param name="dto"></param>
  113. /// <returns></returns>
  114. public async Task<Result> _Del(DelForForeignReceivablesInfoDto dto)
  115. {
  116. Result result = new Result() { Code = -1, Msg = "程序错误!" };
  117. _sqlSugar.BeginTran();
  118. try
  119. {
  120. var res = await _sqlSugar.Updateable<Fin_ForeignReceivables>()
  121. .Where(it => it.Id == dto.Id)
  122. .SetColumns(it => new Fin_ForeignReceivables()
  123. {
  124. IsDel = 1,
  125. DeleteUserId = dto.UserId,
  126. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  127. }
  128. ).ExecuteCommandAsync();
  129. if (res > 0)
  130. {
  131. await _sqlSugar.Updateable<Fin_ProceedsReceived>()
  132. .Where(a => a.FID == dto.Id)
  133. .SetColumns(a => new Fin_ProceedsReceived
  134. {
  135. IsDel = 1,
  136. DeleteUserId = dto.UserId,
  137. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  138. }).ExecuteCommandAsync();
  139. _sqlSugar.CommitTran();
  140. result.Msg = "删除成功!";
  141. result.Code = 0;
  142. }
  143. else
  144. {
  145. _sqlSugar.RollbackTran();
  146. result.Msg = "删除失败!";
  147. return result;
  148. }
  149. }
  150. catch (Exception ex)
  151. {
  152. _sqlSugar.RollbackTran();
  153. result.Msg = ex.Message;
  154. return result;
  155. }
  156. return result;
  157. }
  158. /// <summary>
  159. /// 财务模块
  160. /// 收款账单 Add And Update
  161. /// </summary>
  162. /// <param name="diid"></param>
  163. /// <returns></returns>
  164. public async Task<Result> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  165. {
  166. Result result = new() { Code = -2 };
  167. if (dto.foreignReceivablesInfos.Count <= 0)
  168. {
  169. result.Msg = "收款账单没有信息,不能进行,添加或修改操作!!!";
  170. return result;
  171. }
  172. int addCount = 0, updateCount = 0;
  173. if (dto.PortType == 1)
  174. {
  175. List<Fin_ForeignReceivables> _ForeignReceivables = new List<Fin_ForeignReceivables>();
  176. foreach (var item in dto.foreignReceivablesInfos)
  177. {
  178. _ForeignReceivables.Add(new Fin_ForeignReceivables()
  179. {
  180. Diid = dto.DiId,
  181. Id = item.Id,
  182. PriceName = item.PriceName,
  183. Price = item.Price,
  184. Count = item.Count,
  185. Unit = item.Unit,
  186. ItemSumPrice = item.ItemSumPrice,
  187. Rate = item.Rate,
  188. Currency = item.Currency,
  189. AddingWay = item.AddingWay,
  190. CreateUserId = dto.UserId,
  191. CreateTime = DateTime.Now,
  192. Remark = item.Remark
  193. });
  194. }
  195. if (_ForeignReceivables.Count > 0)
  196. {
  197. var x = _sqlSugar.Storageable(_ForeignReceivables).ToStorage();
  198. addCount = x.AsInsertable.ExecuteCommand(); //不存在插入
  199. updateCount = x.AsUpdateable.ExecuteCommand(); //存在更新
  200. }
  201. result.Code = 0;
  202. result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount, updateCount);
  203. }
  204. return result;
  205. }
  206. /// <summary>
  207. /// 根据diid查询团组应收款项
  208. /// </summary>
  209. /// <param name="diid"></param>
  210. /// <returns></returns>
  211. public async Task<Result> GetGroupReceivablesByDiid(int diid)
  212. {
  213. Result result = new() { Code = -2 };
  214. string sql = string.Format(@"Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0}", diid);
  215. var groupReceivedList = await _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql).ToListAsync();
  216. result.Code = 0;
  217. result.Msg = "查询成功!";
  218. result.Data = groupReceivedList;
  219. return result;
  220. }
  221. /// <summary>
  222. /// 根据diid 数组 查询团组应收款项
  223. /// </summary>
  224. /// <param name="diid"></param>
  225. /// <returns></returns>
  226. public async Task<Result> GetGroupReceivablesByDiids(int[] diids)
  227. {
  228. Result result = new() { Code = -2 };
  229. //string sql = string.Format(@"Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0}", diids);
  230. var groupReceivedList = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  231. .Where(pr => pr.IsDel == 0 && diids.Contains(pr.Diid)).ToListAsync();
  232. result.Code = 0;
  233. result.Msg = "查询成功!";
  234. result.Data = groupReceivedList;
  235. return result;
  236. }
  237. #endregion
  238. #region 未关联已收款项
  239. /// <summary>
  240. /// 收款账单 数据源
  241. /// </summary>
  242. /// <returns></returns>
  243. public async Task<JsonView> PostDataSource(ForeignReceivablesDataSourcesDto dto)
  244. {
  245. JsonView result = new() { Code = StatusCodes.Status204NoContent };
  246. //已收款项 判断如果是市场部的人员进来的话 只显示自己的 其他的都显示全部的
  247. var userInfos = await _sqlSugar.Queryable<Sys_Users>()
  248. .InnerJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  249. .Where((u, d) => u.IsDel == 0 && d.DepName.Contains("市场部") && u.Id == dto.CurrUserId)
  250. .ToListAsync();
  251. string sqlWhere = "";
  252. if (userInfos.Count > 0) sqlWhere = string.Format(@$" And JietuanOperator={dto.CurrUserId} ");
  253. string sql = string.Format(@$"Select Id,TeamName GroupName From Grp_DelegationInfo
  254. Where TeamName != '' And IsDel = 0 {sqlWhere}
  255. Order By Id Desc");
  256. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  257. //var groupNameData = await _delegationRep.GetGroupNameList(new GroupNameDto());
  258. var currencyData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种
  259. var remittanceMethodData = await _setDataRep.GetSetDataBySTId(_setDataRep, 14); //汇款方式
  260. result.Code = StatusCodes.Status200OK;
  261. result.Msg = "成功!";
  262. result.Data = new
  263. {
  264. GroupNameData = _groupNameList,
  265. CurrencyData = currencyData.Data,
  266. RemittanceMethodData = remittanceMethodData.Data
  267. };
  268. return result;
  269. }
  270. /// <summary>
  271. /// 收款账单数据源团组分页
  272. /// </summary>
  273. /// <returns></returns>
  274. public async Task<JsonView> PostDataSourceOffSet(ForeignReceivablesDataSourcesOffSetDto dto)
  275. {
  276. JsonView result = new() { Code = StatusCodes.Status204NoContent };
  277. if (dto.PageIndex < 1) dto.PageIndex = 1;
  278. if (dto.PageSize < 1) dto.PageSize = 10;
  279. //已收款项 判断如果是市场部的人员进来的话 只显示自己的 其他的都显示全部的
  280. var userInfos = await _sqlSugar.Queryable<Sys_Users>()
  281. .InnerJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  282. .Where((u, d) => u.IsDel == 0 && d.DepName.Contains("市场部") && u.Id == dto.CurrUserId)
  283. .ToListAsync();
  284. var expressionWhere = Expressionable.Create<Grp_DelegationInfo>()
  285. .And(x => x.IsDel == 0 && x.TeamName != "")
  286. .AndIF(userInfos.Count > 0, x => x.JietuanOperator == dto.CurrUserId)
  287. .AndIF(!dto.SearchValue.IsNullOrWhiteSpace(),x=> x.TeamName.Contains(dto.SearchValue))
  288. .ToExpression();
  289. var totalNumber = 0;
  290. var _groupNameList = _sqlSugar.Queryable<Grp_DelegationInfo>()
  291. .Where(expressionWhere)
  292. .ToPageList(dto.PageIndex, dto.PageSize, ref totalNumber)
  293. .Select(x=> new GroupNameView
  294. {
  295. GroupName = x.TeamName,
  296. Id = x.Id,
  297. });
  298. if (totalNumber > 0)
  299. {
  300. totalNumber = totalNumber / dto.PageSize + 1;
  301. }
  302. //var currencyData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种
  303. //var remittanceMethodData = await _setDataRep.GetSetDataBySTId(_setDataRep, 14); //汇款方式
  304. result.Code = StatusCodes.Status200OK;
  305. result.Msg = "成功!";
  306. result.Data = new
  307. {
  308. GroupNameData = _groupNameList,
  309. //CurrencyData = currencyData.Data,
  310. //RemittanceMethodData = remittanceMethodData.Data,
  311. GroupTotalPage = totalNumber
  312. };
  313. return result;
  314. }
  315. /// <summary>
  316. /// 根据diid查询团组应收款项
  317. /// </summary>
  318. /// <param name="diid"></param>
  319. /// <returns></returns>
  320. public async Task<JsonView> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  321. {
  322. JsonView result = new() { Code = 400, Msg = "" };
  323. //var groupInfoData = await _delegationRep.GetGroupInfo(new GroupInfoDto() { Id = dto.DiId });
  324. var groupInfoData = await _delegationRep.Query(x => x.Id == dto.DiId)
  325. .Select(x => new
  326. {
  327. x.Id,
  328. x.TeamName,
  329. x.TourCode,
  330. x.ClientName,
  331. VisitCountry = x.VisitCountry.Replace("|","、"),
  332. x.VisitDays,
  333. x.VisitPNumber,
  334. x.VisitStartDate,
  335. x.VisitEndDate
  336. })
  337. .FirstAsync();
  338. //应收款项
  339. string groupReceivedSql = string.Format(@"Select *,su.CnName As AuditorName From Fin_ForeignReceivables ffr
  340. Left Join Sys_Users su On ffr.Auditor = su.Id
  341. Where ffr.IsDel=0 And ffr.Diid={0}", dto.DiId);
  342. var groupReceivedList = await _sqlSugar.SqlQueryable<ProceedsReceivedNewView>(groupReceivedSql).ToListAsync();
  343. result.Code = 200;
  344. result.Msg = "查询成功!";
  345. result.Data = new
  346. {
  347. GroupInfo = groupInfoData,
  348. GroupCollectionStatementData = groupReceivedList
  349. };
  350. return result;
  351. }
  352. /// <summary>
  353. /// 财务模块
  354. /// 收款账单 Add And Update
  355. /// </summary>
  356. /// <param name="diid"></param>
  357. /// <returns></returns>
  358. public async Task<JsonView> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  359. {
  360. JsonView result = new() { Code = 4002 };
  361. if (dto.foreignReceivablesInfos.Count <= 0)
  362. {
  363. result.Msg = "收款账单没有信息,不能进行,添加或修改操作!!!";
  364. return result;
  365. }
  366. int addCount = 0, updateCount = 0;
  367. //if (dto.PortType == 1)
  368. //{
  369. //查询值是否更改
  370. var selectInfos = await _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.Diid == dto.DiId && it.Status == 1).ToListAsync();
  371. List <Fin_ForeignReceivables> _ForeignReceivables = new List<Fin_ForeignReceivables>();
  372. foreach (var item in dto.foreignReceivablesInfos)
  373. {
  374. int status = 0, auditor = 0;
  375. string auditTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  376. var info = selectInfos.Find(x => x.Id == item.Id);
  377. if (info != null)
  378. {
  379. if (info.ItemSumPrice == item.ItemSumPrice)
  380. {
  381. status = info.Status;
  382. auditor = info.Auditor;
  383. auditTime = info.AuditTime;
  384. }
  385. }
  386. _ForeignReceivables.Add(new Fin_ForeignReceivables()
  387. {
  388. Diid = dto.DiId,
  389. Id = item.Id,
  390. PriceName = item.PriceName,
  391. Price = item.Price,
  392. Count = item.Count,
  393. Unit = item.Unit,
  394. ItemSumPrice = item.ItemSumPrice,
  395. Rate = item.Rate,
  396. Currency = item.Currency,
  397. AddingWay = item.AddingWay,
  398. CreateUserId = dto.UserId,
  399. CreateTime = DateTime.Now,
  400. Remark = item.Remark,
  401. Status = status,
  402. Auditor = auditor,
  403. AuditTime = auditTime
  404. });
  405. }
  406. if (_ForeignReceivables.Count > 0)
  407. {
  408. var x = _sqlSugar.Storageable(_ForeignReceivables).ToStorage();
  409. addCount = x.AsInsertable.ExecuteCommand(); //不存在插入
  410. updateCount = x.AsUpdateable.IgnoreColumns(it => new
  411. {
  412. //it.Status,
  413. //it.Auditor,
  414. //it.AuditTime,
  415. it.CreateUserId,
  416. it.CreateTime
  417. }).ExecuteCommand(); //存在更新
  418. }
  419. result.Code = 200;
  420. result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount, updateCount);
  421. //}
  422. return result;
  423. }
  424. /// <summary>
  425. /// 财务模块
  426. /// 收款账单
  427. /// Audit
  428. /// </summary>
  429. /// <param name="diid"></param>
  430. /// <returns></returns>
  431. public async Task<JsonView> FeeAudit(FeeAuditDto dto)
  432. {
  433. JsonView result = new() { Code = 400 };
  434. //验证
  435. var info = await _sqlSugar.Queryable<Fin_ForeignReceivables>().FirstAsync(x => x.Id == dto.Id);
  436. if (info == null)
  437. {
  438. result.Msg = "数据不存在";
  439. return result;
  440. }
  441. if (info.AddingWay != 2)
  442. {
  443. result.Msg = "该条数据类型不是“实际报价”类型不可审核!";
  444. return result;
  445. }
  446. var AuditStatus = await _sqlSugar.Updateable<Fin_ForeignReceivables>()
  447. .SetColumns(a => new Fin_ForeignReceivables
  448. {
  449. Status = dto.Status,
  450. Auditor = dto.UserId,
  451. AuditTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  452. })
  453. .Where(a => a.Id == dto.Id)
  454. .ExecuteCommandAsync();
  455. if (AuditStatus > 0)
  456. {
  457. result.Msg = "操作成功!";
  458. result.Code = 200;
  459. }
  460. else result.Msg = "操作失败!";
  461. return result;
  462. }
  463. /// <summary>
  464. /// 财务模块
  465. /// 收款账单
  466. /// Del
  467. /// </summary>
  468. /// <param name="diid"></param>
  469. /// <returns></returns>
  470. public async Task<Result> PostReceivablesDel(ForeignReceivablesDelDto dto)
  471. {
  472. Result result = new() { Code = -2 };
  473. var delStatus = await _sqlSugar.Updateable<Fin_ForeignReceivables>()
  474. .SetColumns(a => new Fin_ForeignReceivables
  475. {
  476. IsDel = 1,
  477. DeleteUserId = dto.UserId,
  478. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  479. })
  480. .Where(a => a.Id == dto.Id)
  481. .ExecuteCommandAsync();
  482. if (delStatus > 0)
  483. {
  484. result.Msg = "操作成功!";
  485. result.Code = 0;
  486. }
  487. else
  488. {
  489. result.Msg = "操作成功!";
  490. }
  491. return result;
  492. }
  493. public void OverSpSeteceivables(OverSpSeteceivablesDto dto)
  494. {
  495. var querySaveReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>()
  496. .First(x => x.Diid == dto.DiId && x.AddingWay == 3 && x.IsDel == 0);
  497. //获取所有超支数据
  498. //整理超支数据
  499. //币种不同则计算rmb值
  500. var overspList = _sqlSugar.Queryable<Fin_GroupExtraCost, Grp_CreditCardPayment>
  501. ((e, c) => c.CTable == 1015 && c.CId == e.Id && c.IsDel == 0).
  502. Where((e, c) => e.IsDel == 0 && e.DiId == dto.DiId).
  503. Select((e, c) => new
  504. {
  505. e.Price,
  506. e.PriceCount,
  507. e.Coefficient,
  508. e.PriceSum,
  509. c.RMBPrice,
  510. c.DayRate,
  511. e.PriceCurrency,
  512. e.Remark,
  513. })
  514. .ToList().
  515. Where(x =>
  516. {
  517. var count = 0;
  518. var stringArr = new string[] { "SYsupervisorConfirm" , "SupervisorConfirm" , "ManagerConfirm" };
  519. foreach (var item in stringArr)
  520. {
  521. var number = x.GetType()?.GetProperty(item)?.GetValue(x).ObjToInt();
  522. if (number > 0)
  523. {
  524. count++;
  525. }
  526. }
  527. return count > 1;
  528. }).ToList();
  529. var overspListGroup = overspList.GroupBy(x => x.PriceCurrency).ToList();
  530. string foreignReceivablesRemake = string.Empty;
  531. int count = 1;
  532. overspList.ForEach(x =>
  533. {
  534. foreignReceivablesRemake += $"{count}.{x.Remark}";
  535. count++;
  536. });
  537. if (querySaveReceivables != null)
  538. {
  539. if (overspList.Count() > 0)
  540. {
  541. if (overspListGroup.Count() > 1)
  542. {
  543. querySaveReceivables.Currency = 836; //人民币
  544. querySaveReceivables.Rate = 1;
  545. querySaveReceivables.Price = overspListGroup.Sum(x => x.Sum(y => y.PriceSum * y.Coefficient * y.DayRate));
  546. querySaveReceivables.ItemSumPrice = overspListGroup.Sum(x => x.Sum(y => y.PriceSum * y.Coefficient * y.DayRate));
  547. querySaveReceivables.Remark = foreignReceivablesRemake;
  548. querySaveReceivables.CreateTime = DateTime.Now;
  549. }
  550. else
  551. {
  552. querySaveReceivables.Currency = overspList[0].PriceCurrency;
  553. querySaveReceivables.Rate = overspList[0].DayRate;
  554. querySaveReceivables.Price = overspListGroup[0].Sum(x => x.PriceSum * x.Coefficient);
  555. querySaveReceivables.ItemSumPrice = overspListGroup[0].Sum(x => x.PriceSum * x.Coefficient);
  556. querySaveReceivables.Remark = foreignReceivablesRemake;
  557. querySaveReceivables.AddingWay = 3;
  558. querySaveReceivables.CreateTime = DateTime.Now;
  559. }
  560. }
  561. else
  562. {
  563. querySaveReceivables.Currency = 836; //人民币
  564. querySaveReceivables.Rate = 1;
  565. querySaveReceivables.Price = 0;
  566. querySaveReceivables.ItemSumPrice = 0;
  567. querySaveReceivables.Remark = "";
  568. querySaveReceivables.CreateTime = DateTime.Now;
  569. querySaveReceivables.Count = 1;
  570. }
  571. _sqlSugar.Updateable(querySaveReceivables).ExecuteCommand();
  572. }
  573. else
  574. {
  575. if (overspList.Count() > 0)
  576. {
  577. if (overspListGroup.Count() > 1)
  578. {
  579. querySaveReceivables = new Fin_ForeignReceivables
  580. {
  581. CreateTime = DateTime.Now,
  582. CreateUserId = dto.CreateUserId,
  583. Diid = dto.DiId,
  584. PriceName = "超支费用",
  585. AddingWay = 3,
  586. Count = 1,
  587. Currency = 836,
  588. ItemSumPrice = overspList.Sum(x => x.PriceSum * x.Coefficient * x.DayRate),
  589. Price = overspList.Sum(x => x.PriceSum * x.Coefficient * x.DayRate),
  590. Rate = 1,
  591. IsDel = 0,
  592. Remark = foreignReceivablesRemake,
  593. Unit = "团",
  594. };
  595. }
  596. else
  597. {
  598. querySaveReceivables = new Fin_ForeignReceivables
  599. {
  600. CreateTime = DateTime.Now,
  601. CreateUserId = dto.CreateUserId,
  602. Diid = dto.DiId,
  603. PriceName = "超支费用",
  604. AddingWay = 3,
  605. Count = 1,
  606. Currency = overspList[0].PriceCurrency,
  607. ItemSumPrice = overspList.Sum(x => x.PriceSum * x.Coefficient),
  608. Price = overspList.Sum(x => x.PriceSum * x.Coefficient),
  609. Rate = overspList[0].DayRate,
  610. IsDel = 0,
  611. Remark = foreignReceivablesRemake,
  612. Unit = "团",
  613. };
  614. }
  615. }
  616. _sqlSugar.Insertable(querySaveReceivables).ExecuteCommand();
  617. }
  618. }
  619. #endregion
  620. }
  621. }