ForeignReceivablesRepository.cs 32 KB

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