ForeignReceivablesRepository.cs 32 KB

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