FinancialController.cs 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174
  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 = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/File/{ClientItem.Key}.docx";
  1009. doc.Save(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(AppSettingsHelper.Get("WordBasePath") + 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("WordBaseUrl") + $"Office/Word/{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. #region 超支费用
  1612. /// <summary>
  1613. /// 超支费用
  1614. /// 1增、2改、3删
  1615. /// </summary>
  1616. /// <param name="dto"></param>
  1617. /// <returns></returns>
  1618. [HttpPost]
  1619. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1620. public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  1621. {
  1622. #region 验证
  1623. #endregion
  1624. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  1625. _entity.DiId = dto.diId;
  1626. _entity.PriceName = dto.priceName;
  1627. _entity.Price = dto.price;
  1628. _entity.PriceCurrency = dto.currency;
  1629. _entity.PriceType = dto.priceType;
  1630. _entity.Coefficient = dto.coefficient;
  1631. _entity.PriceDetailType = dto.priceDetailType;
  1632. _entity.FilePath = dto.filePath;
  1633. _entity.Remark = dto.remark;
  1634. _daiRep.BeginTran();
  1635. if (dto.editType == 1)
  1636. {
  1637. _entity.CreateUserId = dto.createUser;
  1638. _entity.CreateTime = DateTime.Now;
  1639. _entity.IsDel = 0;
  1640. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  1641. if (returnId > 0)
  1642. {
  1643. dto.Id = returnId;
  1644. }
  1645. }
  1646. else if (dto.editType == 2)
  1647. {
  1648. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1649. {
  1650. PriceName = dto.priceName,
  1651. Price = dto.price,
  1652. PriceCurrency = dto.currency,
  1653. PriceType = dto.priceType,
  1654. PriceDetailType = dto.priceDetailType,
  1655. Coefficient = dto.coefficient,
  1656. FilePath = dto.filePath,
  1657. Remark = dto.remark
  1658. });
  1659. if (!res)
  1660. {
  1661. _daiRep.RollbackTran();
  1662. return Ok(JsonView(false, "2操作失败!"));
  1663. }
  1664. }
  1665. else if (dto.editType == 3)
  1666. {
  1667. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1668. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1669. {
  1670. IsDel = 1,
  1671. DeleteTime = delTime,
  1672. DeleteUserId = dto.createUser
  1673. });
  1674. if (!res)
  1675. {
  1676. _daiRep.RollbackTran();
  1677. return Ok(JsonView(false, "3操作失败!"));
  1678. }
  1679. }
  1680. else
  1681. {
  1682. _daiRep.RollbackTran();
  1683. return Ok(JsonView(false, "未知的editType"));
  1684. }
  1685. if (!extraCost_editCreditCardPayment(dto))
  1686. {
  1687. return Ok(JsonView(false, "ccp操作失败"));
  1688. }
  1689. _daiRep.CommitTran();
  1690. return Ok(JsonView(false, "操作成功"));
  1691. }
  1692. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1693. {
  1694. //设置团组汇率
  1695. decimal dcm_dayrate = 1M;
  1696. decimal dcm_rmbPrice = costDto.price;
  1697. int ispay = costDto.payType == 72 ? 1 : 0;
  1698. if (costDto.costSign != 3)
  1699. {
  1700. Grp_TeamRate tr = _daiRep.Query<Grp_TeamRate>(s => s.DiId == costDto.diId && s.CTable == 1015).First();
  1701. if (tr != null)
  1702. {
  1703. if (costDto.currency == 49)
  1704. {
  1705. dcm_dayrate = tr.RateU;
  1706. dcm_rmbPrice = dcm_rmbPrice * tr.RateU;
  1707. }
  1708. else if (costDto.currency == 51)
  1709. {
  1710. dcm_dayrate = tr.RateE;
  1711. dcm_rmbPrice = dcm_rmbPrice * tr.RateE;
  1712. }
  1713. }
  1714. }
  1715. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1716. if (ccp == null)
  1717. {
  1718. ccp = new Grp_CreditCardPayment();
  1719. ccp.PayDId = costDto.payType;// dto
  1720. ccp.ConsumptionPatterns = "";
  1721. ccp.ConsumptionDate = "";
  1722. ccp.CTDId = costDto.payCardId;// dto
  1723. ccp.BankNo = "";
  1724. ccp.CardholderName = "";
  1725. ccp.PayMoney = costDto.price;// dto
  1726. ccp.PaymentCurrency = costDto.currency;// dto
  1727. ccp.CompanyBankNo = "";
  1728. ccp.OtherBankName = "";
  1729. ccp.OtherSideNo = "";
  1730. ccp.OtherSideName = "";
  1731. ccp.Remark = "";
  1732. ccp.CreateUserId = costDto.createUser;
  1733. ccp.CreateTime = DateTime.Now;
  1734. ccp.MFOperator = 0;
  1735. ccp.MFOperatorDate = "";
  1736. ccp.IsAuditDM = 0;
  1737. ccp.AuditDMOperate = 0;
  1738. ccp.AuditDMDate = "";
  1739. ccp.IsAuditMF = 0;
  1740. ccp.AuditMFOperate = 0;
  1741. ccp.AuditMFDate = "";
  1742. ccp.IsAuditGM = 0;
  1743. ccp.AuditGMOperate = 0;
  1744. ccp.AuditGMDate = "";
  1745. ccp.IsPay = ispay; // upd
  1746. ccp.DIId = costDto.diId;// dto
  1747. ccp.CId = costDto.Id;// dto
  1748. ccp.CTable = 1015; //超支费用指向id
  1749. ccp.IsDel = 0;
  1750. ccp.PayPercentage = 100M;
  1751. ccp.PayThenMoney = 0M;
  1752. ccp.PayPercentageOld = 100M;
  1753. ccp.PayThenMoneyOld = 0M;
  1754. ccp.UpdateDate = "";
  1755. ccp.Payee = costDto.payee;// dto
  1756. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1757. ccp.ExceedBudget = 0;
  1758. ccp.DayRate = dcm_dayrate; //upd
  1759. ccp.RMBPrice = dcm_rmbPrice; //upd
  1760. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1761. if (ccpInsertId > 0)
  1762. {
  1763. return true;
  1764. }
  1765. }
  1766. else
  1767. {
  1768. if (costDto.editType == 2)
  1769. {
  1770. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1771. {
  1772. PayDId = costDto.payType,
  1773. CTDId = costDto.payCardId,
  1774. PayMoney = costDto.price,
  1775. PaymentCurrency = costDto.currency,
  1776. IsPay = ispay,
  1777. Payee = costDto.payee,
  1778. OrbitalPrivateTransfer = costDto.costSign,
  1779. DayRate = dcm_dayrate,
  1780. RMBPrice = dcm_rmbPrice
  1781. });
  1782. return res;
  1783. }
  1784. else if (costDto.editType == 3)
  1785. {
  1786. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1787. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1788. {
  1789. IsDel = 1,
  1790. DeleteTime = delTime,
  1791. DeleteUserId = costDto.createUser
  1792. });
  1793. return res2;
  1794. }
  1795. }
  1796. return false;
  1797. }
  1798. /// <summary>
  1799. /// 超支费用
  1800. /// 列表查询
  1801. /// </summary>
  1802. /// <param name="dto"></param>
  1803. /// <returns></returns>
  1804. [HttpPost]
  1805. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1806. public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
  1807. {
  1808. string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
  1809. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  1810. int endIndex = startIndex + dto.PageSize - 1;
  1811. string sql_data = string.Format(@"Select * From (
  1812. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  1813. f.PriceName,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  1814. From Fin_GroupExtraCost f
  1815. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  1816. Left Join Sys_Users u On f.CreateUserId = u.Id
  1817. Where f.IsDel=0 And c.CTable = 1015 {0}
  1818. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  1819. string sql_count = string.Format(@"Select Count(1) as DataCount From (
  1820. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  1821. f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  1822. From Fin_GroupExtraCost f
  1823. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  1824. Left Join Sys_Users u On f.CreateUserId = u.Id
  1825. Where f.IsDel=0 And c.CTable = 1015 {0}
  1826. ) temp ", sqlWhere);
  1827. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  1828. {
  1829. //Fin_DailyFeePaymentPageCount
  1830. var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
  1831. List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
  1832. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  1833. Dictionary<int, string> dic_user = new Dictionary<int, string>();
  1834. foreach (var item in dataList)
  1835. {
  1836. //费用详细类型
  1837. if (dic_setData.ContainsKey(item.PriceType))
  1838. {
  1839. item.PriceTypeStr = dic_setData[item.PriceType];
  1840. }
  1841. else
  1842. {
  1843. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
  1844. if (sd_priceTypeDetail != null)
  1845. {
  1846. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  1847. item.PriceTypeStr = tempName;
  1848. dic_setData.Add(item.PriceType, tempName);
  1849. }
  1850. }
  1851. //系统用户
  1852. if (dic_user.ContainsKey(item.CreateUserId))
  1853. {
  1854. item.CreateUserIdStr = dic_setData[item.CreateUserId];
  1855. }
  1856. else
  1857. {
  1858. Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
  1859. if (users != null)
  1860. {
  1861. item.CreateUserIdStr = users.CnName;
  1862. dic_setData.Add(item.CreateUserId, users.CnName);
  1863. }
  1864. }
  1865. switch (item.IsAuditGM)
  1866. {
  1867. case 0: item.IsAuditGMStr = "未审核"; break;
  1868. case 1: item.IsAuditGMStr = "已通过"; break;
  1869. case 2: item.IsAuditGMStr = "未通过"; break;
  1870. default: item.IsAuditGMStr = "未知状态"; break;
  1871. }
  1872. }
  1873. var result = new ListViewBase<Fin_GroupExtraCostView>
  1874. {
  1875. CurrPageIndex = dto.PageIndex,
  1876. CurrPageSize = dto.PageSize,
  1877. DataCount = count.DataCount,
  1878. DataList = dataList
  1879. };
  1880. return Ok(JsonView(true, "查询成功", result));
  1881. }
  1882. return Ok(JsonView(false, "查询成功"));
  1883. }
  1884. /// <summary>
  1885. /// 超支费用
  1886. /// 数据集合配置
  1887. /// </summary>
  1888. /// <param name="dto"></param>
  1889. /// <returns></returns>
  1890. [HttpPost]
  1891. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1892. public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
  1893. {
  1894. //支付方式
  1895. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  1896. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  1897. //超支费用类型
  1898. List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
  1899. List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
  1900. //超支费用详细类型
  1901. List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
  1902. PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
  1903. List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
  1904. var data = new
  1905. {
  1906. Payment = _Payment,
  1907. PriceType = _PriceType,
  1908. PriceDetailType = _PriceDetailType
  1909. };
  1910. return Ok(JsonView(true, "", data));
  1911. }
  1912. #endregion
  1913. }
  1914. }