ForeignReceivablesRepository.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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, ssd.Name as 'CurrencyStr' From Fin_ForeignReceivables ffr
  340. Left Join Sys_Users su On ffr.Auditor = su.Id
  341. LEFT JOIN Sys_SetData ssd on ffr.Currency = ssd.Id AND ssd.IsDel = 0
  342. Where ffr.IsDel=0 And ffr.Diid={0}", dto.DiId);
  343. var groupReceivedList = await _sqlSugar.SqlQueryable<ProceedsReceivedNewView>(groupReceivedSql).ToListAsync();
  344. result.Code = 200;
  345. result.Msg = "查询成功!";
  346. result.Data = new
  347. {
  348. GroupInfo = groupInfoData,
  349. GroupCollectionStatementData = groupReceivedList
  350. };
  351. return result;
  352. }
  353. /// <summary>
  354. /// 财务模块
  355. /// 收款账单 Add And Update
  356. /// </summary>
  357. /// <param name="diid"></param>
  358. /// <returns></returns>
  359. public async Task<JsonView> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  360. {
  361. JsonView result = new() { Code = 4002 };
  362. if (dto.foreignReceivablesInfos.Count <= 0)
  363. {
  364. result.Msg = "收款账单没有信息,不能进行,添加或修改操作!!!";
  365. return result;
  366. }
  367. int addCount = 0, updateCount = 0;
  368. //if (dto.PortType == 1)
  369. //{
  370. //查询值是否更改
  371. var selectInfos = await _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.Diid == dto.DiId && it.Status == 1).ToListAsync();
  372. List <Fin_ForeignReceivables> _ForeignReceivables = new List<Fin_ForeignReceivables>();
  373. foreach (var item in dto.foreignReceivablesInfos)
  374. {
  375. int status = 0, auditor = 0;
  376. string auditTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  377. var info = selectInfos.Find(x => x.Id == item.Id);
  378. if (info != null)
  379. {
  380. if (info.ItemSumPrice == item.ItemSumPrice)
  381. {
  382. status = info.Status;
  383. auditor = info.Auditor;
  384. auditTime = info.AuditTime;
  385. }
  386. }
  387. _ForeignReceivables.Add(new Fin_ForeignReceivables()
  388. {
  389. Diid = dto.DiId,
  390. Id = item.Id,
  391. PriceName = item.PriceName,
  392. Price = item.Price,
  393. Count = item.Count,
  394. Unit = item.Unit,
  395. ItemSumPrice = item.ItemSumPrice,
  396. Rate = item.Rate,
  397. Currency = item.Currency,
  398. AddingWay = item.AddingWay,
  399. CreateUserId = dto.UserId,
  400. CreateTime = DateTime.Now,
  401. Remark = item.Remark,
  402. Status = status,
  403. Auditor = auditor,
  404. AuditTime = auditTime
  405. });
  406. }
  407. if (_ForeignReceivables.Count > 0)
  408. {
  409. var x = _sqlSugar.Storageable(_ForeignReceivables).ToStorage();
  410. addCount = x.AsInsertable.ExecuteCommand(); //不存在插入
  411. updateCount = x.AsUpdateable.IgnoreColumns(it => new
  412. {
  413. //it.Status,
  414. //it.Auditor,
  415. //it.AuditTime,
  416. it.CreateUserId,
  417. it.CreateTime
  418. }).ExecuteCommand(); //存在更新
  419. }
  420. result.Code = 200;
  421. result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount, updateCount);
  422. //}
  423. return result;
  424. }
  425. /// <summary>
  426. /// 财务模块
  427. /// 收款账单(单条) Add And Update
  428. /// </summary>
  429. /// <param name="diid"></param>
  430. /// <returns></returns>
  431. public async Task<JsonView> PostReceivablesSingleSave(PostReceivablesSingleSaveDto dto)
  432. {
  433. JsonView result = new() { Code = 400 };
  434. var portIds = new List<int>() { 2, 3 };
  435. if (!portIds.Contains(dto.PortType))
  436. {
  437. result.Msg = MsgTips.MobilePort;
  438. return result;
  439. }
  440. if (dto.DiId < 1)
  441. {
  442. result.Msg = MsgTips.DiId;
  443. return result;
  444. }
  445. var selectInfos = await _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.Diid == dto.DiId && it.Status == 1 && it.Id == dto.Id).FirstAsync();
  446. string auditTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  447. int status = 0, auditor = 0;
  448. if (selectInfos != null)
  449. {
  450. if (selectInfos.ItemSumPrice == dto.ItemSumPrice)
  451. {
  452. status = selectInfos.Status;
  453. auditor = selectInfos.Auditor;
  454. auditTime = selectInfos.AuditTime;
  455. }
  456. }
  457. var info = new Fin_ForeignReceivables()
  458. {
  459. Diid = dto.DiId,
  460. Id = dto.Id,
  461. PriceName = dto.PriceName,
  462. Price = dto.Price,
  463. Count = dto.Count,
  464. Unit = dto.Unit,
  465. ItemSumPrice = dto.ItemSumPrice,
  466. Rate = dto.Rate,
  467. Currency = dto.Currency,
  468. AddingWay = dto.AddingWay,
  469. CreateUserId = dto.UserId,
  470. CreateTime = DateTime.Now,
  471. Remark = dto.Remark,
  472. Auditor = auditor,
  473. Status = status,
  474. AuditTime = auditTime,
  475. };
  476. if (dto.Id < 1) //添加
  477. {
  478. var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
  479. if (add > 0)
  480. {
  481. result.Code = 200;
  482. result.Msg = "操作成功";
  483. }
  484. else result.Msg = "操作失败";
  485. }
  486. else if (dto.Id > 1) //更新
  487. {
  488. var update = await _sqlSugar.Updateable(info).IgnoreColumns(it => new { it.CreateUserId, it.CreateTime }).ExecuteCommandAsync();
  489. if (update > 0)
  490. {
  491. result.Code = 200;
  492. result.Msg = "操作成功";
  493. }
  494. else result.Msg = "操作失败";
  495. }
  496. else result.Msg = MsgTips.Id;
  497. return result;
  498. }
  499. /// <summary>
  500. /// 财务模块
  501. /// 收款账单
  502. /// Audit
  503. /// </summary>
  504. /// <param name="diid"></param>
  505. /// <returns></returns>
  506. public async Task<JsonView> FeeAudit(FeeAuditDto dto)
  507. {
  508. JsonView result = new() { Code = 400 };
  509. //验证
  510. var info = await _sqlSugar.Queryable<Fin_ForeignReceivables>().FirstAsync(x => x.Id == dto.Id);
  511. if (info == null)
  512. {
  513. result.Msg = "数据不存在";
  514. return result;
  515. }
  516. if (info.AddingWay != 2)
  517. {
  518. result.Msg = "该条数据类型不是“实际报价”类型不可审核!";
  519. return result;
  520. }
  521. var AuditStatus = await _sqlSugar.Updateable<Fin_ForeignReceivables>()
  522. .SetColumns(a => new Fin_ForeignReceivables
  523. {
  524. Status = dto.Status,
  525. Auditor = dto.UserId,
  526. AuditTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  527. })
  528. .Where(a => a.Id == dto.Id)
  529. .ExecuteCommandAsync();
  530. if (AuditStatus > 0)
  531. {
  532. result.Msg = "操作成功!";
  533. result.Code = 200;
  534. }
  535. else result.Msg = "操作失败!";
  536. return result;
  537. }
  538. /// <summary>
  539. /// 财务模块
  540. /// 收款账单
  541. /// Del
  542. /// </summary>
  543. /// <param name="diid"></param>
  544. /// <returns></returns>
  545. public async Task<Result> PostReceivablesDel(ForeignReceivablesDelDto dto)
  546. {
  547. Result result = new() { Code = -2 };
  548. var delStatus = await _sqlSugar.Updateable<Fin_ForeignReceivables>()
  549. .SetColumns(a => new Fin_ForeignReceivables
  550. {
  551. IsDel = 1,
  552. DeleteUserId = dto.UserId,
  553. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  554. })
  555. .Where(a => a.Id == dto.Id)
  556. .ExecuteCommandAsync();
  557. if (delStatus > 0)
  558. {
  559. result.Msg = "操作成功!";
  560. result.Code = 0;
  561. }
  562. else
  563. {
  564. result.Msg = "操作成功!";
  565. }
  566. return result;
  567. }
  568. public void OverSpSeteceivables(OverSpSeteceivablesDto dto)
  569. {
  570. var querySaveReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>()
  571. .First(x => x.Diid == dto.DiId && x.AddingWay == 3 && x.IsDel == 0);
  572. //获取所有超支数据
  573. //整理超支数据
  574. //币种不同则计算rmb值
  575. var overspList = _sqlSugar.Queryable<Fin_GroupExtraCost, Grp_CreditCardPayment>
  576. ((e, c) => c.CTable == 1015 && c.CId == e.Id && c.IsDel == 0).
  577. Where((e, c) => e.IsDel == 0 && e.DiId == dto.DiId).
  578. Select((e, c) => new
  579. {
  580. e.Price,
  581. e.PriceCount,
  582. e.Coefficient,
  583. e.PriceSum,
  584. c.RMBPrice,
  585. c.DayRate,
  586. e.PriceCurrency,
  587. e.Remark,
  588. })
  589. .ToList().
  590. Where(x =>
  591. {
  592. var count = 0;
  593. var stringArr = new string[] { "SYsupervisorConfirm" , "SupervisorConfirm" , "ManagerConfirm" };
  594. foreach (var item in stringArr)
  595. {
  596. var number = x.GetType()?.GetProperty(item)?.GetValue(x).ObjToInt();
  597. if (number > 0)
  598. {
  599. count++;
  600. }
  601. }
  602. return count > 1;
  603. }).ToList();
  604. var overspListGroup = overspList.GroupBy(x => x.PriceCurrency).ToList();
  605. string foreignReceivablesRemake = string.Empty;
  606. int count = 1;
  607. overspList.ForEach(x =>
  608. {
  609. foreignReceivablesRemake += $"{count}.{x.Remark}";
  610. count++;
  611. });
  612. if (querySaveReceivables != null)
  613. {
  614. if (overspList.Count() > 0)
  615. {
  616. if (overspListGroup.Count() > 1)
  617. {
  618. querySaveReceivables.Currency = 836; //人民币
  619. querySaveReceivables.Rate = 1;
  620. querySaveReceivables.Price = overspListGroup.Sum(x => x.Sum(y => y.PriceSum * y.Coefficient * y.DayRate));
  621. querySaveReceivables.ItemSumPrice = overspListGroup.Sum(x => x.Sum(y => y.PriceSum * y.Coefficient * y.DayRate));
  622. querySaveReceivables.Remark = foreignReceivablesRemake;
  623. querySaveReceivables.CreateTime = DateTime.Now;
  624. }
  625. else
  626. {
  627. querySaveReceivables.Currency = overspList[0].PriceCurrency;
  628. querySaveReceivables.Rate = overspList[0].DayRate;
  629. querySaveReceivables.Price = overspListGroup[0].Sum(x => x.PriceSum * x.Coefficient);
  630. querySaveReceivables.ItemSumPrice = overspListGroup[0].Sum(x => x.PriceSum * x.Coefficient);
  631. querySaveReceivables.Remark = foreignReceivablesRemake;
  632. querySaveReceivables.AddingWay = 3;
  633. querySaveReceivables.CreateTime = DateTime.Now;
  634. }
  635. }
  636. else
  637. {
  638. querySaveReceivables.Currency = 836; //人民币
  639. querySaveReceivables.Rate = 1;
  640. querySaveReceivables.Price = 0;
  641. querySaveReceivables.ItemSumPrice = 0;
  642. querySaveReceivables.Remark = "";
  643. querySaveReceivables.CreateTime = DateTime.Now;
  644. querySaveReceivables.Count = 1;
  645. }
  646. _sqlSugar.Updateable(querySaveReceivables).ExecuteCommand();
  647. }
  648. else
  649. {
  650. if (overspList.Count() > 0)
  651. {
  652. if (overspListGroup.Count() > 1)
  653. {
  654. querySaveReceivables = new Fin_ForeignReceivables
  655. {
  656. CreateTime = DateTime.Now,
  657. CreateUserId = dto.CreateUserId,
  658. Diid = dto.DiId,
  659. PriceName = "超支费用",
  660. AddingWay = 3,
  661. Count = 1,
  662. Currency = 836,
  663. ItemSumPrice = overspList.Sum(x => x.PriceSum * x.Coefficient * x.DayRate),
  664. Price = overspList.Sum(x => x.PriceSum * x.Coefficient * x.DayRate),
  665. Rate = 1,
  666. IsDel = 0,
  667. Remark = foreignReceivablesRemake,
  668. Unit = "团",
  669. };
  670. }
  671. else
  672. {
  673. querySaveReceivables = new Fin_ForeignReceivables
  674. {
  675. CreateTime = DateTime.Now,
  676. CreateUserId = dto.CreateUserId,
  677. Diid = dto.DiId,
  678. PriceName = "超支费用",
  679. AddingWay = 3,
  680. Count = 1,
  681. Currency = overspList[0].PriceCurrency,
  682. ItemSumPrice = overspList.Sum(x => x.PriceSum * x.Coefficient),
  683. Price = overspList.Sum(x => x.PriceSum * x.Coefficient),
  684. Rate = overspList[0].DayRate,
  685. IsDel = 0,
  686. Remark = foreignReceivablesRemake,
  687. Unit = "团",
  688. };
  689. }
  690. }
  691. _sqlSugar.Insertable(querySaveReceivables).ExecuteCommand();
  692. }
  693. }
  694. #endregion
  695. }
  696. }