FinancialController.cs 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828
  1. using Aspose.Cells;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using OASystem.API.OAMethodLib;
  5. using OASystem.API.OAMethodLib.File;
  6. using OASystem.Domain;
  7. using OASystem.Domain.Dtos.Financial;
  8. using OASystem.Domain.Dtos.Groups;
  9. using OASystem.Domain.Entities.Financial;
  10. using OASystem.Domain.Entities.Groups;
  11. using OASystem.Domain.ViewModels.Financial;
  12. using OASystem.Domain.ViewModels.Groups;
  13. using OASystem.Domain.ViewModels.SmallFun;
  14. using OASystem.Infrastructure.Repositories.Financial;
  15. using OASystem.Infrastructure.Repositories.Groups;
  16. using SqlSugar;
  17. using StackExchange.Redis;
  18. using System.Data;
  19. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  20. using System.Web;
  21. using Aspose.Words;
  22. using NPOI.HSSF.Util;
  23. using OASystem.Domain.Entities.Customer;
  24. using System.IO.Compression;
  25. using NPOI.SS.UserModel;
  26. using System.Net.Http;
  27. namespace OASystem.API.Controllers
  28. {
  29. /// <summary>
  30. /// 财务模块
  31. /// </summary>
  32. [Route("api/[controller]/[action]")]
  33. [ApiController]
  34. public class FinancialController : ControllerBase
  35. {
  36. private readonly IMapper _mapper;
  37. private readonly IConfiguration _config;
  38. private readonly SqlSugarClient _sqlSugar;
  39. private readonly HttpClient _httpClient;
  40. private readonly SetDataTypeRepository _setDataTypeRep;
  41. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  42. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  43. private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
  44. private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
  45. private readonly PaymentRefundAndOtherMoneyRepository _paymentRefundAndOtherMoneyRep; //收款退还与其他款项 仓库
  46. /// <summary>
  47. /// 初始化
  48. /// </summary>
  49. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
  50. TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
  51. PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient)
  52. {
  53. _mapper = mapper;
  54. _config = configuration;
  55. _daiRep = daiRep;
  56. _sqlSugar = sqlSugar;
  57. _setDataTypeRep = setDataTypeRep;
  58. _teamRateRep = teamRateRep;
  59. _ForForeignReceivablesRep = ForForeignReceivablesRep;
  60. _proceedsReceivedRep = proceedsReceivedRep;
  61. _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
  62. _httpClient = httpClient;
  63. }
  64. #region 日付申请
  65. /// <summary>
  66. /// 获取日付申请 基础数据源
  67. /// </summary>
  68. /// <param name="dto"> 日付申请 分页 dto</param>
  69. /// <returns></returns>
  70. [HttpPost]
  71. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  72. public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
  73. {
  74. var result = await _daiRep.GetPagePriceTypeData(dto);
  75. if (result == null || result.Code != 0)
  76. {
  77. return Ok(JsonView(false, result.Msg));
  78. }
  79. var data = result.Data;
  80. return Ok(JsonView(data));
  81. }
  82. /// <summary>
  83. /// 获取日付申请 基础数据源 - 转账表识
  84. /// </summary>
  85. /// <param name="dto"> 日付申请 分页 dto</param>
  86. /// <returns></returns>
  87. [HttpPost]
  88. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  89. public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
  90. {
  91. var result = await _daiRep.GetPriceTypeAddData(dto);
  92. if (result == null || result.Code != 0)
  93. {
  94. return Ok(JsonView(false, result.Msg));
  95. }
  96. var data = result.Data;
  97. return Ok(JsonView(data));
  98. }
  99. /// <summary>
  100. /// 日付申请 Page Search
  101. /// </summary>
  102. /// <param name="dto"> 日付申请 分页 dto</param>
  103. /// <returns></returns>
  104. [HttpPost]
  105. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  106. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  107. {
  108. var result = await _daiRep.GetPageSearchAll(dto);
  109. if (result == null || result.Code != 0)
  110. {
  111. return Ok(JsonView(false, result.Msg));
  112. }
  113. var data = result.Data;
  114. if (data == null)
  115. {
  116. return Ok(JsonView(false, result.Msg));
  117. }
  118. return Ok(JsonView(data));
  119. }
  120. /// <summary>
  121. /// 日付申请 Single Search By Id
  122. /// </summary>
  123. /// <param name="dto"></param>
  124. /// <returns></returns>
  125. [HttpPost]
  126. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  127. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  128. {
  129. var result = await _daiRep.GetSearchById(dto);
  130. if (result == null || result.Code != 0)
  131. {
  132. return Ok(JsonView(false, result.Msg));
  133. }
  134. return Ok(JsonView(result.Data));
  135. }
  136. /// <summary>
  137. /// 日付申请 添加
  138. /// </summary>
  139. /// <param name="dto"> 日付申请 添加 dto</param>
  140. /// <returns></returns>
  141. [HttpPost]
  142. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  143. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  144. {
  145. var result = await _daiRep.Add(dto);
  146. if (result == null || result.Code != 0)
  147. {
  148. return Ok(JsonView(false, result.Msg));
  149. }
  150. return Ok(JsonView(true));
  151. }
  152. /// <summary>
  153. /// 日付申请 Update
  154. /// </summary>
  155. /// <param name="dto"> 日付申请 修改 dto</param>
  156. /// <returns></returns>
  157. [HttpPost]
  158. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  159. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  160. {
  161. var result = await _daiRep.Edit(dto);
  162. if (result == null || result.Code != 0)
  163. {
  164. return Ok(JsonView(false, result.Msg));
  165. }
  166. return Ok(JsonView(true));
  167. }
  168. /// <summary>
  169. /// 日付申请 Del
  170. /// </summary>
  171. /// <param name="dto"> 日付申请 删除 dto</param>
  172. /// <returns></returns>
  173. [HttpPost]
  174. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  175. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  176. {
  177. var result = await _daiRep.Del(dto);
  178. if (result == null || result.Code != 0)
  179. {
  180. return Ok(JsonView(false, result.Msg));
  181. }
  182. return Ok(JsonView(true));
  183. }
  184. /// <summary>
  185. /// 日付申请 财务审核
  186. /// </summary>
  187. /// <param name="dto"> dto </param>
  188. /// <returns></returns>
  189. [HttpPost]
  190. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  191. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  192. {
  193. var result = await _daiRep.DelDailyPaymentAudit(dto);
  194. if (result == null || result.Code != 0)
  195. {
  196. return Ok(JsonView(false, result.Msg));
  197. }
  198. return Ok(JsonView(true));
  199. }
  200. /// <summary>
  201. /// 日付申请 Single Excel Download
  202. /// </summary>
  203. /// <param name="dto"> dto </param>
  204. /// <returns></returns>
  205. [HttpPost]
  206. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  207. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  208. {
  209. if (dto.PortType == 1 || dto.PortType == 2)
  210. {
  211. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  212. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  213. Where IsDel=0 And Id = {0} ", dto.Id);
  214. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  215. if (feeData == null)
  216. {
  217. return Ok(JsonView(false, "暂无数据!"));
  218. }
  219. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  220. Where IsDel=0 And DFPId = {0} ", dto.Id);
  221. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  222. if (feeData != null)
  223. {
  224. string userName = string.Empty;
  225. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  226. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  227. if (user != null) { userName = user.CnName; }
  228. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  229. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  230. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  231. Dictionary<string, object> pairs = new Dictionary<string, object>();
  232. List<DataTable> datas = new List<DataTable>();
  233. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  234. //{
  235. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  236. // // pairs, datas);
  237. //}
  238. //else //日付常规模板
  239. //{
  240. pairs.Clear();
  241. pairs.Add("Opertor", userName);
  242. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  243. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  244. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  245. pairs.Add("SumPrice", feeData.SumPrice);
  246. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  247. datas.Clear();
  248. datas.Add(data);
  249. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  250. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  251. return Ok(JsonView(true, msg));
  252. //}
  253. }
  254. else
  255. {
  256. return Ok(JsonView(false, "暂无数据!"));
  257. }
  258. }
  259. return Ok(JsonView(true));
  260. }
  261. #endregion
  262. #region 团组提成
  263. /// <summary>
  264. /// 提成 Page Search
  265. /// </summary>
  266. /// <param name="dto"> 提成 分页 dto</param>
  267. /// <returns></returns>
  268. [HttpPost]
  269. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  270. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  271. {
  272. var data = await GroupCommission.GetCommissionPageList(dto);
  273. return Ok(JsonView(data.Data));
  274. }
  275. #endregion
  276. #region 团组汇率
  277. /// <summary>
  278. /// 团组汇率 Select数据源(团组列,汇率列)
  279. /// </summary>
  280. /// <param name="dto"></param>
  281. /// <returns></returns>
  282. [HttpPost]
  283. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  284. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  285. {
  286. try
  287. {
  288. Result teamRateData = await _teamRateRep.GetGroupRateDataSource(dto);
  289. if (teamRateData.Code != 0)
  290. {
  291. return Ok(JsonView(false, teamRateData.Msg));
  292. }
  293. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  294. }
  295. catch (Exception ex)
  296. {
  297. return Ok(JsonView(false, ex.Message));
  298. throw;
  299. }
  300. }
  301. ///// <summary>
  302. ///// 团组汇率 changge
  303. ///// </summary>
  304. ///// <returns></returns>
  305. //[HttpPost]
  306. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  307. //public async Task<IActionResult> ChangeGroupRateInfo()
  308. //{
  309. // try
  310. // {
  311. // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  312. // if (teamRateData.Code != 0)
  313. // {
  314. // return Ok(JsonView(false, teamRateData.Msg));
  315. // }
  316. // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  317. // }
  318. // catch (Exception ex)
  319. // {
  320. // return Ok(JsonView(false, ex.Message));
  321. // throw;
  322. // }
  323. //}
  324. /// <summary>
  325. /// 团组汇率 Select汇率详情
  326. /// </summary>
  327. /// <param name="dto"></param>
  328. /// <returns></returns>
  329. [HttpPost]
  330. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  331. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  332. {
  333. try
  334. {
  335. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  336. if (teamRateData.Code != 0)
  337. {
  338. return Ok(JsonView(false, teamRateData.Msg));
  339. }
  340. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  341. }
  342. catch (Exception ex)
  343. {
  344. return Ok(JsonView(false, ex.Message));
  345. throw;
  346. }
  347. }
  348. /// <summary>
  349. /// 团组汇率 添加 or 更新
  350. /// </summary>
  351. /// <param name="dto"></param>
  352. /// <returns></returns>
  353. [HttpPost]
  354. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  355. public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
  356. {
  357. try
  358. {
  359. Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
  360. if (teamRateData.Code != 0)
  361. {
  362. return Ok(JsonView(false, teamRateData.Msg));
  363. }
  364. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  365. }
  366. catch (Exception ex)
  367. {
  368. return Ok(JsonView(false, ex.Message));
  369. throw;
  370. }
  371. }
  372. #endregion
  373. #region 对外收款账单 关联已收款项
  374. /// <summary>
  375. /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
  376. /// 关联已收款项
  377. /// </summary>
  378. /// <param name="dto"></param>
  379. /// <returns></returns>
  380. [HttpPost]
  381. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  382. public async Task<IActionResult> GetForeignReceivablesDataSources()
  383. {
  384. try
  385. {
  386. Result ffrData = await _ForForeignReceivablesRep.GetDataSource();
  387. if (ffrData.Code != 0)
  388. {
  389. return Ok(JsonView(false, ffrData.Msg));
  390. }
  391. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  392. }
  393. catch (Exception ex)
  394. {
  395. return Ok(JsonView(false, ex.Message));
  396. throw;
  397. }
  398. }
  399. /// <summary>
  400. /// 对外收款账单
  401. /// 账单详情
  402. /// 关联已收款项
  403. /// </summary>
  404. /// <param name="dto"></param>
  405. /// <returns></returns>
  406. [HttpPost]
  407. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  408. public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  409. {
  410. try
  411. {
  412. Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
  413. if (ffrData.Code != 0)
  414. {
  415. return Ok(JsonView(false, ffrData.Msg));
  416. }
  417. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  418. }
  419. catch (Exception ex)
  420. {
  421. return Ok(JsonView(false, ex.Message));
  422. throw;
  423. }
  424. }
  425. /// <summary>
  426. /// 对外收款账单
  427. /// 账单 删除
  428. /// 关联已收款项
  429. /// </summary>
  430. /// <param name="dto"></param>
  431. /// <returns></returns>
  432. [HttpPost]
  433. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  434. public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
  435. {
  436. try
  437. {
  438. Result ffrData = await _ForForeignReceivablesRep._Del(dto);
  439. if (ffrData.Code != 0)
  440. {
  441. return Ok(JsonView(false, ffrData.Msg));
  442. }
  443. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  444. }
  445. catch (Exception ex)
  446. {
  447. return Ok(JsonView(false, ex.Message));
  448. throw;
  449. }
  450. }
  451. /// <summary>
  452. /// 对外收款账单
  453. /// 添加 And 更新
  454. /// 关联已收款项
  455. /// </summary>
  456. /// <param name="dto"></param>
  457. /// <returns></returns>
  458. [HttpPost]
  459. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  460. public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  461. {
  462. try
  463. {
  464. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
  465. if (ffrData.Code != 0)
  466. {
  467. return Ok(JsonView(false, ffrData.Msg));
  468. }
  469. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  470. }
  471. catch (Exception ex)
  472. {
  473. return Ok(JsonView(false, ex.Message));
  474. throw;
  475. }
  476. }
  477. /// <summary>
  478. /// 已收款项
  479. /// 账单 删除
  480. /// 关联已收款项
  481. /// </summary>
  482. /// <param name="dto"></param>
  483. /// <returns></returns>
  484. [HttpPost]
  485. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  486. public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
  487. {
  488. try
  489. {
  490. Result ffrData = await _proceedsReceivedRep._Del(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. /// 添加 And 更新
  506. /// 关联已收款项
  507. /// </summary>
  508. /// <param name="dto"></param>
  509. /// <returns></returns>
  510. [HttpPost]
  511. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  512. public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
  513. {
  514. try
  515. {
  516. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
  517. if (ffrData.Code != 0)
  518. {
  519. return Ok(JsonView(false, ffrData.Msg));
  520. }
  521. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  522. }
  523. catch (Exception ex)
  524. {
  525. return Ok(JsonView(false, ex.Message));
  526. throw;
  527. }
  528. }
  529. /// <summary>
  530. /// 财务 已收款项
  531. /// 分配已收款项至 应收项下
  532. /// 关联已收款项
  533. /// </summary>
  534. /// <param name="dto"></param>
  535. /// <returns></returns>
  536. [HttpPost]
  537. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  538. public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
  539. {
  540. try
  541. {
  542. Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
  543. if (ffrData.Code != 0)
  544. {
  545. return Ok(JsonView(false, ffrData.Msg));
  546. }
  547. return Ok(JsonView(true));
  548. }
  549. catch (Exception ex)
  550. {
  551. return Ok(JsonView(false, ex.Message));
  552. throw;
  553. }
  554. }
  555. ///// <summary>
  556. ///// 财务 收款账单
  557. ///// 导出Word(北京,四川)
  558. ///// </summary>
  559. ///// <param name="dto"></param>
  560. ///// <returns></returns>
  561. //[HttpPost]
  562. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  563. //public async Task<IActionResult> PostAccountReceivableWordExport(AccountReceivableWordExportDto dto)
  564. //{
  565. // try
  566. // {
  567. // //模板处理
  568. // string typeName = string.Empty;
  569. // if (dto.TemplateType == 1) //四川
  570. // {
  571. // typeName = "四川";
  572. // }
  573. // else if (dto.TemplateType == 2) //北京
  574. // {
  575. // typeName = "北京";
  576. // }
  577. // else return Ok(JsonView(false,"请选择正确的模板类型!"));
  578. // string wordTempName = string.Format("收款账单({0})模板.doc", typeName);
  579. // }
  580. // catch (Exception ex)
  581. // {
  582. // return Ok(JsonView(false, ex.Message));
  583. // }
  584. //}
  585. #endregion
  586. #region 对外收款账单
  587. /// <summary>
  588. /// 对外收款账单
  589. /// 数据源
  590. /// </summary>
  591. /// <param name="dto"></param>
  592. /// <returns></returns>
  593. [HttpPost]
  594. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  595. public async Task<IActionResult> PostGroupReceivablesDataSource()
  596. {
  597. try
  598. {
  599. Result ffrData = await _ForForeignReceivablesRep.PostDataSource();
  600. if (ffrData.Code != 0)
  601. {
  602. return Ok(JsonView(false, ffrData.Msg));
  603. }
  604. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  605. }
  606. catch (Exception ex)
  607. {
  608. return Ok(JsonView(false, ex.Message));
  609. }
  610. }
  611. /// <summary>
  612. /// 对外收款账单
  613. /// 账单详情
  614. /// </summary>
  615. /// <param name="dto"></param>
  616. /// <returns></returns>
  617. [HttpPost]
  618. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  619. public async Task<IActionResult> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  620. {
  621. try
  622. {
  623. Result ffrData = await _ForForeignReceivablesRep.PostGroupReceivablesInfoByDiId(dto);
  624. if (ffrData.Code != 0)
  625. {
  626. return Ok(JsonView(false, ffrData.Msg));
  627. }
  628. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  629. }
  630. catch (Exception ex)
  631. {
  632. return Ok(JsonView(false, ex.Message));
  633. }
  634. }
  635. /// <summary>
  636. /// 对外收款账单
  637. /// 添加 And 更新
  638. /// </summary>
  639. /// <param name="dto"></param>
  640. /// <returns></returns>
  641. [HttpPost]
  642. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  643. public async Task<IActionResult> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  644. {
  645. try
  646. {
  647. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesSave(dto);
  648. if (ffrData.Code != 0)
  649. {
  650. return Ok(JsonView(false, ffrData.Msg));
  651. }
  652. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  653. }
  654. catch (Exception ex)
  655. {
  656. return Ok(JsonView(false, ex.Message));
  657. throw;
  658. }
  659. }
  660. /// <summary>
  661. /// 已收账单
  662. /// 删除
  663. /// </summary>
  664. /// <param name="dto"></param>
  665. /// <returns></returns>
  666. [HttpPost]
  667. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  668. public async Task<IActionResult> PostReceivablesDel(ForeignReceivablesDelDto dto)
  669. {
  670. try
  671. {
  672. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesDel(dto);
  673. if (ffrData.Code != 0)
  674. {
  675. return Ok(JsonView(false, ffrData.Msg));
  676. }
  677. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  678. }
  679. catch (Exception ex)
  680. {
  681. return Ok(JsonView(false, ex.Message));
  682. throw;
  683. }
  684. }
  685. /// <summary>
  686. /// 已收账单
  687. /// File Downloasd
  688. /// </summary>
  689. /// <param name="dto"></param>
  690. /// <returns></returns>
  691. [HttpPost]
  692. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  693. public async Task<IActionResult> PostReceivablesFeilDownload(ForeignReceivablesFeilDownloadDto dto)
  694. {
  695. try
  696. {
  697. if (dto.DiId < 1)
  698. {
  699. return Ok(JsonView(false, "请传入有效DiId参数!"));
  700. }
  701. if (dto.FileType < 1 || dto.FileType > 3)
  702. {
  703. return Ok(JsonView(false, "请传入有效FileType参数! 1 生成收款单(四川) 2 生成收款单(北京) 3 汇款账单"));
  704. }
  705. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  706. if (_DelegationInfo == null)
  707. {
  708. return Ok(JsonView(false, "暂无团组信息!!"));
  709. }
  710. if (dto.FileType == 1 || dto.FileType == 2)
  711. {
  712. var _ForeignReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  713. if (_ForeignReceivables.Count < 1)
  714. {
  715. return Ok(JsonView(false, "暂无收款信息!!"));
  716. }
  717. string tempName = "";
  718. if (dto.FileType == 1) tempName = $"收款账单(四川)模板.docx";
  719. else if (dto.FileType == 2) tempName = $"收款账单(北京)模板.docx";
  720. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/{tempName}";
  721. //载入模板
  722. Document doc = new Document(tempPath);
  723. DocumentBuilder builder = new DocumentBuilder(doc);
  724. #region 替换Word模板书签内容
  725. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  726. //付款方
  727. if (doc.Range.Bookmarks["To"] != null)
  728. {
  729. Bookmark mark = doc.Range.Bookmarks["To"];
  730. mark.Text = _ForeignReceivables[0].To == null ? "" : _ForeignReceivables[0].To.ToString();
  731. }
  732. //付款方电话
  733. if (doc.Range.Bookmarks["ToTel"] != null)
  734. {
  735. Bookmark mark = doc.Range.Bookmarks["ToTel"];
  736. mark.Text = _ForeignReceivables[0].ToTel == null ? "" : _ForeignReceivables[0].ToTel.ToString();
  737. }
  738. //导出时间
  739. if (doc.Range.Bookmarks["Date"] != null)
  740. {
  741. Bookmark mark = doc.Range.Bookmarks["Date"];
  742. mark.Text = DateTime.Now.ToString("yyyy-MM-dd");
  743. }
  744. //注
  745. if (doc.Range.Bookmarks["Attention"] != null)
  746. {
  747. Bookmark mark = doc.Range.Bookmarks["Attention"];
  748. mark.Text = _ForeignReceivables[0].Attention == null ? "" : _ForeignReceivables[0].Attention.ToString();
  749. }
  750. //团队名称
  751. if (doc.Range.Bookmarks["Team"] != null)
  752. {
  753. Bookmark mark = doc.Range.Bookmarks["Team"];
  754. mark.Text = _DelegationInfo.VisitCountry == null ? "" : _DelegationInfo.VisitCountry.ToString();
  755. }
  756. //付款日期
  757. if (doc.Range.Bookmarks["PayDate"] != null)
  758. {
  759. Bookmark mark = doc.Range.Bookmarks["PayDate"];
  760. mark.Text = _ForeignReceivables[0].PayDate == null ? "" : Convert.ToDateTime(_ForeignReceivables[0].PayDate).ToString("yyyy年MM月dd日");
  761. }
  762. decimal sumPrice = 0;
  763. //各项费用
  764. if (doc.Range.Bookmarks["PayItemContent"] != null)
  765. {
  766. string items = "";
  767. foreach (var fr in _ForeignReceivables)
  768. {
  769. items += fr.PriceName + " " + fr.Currency + " " + fr.Price.ToString("#0.00") + " * " + fr.Count + " " + fr.Unit + " * " + fr.Rate + ".................. RMB " + fr.ItemSumPrice.ToString("#0.00") + "\n";
  770. sumPrice += fr.ItemSumPrice;
  771. }
  772. Bookmark mark = doc.Range.Bookmarks["PayItemContent"];
  773. mark.Text = items;
  774. }
  775. //合计
  776. if (doc.Range.Bookmarks["Total"] != null)
  777. {
  778. Bookmark mark = doc.Range.Bookmarks["Total"];
  779. mark.Text = sumPrice.ToString("#0.00");
  780. }
  781. #endregion
  782. //文件名
  783. string strFileName = _DelegationInfo.TeamName + "-收款账单.docx";
  784. doc.Save(AppSettingsHelper.Get("WordBasePath") + "ForeignReceivables/File/" + strFileName);
  785. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/ForeignReceivables/File/" + strFileName;
  786. return Ok(JsonView(true, "成功", new { Url = url }));
  787. }
  788. else if (dto.FileType == 3) //汇款通知
  789. {
  790. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  791. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  792. if (_EnterExitCosts == null)
  793. {
  794. return Ok(JsonView(false, "该团组未填写出入境费用;"));
  795. }
  796. //数据源
  797. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  798. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  799. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  800. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  801. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  802. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  803. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  804. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  805. .Select((tcl, dc, cc) => new
  806. {
  807. Name = dc.LastName + dc.FirstName,
  808. Sex = dc.Sex,
  809. Birthday = dc.BirthDay,
  810. Company = cc.CompanyFullName,
  811. Job = dc.Job,
  812. AirType = tcl.ShippingSpaceTypeId
  813. })
  814. .ToList();
  815. if (DeleClientList.Count<1)
  816. {
  817. return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
  818. }
  819. var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
  820. var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
  821. Dictionary<string, string> bookmarkArr = null;
  822. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
  823. //载入模板
  824. Document doc = new Document(tempPath);
  825. DocumentBuilder builder = null;
  826. List<string> filesToZip = new List<string>();
  827. foreach (var ClientItem in _GroupClient) //遍历单位
  828. {
  829. doc = new Document(tempPath);
  830. builder = new DocumentBuilder(doc);
  831. Paragraph paragraph = new Paragraph(doc);
  832. bookmarkArr = new Dictionary<string, string>();
  833. bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
  834. bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
  835. bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
  836. bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
  837. bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry);//出访国家
  838. bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
  839. var ClientItemList = ClientItem.ToList();
  840. string UsersTop = string.Empty;//word中人员以及金额
  841. decimal WordAllPrice = 0.00M;
  842. //int[] infoColumn = new int[5] {dac1.Select(x=>x.Place.Length).ToList().Max(),2, dac1.Select(x => x.Cost.Length).Max() + dac1.Select(x => x.Currency.Length).Max(),
  843. // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
  844. //遍历人员
  845. for (int i = 0; i < ClientItemList.Count(); i++)
  846. {
  847. Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
  848. var client = ClientItemList[i]; //每个人员
  849. var firstName = ClientItemList[i].Name;
  850. //计算费用总和
  851. decimal airPrice = client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW;
  852. decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
  853. dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
  854. _EnterExitCosts.Service;
  855. WordAllPrice += AllPrice;
  856. UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
  857. TeableBookmarkArr.Add("jp",(client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW).ToString("#0.00") + " 元"); //机票金额
  858. TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
  859. TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
  860. string zsinfo = string.Empty;
  861. string hsinfo = string.Empty;
  862. string gzinfo = string.Empty;
  863. List<string> placeArr = new List<string>();
  864. Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  865. Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
  866. Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
  867. Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
  868. int rowIndex = 0;
  869. foreach (var item in dac1)
  870. {
  871. if (string.IsNullOrWhiteSpace(item.Place))
  872. {
  873. continue;
  874. }
  875. if (placeArr.Contains(item.Place))
  876. {
  877. continue;
  878. }
  879. else
  880. {
  881. placeArr.Add(item.Place);
  882. }
  883. if (!string.IsNullOrWhiteSpace(item.Place))
  884. {
  885. if (rowIndex > ChildTable.Rows.Count - 1)
  886. {
  887. var chitableRow = ChildTable.LastRow.Clone(true);
  888. ChildTable.AppendChild(chitableRow);
  889. }
  890. int days = dac1.FindAll(x => x.Place == item.Place).Count();
  891. SetCells(ChildTable, doc, rowIndex, 0, item.Place);
  892. SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
  893. SetCells(ChildTable, doc, rowIndex, 2, item.Cost + item.Currency + "/晚");
  894. SetCells(ChildTable, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  895. SetCells(ChildTable, doc, rowIndex, 4, "CNY" + item.SubTotal * days + "\r\n");
  896. rowIndex++;
  897. zsinfo += item.Place + " " + days + "晚 " + item.Cost + item.Currency + "/晚" + " 汇率" + (item.SubTotal /item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  898. }
  899. }
  900. placeArr.Clear();
  901. rowIndex = 0;
  902. foreach (var item in dac2)
  903. {
  904. if (string.IsNullOrWhiteSpace(item.Place))
  905. {
  906. continue;
  907. }
  908. if (placeArr.Contains(item.Place))
  909. {
  910. continue;
  911. }
  912. else
  913. {
  914. placeArr.Add(item.Place);
  915. }
  916. if (!string.IsNullOrWhiteSpace(item.Place))
  917. {
  918. if (rowIndex > ChildTable1.Rows.Count - 1)
  919. {
  920. var chitableRow = ChildTable1.LastRow.Clone(true);
  921. ChildTable1.AppendChild(chitableRow);
  922. }
  923. int days = dac2.FindAll(x => x.Place == item.Place).Count();
  924. SetCells(ChildTable1, doc, rowIndex, 0, item.Place);
  925. SetCells(ChildTable1, doc, rowIndex, 1, days + "天");
  926. SetCells(ChildTable1, doc, rowIndex, 2, item.Cost + item.Currency + "/天");
  927. SetCells(ChildTable1, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  928. SetCells(ChildTable1, doc, rowIndex, 4, "CNY" +item.SubTotal * days);
  929. rowIndex++;
  930. hsinfo += item.Place + " " + days + "天 " + item.Cost + item.Currency + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" +item.SubTotal * days + "\r\n";
  931. }
  932. }
  933. placeArr.Clear();
  934. rowIndex = 0;
  935. foreach (var item in dac3)
  936. {
  937. if (string.IsNullOrWhiteSpace(item.Place))
  938. {
  939. continue;
  940. }
  941. if (placeArr.Contains(item.Place))
  942. {
  943. continue;
  944. }
  945. else
  946. {
  947. placeArr.Add(item.Place);
  948. }
  949. if (!string.IsNullOrWhiteSpace(item.Place))
  950. {
  951. if (rowIndex > ChildTable2.Rows.Count - 1)
  952. {
  953. var chitableRow = ChildTable2.LastRow.Clone(true);
  954. ChildTable2.AppendChild(chitableRow);
  955. }
  956. int days = dac3.FindAll(x => x.Place == item.Place).Count();
  957. SetCells(ChildTable2, doc, rowIndex, 0, item.Place);
  958. SetCells(ChildTable2, doc, rowIndex, 1, days + "天");
  959. SetCells(ChildTable2, doc, rowIndex, 2, item.Cost + item.Currency + "/天");
  960. SetCells(ChildTable2, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  961. SetCells(ChildTable2, doc, rowIndex, 4, "CNY" + item.SubTotal * days + "\r\n");
  962. rowIndex++;
  963. gzinfo += item.Place + " " + days + "天 " + item.Cost + item.Currency + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  964. }
  965. }
  966. placeArr.Clear();
  967. TeableBookmarkArr.Add("zsinfo", zsinfo); //住宿费详情
  968. TeableBookmarkArr.Add("hs", dac2.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //伙食费
  969. TeableBookmarkArr.Add("hsinfo", hsinfo); //伙食费详情
  970. TeableBookmarkArr.Add("gz", dac3.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //公杂费
  971. TeableBookmarkArr.Add("gzinfo", gzinfo); //公杂费详情
  972. TeableBookmarkArr.Add("qt", (_EnterExitCosts.Visa + _EnterExitCosts.Safe).ToString("#0.00") + " 元");//其他费用
  973. TeableBookmarkArr.Add("qtinfo", $"(签证费{_EnterExitCosts.Visa.ToString("#0.00")}元、保险{_EnterExitCosts.Safe.ToString("#0.00")}元等费用)");//其他费用第二列
  974. TeableBookmarkArr.Add("fw", _EnterExitCosts.Service.ToString("#0.00") + "元/人");//服务费
  975. TeableBookmarkArr.Add("AllPrice", AllPrice.ToString("#0.00") + "元/人");//表格合计费用
  976. string airStr = client.AirType == 460 ? "经济舱" : client.AirType == 458 ? "公务舱" : "";
  977. TeableBookmarkArr.Add("title", $"费用清单-{airStr}({firstName})");
  978. foreach (var book in TeableBookmarkArr.Keys)
  979. {
  980. if (doc.Range.Bookmarks[book] != null)
  981. {
  982. Bookmark mark = doc.Range.Bookmarks[book];
  983. mark.Text = TeableBookmarkArr[book];
  984. }
  985. }
  986. if (i != ClientItemList.Count - 1)
  987. {
  988. builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
  989. Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  990. table.ParentNode.InsertAfter(paragraph, table);
  991. var CloneTable = (Aspose.Words.Tables.Table)table.Clone(true);
  992. table.ParentNode.InsertAfter(CloneTable, paragraph);
  993. }
  994. TeableBookmarkArr.Clear();
  995. }
  996. bookmarkArr.Add("VisitPrice", WordAllPrice.ToString());//出访费用总额
  997. bookmarkArr.Add("CnAllPrice", WordAllPrice.ConvertCNYUpper());//出访费用总额中文
  998. bookmarkArr.Add("namesPrice", UsersTop.TrimEnd('、'));//各人员出访费用 付辰同志出访费用为¥73,604.8元
  999. foreach (var book in bookmarkArr.Keys)
  1000. {
  1001. if (doc.Range.Bookmarks[book] != null)
  1002. {
  1003. Bookmark mark = doc.Range.Bookmarks[book];
  1004. mark.Text = bookmarkArr[book];
  1005. }
  1006. }
  1007. //MemoryStream outSteam = new MemoryStream();
  1008. string filsPath = $"ForeignReceivables/File/{ClientItem.Key}.docx";
  1009. doc.Save(AppSettingsHelper.Get("WordBasePath") + filsPath);
  1010. filesToZip.Add(filsPath);
  1011. //streams.Add(ClientItem.Key + ".docx", outSteam.ToArray());
  1012. }
  1013. //文件名
  1014. string zipFileName = _DelegationInfo.TeamName + "-收款账单.zip";
  1015. string zipPath = $"ForeignReceivables/File/{_DelegationInfo.TeamName}-收款账单{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  1016. try
  1017. {
  1018. using (var zip = ZipFile.Open(zipPath, ZipArchiveMode.Create))
  1019. {
  1020. foreach (var file in filesToZip)
  1021. {
  1022. zip.CreateEntryFromFile(file, Path.GetFileName(file));
  1023. }
  1024. }
  1025. }
  1026. catch (Exception ex)
  1027. {
  1028. return Ok(JsonView(false, ex.Message));
  1029. }
  1030. string url = AppSettingsHelper.Get("WordBasePath") + $"{zipPath}";
  1031. return Ok(JsonView(true, "成功", new { Url = url }));
  1032. }
  1033. return Ok(JsonView(false, "操作失败!"));
  1034. }
  1035. catch (Exception ex)
  1036. {
  1037. return Ok(JsonView(false, ex.Message));
  1038. }
  1039. }
  1040. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val)
  1041. {
  1042. //获取table中的某个单元格,从0开始
  1043. Aspose.Words.Tables.Cell lshCell = table.Rows[rows].Cells[cells];
  1044. //将单元格中的第一个段落移除
  1045. lshCell.FirstParagraph.Remove();
  1046. //新建一个段落
  1047. Paragraph p = new Paragraph(doc);
  1048. var r = new Run(doc, val);
  1049. r.Font.Size = 8;
  1050. //把设置的值赋给之前新建的段落
  1051. p.AppendChild(r);
  1052. //将此段落加到单元格内
  1053. lshCell.AppendChild(p);
  1054. }
  1055. #endregion
  1056. #region 已收款项
  1057. /// <summary>
  1058. /// 已收款项
  1059. /// 查询
  1060. /// </summary>
  1061. /// <param name="dto"></param>
  1062. /// <returns></returns>
  1063. [HttpPost]
  1064. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1065. public async Task<IActionResult> PostAmountReceived(AmountReceivedDto dto)
  1066. {
  1067. try
  1068. {
  1069. if (dto == null)
  1070. {
  1071. return Ok(JsonView(false, "参数不能为空!"));
  1072. }
  1073. Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
  1074. dynamic data = null;
  1075. if (dto.PortType == 1)
  1076. {
  1077. if (ffrData.Code != 0)
  1078. {
  1079. return Ok(JsonView(false, ffrData.Msg));
  1080. }
  1081. data = ffrData.Data;
  1082. }
  1083. else if (dto.PortType == 2)
  1084. {
  1085. if (ffrData.Code != 0)
  1086. {
  1087. return Ok(JsonView(false, ffrData.Msg));
  1088. }
  1089. data = ffrData.Data;
  1090. }
  1091. else if (dto.PortType == 2)
  1092. {
  1093. if (ffrData.Code != 0)
  1094. {
  1095. return Ok(JsonView(false, ffrData.Msg));
  1096. }
  1097. data = ffrData.Data;
  1098. }
  1099. else
  1100. {
  1101. return Ok(JsonView(false, "请选择正确的端口号!"));
  1102. }
  1103. return Ok(JsonView(true, "操作成功!", data));
  1104. }
  1105. catch (Exception ex)
  1106. {
  1107. return Ok(JsonView(false, ex.Message));
  1108. }
  1109. }
  1110. /// <summary>
  1111. /// 已收款项
  1112. /// Add Or Edit
  1113. /// </summary>
  1114. /// <param name="dto"></param>
  1115. /// <returns></returns>
  1116. [HttpPost]
  1117. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1118. public async Task<IActionResult> PostAmountReceivedAddOrEdit(AmountReceivedAddOrEditDto dto)
  1119. {
  1120. try
  1121. {
  1122. if (dto == null)
  1123. {
  1124. return Ok(JsonView(false, "参数不能为空!"));
  1125. }
  1126. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedAddOrEditDto(dto);
  1127. if (dto.PortType == 1)
  1128. {
  1129. if (ffrData.Code != 0)
  1130. {
  1131. return Ok(JsonView(false, ffrData.Msg));
  1132. }
  1133. }
  1134. else if (dto.PortType == 2)
  1135. {
  1136. if (ffrData.Code != 0)
  1137. {
  1138. return Ok(JsonView(false, ffrData.Msg));
  1139. }
  1140. }
  1141. else if (dto.PortType == 2)
  1142. {
  1143. if (ffrData.Code != 0)
  1144. {
  1145. return Ok(JsonView(false, ffrData.Msg));
  1146. }
  1147. }
  1148. else
  1149. {
  1150. return Ok(JsonView(false, "请选择正确的端口号!"));
  1151. }
  1152. return Ok(JsonView(true, "操作成功!"));
  1153. }
  1154. catch (Exception ex)
  1155. {
  1156. return Ok(JsonView(false, ex.Message));
  1157. }
  1158. }
  1159. /// <summary>
  1160. /// 已收款项
  1161. /// Del
  1162. /// </summary>
  1163. /// <param name="dto"></param>
  1164. /// <returns></returns>
  1165. [HttpPost]
  1166. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1167. public async Task<IActionResult> PostAmountReceived_Del(AmountReceivedDelDto dto)
  1168. {
  1169. try
  1170. {
  1171. if (dto == null)
  1172. {
  1173. return Ok(JsonView(false, "参数不能为空!"));
  1174. }
  1175. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedDel(dto);
  1176. if (ffrData.Code != 0)
  1177. {
  1178. return Ok(JsonView(false, ffrData.Msg));
  1179. }
  1180. return Ok(JsonView(true, "操作成功!"));
  1181. }
  1182. catch (Exception ex)
  1183. {
  1184. return Ok(JsonView(false, ex.Message));
  1185. }
  1186. }
  1187. #endregion
  1188. #region 收款退还与其他款项
  1189. /// <summary>
  1190. /// 收款退还与其他款项
  1191. /// 查询 根据团组Id
  1192. /// </summary>
  1193. /// <param name="dto"></param>
  1194. /// <returns></returns>
  1195. [HttpPost]
  1196. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1197. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyItemByDiId(PaymentRefundAndOtherMoneyItemByDiIdDto dto)
  1198. {
  1199. try
  1200. {
  1201. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1202. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1203. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1204. #region 页面功能权限处理
  1205. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1206. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1207. if (pageFunAuth.CheckAuth == 0)
  1208. {
  1209. return Ok(JsonView(false, "您没有当前页面查询权限!"));
  1210. }
  1211. #endregion
  1212. Result _result = await _paymentRefundAndOtherMoneyRep._ItemByDiId(dto.DiId);
  1213. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  1214. {
  1215. if (_result.Code != 0)
  1216. {
  1217. return Ok(JsonView(false, _result.Msg));
  1218. }
  1219. var data = new
  1220. {
  1221. PageFuncAuth = pageFunAuth,
  1222. Data = _result.Data
  1223. };
  1224. return Ok(JsonView(true, "操作成功!", data));
  1225. }
  1226. else
  1227. {
  1228. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  1229. }
  1230. }
  1231. catch (Exception ex)
  1232. {
  1233. return Ok(JsonView(false, ex.Message));
  1234. }
  1235. }
  1236. /// <summary>
  1237. /// 收款退还与其他款项
  1238. /// 删除
  1239. /// </summary>
  1240. /// <param name="dto"></param>
  1241. /// <returns></returns>
  1242. [HttpPost]
  1243. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1244. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyDel(PaymentRefundAndOtherMoneyDelDto dto)
  1245. {
  1246. try
  1247. {
  1248. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1249. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1250. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1251. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1252. #region 页面功能权限处理
  1253. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1254. #endregion
  1255. if (pageFunAuth.DeleteAuth == 0)
  1256. {
  1257. return Ok(JsonView(false, "您没有当前页面删除权限!"));
  1258. }
  1259. Result _result = await _paymentRefundAndOtherMoneyRep._Del(dto);
  1260. if (_result.Code != 0)
  1261. {
  1262. return Ok(JsonView(false, _result.Msg));
  1263. }
  1264. return Ok(JsonView(true, "操作成功!"));
  1265. }
  1266. catch (Exception ex)
  1267. {
  1268. return Ok(JsonView(false, ex.Message));
  1269. }
  1270. }
  1271. /// <summary>
  1272. /// 收款退还与其他款项
  1273. /// Info Data Source
  1274. /// </summary>
  1275. /// <param name="dto"></param>
  1276. /// <returns></returns>
  1277. [HttpPost]
  1278. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1279. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfoDataSource(PortDtoBase dto)
  1280. {
  1281. try
  1282. {
  1283. Result _result = await _paymentRefundAndOtherMoneyRep._InfoDataSource(dto);
  1284. if (_result.Code != 0)
  1285. {
  1286. return Ok(JsonView(false, _result.Msg));
  1287. }
  1288. return Ok(JsonView(true, "查询成功!", _result.Data));
  1289. }
  1290. catch (Exception ex)
  1291. {
  1292. return Ok(JsonView(false, ex.Message));
  1293. }
  1294. }
  1295. /// <summary>
  1296. /// 收款退还与其他款项
  1297. /// Info
  1298. /// </summary>
  1299. /// <param name="dto"></param>
  1300. /// <returns></returns>
  1301. [HttpPost]
  1302. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1303. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfo(PaymentRefundAndOtherMoneyInfoDto dto)
  1304. {
  1305. try
  1306. {
  1307. if (dto == null)
  1308. {
  1309. return Ok(JsonView(false, "参数不能为空!"));
  1310. }
  1311. Result _result = await _paymentRefundAndOtherMoneyRep._Info(dto);
  1312. if (_result.Code != 0)
  1313. {
  1314. return Ok(JsonView(false, _result.Msg));
  1315. }
  1316. return Ok(JsonView(true, "查询成功!", _result.Data));
  1317. }
  1318. catch (Exception ex)
  1319. {
  1320. return Ok(JsonView(false, ex.Message));
  1321. }
  1322. }
  1323. /// <summary>
  1324. /// 收款退还与其他款项
  1325. /// 操作(Add Or Edit)
  1326. /// </summary>
  1327. /// <param name="dto"></param>
  1328. /// <returns></returns>
  1329. [HttpPost]
  1330. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1331. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyAddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
  1332. {
  1333. try
  1334. {
  1335. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1336. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1337. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1338. #region 页面功能权限处理
  1339. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1340. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1341. #endregion
  1342. if (dto.Status == 1) //add
  1343. {
  1344. if (pageFunAuth.AddAuth == 0)
  1345. {
  1346. return Ok(JsonView(false, "您没有当前页面添加权限!"));
  1347. }
  1348. }
  1349. else if (dto.Status == 2) //edit
  1350. {
  1351. if (pageFunAuth.EditAuth == 0)
  1352. {
  1353. return Ok(JsonView(false, "您没有当前页面编辑权限!"));
  1354. }
  1355. }
  1356. else
  1357. {
  1358. return Ok(JsonView(false, "请输入正确的操作状态! 1 添加 2 修改!"));
  1359. }
  1360. Result _result = await _paymentRefundAndOtherMoneyRep._AddOrEdit(dto);
  1361. if (_result.Code != 0)
  1362. {
  1363. return Ok(JsonView(false, _result.Msg));
  1364. }
  1365. return Ok(JsonView(true, "操作成功!"));
  1366. }
  1367. catch (Exception ex)
  1368. {
  1369. return Ok(JsonView(false, ex.Message));
  1370. }
  1371. }
  1372. #endregion
  1373. #region 应收报表
  1374. /// <summary>
  1375. /// 应收报表
  1376. /// 查询 根据日期范围
  1377. /// </summary>
  1378. /// <param name="dto"></param>
  1379. /// <returns></returns>
  1380. [HttpPost]
  1381. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1382. public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
  1383. {
  1384. string sqlWhere = " Where di.IsDel=0 ";
  1385. #region 验证
  1386. if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
  1387. {
  1388. return Ok(JsonView(false, "日期参数至少填写一个!"));
  1389. }
  1390. if (!string.IsNullOrEmpty(dto.beginDt))
  1391. {
  1392. if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1393. {
  1394. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1395. }
  1396. else
  1397. {
  1398. sqlWhere += string.Format(@" And di.VisitDate >= '{0} 00:00:00' ", dto.beginDt);
  1399. }
  1400. }
  1401. if (!string.IsNullOrEmpty(dto.endDt))
  1402. {
  1403. if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1404. {
  1405. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1406. }
  1407. else
  1408. {
  1409. sqlWhere += string.Format(@" And di.VisitDate <= '{0} 23:59:59' ", dto.endDt);
  1410. }
  1411. }
  1412. #endregion
  1413. string sql = string.Format(@" select distinct fr.diid,di.TeamName,di.ClientUnit,di.VisitDate from Fin_ForeignReceivables fr join Grp_DelegationInfo di on fr.DIID = di.id {0} ", sqlWhere);
  1414. List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
  1415. decimal sumAll_fr = 0M;
  1416. decimal sumAll_pr = 0M;
  1417. decimal sumAll_balance = 0M;
  1418. if (list_rst.Count > 0)
  1419. {
  1420. int rowNumber = 1;
  1421. foreach (var item_rst in list_rst)
  1422. {
  1423. item_rst.No = rowNumber;
  1424. rowNumber++;
  1425. int diId = item_rst.diid;
  1426. decimal sum_fr = 0M;
  1427. decimal sum_pr = 0M;
  1428. string str_client = string.Empty;
  1429. decimal sum_other = 0M;
  1430. decimal balance = 0M;
  1431. string str_schedule = string.Empty;
  1432. //1. 缺超支费用!!!!!!!!!!!!!!!!!!!!
  1433. string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
  1434. List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
  1435. sum_fr = list_fr.Sum(s => s.ItemSumPrice);
  1436. //2.
  1437. string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
  1438. List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
  1439. foreach (var item_pr in list_pr)
  1440. {
  1441. sum_pr += item_pr.Price;
  1442. str_client += string.Format(@"{0};", item_pr.Client);
  1443. str_schedule += string.Format(@"{0};", item_pr.Remark);
  1444. }
  1445. if (str_schedule.Length > 0)
  1446. {
  1447. str_schedule = str_schedule.TrimEnd(';');
  1448. }
  1449. if (str_client.Length > 0)
  1450. {
  1451. str_client = str_client.TrimEnd(';');
  1452. }
  1453. //3.
  1454. string sql_other = string.Format(@" Select * From Fin_OtherPrice where diid = {0} and isdel = 0 and RefundType = 1 and PayType=1 ", diId);
  1455. List<Fin_OtherPrice> list_other = _sqlSugar.SqlQueryable<Fin_OtherPrice>(sql_other).ToList();
  1456. sum_other = list_other.Sum(s => s.Price);
  1457. item_rst.frPrice = sum_fr.ToString("#0.00");
  1458. item_rst.prPrice = (sum_pr - sum_other).ToString("#0.00");
  1459. item_rst.balPrice = (sum_fr - (sum_pr - sum_other)).ToString("#0.00");
  1460. item_rst.prClient = str_client;
  1461. item_rst.schedule = str_schedule;
  1462. string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
  1463. sumAll_fr += sum_fr;
  1464. sumAll_pr += (sum_pr - sum_other);
  1465. sumAll_balance += (sum_fr - (sum_pr - sum_other));
  1466. }
  1467. PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
  1468. result.total_fr = sumAll_fr.ToString("#0.00");
  1469. result.total_pr = sumAll_pr.ToString("#0.00");
  1470. result.total_balance = sumAll_balance.ToString("#0.00");
  1471. result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
  1472. if (dto.requestType == 1)
  1473. {
  1474. return Ok(JsonView(true, "请求成功", result, list_rst.Count));
  1475. }
  1476. else
  1477. {
  1478. //----------------------------
  1479. List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
  1480. WorkbookDesigner designer = new WorkbookDesigner();
  1481. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
  1482. int excNo = 1;
  1483. foreach (var item in list_rst)
  1484. {
  1485. Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
  1486. exc.No = excNo.ToString();
  1487. excNo++;
  1488. exc.TeamName = item.teamName;
  1489. exc.ClientUnit = item.clientUnit;
  1490. exc.VisitDate = item.visitDate;
  1491. exc.Accounts = item.frPrice;
  1492. exc.Received = item.prPrice;
  1493. exc.Balance = item.balPrice;
  1494. exc.Collection = item.schedule;
  1495. DateTime time = Convert.ToDateTime(item.visitDate);
  1496. TimeSpan ts = DateTime.Now - time;
  1497. float SY = float.Parse(item.balPrice);
  1498. if (ts.Days >= 365 && SY > 0)
  1499. {
  1500. exc.Sign = "需收款";
  1501. }
  1502. else
  1503. {
  1504. exc.Sign = "";
  1505. }
  1506. list_Ex.Add(exc);
  1507. }
  1508. var dt = CommonFun.GetDataTableFromIList(list_Ex);
  1509. dt.TableName = "Excel_SyntheticalReceivableByDateRange";
  1510. if (dt != null)
  1511. {
  1512. designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
  1513. //数据源
  1514. designer.SetDataSource(dt);
  1515. //根据数据源处理生成报表内容
  1516. designer.Process();
  1517. string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  1518. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  1519. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  1520. return Ok(JsonView(true, "成功", new { url = rst }));
  1521. }
  1522. }
  1523. }
  1524. return Ok(JsonView(true, "获取成功", "", list_rst.Count));
  1525. }
  1526. #endregion
  1527. #region 付款申请
  1528. /// <summary>
  1529. /// 应收报表
  1530. /// 查询 根据日期范围
  1531. /// </summary>
  1532. /// <param name="dto"></param>
  1533. /// <returns></returns>
  1534. [HttpPost]
  1535. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1536. public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
  1537. {
  1538. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.beginDt, dto.endDt);
  1539. return Ok(JsonView(true, "获取成功", new { daily = dailyResult }));
  1540. return Ok(JsonView(false, "获取失败"));
  1541. }
  1542. /// <summary>
  1543. /// 付款申请
  1544. /// 查询 根据日期范围
  1545. /// </summary>
  1546. /// <param name="dto"></param>
  1547. /// <returns></returns>
  1548. private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(string beginDt, string endDt)
  1549. {
  1550. #region sql条件处理
  1551. string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
  1552. string sql_1 = string.Format(@"Select * From (
  1553. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  1554. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  1555. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  1556. dfp.PriceTypeId,dfp.TransferTypeId
  1557. From Fin_DailyFeePayment dfp
  1558. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  1559. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  1560. Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1
  1561. ) temp ", sqlWhere);
  1562. #endregion
  1563. List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
  1564. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  1565. foreach (var item in DailyFeePaymentData)
  1566. {
  1567. if (dic_setData.ContainsKey(item.PriceTypeId))
  1568. {
  1569. item.priceTypeStr = dic_setData[item.PriceTypeId];
  1570. }
  1571. else
  1572. {
  1573. Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
  1574. if (sd_priceType != null)
  1575. {
  1576. item.priceTypeStr = sd_priceType.Name;
  1577. dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
  1578. }
  1579. }
  1580. if (dic_setData.ContainsKey(item.transferTypeId))
  1581. {
  1582. item.transferTypeIdStr = dic_setData[item.transferTypeId];
  1583. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1584. if (sd_transfer != null)
  1585. {
  1586. item.transferParentId = sd_transfer.STid;
  1587. item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
  1588. }
  1589. }
  1590. else
  1591. {
  1592. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1593. if (sd_transfer != null)
  1594. {
  1595. item.transferTypeIdStr = sd_transfer.Name;
  1596. item.transferParentId = sd_transfer.STid;
  1597. item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
  1598. dic_setData.Add(item.transferTypeId, sd_transfer.Name);
  1599. }
  1600. }
  1601. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  1602. Where IsDel=0 And DFPId = {0} ", item.Id);
  1603. item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
  1604. }
  1605. decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == 62).Sum(d => d.SumPrice ?? 0M);
  1606. decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == 63).Sum(d => d.SumPrice ?? 0M);
  1607. var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
  1608. return result;
  1609. }
  1610. #endregion
  1611. }
  1612. }