ForeignReceivablesRepository.cs 26 KB

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