ForeignReceivablesRepository.cs 29 KB

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