ForeignReceivablesRepository.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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. /// 根据diid查询团组应收款项
  271. /// </summary>
  272. /// <param name="diid"></param>
  273. /// <returns></returns>
  274. public async Task<JsonView> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  275. {
  276. JsonView result = new() { Code = 400, Msg = "" };
  277. //var groupInfoData = await _delegationRep.GetGroupInfo(new GroupInfoDto() { Id = dto.DiId });
  278. var groupInfoData = await _delegationRep.Query(x => x.Id == dto.DiId)
  279. .Select(x => new
  280. {
  281. x.Id,
  282. x.TeamName,
  283. x.TourCode,
  284. x.ClientName,
  285. VisitCountry = x.VisitCountry.Replace("|","、"),
  286. x.VisitDays,
  287. x.VisitPNumber,
  288. x.VisitStartDate,
  289. x.VisitEndDate
  290. })
  291. .FirstAsync();
  292. //应收款项
  293. string groupReceivedSql = string.Format(@"Select *,su.CnName As AuditorName From Fin_ForeignReceivables ffr
  294. Left Join Sys_Users su On ffr.Auditor = su.Id
  295. Where ffr.IsDel=0 And ffr.Diid={0}", dto.DiId);
  296. var groupReceivedList = await _sqlSugar.SqlQueryable<ProceedsReceivedNewView>(groupReceivedSql).ToListAsync();
  297. result.Code = 200;
  298. result.Msg = "查询成功!";
  299. result.Data = new
  300. {
  301. GroupInfo = groupInfoData,
  302. GroupCollectionStatementData = groupReceivedList
  303. };
  304. return result;
  305. }
  306. /// <summary>
  307. /// 财务模块
  308. /// 收款账单 Add And Update
  309. /// </summary>
  310. /// <param name="diid"></param>
  311. /// <returns></returns>
  312. public async Task<JsonView> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  313. {
  314. JsonView result = new() { Code = 4002 };
  315. if (dto.foreignReceivablesInfos.Count <= 0)
  316. {
  317. result.Msg = "收款账单没有信息,不能进行,添加或修改操作!!!";
  318. return result;
  319. }
  320. int addCount = 0, updateCount = 0;
  321. //if (dto.PortType == 1)
  322. //{
  323. //查询值是否更改
  324. var selectInfos = await _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.Diid == dto.DiId && it.Status == 1).ToListAsync();
  325. List <Fin_ForeignReceivables> _ForeignReceivables = new List<Fin_ForeignReceivables>();
  326. foreach (var item in dto.foreignReceivablesInfos)
  327. {
  328. int status = 0, auditor = 0;
  329. string auditTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  330. var info = selectInfos.Find(x => x.Id == item.Id);
  331. if (info != null)
  332. {
  333. if (info.ItemSumPrice == item.ItemSumPrice)
  334. {
  335. status = info.Status;
  336. auditor = info.Auditor;
  337. auditTime = info.AuditTime;
  338. }
  339. }
  340. _ForeignReceivables.Add(new Fin_ForeignReceivables()
  341. {
  342. Diid = dto.DiId,
  343. Id = item.Id,
  344. PriceName = item.PriceName,
  345. Price = item.Price,
  346. Count = item.Count,
  347. Unit = item.Unit,
  348. ItemSumPrice = item.ItemSumPrice,
  349. Rate = item.Rate,
  350. Currency = item.Currency,
  351. AddingWay = item.AddingWay,
  352. CreateUserId = dto.UserId,
  353. CreateTime = DateTime.Now,
  354. Remark = item.Remark,
  355. Status = status,
  356. Auditor = auditor,
  357. AuditTime = auditTime
  358. });
  359. }
  360. if (_ForeignReceivables.Count > 0)
  361. {
  362. var x = _sqlSugar.Storageable(_ForeignReceivables).ToStorage();
  363. addCount = x.AsInsertable.ExecuteCommand(); //不存在插入
  364. updateCount = x.AsUpdateable.IgnoreColumns(it => new
  365. {
  366. //it.Status,
  367. //it.Auditor,
  368. //it.AuditTime,
  369. it.CreateUserId,
  370. it.CreateTime
  371. }).ExecuteCommand(); //存在更新
  372. }
  373. result.Code = 200;
  374. result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount, updateCount);
  375. //}
  376. return result;
  377. }
  378. /// <summary>
  379. /// 财务模块
  380. /// 收款账单
  381. /// Audit
  382. /// </summary>
  383. /// <param name="diid"></param>
  384. /// <returns></returns>
  385. public async Task<JsonView> FeeAudit(FeeAuditDto dto)
  386. {
  387. JsonView result = new() { Code = 400 };
  388. //验证
  389. var info = await _sqlSugar.Queryable<Fin_ForeignReceivables>().FirstAsync(x => x.Id == dto.Id);
  390. if (info == null)
  391. {
  392. result.Msg = "数据不存在";
  393. return result;
  394. }
  395. if (info.AddingWay != 2)
  396. {
  397. result.Msg = "该条数据类型不是“实际报价”类型不可审核!";
  398. return result;
  399. }
  400. var AuditStatus = await _sqlSugar.Updateable<Fin_ForeignReceivables>()
  401. .SetColumns(a => new Fin_ForeignReceivables
  402. {
  403. Status = dto.Status,
  404. Auditor = dto.UserId,
  405. AuditTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  406. })
  407. .Where(a => a.Id == dto.Id)
  408. .ExecuteCommandAsync();
  409. if (AuditStatus > 0)
  410. {
  411. result.Msg = "操作成功!";
  412. result.Code = 200;
  413. }
  414. else result.Msg = "操作失败!";
  415. return result;
  416. }
  417. /// <summary>
  418. /// 财务模块
  419. /// 收款账单
  420. /// Del
  421. /// </summary>
  422. /// <param name="diid"></param>
  423. /// <returns></returns>
  424. public async Task<Result> PostReceivablesDel(ForeignReceivablesDelDto dto)
  425. {
  426. Result result = new() { Code = -2 };
  427. var delStatus = await _sqlSugar.Updateable<Fin_ForeignReceivables>()
  428. .SetColumns(a => new Fin_ForeignReceivables
  429. {
  430. IsDel = 1,
  431. DeleteUserId = dto.UserId,
  432. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  433. })
  434. .Where(a => a.Id == dto.Id)
  435. .ExecuteCommandAsync();
  436. if (delStatus > 0)
  437. {
  438. result.Msg = "操作成功!";
  439. result.Code = 0;
  440. }
  441. else
  442. {
  443. result.Msg = "操作成功!";
  444. }
  445. return result;
  446. }
  447. public void OverSpSeteceivables(OverSpSeteceivablesDto dto)
  448. {
  449. var querySaveReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>()
  450. .First(x => x.Diid == dto.DiId && x.AddingWay == 3 && x.IsDel == 0);
  451. //获取所有超支数据
  452. //整理超支数据
  453. //币种不同则计算rmb值
  454. var overspList = _sqlSugar.Queryable<Fin_GroupExtraCost, Grp_CreditCardPayment>
  455. ((e, c) => c.CTable == 1015 && c.CId == e.Id && c.IsDel == 0).
  456. Where((e, c) => e.IsDel == 0 && e.DiId == dto.DiId).
  457. Select((e, c) => new
  458. {
  459. e.Price,
  460. e.PriceCount,
  461. e.Coefficient,
  462. e.PriceSum,
  463. c.RMBPrice,
  464. c.DayRate,
  465. e.PriceCurrency,
  466. e.Remark,
  467. })
  468. .ToList().
  469. Where(x =>
  470. {
  471. var count = 0;
  472. var stringArr = new string[] { "SYsupervisorConfirm" , "SupervisorConfirm" , "ManagerConfirm" };
  473. foreach (var item in stringArr)
  474. {
  475. var number = x.GetType()?.GetProperty(item)?.GetValue(x).ObjToInt();
  476. if (number > 0)
  477. {
  478. count++;
  479. }
  480. }
  481. return count > 1;
  482. }).ToList();
  483. var overspListGroup = overspList.GroupBy(x => x.PriceCurrency).ToList();
  484. string foreignReceivablesRemake = string.Empty;
  485. int count = 1;
  486. overspList.ForEach(x =>
  487. {
  488. foreignReceivablesRemake += $"{count}.{x.Remark}";
  489. count++;
  490. });
  491. if (querySaveReceivables != null)
  492. {
  493. if (overspList.Count() > 0)
  494. {
  495. if (overspListGroup.Count() > 1)
  496. {
  497. querySaveReceivables.Currency = 836; //人民币
  498. querySaveReceivables.Rate = 1;
  499. querySaveReceivables.Price = overspListGroup.Sum(x => x.Sum(y => y.PriceSum * y.Coefficient * y.DayRate));
  500. querySaveReceivables.ItemSumPrice = overspListGroup.Sum(x => x.Sum(y => y.PriceSum * y.Coefficient * y.DayRate));
  501. querySaveReceivables.Remark = foreignReceivablesRemake;
  502. querySaveReceivables.CreateTime = DateTime.Now;
  503. }
  504. else
  505. {
  506. querySaveReceivables.Currency = overspList[0].PriceCurrency;
  507. querySaveReceivables.Rate = overspList[0].DayRate;
  508. querySaveReceivables.Price = overspListGroup[0].Sum(x => x.PriceSum * x.Coefficient);
  509. querySaveReceivables.ItemSumPrice = overspListGroup[0].Sum(x => x.PriceSum * x.Coefficient);
  510. querySaveReceivables.Remark = foreignReceivablesRemake;
  511. querySaveReceivables.AddingWay = 3;
  512. querySaveReceivables.CreateTime = DateTime.Now;
  513. }
  514. }
  515. else
  516. {
  517. querySaveReceivables.Currency = 836; //人民币
  518. querySaveReceivables.Rate = 1;
  519. querySaveReceivables.Price = 0;
  520. querySaveReceivables.ItemSumPrice = 0;
  521. querySaveReceivables.Remark = "";
  522. querySaveReceivables.CreateTime = DateTime.Now;
  523. querySaveReceivables.Count = 1;
  524. }
  525. _sqlSugar.Updateable(querySaveReceivables).ExecuteCommand();
  526. }
  527. else
  528. {
  529. if (overspList.Count() > 0)
  530. {
  531. if (overspListGroup.Count() > 1)
  532. {
  533. querySaveReceivables = new Fin_ForeignReceivables
  534. {
  535. CreateTime = DateTime.Now,
  536. CreateUserId = dto.CreateUserId,
  537. Diid = dto.DiId,
  538. PriceName = "超支费用",
  539. AddingWay = 3,
  540. Count = 1,
  541. Currency = 836,
  542. ItemSumPrice = overspList.Sum(x => x.PriceSum * x.Coefficient * x.DayRate),
  543. Price = overspList.Sum(x => x.PriceSum * x.Coefficient * x.DayRate),
  544. Rate = 1,
  545. IsDel = 0,
  546. Remark = foreignReceivablesRemake,
  547. Unit = "团",
  548. };
  549. }
  550. else
  551. {
  552. querySaveReceivables = new Fin_ForeignReceivables
  553. {
  554. CreateTime = DateTime.Now,
  555. CreateUserId = dto.CreateUserId,
  556. Diid = dto.DiId,
  557. PriceName = "超支费用",
  558. AddingWay = 3,
  559. Count = 1,
  560. Currency = overspList[0].PriceCurrency,
  561. ItemSumPrice = overspList.Sum(x => x.PriceSum * x.Coefficient),
  562. Price = overspList.Sum(x => x.PriceSum * x.Coefficient),
  563. Rate = overspList[0].DayRate,
  564. IsDel = 0,
  565. Remark = foreignReceivablesRemake,
  566. Unit = "团",
  567. };
  568. }
  569. }
  570. _sqlSugar.Insertable(querySaveReceivables).ExecuteCommand();
  571. }
  572. }
  573. #endregion
  574. }
  575. }