FinancialController.cs 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181
  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 sum_extra = 0M; //超支费用
  1431. decimal balance = 0M;
  1432. string str_schedule = string.Empty;
  1433. //1. 缺超支费用!!!!!!!!!!!!!!!!!!!!
  1434. string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
  1435. List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
  1436. sum_fr = list_fr.Sum(s => s.ItemSumPrice);
  1437. //2.
  1438. string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
  1439. List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
  1440. foreach (var item_pr in list_pr)
  1441. {
  1442. sum_pr += item_pr.Price;
  1443. str_client += string.Format(@"{0};", item_pr.Client);
  1444. str_schedule += string.Format(@"{0};", item_pr.Remark);
  1445. }
  1446. if (str_schedule.Length > 0)
  1447. {
  1448. str_schedule = str_schedule.TrimEnd(';');
  1449. }
  1450. if (str_client.Length > 0)
  1451. {
  1452. str_client = str_client.TrimEnd(';');
  1453. }
  1454. //3.
  1455. string sql_other = string.Format(@" Select * From Fin_OtherPrice where diid = {0} and isdel = 0 and RefundType = 1 and PayType=1 ", diId);
  1456. List<Fin_OtherPrice> list_other = _sqlSugar.SqlQueryable<Fin_OtherPrice>(sql_other).ToList();
  1457. sum_other = list_other.Sum(s => s.Price);
  1458. //4.
  1459. string sql_extra = string.Format(@" Select c.* From Fin_GroupExtraCost f
  1460. Inner join Grp_CreditCardPayment c On f.Id = c.CId
  1461. Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId = {0} ", diId);
  1462. List<Grp_CreditCardPayment> list_extra = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_extra).ToList();
  1463. sum_extra = list_extra.Sum(s => s.RMBPrice);
  1464. item_rst.frPrice = (sum_fr + sum_extra).ToString("#0.00");
  1465. item_rst.prPrice = (sum_pr - sum_other).ToString("#0.00");
  1466. item_rst.balPrice = ((sum_fr + sum_extra) - (sum_pr - sum_other)).ToString("#0.00");
  1467. item_rst.prClient = str_client;
  1468. item_rst.schedule = str_schedule;
  1469. string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
  1470. sumAll_fr += (sum_fr + sum_extra);
  1471. sumAll_pr += (sum_pr - sum_other);
  1472. sumAll_balance += ((sum_fr + sum_extra) - (sum_pr - sum_other));
  1473. }
  1474. PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
  1475. result.total_fr = sumAll_fr.ToString("#0.00");
  1476. result.total_pr = sumAll_pr.ToString("#0.00");
  1477. result.total_balance = sumAll_balance.ToString("#0.00");
  1478. result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
  1479. if (dto.requestType == 1)
  1480. {
  1481. return Ok(JsonView(true, "请求成功", result, list_rst.Count));
  1482. }
  1483. else
  1484. {
  1485. //----------------------------
  1486. List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
  1487. WorkbookDesigner designer = new WorkbookDesigner();
  1488. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
  1489. int excNo = 1;
  1490. foreach (var item in list_rst)
  1491. {
  1492. Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
  1493. exc.No = excNo.ToString();
  1494. excNo++;
  1495. exc.TeamName = item.teamName;
  1496. exc.ClientUnit = item.clientUnit;
  1497. exc.VisitDate = item.visitDate;
  1498. exc.Accounts = item.frPrice;
  1499. exc.Received = item.prPrice;
  1500. exc.Balance = item.balPrice;
  1501. exc.Collection = item.schedule;
  1502. DateTime time = Convert.ToDateTime(item.visitDate);
  1503. TimeSpan ts = DateTime.Now - time;
  1504. float SY = float.Parse(item.balPrice);
  1505. if (ts.Days >= 365 && SY > 0)
  1506. {
  1507. exc.Sign = "需收款";
  1508. }
  1509. else
  1510. {
  1511. exc.Sign = "";
  1512. }
  1513. list_Ex.Add(exc);
  1514. }
  1515. var dt = CommonFun.GetDataTableFromIList(list_Ex);
  1516. dt.TableName = "Excel_SyntheticalReceivableByDateRange";
  1517. if (dt != null)
  1518. {
  1519. designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
  1520. //数据源
  1521. designer.SetDataSource(dt);
  1522. //根据数据源处理生成报表内容
  1523. designer.Process();
  1524. string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  1525. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  1526. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  1527. return Ok(JsonView(true, "成功", new { url = rst }));
  1528. }
  1529. }
  1530. }
  1531. return Ok(JsonView(true, "获取成功", "", list_rst.Count));
  1532. }
  1533. #endregion
  1534. #region 付款申请
  1535. /// <summary>
  1536. /// 应收报表
  1537. /// 查询 根据日期范围
  1538. /// </summary>
  1539. /// <param name="dto"></param>
  1540. /// <returns></returns>
  1541. [HttpPost]
  1542. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1543. public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
  1544. {
  1545. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.beginDt, dto.endDt);
  1546. return Ok(JsonView(true, "获取成功", new { daily = dailyResult }));
  1547. return Ok(JsonView(false, "获取失败"));
  1548. }
  1549. /// <summary>
  1550. /// 付款申请
  1551. /// 查询 根据日期范围
  1552. /// </summary>
  1553. /// <param name="dto"></param>
  1554. /// <returns></returns>
  1555. private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(string beginDt, string endDt)
  1556. {
  1557. #region sql条件处理
  1558. string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
  1559. string sql_1 = string.Format(@"Select * From (
  1560. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  1561. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  1562. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  1563. dfp.PriceTypeId,dfp.TransferTypeId
  1564. From Fin_DailyFeePayment dfp
  1565. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  1566. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  1567. Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1
  1568. ) temp ", sqlWhere);
  1569. #endregion
  1570. List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
  1571. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  1572. foreach (var item in DailyFeePaymentData)
  1573. {
  1574. if (dic_setData.ContainsKey(item.PriceTypeId))
  1575. {
  1576. item.priceTypeStr = dic_setData[item.PriceTypeId];
  1577. }
  1578. else
  1579. {
  1580. Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
  1581. if (sd_priceType != null)
  1582. {
  1583. item.priceTypeStr = sd_priceType.Name;
  1584. dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
  1585. }
  1586. }
  1587. if (dic_setData.ContainsKey(item.transferTypeId))
  1588. {
  1589. item.transferTypeIdStr = dic_setData[item.transferTypeId];
  1590. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1591. if (sd_transfer != null)
  1592. {
  1593. item.transferParentId = sd_transfer.STid;
  1594. item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
  1595. }
  1596. }
  1597. else
  1598. {
  1599. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1600. if (sd_transfer != null)
  1601. {
  1602. item.transferTypeIdStr = sd_transfer.Name;
  1603. item.transferParentId = sd_transfer.STid;
  1604. item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
  1605. dic_setData.Add(item.transferTypeId, sd_transfer.Name);
  1606. }
  1607. }
  1608. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  1609. Where IsDel=0 And DFPId = {0} ", item.Id);
  1610. item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
  1611. }
  1612. decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == 62).Sum(d => d.SumPrice ?? 0M);
  1613. decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == 63).Sum(d => d.SumPrice ?? 0M);
  1614. var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
  1615. return result;
  1616. }
  1617. #endregion
  1618. #region 超支费用
  1619. /// <summary>
  1620. /// 超支费用
  1621. /// 1增、2改、3删
  1622. /// </summary>
  1623. /// <param name="dto"></param>
  1624. /// <returns></returns>
  1625. [HttpPost]
  1626. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1627. public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  1628. {
  1629. #region 验证
  1630. #endregion
  1631. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  1632. _entity.DiId = dto.diId;
  1633. _entity.PriceName = dto.priceName;
  1634. _entity.Price = dto.price;
  1635. _entity.PriceCurrency = dto.currency;
  1636. _entity.PriceType = dto.priceType;
  1637. _entity.Coefficient = dto.coefficient;
  1638. _entity.PriceDetailType = dto.priceDetailType;
  1639. _entity.FilePath = dto.filePath;
  1640. _entity.Remark = dto.remark;
  1641. _daiRep.BeginTran();
  1642. if (dto.editType == 1)
  1643. {
  1644. _entity.CreateUserId = dto.createUser;
  1645. _entity.CreateTime = DateTime.Now;
  1646. _entity.IsDel = 0;
  1647. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  1648. if (returnId > 0)
  1649. {
  1650. dto.Id = returnId;
  1651. }
  1652. }
  1653. else if (dto.editType == 2)
  1654. {
  1655. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1656. {
  1657. PriceName = dto.priceName,
  1658. Price = dto.price,
  1659. PriceCurrency = dto.currency,
  1660. PriceType = dto.priceType,
  1661. PriceDetailType = dto.priceDetailType,
  1662. Coefficient = dto.coefficient,
  1663. FilePath = dto.filePath,
  1664. Remark = dto.remark
  1665. });
  1666. if (!res)
  1667. {
  1668. _daiRep.RollbackTran();
  1669. return Ok(JsonView(false, "2操作失败!"));
  1670. }
  1671. }
  1672. else if (dto.editType == 3)
  1673. {
  1674. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1675. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1676. {
  1677. IsDel = 1,
  1678. DeleteTime = delTime,
  1679. DeleteUserId = dto.createUser
  1680. });
  1681. if (!res)
  1682. {
  1683. _daiRep.RollbackTran();
  1684. return Ok(JsonView(false, "3操作失败!"));
  1685. }
  1686. }
  1687. else
  1688. {
  1689. _daiRep.RollbackTran();
  1690. return Ok(JsonView(false, "未知的editType"));
  1691. }
  1692. if (!extraCost_editCreditCardPayment(dto))
  1693. {
  1694. return Ok(JsonView(false, "ccp操作失败"));
  1695. }
  1696. _daiRep.CommitTran();
  1697. return Ok(JsonView(false, "操作成功"));
  1698. }
  1699. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1700. {
  1701. //设置团组汇率
  1702. decimal dcm_dayrate = 1M;
  1703. decimal dcm_rmbPrice = costDto.price;
  1704. int ispay = costDto.payType == 72 ? 1 : 0;
  1705. if (costDto.costSign != 3)
  1706. {
  1707. Grp_TeamRate tr = _daiRep.Query<Grp_TeamRate>(s => s.DiId == costDto.diId && s.CTable == 1015).First();
  1708. if (tr != null)
  1709. {
  1710. if (costDto.currency == 49)
  1711. {
  1712. dcm_dayrate = tr.RateU;
  1713. dcm_rmbPrice = dcm_rmbPrice * tr.RateU;
  1714. }
  1715. else if (costDto.currency == 51)
  1716. {
  1717. dcm_dayrate = tr.RateE;
  1718. dcm_rmbPrice = dcm_rmbPrice * tr.RateE;
  1719. }
  1720. }
  1721. }
  1722. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1723. if (ccp == null)
  1724. {
  1725. ccp = new Grp_CreditCardPayment();
  1726. ccp.PayDId = costDto.payType;// dto
  1727. ccp.ConsumptionPatterns = "";
  1728. ccp.ConsumptionDate = "";
  1729. ccp.CTDId = costDto.payCardId;// dto
  1730. ccp.BankNo = "";
  1731. ccp.CardholderName = "";
  1732. ccp.PayMoney = costDto.price;// dto
  1733. ccp.PaymentCurrency = costDto.currency;// dto
  1734. ccp.CompanyBankNo = "";
  1735. ccp.OtherBankName = "";
  1736. ccp.OtherSideNo = "";
  1737. ccp.OtherSideName = "";
  1738. ccp.Remark = "";
  1739. ccp.CreateUserId = costDto.createUser;
  1740. ccp.CreateTime = DateTime.Now;
  1741. ccp.MFOperator = 0;
  1742. ccp.MFOperatorDate = "";
  1743. ccp.IsAuditDM = 0;
  1744. ccp.AuditDMOperate = 0;
  1745. ccp.AuditDMDate = "";
  1746. ccp.IsAuditMF = 0;
  1747. ccp.AuditMFOperate = 0;
  1748. ccp.AuditMFDate = "";
  1749. ccp.IsAuditGM = 0;
  1750. ccp.AuditGMOperate = 0;
  1751. ccp.AuditGMDate = "";
  1752. ccp.IsPay = ispay; // upd
  1753. ccp.DIId = costDto.diId;// dto
  1754. ccp.CId = costDto.Id;// dto
  1755. ccp.CTable = 1015; //超支费用指向id
  1756. ccp.IsDel = 0;
  1757. ccp.PayPercentage = 100M;
  1758. ccp.PayThenMoney = 0M;
  1759. ccp.PayPercentageOld = 100M;
  1760. ccp.PayThenMoneyOld = 0M;
  1761. ccp.UpdateDate = "";
  1762. ccp.Payee = costDto.payee;// dto
  1763. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1764. ccp.ExceedBudget = 0;
  1765. ccp.DayRate = dcm_dayrate; //upd
  1766. ccp.RMBPrice = dcm_rmbPrice; //upd
  1767. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1768. if (ccpInsertId > 0)
  1769. {
  1770. return true;
  1771. }
  1772. }
  1773. else
  1774. {
  1775. if (costDto.editType == 2)
  1776. {
  1777. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1778. {
  1779. PayDId = costDto.payType,
  1780. CTDId = costDto.payCardId,
  1781. PayMoney = costDto.price,
  1782. PaymentCurrency = costDto.currency,
  1783. IsPay = ispay,
  1784. Payee = costDto.payee,
  1785. OrbitalPrivateTransfer = costDto.costSign,
  1786. DayRate = dcm_dayrate,
  1787. RMBPrice = dcm_rmbPrice
  1788. });
  1789. return res;
  1790. }
  1791. else if (costDto.editType == 3)
  1792. {
  1793. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1794. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1795. {
  1796. IsDel = 1,
  1797. DeleteTime = delTime,
  1798. DeleteUserId = costDto.createUser
  1799. });
  1800. return res2;
  1801. }
  1802. }
  1803. return false;
  1804. }
  1805. /// <summary>
  1806. /// 超支费用
  1807. /// 列表查询
  1808. /// </summary>
  1809. /// <param name="dto"></param>
  1810. /// <returns></returns>
  1811. [HttpPost]
  1812. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1813. public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
  1814. {
  1815. string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
  1816. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  1817. int endIndex = startIndex + dto.PageSize - 1;
  1818. string sql_data = string.Format(@"Select * From (
  1819. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  1820. f.PriceName,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  1821. From Fin_GroupExtraCost f
  1822. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  1823. Left Join Sys_Users u On f.CreateUserId = u.Id
  1824. Where f.IsDel=0 And c.CTable = 1015 {0}
  1825. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  1826. string sql_count = string.Format(@"Select Count(1) as DataCount From (
  1827. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  1828. f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  1829. From Fin_GroupExtraCost f
  1830. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  1831. Left Join Sys_Users u On f.CreateUserId = u.Id
  1832. Where f.IsDel=0 And c.CTable = 1015 {0}
  1833. ) temp ", sqlWhere);
  1834. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  1835. {
  1836. //Fin_DailyFeePaymentPageCount
  1837. var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
  1838. List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
  1839. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  1840. Dictionary<int, string> dic_user = new Dictionary<int, string>();
  1841. foreach (var item in dataList)
  1842. {
  1843. //费用详细类型
  1844. if (dic_setData.ContainsKey(item.PriceType))
  1845. {
  1846. item.PriceTypeStr = dic_setData[item.PriceType];
  1847. }
  1848. else
  1849. {
  1850. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
  1851. if (sd_priceTypeDetail != null)
  1852. {
  1853. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  1854. item.PriceTypeStr = tempName;
  1855. dic_setData.Add(item.PriceType, tempName);
  1856. }
  1857. }
  1858. //系统用户
  1859. if (dic_user.ContainsKey(item.CreateUserId))
  1860. {
  1861. item.CreateUserIdStr = dic_setData[item.CreateUserId];
  1862. }
  1863. else
  1864. {
  1865. Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
  1866. if (users != null)
  1867. {
  1868. item.CreateUserIdStr = users.CnName;
  1869. dic_setData.Add(item.CreateUserId, users.CnName);
  1870. }
  1871. }
  1872. switch (item.IsAuditGM)
  1873. {
  1874. case 0: item.IsAuditGMStr = "未审核"; break;
  1875. case 1: item.IsAuditGMStr = "已通过"; break;
  1876. case 2: item.IsAuditGMStr = "未通过"; break;
  1877. default: item.IsAuditGMStr = "未知状态"; break;
  1878. }
  1879. }
  1880. var result = new ListViewBase<Fin_GroupExtraCostView>
  1881. {
  1882. CurrPageIndex = dto.PageIndex,
  1883. CurrPageSize = dto.PageSize,
  1884. DataCount = count.DataCount,
  1885. DataList = dataList
  1886. };
  1887. return Ok(JsonView(true, "查询成功", result));
  1888. }
  1889. return Ok(JsonView(false, "查询成功"));
  1890. }
  1891. /// <summary>
  1892. /// 超支费用
  1893. /// 数据集合配置
  1894. /// </summary>
  1895. /// <param name="dto"></param>
  1896. /// <returns></returns>
  1897. [HttpPost]
  1898. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1899. public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
  1900. {
  1901. //支付方式
  1902. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  1903. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  1904. //超支费用类型
  1905. List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
  1906. List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
  1907. //超支费用详细类型
  1908. List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
  1909. PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
  1910. List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
  1911. var data = new
  1912. {
  1913. Payment = _Payment,
  1914. PriceType = _PriceType,
  1915. PriceDetailType = _PriceDetailType
  1916. };
  1917. return Ok(JsonView(true, "", data));
  1918. }
  1919. #endregion
  1920. }
  1921. }