FinancialController.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using OASystem.API.OAMethodLib;
  4. using OASystem.API.OAMethodLib.File;
  5. using OASystem.Domain;
  6. using OASystem.Domain.Dtos.Financial;
  7. using OASystem.Domain.Entities.Groups;
  8. using OASystem.Domain.ViewModels.Financial;
  9. using OASystem.Domain.ViewModels.Groups;
  10. using OASystem.Infrastructure.Repositories.Financial;
  11. using OASystem.Infrastructure.Repositories.Groups;
  12. using System.Data;
  13. namespace OASystem.API.Controllers
  14. {
  15. /// <summary>
  16. /// 财务模块
  17. /// </summary>
  18. [Route("api/[controller]/[action]")]
  19. [ApiController]
  20. public class FinancialController : ControllerBase
  21. {
  22. private readonly IMapper _mapper;
  23. private readonly IConfiguration _config;
  24. private readonly SqlSugarClient _sqlSugar;
  25. private readonly SetDataTypeRepository _setDataTypeRep;
  26. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  27. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  28. private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
  29. private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
  30. /// <summary>
  31. /// 初始化
  32. /// </summary>
  33. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep, TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep)
  34. {
  35. _mapper = mapper;
  36. _config = configuration;
  37. _daiRep = daiRep;
  38. _sqlSugar = sqlSugar;
  39. _setDataTypeRep = setDataTypeRep;
  40. _teamRateRep = teamRateRep;
  41. _ForForeignReceivablesRep = ForForeignReceivablesRep;
  42. _proceedsReceivedRep = proceedsReceivedRep;
  43. }
  44. #region 日付申请
  45. /// <summary>
  46. /// 获取日付申请 基础数据源
  47. /// </summary>
  48. /// <param name="dto"> 日付申请 分页 dto</param>
  49. /// <returns></returns>
  50. [HttpPost]
  51. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  52. public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
  53. {
  54. var result = await _daiRep.GetPagePriceTypeData(dto);
  55. if (result == null || result.Code != 0)
  56. {
  57. return Ok(JsonView(false, result.Msg));
  58. }
  59. var data = result.Data;
  60. return Ok(JsonView(data));
  61. }
  62. /// <summary>
  63. /// 获取日付申请 基础数据源 - 转账表识
  64. /// </summary>
  65. /// <param name="dto"> 日付申请 分页 dto</param>
  66. /// <returns></returns>
  67. [HttpPost]
  68. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  69. public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
  70. {
  71. var result = await _daiRep.GetPriceTypeAddData(dto);
  72. if (result == null || result.Code != 0)
  73. {
  74. return Ok(JsonView(false, result.Msg));
  75. }
  76. var data = result.Data;
  77. return Ok(JsonView(data));
  78. }
  79. /// <summary>
  80. /// 日付申请 Page Search
  81. /// </summary>
  82. /// <param name="dto"> 日付申请 分页 dto</param>
  83. /// <returns></returns>
  84. [HttpPost]
  85. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  86. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  87. {
  88. var result = await _daiRep.GetPageSearchAll(dto);
  89. if (result == null || result.Code != 0)
  90. {
  91. return Ok(JsonView(false, result.Msg));
  92. }
  93. var data = result.Data;
  94. if (data == null)
  95. {
  96. return Ok(JsonView(false, result.Msg));
  97. }
  98. return Ok(JsonView(data));
  99. }
  100. /// <summary>
  101. /// 日付申请 Single Search By Id
  102. /// </summary>
  103. /// <param name="dto"></param>
  104. /// <returns></returns>
  105. [HttpPost]
  106. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  107. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  108. {
  109. var result = await _daiRep.GetSearchById(dto);
  110. if (result == null || result.Code != 0)
  111. {
  112. return Ok(JsonView(false, result.Msg));
  113. }
  114. return Ok(JsonView(result.Data));
  115. }
  116. /// <summary>
  117. /// 日付申请 添加
  118. /// </summary>
  119. /// <param name="dto"> 日付申请 添加 dto</param>
  120. /// <returns></returns>
  121. [HttpPost]
  122. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  123. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  124. {
  125. var result = await _daiRep.Add(dto);
  126. if (result == null || result.Code != 0)
  127. {
  128. return Ok(JsonView(false, result.Msg));
  129. }
  130. return Ok(JsonView(true));
  131. }
  132. /// <summary>
  133. /// 日付申请 Update
  134. /// </summary>
  135. /// <param name="dto"> 日付申请 修改 dto</param>
  136. /// <returns></returns>
  137. [HttpPost]
  138. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  139. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  140. {
  141. var result = await _daiRep.Edit(dto);
  142. if (result == null || result.Code != 0)
  143. {
  144. return Ok(JsonView(false, result.Msg));
  145. }
  146. return Ok(JsonView(true));
  147. }
  148. /// <summary>
  149. /// 日付申请 Del
  150. /// </summary>
  151. /// <param name="dto"> 日付申请 删除 dto</param>
  152. /// <returns></returns>
  153. [HttpPost]
  154. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  155. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  156. {
  157. var result = await _daiRep.Del(dto);
  158. if (result == null || result.Code != 0)
  159. {
  160. return Ok(JsonView(false, result.Msg));
  161. }
  162. return Ok(JsonView(true));
  163. }
  164. /// <summary>
  165. /// 日付申请 财务审核
  166. /// </summary>
  167. /// <param name="dto"> dto </param>
  168. /// <returns></returns>
  169. [HttpPost]
  170. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  171. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  172. {
  173. var result = await _daiRep.DelDailyPaymentAudit(dto);
  174. if (result == null || result.Code != 0)
  175. {
  176. return Ok(JsonView(false, result.Msg));
  177. }
  178. return Ok(JsonView(true));
  179. }
  180. /// <summary>
  181. /// 日付申请 Single Excel Download
  182. /// </summary>
  183. /// <param name="dto"> dto </param>
  184. /// <returns></returns>
  185. [HttpPost]
  186. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  187. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  188. {
  189. if (dto.PortType == 1 || dto.PortType == 2)
  190. {
  191. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  192. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  193. Where IsDel=0 And Id = {0} ", dto.Id);
  194. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  195. if (feeData == null)
  196. {
  197. return Ok(JsonView(false, "暂无数据!"));
  198. }
  199. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  200. Where IsDel=0 And DFPId = {0} ", dto.Id);
  201. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  202. if (feeData != null)
  203. {
  204. string userName = string.Empty;
  205. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  206. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  207. if (user != null) { userName = user.CnName; }
  208. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  209. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  210. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  211. Dictionary<string, object> pairs = new Dictionary<string, object>();
  212. List<DataTable> datas = new List<DataTable>();
  213. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  214. //{
  215. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  216. // // pairs, datas);
  217. //}
  218. //else //日付常规模板
  219. //{
  220. pairs.Clear();
  221. pairs.Add("Opertor", userName);
  222. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  223. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  224. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  225. pairs.Add("SumPrice", feeData.SumPrice);
  226. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  227. datas.Clear();
  228. datas.Add(data);
  229. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  230. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  231. return Ok(JsonView(true, msg));
  232. //}
  233. }
  234. else
  235. {
  236. return Ok(JsonView(false, "暂无数据!"));
  237. }
  238. }
  239. return Ok(JsonView(true));
  240. }
  241. #endregion
  242. #region 团组提成
  243. /// <summary>
  244. /// 提成 Page Search
  245. /// </summary>
  246. /// <param name="dto"> 提成 分页 dto</param>
  247. /// <returns></returns>
  248. [HttpPost]
  249. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  250. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  251. {
  252. var data = await GroupCommission.GetCommissionPageList(dto);
  253. return Ok(JsonView(data.Data));
  254. }
  255. #endregion
  256. #region 团组汇率
  257. /// <summary>
  258. /// 团组汇率 Select数据源(团组列,汇率列)
  259. /// </summary>
  260. /// <param name="dto"></param>
  261. /// <returns></returns>
  262. [HttpPost]
  263. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  264. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  265. {
  266. try
  267. {
  268. Result teamRateData = await _teamRateRep.GetGroupRateDataSource(dto);
  269. if (teamRateData.Code != 0)
  270. {
  271. return Ok(JsonView(false, teamRateData.Msg));
  272. }
  273. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  274. }
  275. catch (Exception ex)
  276. {
  277. return Ok(JsonView(false, ex.Message));
  278. throw;
  279. }
  280. }
  281. ///// <summary>
  282. ///// 团组汇率 changge
  283. ///// </summary>
  284. ///// <returns></returns>
  285. //[HttpPost]
  286. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  287. //public async Task<IActionResult> ChangeGroupRateInfo()
  288. //{
  289. // try
  290. // {
  291. // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  292. // if (teamRateData.Code != 0)
  293. // {
  294. // return Ok(JsonView(false, teamRateData.Msg));
  295. // }
  296. // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  297. // }
  298. // catch (Exception ex)
  299. // {
  300. // return Ok(JsonView(false, ex.Message));
  301. // throw;
  302. // }
  303. //}
  304. /// <summary>
  305. /// 团组汇率 Select汇率详情
  306. /// </summary>
  307. /// <param name="dto"></param>
  308. /// <returns></returns>
  309. [HttpPost]
  310. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  311. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  312. {
  313. try
  314. {
  315. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  316. if (teamRateData.Code != 0)
  317. {
  318. return Ok(JsonView(false, teamRateData.Msg));
  319. }
  320. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  321. }
  322. catch (Exception ex)
  323. {
  324. return Ok(JsonView(false, ex.Message));
  325. throw;
  326. }
  327. }
  328. /// <summary>
  329. /// 团组汇率 添加 or 更新
  330. /// </summary>
  331. /// <param name="dto"></param>
  332. /// <returns></returns>
  333. [HttpPost]
  334. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  335. public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
  336. {
  337. try
  338. {
  339. Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
  340. if (teamRateData.Code != 0)
  341. {
  342. return Ok(JsonView(false, teamRateData.Msg));
  343. }
  344. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  345. }
  346. catch (Exception ex)
  347. {
  348. return Ok(JsonView(false, ex.Message));
  349. throw;
  350. }
  351. }
  352. #endregion
  353. #region 对外收款账单
  354. /// <summary>
  355. /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
  356. /// </summary>
  357. /// <param name="dto"></param>
  358. /// <returns></returns>
  359. [HttpPost]
  360. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  361. public async Task<IActionResult> GetForeignReceivablesDataSources()
  362. {
  363. try
  364. {
  365. Result ffrData = await _ForForeignReceivablesRep.GetDataSource();
  366. if (ffrData.Code != 0)
  367. {
  368. return Ok(JsonView(false, ffrData.Msg));
  369. }
  370. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  371. }
  372. catch (Exception ex)
  373. {
  374. return Ok(JsonView(false, ex.Message));
  375. throw;
  376. }
  377. }
  378. /// <summary>
  379. /// 对外收款账单
  380. /// 账单详情
  381. /// </summary>
  382. /// <param name="dto"></param>
  383. /// <returns></returns>
  384. [HttpPost]
  385. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  386. public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  387. {
  388. try
  389. {
  390. Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
  391. if (ffrData.Code != 0)
  392. {
  393. return Ok(JsonView(false, ffrData.Msg));
  394. }
  395. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  396. }
  397. catch (Exception ex)
  398. {
  399. return Ok(JsonView(false, ex.Message));
  400. throw;
  401. }
  402. }
  403. /// <summary>
  404. /// 对外收款账单
  405. /// 账单 删除
  406. /// </summary>
  407. /// <param name="dto"></param>
  408. /// <returns></returns>
  409. [HttpPost]
  410. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  411. public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
  412. {
  413. try
  414. {
  415. Result ffrData = await _ForForeignReceivablesRep._Del(dto);
  416. if (ffrData.Code != 0)
  417. {
  418. return Ok(JsonView(false, ffrData.Msg));
  419. }
  420. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  421. }
  422. catch (Exception ex)
  423. {
  424. return Ok(JsonView(false, ex.Message));
  425. throw;
  426. }
  427. }
  428. /// <summary>
  429. /// 对外收款账单
  430. /// 添加 And 更新
  431. /// </summary>
  432. /// <param name="dto"></param>
  433. /// <returns></returns>
  434. [HttpPost]
  435. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  436. public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  437. {
  438. try
  439. {
  440. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
  441. if (ffrData.Code != 0)
  442. {
  443. return Ok(JsonView(false, ffrData.Msg));
  444. }
  445. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  446. }
  447. catch (Exception ex)
  448. {
  449. return Ok(JsonView(false, ex.Message));
  450. throw;
  451. }
  452. }
  453. /// <summary>
  454. /// 已收款项
  455. /// 账单 删除
  456. /// </summary>
  457. /// <param name="dto"></param>
  458. /// <returns></returns>
  459. [HttpPost]
  460. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  461. public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
  462. {
  463. try
  464. {
  465. Result ffrData = await _proceedsReceivedRep._Del(dto);
  466. if (ffrData.Code != 0)
  467. {
  468. return Ok(JsonView(false, ffrData.Msg));
  469. }
  470. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  471. }
  472. catch (Exception ex)
  473. {
  474. return Ok(JsonView(false, ex.Message));
  475. throw;
  476. }
  477. }
  478. /// <summary>
  479. /// 已收款项
  480. /// 添加 And 更新
  481. /// </summary>
  482. /// <param name="dto"></param>
  483. /// <returns></returns>
  484. [HttpPost]
  485. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  486. public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
  487. {
  488. try
  489. {
  490. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
  491. if (ffrData.Code != 0)
  492. {
  493. return Ok(JsonView(false, ffrData.Msg));
  494. }
  495. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  496. }
  497. catch (Exception ex)
  498. {
  499. return Ok(JsonView(false, ex.Message));
  500. throw;
  501. }
  502. }
  503. /// <summary>
  504. /// 财务 已收款项
  505. /// 分配已收款项至 应收项下
  506. /// </summary>
  507. /// <param name="dto"></param>
  508. /// <returns></returns>
  509. [HttpPost]
  510. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  511. public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
  512. {
  513. try
  514. {
  515. Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
  516. if (ffrData.Code != 0)
  517. {
  518. return Ok(JsonView(false, ffrData.Msg));
  519. }
  520. return Ok(JsonView(true));
  521. }
  522. catch (Exception ex)
  523. {
  524. return Ok(JsonView(false, ex.Message));
  525. throw;
  526. }
  527. }
  528. #endregion
  529. }
  530. }