FinancialController.cs 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328
  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. using Google.Protobuf;
  28. using NPOI.SS.Formula.Functions;
  29. using System.Globalization;
  30. namespace OASystem.API.Controllers
  31. {
  32. /// <summary>
  33. /// 财务模块
  34. /// </summary>
  35. [Route("api/[controller]/[action]")]
  36. [ApiController]
  37. public class FinancialController : ControllerBase
  38. {
  39. private readonly IMapper _mapper;
  40. private readonly IConfiguration _config;
  41. private readonly SqlSugarClient _sqlSugar;
  42. private readonly HttpClient _httpClient;
  43. private readonly SetDataTypeRepository _setDataTypeRep;
  44. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  45. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  46. private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
  47. private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
  48. private readonly PaymentRefundAndOtherMoneyRepository _paymentRefundAndOtherMoneyRep; //收款退还与其他款项 仓库
  49. /// <summary>
  50. /// 初始化
  51. /// </summary>
  52. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
  53. TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
  54. PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient)
  55. {
  56. _mapper = mapper;
  57. _config = configuration;
  58. _daiRep = daiRep;
  59. _sqlSugar = sqlSugar;
  60. _setDataTypeRep = setDataTypeRep;
  61. _teamRateRep = teamRateRep;
  62. _ForForeignReceivablesRep = ForForeignReceivablesRep;
  63. _proceedsReceivedRep = proceedsReceivedRep;
  64. _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
  65. _httpClient = httpClient;
  66. }
  67. #region 日付申请
  68. /// <summary>
  69. /// 获取日付申请 基础数据源
  70. /// </summary>
  71. /// <param name="dto"> 日付申请 分页 dto</param>
  72. /// <returns></returns>
  73. [HttpPost]
  74. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  75. public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
  76. {
  77. var result = await _daiRep.GetPagePriceTypeData(dto);
  78. if (result == null || result.Code != 0)
  79. {
  80. return Ok(JsonView(false, result.Msg));
  81. }
  82. var data = result.Data;
  83. return Ok(JsonView(data));
  84. }
  85. /// <summary>
  86. /// 获取日付申请 基础数据源 - 转账表识
  87. /// </summary>
  88. /// <param name="dto"> 日付申请 分页 dto</param>
  89. /// <returns></returns>
  90. [HttpPost]
  91. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  92. public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
  93. {
  94. var result = await _daiRep.GetPriceTypeAddData(dto);
  95. if (result == null || result.Code != 0)
  96. {
  97. return Ok(JsonView(false, result.Msg));
  98. }
  99. var data = result.Data;
  100. return Ok(JsonView(data));
  101. }
  102. /// <summary>
  103. /// 日付申请 Page Search
  104. /// </summary>
  105. /// <param name="dto"> 日付申请 分页 dto</param>
  106. /// <returns></returns>
  107. [HttpPost]
  108. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  109. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  110. {
  111. var result = await _daiRep.GetPageSearchAll(dto);
  112. if (result == null || result.Code != 0)
  113. {
  114. return Ok(JsonView(false, result.Msg));
  115. }
  116. var data = result.Data;
  117. if (data == null)
  118. {
  119. return Ok(JsonView(false, result.Msg));
  120. }
  121. return Ok(JsonView(data));
  122. }
  123. /// <summary>
  124. /// 日付申请 Single Search By Id
  125. /// </summary>
  126. /// <param name="dto"></param>
  127. /// <returns></returns>
  128. [HttpPost]
  129. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  130. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  131. {
  132. var result = await _daiRep.GetSearchById(dto);
  133. if (result == null || result.Code != 0)
  134. {
  135. return Ok(JsonView(false, result.Msg));
  136. }
  137. return Ok(JsonView(result.Data));
  138. }
  139. /// <summary>
  140. /// 日付申请 添加
  141. /// </summary>
  142. /// <param name="dto"> 日付申请 添加 dto</param>
  143. /// <returns></returns>
  144. [HttpPost]
  145. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  146. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  147. {
  148. var result = await _daiRep.Add(dto);
  149. if (result == null || result.Code != 0)
  150. {
  151. return Ok(JsonView(false, result.Msg));
  152. }
  153. return Ok(JsonView(true));
  154. }
  155. /// <summary>
  156. /// 日付申请 Update
  157. /// </summary>
  158. /// <param name="dto"> 日付申请 修改 dto</param>
  159. /// <returns></returns>
  160. [HttpPost]
  161. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  162. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  163. {
  164. var result = await _daiRep.Edit(dto);
  165. if (result == null || result.Code != 0)
  166. {
  167. return Ok(JsonView(false, result.Msg));
  168. }
  169. return Ok(JsonView(true));
  170. }
  171. /// <summary>
  172. /// 日付申请 Del
  173. /// </summary>
  174. /// <param name="dto"> 日付申请 删除 dto</param>
  175. /// <returns></returns>
  176. [HttpPost]
  177. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  178. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  179. {
  180. var result = await _daiRep.Del(dto);
  181. if (result == null || result.Code != 0)
  182. {
  183. return Ok(JsonView(false, result.Msg));
  184. }
  185. return Ok(JsonView(true));
  186. }
  187. /// <summary>
  188. /// 日付申请 财务审核
  189. /// </summary>
  190. /// <param name="dto"> dto </param>
  191. /// <returns></returns>
  192. [HttpPost]
  193. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  194. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  195. {
  196. var result = await _daiRep.DelDailyPaymentAudit(dto);
  197. if (result == null || result.Code != 0)
  198. {
  199. return Ok(JsonView(false, result.Msg));
  200. }
  201. return Ok(JsonView(true));
  202. }
  203. /// <summary>
  204. /// 日付申请 Single Excel Download
  205. /// </summary>
  206. /// <param name="dto"> dto </param>
  207. /// <returns></returns>
  208. [HttpPost]
  209. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  210. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  211. {
  212. if (dto.PortType == 1 || dto.PortType == 2)
  213. {
  214. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  215. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  216. Where IsDel=0 And Id = {0} ", dto.Id);
  217. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  218. if (feeData == null)
  219. {
  220. return Ok(JsonView(false, "暂无数据!"));
  221. }
  222. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  223. Where IsDel=0 And DFPId = {0} ", dto.Id);
  224. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  225. if (feeData != null)
  226. {
  227. string userName = string.Empty;
  228. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  229. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  230. if (user != null) { userName = user.CnName; }
  231. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  232. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  233. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  234. Dictionary<string, object> pairs = new Dictionary<string, object>();
  235. List<DataTable> datas = new List<DataTable>();
  236. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  237. //{
  238. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  239. // // pairs, datas);
  240. //}
  241. //else //日付常规模板
  242. //{
  243. pairs.Clear();
  244. pairs.Add("Opertor", userName);
  245. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  246. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  247. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  248. pairs.Add("SumPrice", feeData.SumPrice);
  249. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  250. datas.Clear();
  251. datas.Add(data);
  252. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  253. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  254. return Ok(JsonView(true, msg));
  255. //}
  256. }
  257. else
  258. {
  259. return Ok(JsonView(false, "暂无数据!"));
  260. }
  261. }
  262. return Ok(JsonView(true));
  263. }
  264. #endregion
  265. #region 团组提成
  266. /// <summary>
  267. /// 提成 Page Search
  268. /// </summary>
  269. /// <param name="dto"> 提成 分页 dto</param>
  270. /// <returns></returns>
  271. [HttpPost]
  272. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  273. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  274. {
  275. var data = await GroupCommission.GetCommissionPageList(dto);
  276. return Ok(JsonView(data.Data));
  277. }
  278. #endregion
  279. #region 团组汇率
  280. /// <summary>
  281. /// 团组汇率 Select数据源(团组列,汇率列)
  282. /// </summary>
  283. /// <param name="dto"></param>
  284. /// <returns></returns>
  285. [HttpPost]
  286. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  287. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  288. {
  289. try
  290. {
  291. Result teamRateData = await _teamRateRep.GetGroupRateDataSource(dto);
  292. if (teamRateData.Code != 0)
  293. {
  294. return Ok(JsonView(false, teamRateData.Msg));
  295. }
  296. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  297. }
  298. catch (Exception ex)
  299. {
  300. return Ok(JsonView(false, ex.Message));
  301. throw;
  302. }
  303. }
  304. ///// <summary>
  305. ///// 团组汇率 changge
  306. ///// </summary>
  307. ///// <returns></returns>
  308. //[HttpPost]
  309. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  310. //public async Task<IActionResult> ChangeGroupRateInfo()
  311. //{
  312. // try
  313. // {
  314. // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  315. // if (teamRateData.Code != 0)
  316. // {
  317. // return Ok(JsonView(false, teamRateData.Msg));
  318. // }
  319. // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  320. // }
  321. // catch (Exception ex)
  322. // {
  323. // return Ok(JsonView(false, ex.Message));
  324. // throw;
  325. // }
  326. //}
  327. /// <summary>
  328. /// 团组汇率 Select汇率详情
  329. /// </summary>
  330. /// <param name="dto"></param>
  331. /// <returns></returns>
  332. [HttpPost]
  333. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  334. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  335. {
  336. try
  337. {
  338. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  339. if (teamRateData.Code != 0)
  340. {
  341. return Ok(JsonView(false, teamRateData.Msg));
  342. }
  343. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  344. }
  345. catch (Exception ex)
  346. {
  347. return Ok(JsonView(false, ex.Message));
  348. throw;
  349. }
  350. }
  351. /// <summary>
  352. /// 团组汇率 添加 or 更新
  353. /// </summary>
  354. /// <param name="dto"></param>
  355. /// <returns></returns>
  356. [HttpPost]
  357. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  358. public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
  359. {
  360. try
  361. {
  362. Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
  363. if (teamRateData.Code != 0)
  364. {
  365. return Ok(JsonView(false, teamRateData.Msg));
  366. }
  367. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  368. }
  369. catch (Exception ex)
  370. {
  371. return Ok(JsonView(false, ex.Message));
  372. throw;
  373. }
  374. }
  375. #endregion
  376. #region 对外收款账单 关联已收款项
  377. /// <summary>
  378. /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
  379. /// 关联已收款项
  380. /// </summary>
  381. /// <param name="dto"></param>
  382. /// <returns></returns>
  383. [HttpPost]
  384. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  385. public async Task<IActionResult> GetForeignReceivablesDataSources()
  386. {
  387. try
  388. {
  389. Result ffrData = await _ForForeignReceivablesRep.GetDataSource();
  390. if (ffrData.Code != 0)
  391. {
  392. return Ok(JsonView(false, ffrData.Msg));
  393. }
  394. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  395. }
  396. catch (Exception ex)
  397. {
  398. return Ok(JsonView(false, ex.Message));
  399. throw;
  400. }
  401. }
  402. /// <summary>
  403. /// 对外收款账单
  404. /// 账单详情
  405. /// 关联已收款项
  406. /// </summary>
  407. /// <param name="dto"></param>
  408. /// <returns></returns>
  409. [HttpPost]
  410. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  411. public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  412. {
  413. try
  414. {
  415. Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
  416. if (ffrData.Code != 0)
  417. {
  418. return Ok(JsonView(false, ffrData.Msg));
  419. }
  420. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  421. }
  422. catch (Exception ex)
  423. {
  424. return Ok(JsonView(false, ex.Message));
  425. throw;
  426. }
  427. }
  428. /// <summary>
  429. /// 对外收款账单
  430. /// 账单 删除
  431. /// 关联已收款项
  432. /// </summary>
  433. /// <param name="dto"></param>
  434. /// <returns></returns>
  435. [HttpPost]
  436. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  437. public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
  438. {
  439. try
  440. {
  441. Result ffrData = await _ForForeignReceivablesRep._Del(dto);
  442. if (ffrData.Code != 0)
  443. {
  444. return Ok(JsonView(false, ffrData.Msg));
  445. }
  446. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  447. }
  448. catch (Exception ex)
  449. {
  450. return Ok(JsonView(false, ex.Message));
  451. throw;
  452. }
  453. }
  454. /// <summary>
  455. /// 对外收款账单
  456. /// 添加 And 更新
  457. /// 关联已收款项
  458. /// </summary>
  459. /// <param name="dto"></param>
  460. /// <returns></returns>
  461. [HttpPost]
  462. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  463. public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  464. {
  465. try
  466. {
  467. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
  468. if (ffrData.Code != 0)
  469. {
  470. return Ok(JsonView(false, ffrData.Msg));
  471. }
  472. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  473. }
  474. catch (Exception ex)
  475. {
  476. return Ok(JsonView(false, ex.Message));
  477. throw;
  478. }
  479. }
  480. /// <summary>
  481. /// 已收款项
  482. /// 账单 删除
  483. /// 关联已收款项
  484. /// </summary>
  485. /// <param name="dto"></param>
  486. /// <returns></returns>
  487. [HttpPost]
  488. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  489. public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
  490. {
  491. try
  492. {
  493. Result ffrData = await _proceedsReceivedRep._Del(dto);
  494. if (ffrData.Code != 0)
  495. {
  496. return Ok(JsonView(false, ffrData.Msg));
  497. }
  498. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  499. }
  500. catch (Exception ex)
  501. {
  502. return Ok(JsonView(false, ex.Message));
  503. throw;
  504. }
  505. }
  506. /// <summary>
  507. /// 已收款项
  508. /// 添加 And 更新
  509. /// 关联已收款项
  510. /// </summary>
  511. /// <param name="dto"></param>
  512. /// <returns></returns>
  513. [HttpPost]
  514. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  515. public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
  516. {
  517. try
  518. {
  519. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
  520. if (ffrData.Code != 0)
  521. {
  522. return Ok(JsonView(false, ffrData.Msg));
  523. }
  524. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  525. }
  526. catch (Exception ex)
  527. {
  528. return Ok(JsonView(false, ex.Message));
  529. throw;
  530. }
  531. }
  532. /// <summary>
  533. /// 财务 已收款项
  534. /// 分配已收款项至 应收项下
  535. /// 关联已收款项
  536. /// </summary>
  537. /// <param name="dto"></param>
  538. /// <returns></returns>
  539. [HttpPost]
  540. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  541. public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
  542. {
  543. try
  544. {
  545. Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
  546. if (ffrData.Code != 0)
  547. {
  548. return Ok(JsonView(false, ffrData.Msg));
  549. }
  550. return Ok(JsonView(true));
  551. }
  552. catch (Exception ex)
  553. {
  554. return Ok(JsonView(false, ex.Message));
  555. throw;
  556. }
  557. }
  558. ///// <summary>
  559. ///// 财务 收款账单
  560. ///// 导出Word(北京,四川)
  561. ///// </summary>
  562. ///// <param name="dto"></param>
  563. ///// <returns></returns>
  564. //[HttpPost]
  565. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  566. //public async Task<IActionResult> PostAccountReceivableWordExport(AccountReceivableWordExportDto dto)
  567. //{
  568. // try
  569. // {
  570. // //模板处理
  571. // string typeName = string.Empty;
  572. // if (dto.TemplateType == 1) //四川
  573. // {
  574. // typeName = "四川";
  575. // }
  576. // else if (dto.TemplateType == 2) //北京
  577. // {
  578. // typeName = "北京";
  579. // }
  580. // else return Ok(JsonView(false,"请选择正确的模板类型!"));
  581. // string wordTempName = string.Format("收款账单({0})模板.doc", typeName);
  582. // }
  583. // catch (Exception ex)
  584. // {
  585. // return Ok(JsonView(false, ex.Message));
  586. // }
  587. //}
  588. #endregion
  589. #region 对外收款账单
  590. /// <summary>
  591. /// 对外收款账单
  592. /// 数据源
  593. /// </summary>
  594. /// <param name="dto"></param>
  595. /// <returns></returns>
  596. [HttpPost]
  597. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  598. public async Task<IActionResult> PostGroupReceivablesDataSource()
  599. {
  600. try
  601. {
  602. Result ffrData = await _ForForeignReceivablesRep.PostDataSource();
  603. if (ffrData.Code != 0)
  604. {
  605. return Ok(JsonView(false, ffrData.Msg));
  606. }
  607. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  608. }
  609. catch (Exception ex)
  610. {
  611. return Ok(JsonView(false, ex.Message));
  612. }
  613. }
  614. /// <summary>
  615. /// 对外收款账单
  616. /// 账单详情
  617. /// </summary>
  618. /// <param name="dto"></param>
  619. /// <returns></returns>
  620. [HttpPost]
  621. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  622. public async Task<IActionResult> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  623. {
  624. try
  625. {
  626. Result ffrData = await _ForForeignReceivablesRep.PostGroupReceivablesInfoByDiId(dto);
  627. if (ffrData.Code != 0)
  628. {
  629. return Ok(JsonView(false, ffrData.Msg));
  630. }
  631. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  632. }
  633. catch (Exception ex)
  634. {
  635. return Ok(JsonView(false, ex.Message));
  636. }
  637. }
  638. /// <summary>
  639. /// 对外收款账单
  640. /// 添加 And 更新
  641. /// </summary>
  642. /// <param name="dto"></param>
  643. /// <returns></returns>
  644. [HttpPost]
  645. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  646. public async Task<IActionResult> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  647. {
  648. try
  649. {
  650. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesSave(dto);
  651. if (ffrData.Code != 0)
  652. {
  653. return Ok(JsonView(false, ffrData.Msg));
  654. }
  655. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  656. }
  657. catch (Exception ex)
  658. {
  659. return Ok(JsonView(false, ex.Message));
  660. throw;
  661. }
  662. }
  663. /// <summary>
  664. /// 已收账单
  665. /// 删除
  666. /// </summary>
  667. /// <param name="dto"></param>
  668. /// <returns></returns>
  669. [HttpPost]
  670. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  671. public async Task<IActionResult> PostReceivablesDel(ForeignReceivablesDelDto dto)
  672. {
  673. try
  674. {
  675. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesDel(dto);
  676. if (ffrData.Code != 0)
  677. {
  678. return Ok(JsonView(false, ffrData.Msg));
  679. }
  680. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  681. }
  682. catch (Exception ex)
  683. {
  684. return Ok(JsonView(false, ex.Message));
  685. throw;
  686. }
  687. }
  688. /// <summary>
  689. /// 已收账单
  690. /// File Downloasd
  691. /// </summary>
  692. /// <param name="dto"></param>
  693. /// <returns></returns>
  694. [HttpPost]
  695. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  696. public async Task<IActionResult> PostReceivablesFeilDownload(ForeignReceivablesFeilDownloadDto dto)
  697. {
  698. try
  699. {
  700. if (dto.DiId < 1)
  701. {
  702. return Ok(JsonView(false, "请传入有效DiId参数!"));
  703. }
  704. if (dto.FileType < 1 || dto.FileType > 3)
  705. {
  706. return Ok(JsonView(false, "请传入有效FileType参数! 1 生成收款单(四川) 2 生成收款单(北京) 3 汇款账单"));
  707. }
  708. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  709. if (_DelegationInfo == null)
  710. {
  711. return Ok(JsonView(false, "暂无团组信息!!"));
  712. }
  713. if (dto.FileType == 1 || dto.FileType == 2)
  714. {
  715. var _ForeignReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  716. if (_ForeignReceivables.Count < 1)
  717. {
  718. return Ok(JsonView(false, "暂无收款信息!!"));
  719. }
  720. string tempName = "";
  721. if (dto.FileType == 1) tempName = $"收款账单(四川)模板.docx";
  722. else if (dto.FileType == 2) tempName = $"收款账单(北京)模板.docx";
  723. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/{tempName}";
  724. //载入模板
  725. Document doc = new Document(tempPath);
  726. DocumentBuilder builder = new DocumentBuilder(doc);
  727. #region 替换Word模板书签内容
  728. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  729. //付款方
  730. if (doc.Range.Bookmarks["To"] != null)
  731. {
  732. Bookmark mark = doc.Range.Bookmarks["To"];
  733. mark.Text = _ForeignReceivables[0].To == null ? "" : _ForeignReceivables[0].To.ToString();
  734. }
  735. //付款方电话
  736. if (doc.Range.Bookmarks["ToTel"] != null)
  737. {
  738. Bookmark mark = doc.Range.Bookmarks["ToTel"];
  739. mark.Text = _ForeignReceivables[0].ToTel == null ? "" : _ForeignReceivables[0].ToTel.ToString();
  740. }
  741. //导出时间
  742. if (doc.Range.Bookmarks["Date"] != null)
  743. {
  744. Bookmark mark = doc.Range.Bookmarks["Date"];
  745. mark.Text = DateTime.Now.ToString("yyyy-MM-dd");
  746. }
  747. //注
  748. if (doc.Range.Bookmarks["Attention"] != null)
  749. {
  750. Bookmark mark = doc.Range.Bookmarks["Attention"];
  751. mark.Text = _ForeignReceivables[0].Attention == null ? "" : _ForeignReceivables[0].Attention.ToString();
  752. }
  753. //团队名称
  754. if (doc.Range.Bookmarks["Team"] != null)
  755. {
  756. Bookmark mark = doc.Range.Bookmarks["Team"];
  757. mark.Text = _DelegationInfo.VisitCountry == null ? "" : _DelegationInfo.VisitCountry.ToString();
  758. }
  759. //付款日期
  760. if (doc.Range.Bookmarks["PayDate"] != null)
  761. {
  762. Bookmark mark = doc.Range.Bookmarks["PayDate"];
  763. mark.Text = _ForeignReceivables[0].PayDate == null ? "" : Convert.ToDateTime(_ForeignReceivables[0].PayDate).ToString("yyyy年MM月dd日");
  764. }
  765. decimal sumPrice = 0;
  766. //各项费用
  767. if (doc.Range.Bookmarks["PayItemContent"] != null)
  768. {
  769. string items = "";
  770. foreach (var fr in _ForeignReceivables)
  771. {
  772. items += fr.PriceName + " " + fr.Currency + " " + fr.Price.ToString("#0.00") + " * " + fr.Count + " " + fr.Unit + " * " + fr.Rate + ".................. RMB " + fr.ItemSumPrice.ToString("#0.00") + "\n";
  773. sumPrice += fr.ItemSumPrice;
  774. }
  775. Bookmark mark = doc.Range.Bookmarks["PayItemContent"];
  776. mark.Text = items;
  777. }
  778. //合计
  779. if (doc.Range.Bookmarks["Total"] != null)
  780. {
  781. Bookmark mark = doc.Range.Bookmarks["Total"];
  782. mark.Text = sumPrice.ToString("#0.00");
  783. }
  784. #endregion
  785. //文件名
  786. string strFileName = _DelegationInfo.TeamName + "-收款账单.docx";
  787. doc.Save(AppSettingsHelper.Get("WordBasePath") + "ForeignReceivables/File/" + strFileName);
  788. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/ForeignReceivables/File/" + strFileName;
  789. return Ok(JsonView(true, "成功", new { Url = url }));
  790. }
  791. else if (dto.FileType == 3) //汇款通知
  792. {
  793. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  794. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  795. if (_EnterExitCosts == null)
  796. {
  797. return Ok(JsonView(false, "该团组未填写出入境费用;"));
  798. }
  799. //数据源
  800. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  801. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  802. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  803. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  804. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  805. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  806. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  807. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  808. .Select((tcl, dc, cc) => new
  809. {
  810. Name = dc.LastName + dc.FirstName,
  811. Sex = dc.Sex,
  812. Birthday = dc.BirthDay,
  813. Company = cc.CompanyFullName,
  814. Job = dc.Job,
  815. AirType = tcl.ShippingSpaceTypeId
  816. })
  817. .ToList();
  818. if (DeleClientList.Count<1)
  819. {
  820. return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
  821. }
  822. var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
  823. var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
  824. Dictionary<string, string> bookmarkArr = null;
  825. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
  826. //载入模板
  827. Document doc = new Document(tempPath);
  828. DocumentBuilder builder = null;
  829. List<string> filesToZip = new List<string>();
  830. foreach (var ClientItem in _GroupClient) //遍历单位
  831. {
  832. doc = new Document(tempPath);
  833. builder = new DocumentBuilder(doc);
  834. Paragraph paragraph = new Paragraph(doc);
  835. bookmarkArr = new Dictionary<string, string>();
  836. bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
  837. bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
  838. bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
  839. bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
  840. bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry);//出访国家
  841. bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
  842. var ClientItemList = ClientItem.ToList();
  843. string UsersTop = string.Empty;//word中人员以及金额
  844. decimal WordAllPrice = 0.00M;
  845. //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(),
  846. // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
  847. //遍历人员
  848. for (int i = 0; i < ClientItemList.Count(); i++)
  849. {
  850. Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
  851. var client = ClientItemList[i]; //每个人员
  852. var firstName = ClientItemList[i].Name;
  853. //计算费用总和
  854. decimal airPrice = client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW;
  855. decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
  856. dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
  857. _EnterExitCosts.Service;
  858. WordAllPrice += AllPrice;
  859. UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
  860. TeableBookmarkArr.Add("jp",(client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW).ToString("#0.00") + " 元"); //机票金额
  861. TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
  862. TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
  863. string zsinfo = string.Empty;
  864. string hsinfo = string.Empty;
  865. string gzinfo = string.Empty;
  866. List<string> placeArr = new List<string>();
  867. Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  868. Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
  869. Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
  870. Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
  871. int rowIndex = 0;
  872. foreach (var item in dac1)
  873. {
  874. if (string.IsNullOrWhiteSpace(item.Place))
  875. {
  876. continue;
  877. }
  878. if (placeArr.Contains(item.Place))
  879. {
  880. continue;
  881. }
  882. else
  883. {
  884. placeArr.Add(item.Place);
  885. }
  886. if (!string.IsNullOrWhiteSpace(item.Place))
  887. {
  888. if (rowIndex > ChildTable.Rows.Count - 1)
  889. {
  890. var chitableRow = ChildTable.LastRow.Clone(true);
  891. ChildTable.AppendChild(chitableRow);
  892. }
  893. int days = dac1.FindAll(x => x.Place == item.Place).Count();
  894. SetCells(ChildTable, doc, rowIndex, 0, item.Place);
  895. SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
  896. SetCells(ChildTable, doc, rowIndex, 2, item.Cost + item.Currency + "/晚");
  897. SetCells(ChildTable, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  898. SetCells(ChildTable, doc, rowIndex, 4, "CNY" + item.SubTotal * days + "\r\n");
  899. rowIndex++;
  900. zsinfo += item.Place + " " + days + "晚 " + item.Cost + item.Currency + "/晚" + " 汇率" + (item.SubTotal /item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  901. }
  902. }
  903. placeArr.Clear();
  904. rowIndex = 0;
  905. foreach (var item in dac2)
  906. {
  907. if (string.IsNullOrWhiteSpace(item.Place))
  908. {
  909. continue;
  910. }
  911. if (placeArr.Contains(item.Place))
  912. {
  913. continue;
  914. }
  915. else
  916. {
  917. placeArr.Add(item.Place);
  918. }
  919. if (!string.IsNullOrWhiteSpace(item.Place))
  920. {
  921. if (rowIndex > ChildTable1.Rows.Count - 1)
  922. {
  923. var chitableRow = ChildTable1.LastRow.Clone(true);
  924. ChildTable1.AppendChild(chitableRow);
  925. }
  926. int days = dac2.FindAll(x => x.Place == item.Place).Count();
  927. SetCells(ChildTable1, doc, rowIndex, 0, item.Place);
  928. SetCells(ChildTable1, doc, rowIndex, 1, days + "天");
  929. SetCells(ChildTable1, doc, rowIndex, 2, item.Cost + item.Currency + "/天");
  930. SetCells(ChildTable1, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  931. SetCells(ChildTable1, doc, rowIndex, 4, "CNY" +item.SubTotal * days);
  932. rowIndex++;
  933. hsinfo += item.Place + " " + days + "天 " + item.Cost + item.Currency + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" +item.SubTotal * days + "\r\n";
  934. }
  935. }
  936. placeArr.Clear();
  937. rowIndex = 0;
  938. foreach (var item in dac3)
  939. {
  940. if (string.IsNullOrWhiteSpace(item.Place))
  941. {
  942. continue;
  943. }
  944. if (placeArr.Contains(item.Place))
  945. {
  946. continue;
  947. }
  948. else
  949. {
  950. placeArr.Add(item.Place);
  951. }
  952. if (!string.IsNullOrWhiteSpace(item.Place))
  953. {
  954. if (rowIndex > ChildTable2.Rows.Count - 1)
  955. {
  956. var chitableRow = ChildTable2.LastRow.Clone(true);
  957. ChildTable2.AppendChild(chitableRow);
  958. }
  959. int days = dac3.FindAll(x => x.Place == item.Place).Count();
  960. SetCells(ChildTable2, doc, rowIndex, 0, item.Place);
  961. SetCells(ChildTable2, doc, rowIndex, 1, days + "天");
  962. SetCells(ChildTable2, doc, rowIndex, 2, item.Cost + item.Currency + "/天");
  963. SetCells(ChildTable2, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  964. SetCells(ChildTable2, doc, rowIndex, 4, "CNY" + item.SubTotal * days + "\r\n");
  965. rowIndex++;
  966. gzinfo += item.Place + " " + days + "天 " + item.Cost + item.Currency + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  967. }
  968. }
  969. placeArr.Clear();
  970. TeableBookmarkArr.Add("zsinfo", zsinfo); //住宿费详情
  971. TeableBookmarkArr.Add("hs", dac2.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //伙食费
  972. TeableBookmarkArr.Add("hsinfo", hsinfo); //伙食费详情
  973. TeableBookmarkArr.Add("gz", dac3.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //公杂费
  974. TeableBookmarkArr.Add("gzinfo", gzinfo); //公杂费详情
  975. TeableBookmarkArr.Add("qt", (_EnterExitCosts.Visa + _EnterExitCosts.Safe).ToString("#0.00") + " 元");//其他费用
  976. TeableBookmarkArr.Add("qtinfo", $"(签证费{_EnterExitCosts.Visa.ToString("#0.00")}元、保险{_EnterExitCosts.Safe.ToString("#0.00")}元等费用)");//其他费用第二列
  977. TeableBookmarkArr.Add("fw", _EnterExitCosts.Service.ToString("#0.00") + "元/人");//服务费
  978. TeableBookmarkArr.Add("AllPrice", AllPrice.ToString("#0.00") + "元/人");//表格合计费用
  979. string airStr = client.AirType == 460 ? "经济舱" : client.AirType == 458 ? "公务舱" : "";
  980. TeableBookmarkArr.Add("title", $"费用清单-{airStr}({firstName})");
  981. foreach (var book in TeableBookmarkArr.Keys)
  982. {
  983. if (doc.Range.Bookmarks[book] != null)
  984. {
  985. Bookmark mark = doc.Range.Bookmarks[book];
  986. mark.Text = TeableBookmarkArr[book];
  987. }
  988. }
  989. if (i != ClientItemList.Count - 1)
  990. {
  991. builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
  992. Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  993. table.ParentNode.InsertAfter(paragraph, table);
  994. var CloneTable = (Aspose.Words.Tables.Table)table.Clone(true);
  995. table.ParentNode.InsertAfter(CloneTable, paragraph);
  996. }
  997. TeableBookmarkArr.Clear();
  998. }
  999. bookmarkArr.Add("VisitPrice", WordAllPrice.ToString());//出访费用总额
  1000. bookmarkArr.Add("CnAllPrice", WordAllPrice.ConvertCNYUpper());//出访费用总额中文
  1001. bookmarkArr.Add("namesPrice", UsersTop.TrimEnd('、'));//各人员出访费用 付辰同志出访费用为¥73,604.8元
  1002. foreach (var book in bookmarkArr.Keys)
  1003. {
  1004. if (doc.Range.Bookmarks[book] != null)
  1005. {
  1006. Bookmark mark = doc.Range.Bookmarks[book];
  1007. mark.Text = bookmarkArr[book];
  1008. }
  1009. }
  1010. //MemoryStream outSteam = new MemoryStream();
  1011. string filsPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/File/{ClientItem.Key}.docx";
  1012. doc.Save(filsPath);
  1013. filesToZip.Add(filsPath);
  1014. //streams.Add(ClientItem.Key + ".docx", outSteam.ToArray());
  1015. }
  1016. //文件名
  1017. string zipFileName = _DelegationInfo.TeamName + "-收款账单.zip";
  1018. string zipPath = $"ForeignReceivables/File/{_DelegationInfo.TeamName}-收款账单{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  1019. try
  1020. {
  1021. using (var zip = ZipFile.Open(AppSettingsHelper.Get("WordBasePath") + zipPath, ZipArchiveMode.Create))
  1022. {
  1023. foreach (var file in filesToZip)
  1024. {
  1025. zip.CreateEntryFromFile(file, Path.GetFileName(file));
  1026. }
  1027. }
  1028. }
  1029. catch (Exception ex)
  1030. {
  1031. return Ok(JsonView(false, ex.Message));
  1032. }
  1033. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{zipPath}";
  1034. return Ok(JsonView(true, "成功", new { Url = url }));
  1035. }
  1036. return Ok(JsonView(false, "操作失败!"));
  1037. }
  1038. catch (Exception ex)
  1039. {
  1040. return Ok(JsonView(false, ex.Message));
  1041. }
  1042. }
  1043. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val)
  1044. {
  1045. //获取table中的某个单元格,从0开始
  1046. Aspose.Words.Tables.Cell lshCell = table.Rows[rows].Cells[cells];
  1047. //将单元格中的第一个段落移除
  1048. lshCell.FirstParagraph.Remove();
  1049. //新建一个段落
  1050. Paragraph p = new Paragraph(doc);
  1051. var r = new Run(doc, val);
  1052. r.Font.Size = 8;
  1053. //把设置的值赋给之前新建的段落
  1054. p.AppendChild(r);
  1055. //将此段落加到单元格内
  1056. lshCell.AppendChild(p);
  1057. }
  1058. #endregion
  1059. #region 已收款项
  1060. /// <summary>
  1061. /// 已收款项
  1062. /// 查询
  1063. /// </summary>
  1064. /// <param name="dto"></param>
  1065. /// <returns></returns>
  1066. [HttpPost]
  1067. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1068. public async Task<IActionResult> PostAmountReceived(AmountReceivedDto dto)
  1069. {
  1070. try
  1071. {
  1072. if (dto == null)
  1073. {
  1074. return Ok(JsonView(false, "参数不能为空!"));
  1075. }
  1076. Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
  1077. dynamic data = null;
  1078. if (dto.PortType == 1)
  1079. {
  1080. if (ffrData.Code != 0)
  1081. {
  1082. return Ok(JsonView(false, ffrData.Msg));
  1083. }
  1084. data = ffrData.Data;
  1085. }
  1086. else if (dto.PortType == 2)
  1087. {
  1088. if (ffrData.Code != 0)
  1089. {
  1090. return Ok(JsonView(false, ffrData.Msg));
  1091. }
  1092. data = ffrData.Data;
  1093. }
  1094. else if (dto.PortType == 2)
  1095. {
  1096. if (ffrData.Code != 0)
  1097. {
  1098. return Ok(JsonView(false, ffrData.Msg));
  1099. }
  1100. data = ffrData.Data;
  1101. }
  1102. else
  1103. {
  1104. return Ok(JsonView(false, "请选择正确的端口号!"));
  1105. }
  1106. return Ok(JsonView(true, "操作成功!", data));
  1107. }
  1108. catch (Exception ex)
  1109. {
  1110. return Ok(JsonView(false, ex.Message));
  1111. }
  1112. }
  1113. /// <summary>
  1114. /// 已收款项
  1115. /// Add Or Edit
  1116. /// </summary>
  1117. /// <param name="dto"></param>
  1118. /// <returns></returns>
  1119. [HttpPost]
  1120. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1121. public async Task<IActionResult> PostAmountReceivedAddOrEdit(AmountReceivedAddOrEditDto dto)
  1122. {
  1123. try
  1124. {
  1125. if (dto == null)
  1126. {
  1127. return Ok(JsonView(false, "参数不能为空!"));
  1128. }
  1129. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedAddOrEditDto(dto);
  1130. if (dto.PortType == 1)
  1131. {
  1132. if (ffrData.Code != 0)
  1133. {
  1134. return Ok(JsonView(false, ffrData.Msg));
  1135. }
  1136. }
  1137. else if (dto.PortType == 2)
  1138. {
  1139. if (ffrData.Code != 0)
  1140. {
  1141. return Ok(JsonView(false, ffrData.Msg));
  1142. }
  1143. }
  1144. else if (dto.PortType == 2)
  1145. {
  1146. if (ffrData.Code != 0)
  1147. {
  1148. return Ok(JsonView(false, ffrData.Msg));
  1149. }
  1150. }
  1151. else
  1152. {
  1153. return Ok(JsonView(false, "请选择正确的端口号!"));
  1154. }
  1155. return Ok(JsonView(true, "操作成功!"));
  1156. }
  1157. catch (Exception ex)
  1158. {
  1159. return Ok(JsonView(false, ex.Message));
  1160. }
  1161. }
  1162. /// <summary>
  1163. /// 已收款项
  1164. /// Del
  1165. /// </summary>
  1166. /// <param name="dto"></param>
  1167. /// <returns></returns>
  1168. [HttpPost]
  1169. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1170. public async Task<IActionResult> PostAmountReceived_Del(AmountReceivedDelDto dto)
  1171. {
  1172. try
  1173. {
  1174. if (dto == null)
  1175. {
  1176. return Ok(JsonView(false, "参数不能为空!"));
  1177. }
  1178. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedDel(dto);
  1179. if (ffrData.Code != 0)
  1180. {
  1181. return Ok(JsonView(false, ffrData.Msg));
  1182. }
  1183. return Ok(JsonView(true, "操作成功!"));
  1184. }
  1185. catch (Exception ex)
  1186. {
  1187. return Ok(JsonView(false, ex.Message));
  1188. }
  1189. }
  1190. #endregion
  1191. #region 收款退还与其他款项
  1192. /// <summary>
  1193. /// 收款退还与其他款项
  1194. /// 查询 根据团组Id
  1195. /// </summary>
  1196. /// <param name="dto"></param>
  1197. /// <returns></returns>
  1198. [HttpPost]
  1199. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1200. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyItemByDiId(PaymentRefundAndOtherMoneyItemByDiIdDto dto)
  1201. {
  1202. try
  1203. {
  1204. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1205. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1206. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1207. #region 页面功能权限处理
  1208. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1209. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1210. if (pageFunAuth.CheckAuth == 0)
  1211. {
  1212. return Ok(JsonView(false, "您没有当前页面查询权限!"));
  1213. }
  1214. #endregion
  1215. Result _result = await _paymentRefundAndOtherMoneyRep._ItemByDiId(dto.DiId);
  1216. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  1217. {
  1218. if (_result.Code != 0)
  1219. {
  1220. return Ok(JsonView(false, _result.Msg));
  1221. }
  1222. var data = new
  1223. {
  1224. PageFuncAuth = pageFunAuth,
  1225. Data = _result.Data
  1226. };
  1227. return Ok(JsonView(true, "操作成功!", data));
  1228. }
  1229. else
  1230. {
  1231. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  1232. }
  1233. }
  1234. catch (Exception ex)
  1235. {
  1236. return Ok(JsonView(false, ex.Message));
  1237. }
  1238. }
  1239. /// <summary>
  1240. /// 收款退还与其他款项
  1241. /// 删除
  1242. /// </summary>
  1243. /// <param name="dto"></param>
  1244. /// <returns></returns>
  1245. [HttpPost]
  1246. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1247. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyDel(PaymentRefundAndOtherMoneyDelDto dto)
  1248. {
  1249. try
  1250. {
  1251. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1252. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1253. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1254. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1255. #region 页面功能权限处理
  1256. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1257. #endregion
  1258. if (pageFunAuth.DeleteAuth == 0)
  1259. {
  1260. return Ok(JsonView(false, "您没有当前页面删除权限!"));
  1261. }
  1262. Result _result = await _paymentRefundAndOtherMoneyRep._Del(dto);
  1263. if (_result.Code != 0)
  1264. {
  1265. return Ok(JsonView(false, _result.Msg));
  1266. }
  1267. return Ok(JsonView(true, "操作成功!"));
  1268. }
  1269. catch (Exception ex)
  1270. {
  1271. return Ok(JsonView(false, ex.Message));
  1272. }
  1273. }
  1274. /// <summary>
  1275. /// 收款退还与其他款项
  1276. /// Info Data Source
  1277. /// </summary>
  1278. /// <param name="dto"></param>
  1279. /// <returns></returns>
  1280. [HttpPost]
  1281. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1282. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfoDataSource(PortDtoBase dto)
  1283. {
  1284. try
  1285. {
  1286. Result _result = await _paymentRefundAndOtherMoneyRep._InfoDataSource(dto);
  1287. if (_result.Code != 0)
  1288. {
  1289. return Ok(JsonView(false, _result.Msg));
  1290. }
  1291. return Ok(JsonView(true, "查询成功!", _result.Data));
  1292. }
  1293. catch (Exception ex)
  1294. {
  1295. return Ok(JsonView(false, ex.Message));
  1296. }
  1297. }
  1298. /// <summary>
  1299. /// 收款退还与其他款项
  1300. /// Info
  1301. /// </summary>
  1302. /// <param name="dto"></param>
  1303. /// <returns></returns>
  1304. [HttpPost]
  1305. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1306. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfo(PaymentRefundAndOtherMoneyInfoDto dto)
  1307. {
  1308. try
  1309. {
  1310. if (dto == null)
  1311. {
  1312. return Ok(JsonView(false, "参数不能为空!"));
  1313. }
  1314. Result _result = await _paymentRefundAndOtherMoneyRep._Info(dto);
  1315. if (_result.Code != 0)
  1316. {
  1317. return Ok(JsonView(false, _result.Msg));
  1318. }
  1319. return Ok(JsonView(true, "查询成功!", _result.Data));
  1320. }
  1321. catch (Exception ex)
  1322. {
  1323. return Ok(JsonView(false, ex.Message));
  1324. }
  1325. }
  1326. /// <summary>
  1327. /// 收款退还与其他款项
  1328. /// 操作(Add Or Edit)
  1329. /// </summary>
  1330. /// <param name="dto"></param>
  1331. /// <returns></returns>
  1332. [HttpPost]
  1333. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1334. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyAddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
  1335. {
  1336. try
  1337. {
  1338. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1339. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1340. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1341. #region 页面功能权限处理
  1342. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1343. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1344. #endregion
  1345. if (dto.Status == 1) //add
  1346. {
  1347. if (pageFunAuth.AddAuth == 0)
  1348. {
  1349. return Ok(JsonView(false, "您没有当前页面添加权限!"));
  1350. }
  1351. }
  1352. else if (dto.Status == 2) //edit
  1353. {
  1354. if (pageFunAuth.EditAuth == 0)
  1355. {
  1356. return Ok(JsonView(false, "您没有当前页面编辑权限!"));
  1357. }
  1358. }
  1359. else
  1360. {
  1361. return Ok(JsonView(false, "请输入正确的操作状态! 1 添加 2 修改!"));
  1362. }
  1363. Result _result = await _paymentRefundAndOtherMoneyRep._AddOrEdit(dto);
  1364. if (_result.Code != 0)
  1365. {
  1366. return Ok(JsonView(false, _result.Msg));
  1367. }
  1368. return Ok(JsonView(true, "操作成功!"));
  1369. }
  1370. catch (Exception ex)
  1371. {
  1372. return Ok(JsonView(false, ex.Message));
  1373. }
  1374. }
  1375. #endregion
  1376. #region 应收报表
  1377. /// <summary>
  1378. /// 应收报表
  1379. /// 查询 根据日期范围
  1380. /// </summary>
  1381. /// <param name="dto"></param>
  1382. /// <returns></returns>
  1383. [HttpPost]
  1384. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1385. public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
  1386. {
  1387. string sqlWhere = " Where di.IsDel=0 ";
  1388. #region 验证
  1389. if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
  1390. {
  1391. return Ok(JsonView(false, "日期参数至少填写一个!"));
  1392. }
  1393. if (!string.IsNullOrEmpty(dto.beginDt))
  1394. {
  1395. if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1396. {
  1397. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1398. }
  1399. else
  1400. {
  1401. sqlWhere += string.Format(@" And di.VisitDate >= '{0} 00:00:00' ", dto.beginDt);
  1402. }
  1403. }
  1404. if (!string.IsNullOrEmpty(dto.endDt))
  1405. {
  1406. if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1407. {
  1408. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1409. }
  1410. else
  1411. {
  1412. sqlWhere += string.Format(@" And di.VisitDate <= '{0} 23:59:59' ", dto.endDt);
  1413. }
  1414. }
  1415. #endregion
  1416. 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);
  1417. List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
  1418. decimal sumAll_fr = 0M;
  1419. decimal sumAll_pr = 0M;
  1420. decimal sumAll_balance = 0M;
  1421. if (list_rst.Count > 0)
  1422. {
  1423. int rowNumber = 1;
  1424. foreach (var item_rst in list_rst)
  1425. {
  1426. item_rst.No = rowNumber;
  1427. rowNumber++;
  1428. int diId = item_rst.diid;
  1429. decimal sum_fr = 0M;
  1430. decimal sum_pr = 0M;
  1431. string str_client = string.Empty;
  1432. decimal sum_other = 0M; //收款退还
  1433. decimal sum_extra = 0M; //超支费用
  1434. decimal balance = 0M;
  1435. string str_schedule = string.Empty;
  1436. //1. 缺超支费用!!!!!!!!!!!!!!!!!!!!
  1437. string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
  1438. List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
  1439. sum_fr = list_fr.Sum(s => s.ItemSumPrice);
  1440. //2.
  1441. string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
  1442. List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
  1443. foreach (var item_pr in list_pr)
  1444. {
  1445. sum_pr += item_pr.Price;
  1446. str_client += string.Format(@"{0};", item_pr.Client);
  1447. str_schedule += string.Format(@"{0};", item_pr.Remark);
  1448. }
  1449. if (str_schedule.Length > 0)
  1450. {
  1451. str_schedule = str_schedule.TrimEnd(';');
  1452. }
  1453. if (str_client.Length > 0)
  1454. {
  1455. str_client = str_client.TrimEnd(';');
  1456. }
  1457. //3.
  1458. string sql_other = string.Format(@" Select * From Fin_OtherPrice where diid = {0} and isdel = 0 and RefundType = 1 and PayType=1 ", diId);
  1459. List<Fin_OtherPrice> list_other = _sqlSugar.SqlQueryable<Fin_OtherPrice>(sql_other).ToList();
  1460. sum_other = list_other.Sum(s => s.Price);
  1461. //4.
  1462. string sql_extra = string.Format(@" Select c.* From Fin_GroupExtraCost f
  1463. Inner join Grp_CreditCardPayment c On f.Id = c.CId
  1464. Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId = {0} ", diId);
  1465. List<Grp_CreditCardPayment> list_extra = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_extra).ToList();
  1466. sum_extra = list_extra.Sum(s => s.RMBPrice);
  1467. item_rst.frPrice = (sum_fr + sum_extra).ToString("#0.00");
  1468. item_rst.prPrice = (sum_pr - sum_other).ToString("#0.00");
  1469. item_rst.balPrice = ((sum_fr + sum_extra) - (sum_pr - sum_other)).ToString("#0.00");
  1470. item_rst.prClient = str_client;
  1471. item_rst.schedule = str_schedule;
  1472. string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
  1473. sumAll_fr += (sum_fr + sum_extra);
  1474. sumAll_pr += (sum_pr - sum_other);
  1475. sumAll_balance += ((sum_fr + sum_extra) - (sum_pr - sum_other));
  1476. }
  1477. PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
  1478. result.total_fr = sumAll_fr.ToString("#0.00");
  1479. result.total_pr = sumAll_pr.ToString("#0.00");
  1480. result.total_balance = sumAll_balance.ToString("#0.00");
  1481. result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
  1482. if (dto.requestType == 1)
  1483. {
  1484. return Ok(JsonView(true, "请求成功", result, list_rst.Count));
  1485. }
  1486. else
  1487. {
  1488. //----------------------------
  1489. List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
  1490. WorkbookDesigner designer = new WorkbookDesigner();
  1491. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
  1492. int excNo = 1;
  1493. foreach (var item in list_rst)
  1494. {
  1495. Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
  1496. exc.No = excNo.ToString();
  1497. excNo++;
  1498. exc.TeamName = item.teamName;
  1499. exc.ClientUnit = item.clientUnit;
  1500. exc.VisitDate = item.visitDate;
  1501. exc.Accounts = item.frPrice;
  1502. exc.Received = item.prPrice;
  1503. exc.Balance = item.balPrice;
  1504. exc.Collection = item.schedule;
  1505. DateTime time = Convert.ToDateTime(item.visitDate);
  1506. TimeSpan ts = DateTime.Now - time;
  1507. float SY = float.Parse(item.balPrice);
  1508. if (ts.Days >= 365 && SY > 0)
  1509. {
  1510. exc.Sign = "需收款";
  1511. }
  1512. else
  1513. {
  1514. exc.Sign = "";
  1515. }
  1516. list_Ex.Add(exc);
  1517. }
  1518. var dt = CommonFun.GetDataTableFromIList(list_Ex);
  1519. dt.TableName = "Excel_SyntheticalReceivableByDateRange";
  1520. if (dt != null)
  1521. {
  1522. designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
  1523. //数据源
  1524. designer.SetDataSource(dt);
  1525. //根据数据源处理生成报表内容
  1526. designer.Process();
  1527. string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  1528. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  1529. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  1530. return Ok(JsonView(true, "成功", new { url = rst }));
  1531. }
  1532. }
  1533. }
  1534. return Ok(JsonView(true, "获取成功", "", list_rst.Count));
  1535. }
  1536. #endregion
  1537. #region 付款申请
  1538. /// <summary>
  1539. /// 付款申请
  1540. /// 查询 根据日期范围
  1541. /// </summary>
  1542. /// <param name="dto"></param>
  1543. /// <returns></returns>
  1544. [HttpPost]
  1545. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1546. public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
  1547. {
  1548. #region 验证
  1549. DateTime beginDt, endDt;
  1550. string format = "yyyy-MM-dd";
  1551. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  1552. {
  1553. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  1554. }
  1555. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  1556. {
  1557. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  1558. }
  1559. #endregion
  1560. try
  1561. {
  1562. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.beginDt, dto.endDt);
  1563. tree_Group_DailyFeePaymentResult groupResult = PayRequest_PaymentByDateRange(dto.beginDt, dto.endDt);
  1564. return Ok(JsonView(true, "获取成功", new { daily = dailyResult, group = groupResult }));
  1565. }
  1566. catch (Exception ex)
  1567. {
  1568. return Ok(JsonView(false, ex.Message));
  1569. }
  1570. }
  1571. /// <summary>
  1572. /// 付款申请(日付申请相关)
  1573. /// 查询 根据日期范围
  1574. /// </summary>
  1575. /// <param name="dto"></param>
  1576. /// <returns></returns>
  1577. private tree_Group_DailyFeePaymentResult PayRequest_PaymentByDateRange(string beginDt, string endDt)
  1578. {
  1579. tree_Group_DailyFeePaymentResult _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
  1580. List<tree_Group_DailyFeePaymentPageListView> dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1581. #region sql条件处理
  1582. string sqlWhere = string.Format(@"And (AuditGMDate Between '{0} 00:00:00' And '{1} 23:59:59') ", beginDt, endDt);
  1583. string sql_1 = string.Format(@"Select * From Grp_CreditCardPayment Where IsDel = 0 And IsPay = 0 And IsAuditGM = 1 {0}", sqlWhere);
  1584. #endregion
  1585. var _paymentDatas = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_1).ToList();//付款信息
  1586. _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
  1587. _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
  1588. List<int> groupIds = _paymentDatas.Select(it => it.DIId).Distinct().ToList();
  1589. List<int> teamDids = new List<int> { 300, 302, 248 }; //团组类型 不含
  1590. var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id) && !teamDids.Contains(it.TeamDid)).ToList();
  1591. #region 相关基础数据源
  1592. var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
  1593. var setDatas = _sqlSugar.Queryable<Sys_SetData>().ToList();
  1594. var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1595. var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1596. var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1597. var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1598. var insureDatas = _sqlSugar.Queryable<Grp_Customers>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1599. var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1600. var otherMoneyDatas = _sqlSugar.Queryable<Fin_OtherPrice>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Diid)).ToList();
  1601. var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1602. var ExtraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1603. #endregion
  1604. foreach ( var groupInfo in _groupDatas)
  1605. {
  1606. List<Group_DailyFeePaymentContentInfolView> childList = new List<Group_DailyFeePaymentContentInfolView>();
  1607. var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
  1608. int rouNumber = 1;
  1609. foreach (var payInfo in groupPaymentDatas)
  1610. {
  1611. string priName = "";
  1612. switch (payInfo.CTable)
  1613. {
  1614. case 76: //76 酒店预订
  1615. priName = hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? "";
  1616. break;
  1617. case 79: //79 车/导游地接
  1618. var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
  1619. if (opData != null)
  1620. {
  1621. if (payInfo.OrbitalPrivateTransfer == 0) //公转
  1622. {
  1623. priName = "【四川泛美交流有限公司】" + "【公转】" + "【导游:" + opData.ServiceGuide + "】" + opData.Area;
  1624. }
  1625. else if (payInfo.OrbitalPrivateTransfer == 1) //私转
  1626. {
  1627. priName = "【四川泛美交流有限公司】" + "【私转】" + "【导游:" + opData.ServiceGuide + "】" + opData.Area;
  1628. }
  1629. }
  1630. break;
  1631. case 80: // 80 签证
  1632. priName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "";
  1633. break;
  1634. case 81: // 81 邀请/公务活动
  1635. priName = ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? "";
  1636. break;
  1637. case 82: // 82 团组客户保险
  1638. priName = insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? "";
  1639. break;
  1640. case 85: // 85 机票预订
  1641. string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "";
  1642. string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "";
  1643. priName = $"{flightsCode}【{airPayType}】";
  1644. break;
  1645. case 98: // 98 其他款项
  1646. priName = otherMoneyDatas.Find(it => payInfo.DIId == it.Diid && payInfo.CId == it.Id)?.PriceName ?? "";
  1647. break;
  1648. case 285: // 285 收款退还
  1649. priName = refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? "";
  1650. break;
  1651. case 1015: // 1015 超支费用
  1652. priName = ExtraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? "";
  1653. break;
  1654. default:
  1655. priName = "";
  1656. break;
  1657. }
  1658. childList.Add(new Group_DailyFeePaymentContentInfolView()
  1659. {
  1660. Id = payInfo.Id,
  1661. Payee = payInfo.Payee,
  1662. RowNumber = rouNumber,
  1663. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  1664. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  1665. PriceName = priName,
  1666. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  1667. PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
  1668. PaymentAmount = payInfo.PayMoney,
  1669. PayRate = payInfo.DayRate,
  1670. CNYSubTotalAmount = ((payInfo.DayRate * payInfo.PayMoney) / 100) * payInfo.PayPercentage //此次付款金额
  1671. }) ;
  1672. rouNumber++;
  1673. }
  1674. dataList.Add(new tree_Group_DailyFeePaymentPageListView()
  1675. {
  1676. GroupName = groupInfo.TeamName,
  1677. CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
  1678. ChildList = childList,
  1679. });
  1680. }
  1681. _DailyFeePaymentResult.dataList = dataList;
  1682. return _DailyFeePaymentResult;
  1683. }
  1684. /// <summary>
  1685. /// 付款申请(日付申请相关)
  1686. /// 查询 根据日期范围
  1687. /// </summary>
  1688. /// <param name="dto"></param>
  1689. /// <returns></returns>
  1690. private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(string beginDt, string endDt)
  1691. {
  1692. #region sql条件处理
  1693. string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
  1694. string sql_1 = string.Format(@"Select * From (
  1695. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  1696. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  1697. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  1698. dfp.PriceTypeId,dfp.TransferTypeId
  1699. From Fin_DailyFeePayment dfp
  1700. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  1701. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  1702. Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1
  1703. ) temp ", sqlWhere);
  1704. #endregion
  1705. List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
  1706. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  1707. foreach (var item in DailyFeePaymentData)
  1708. {
  1709. if (dic_setData.ContainsKey(item.PriceTypeId))
  1710. {
  1711. item.priceTypeStr = dic_setData[item.PriceTypeId];
  1712. }
  1713. else
  1714. {
  1715. Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
  1716. if (sd_priceType != null)
  1717. {
  1718. item.priceTypeStr = sd_priceType.Name;
  1719. dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
  1720. }
  1721. }
  1722. if (dic_setData.ContainsKey(item.transferTypeId))
  1723. {
  1724. item.transferTypeIdStr = dic_setData[item.transferTypeId];
  1725. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1726. if (sd_transfer != null)
  1727. {
  1728. item.transferParentId = sd_transfer.STid;
  1729. item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
  1730. }
  1731. }
  1732. else
  1733. {
  1734. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1735. if (sd_transfer != null)
  1736. {
  1737. item.transferTypeIdStr = sd_transfer.Name;
  1738. item.transferParentId = sd_transfer.STid;
  1739. item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
  1740. dic_setData.Add(item.transferTypeId, sd_transfer.Name);
  1741. }
  1742. }
  1743. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  1744. Where IsDel=0 And DFPId = {0} ", item.Id);
  1745. item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
  1746. }
  1747. decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == 62).Sum(d => d.SumPrice ?? 0M);
  1748. decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == 63).Sum(d => d.SumPrice ?? 0M);
  1749. var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
  1750. return result;
  1751. }
  1752. #endregion
  1753. #region 超支费用
  1754. /// <summary>
  1755. /// 超支费用
  1756. /// 1增、2改、3删
  1757. /// </summary>
  1758. /// <param name="dto"></param>
  1759. /// <returns></returns>
  1760. [HttpPost]
  1761. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1762. public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  1763. {
  1764. #region 验证
  1765. #endregion
  1766. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  1767. _entity.DiId = dto.diId;
  1768. _entity.PriceName = dto.priceName;
  1769. _entity.Price = dto.price;
  1770. _entity.PriceCurrency = dto.currency;
  1771. _entity.PriceType = dto.priceType;
  1772. _entity.Coefficient = dto.coefficient;
  1773. _entity.PriceDetailType = dto.priceDetailType;
  1774. _entity.FilePath = dto.filePath;
  1775. _entity.Remark = dto.remark;
  1776. _daiRep.BeginTran();
  1777. if (dto.editType == 1)
  1778. {
  1779. _entity.CreateUserId = dto.createUser;
  1780. _entity.CreateTime = DateTime.Now;
  1781. _entity.IsDel = 0;
  1782. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  1783. if (returnId > 0)
  1784. {
  1785. dto.Id = returnId;
  1786. }
  1787. }
  1788. else if (dto.editType == 2)
  1789. {
  1790. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1791. {
  1792. PriceName = dto.priceName,
  1793. Price = dto.price,
  1794. PriceCurrency = dto.currency,
  1795. PriceType = dto.priceType,
  1796. PriceDetailType = dto.priceDetailType,
  1797. Coefficient = dto.coefficient,
  1798. FilePath = dto.filePath,
  1799. Remark = dto.remark
  1800. });
  1801. if (!res)
  1802. {
  1803. _daiRep.RollbackTran();
  1804. return Ok(JsonView(false, "2操作失败!"));
  1805. }
  1806. }
  1807. else if (dto.editType == 3)
  1808. {
  1809. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1810. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1811. {
  1812. IsDel = 1,
  1813. DeleteTime = delTime,
  1814. DeleteUserId = dto.createUser
  1815. });
  1816. if (!res)
  1817. {
  1818. _daiRep.RollbackTran();
  1819. return Ok(JsonView(false, "3操作失败!"));
  1820. }
  1821. }
  1822. else
  1823. {
  1824. _daiRep.RollbackTran();
  1825. return Ok(JsonView(false, "未知的editType"));
  1826. }
  1827. if (!extraCost_editCreditCardPayment(dto))
  1828. {
  1829. return Ok(JsonView(false, "ccp操作失败"));
  1830. }
  1831. _daiRep.CommitTran();
  1832. return Ok(JsonView(false, "操作成功"));
  1833. }
  1834. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1835. {
  1836. //设置团组汇率
  1837. decimal dcm_dayrate = 1M;
  1838. decimal dcm_rmbPrice = costDto.price;
  1839. int ispay = costDto.payType == 72 ? 1 : 0;
  1840. if (costDto.costSign != 3)
  1841. {
  1842. Grp_TeamRate tr = _daiRep.Query<Grp_TeamRate>(s => s.DiId == costDto.diId && s.CTable == 1015).First();
  1843. if (tr != null)
  1844. {
  1845. if (costDto.currency == 49)
  1846. {
  1847. dcm_dayrate = tr.RateU;
  1848. dcm_rmbPrice = dcm_rmbPrice * tr.RateU;
  1849. }
  1850. else if (costDto.currency == 51)
  1851. {
  1852. dcm_dayrate = tr.RateE;
  1853. dcm_rmbPrice = dcm_rmbPrice * tr.RateE;
  1854. }
  1855. }
  1856. }
  1857. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1858. if (ccp == null)
  1859. {
  1860. ccp = new Grp_CreditCardPayment();
  1861. ccp.PayDId = costDto.payType;// dto
  1862. ccp.ConsumptionPatterns = "";
  1863. ccp.ConsumptionDate = "";
  1864. ccp.CTDId = costDto.payCardId;// dto
  1865. ccp.BankNo = "";
  1866. ccp.CardholderName = "";
  1867. ccp.PayMoney = costDto.price;// dto
  1868. ccp.PaymentCurrency = costDto.currency;// dto
  1869. ccp.CompanyBankNo = "";
  1870. ccp.OtherBankName = "";
  1871. ccp.OtherSideNo = "";
  1872. ccp.OtherSideName = "";
  1873. ccp.Remark = "";
  1874. ccp.CreateUserId = costDto.createUser;
  1875. ccp.CreateTime = DateTime.Now;
  1876. ccp.MFOperator = 0;
  1877. ccp.MFOperatorDate = "";
  1878. ccp.IsAuditDM = 0;
  1879. ccp.AuditDMOperate = 0;
  1880. ccp.AuditDMDate = "";
  1881. ccp.IsAuditMF = 0;
  1882. ccp.AuditMFOperate = 0;
  1883. ccp.AuditMFDate = "";
  1884. ccp.IsAuditGM = 0;
  1885. ccp.AuditGMOperate = 0;
  1886. ccp.AuditGMDate = "";
  1887. ccp.IsPay = ispay; // upd
  1888. ccp.DIId = costDto.diId;// dto
  1889. ccp.CId = costDto.Id;// dto
  1890. ccp.CTable = 1015; //超支费用指向id
  1891. ccp.IsDel = 0;
  1892. ccp.PayPercentage = 100M;
  1893. ccp.PayThenMoney = 0M;
  1894. ccp.PayPercentageOld = 100M;
  1895. ccp.PayThenMoneyOld = 0M;
  1896. ccp.UpdateDate = "";
  1897. ccp.Payee = costDto.payee;// dto
  1898. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1899. ccp.ExceedBudget = 0;
  1900. ccp.DayRate = dcm_dayrate; //upd
  1901. ccp.RMBPrice = dcm_rmbPrice; //upd
  1902. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1903. if (ccpInsertId > 0)
  1904. {
  1905. return true;
  1906. }
  1907. }
  1908. else
  1909. {
  1910. if (costDto.editType == 2)
  1911. {
  1912. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1913. {
  1914. PayDId = costDto.payType,
  1915. CTDId = costDto.payCardId,
  1916. PayMoney = costDto.price,
  1917. PaymentCurrency = costDto.currency,
  1918. IsPay = ispay,
  1919. Payee = costDto.payee,
  1920. OrbitalPrivateTransfer = costDto.costSign,
  1921. DayRate = dcm_dayrate,
  1922. RMBPrice = dcm_rmbPrice
  1923. });
  1924. return res;
  1925. }
  1926. else if (costDto.editType == 3)
  1927. {
  1928. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1929. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1930. {
  1931. IsDel = 1,
  1932. DeleteTime = delTime,
  1933. DeleteUserId = costDto.createUser
  1934. });
  1935. return res2;
  1936. }
  1937. }
  1938. return false;
  1939. }
  1940. /// <summary>
  1941. /// 超支费用
  1942. /// 列表查询
  1943. /// </summary>
  1944. /// <param name="dto"></param>
  1945. /// <returns></returns>
  1946. [HttpPost]
  1947. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1948. public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
  1949. {
  1950. string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
  1951. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  1952. int endIndex = startIndex + dto.PageSize - 1;
  1953. string sql_data = string.Format(@"Select * From (
  1954. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  1955. f.PriceName,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  1956. From Fin_GroupExtraCost f
  1957. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  1958. Left Join Sys_Users u On f.CreateUserId = u.Id
  1959. Where f.IsDel=0 And c.CTable = 1015 {0}
  1960. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  1961. string sql_count = string.Format(@"Select Count(1) as DataCount From (
  1962. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  1963. f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  1964. From Fin_GroupExtraCost f
  1965. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  1966. Left Join Sys_Users u On f.CreateUserId = u.Id
  1967. Where f.IsDel=0 And c.CTable = 1015 {0}
  1968. ) temp ", sqlWhere);
  1969. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  1970. {
  1971. //Fin_DailyFeePaymentPageCount
  1972. var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
  1973. List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
  1974. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  1975. Dictionary<int, string> dic_user = new Dictionary<int, string>();
  1976. foreach (var item in dataList)
  1977. {
  1978. //费用详细类型
  1979. if (dic_setData.ContainsKey(item.PriceType))
  1980. {
  1981. item.PriceTypeStr = dic_setData[item.PriceType];
  1982. }
  1983. else
  1984. {
  1985. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
  1986. if (sd_priceTypeDetail != null)
  1987. {
  1988. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  1989. item.PriceTypeStr = tempName;
  1990. dic_setData.Add(item.PriceType, tempName);
  1991. }
  1992. }
  1993. //系统用户
  1994. if (dic_user.ContainsKey(item.CreateUserId))
  1995. {
  1996. item.CreateUserIdStr = dic_setData[item.CreateUserId];
  1997. }
  1998. else
  1999. {
  2000. Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
  2001. if (users != null)
  2002. {
  2003. item.CreateUserIdStr = users.CnName;
  2004. dic_setData.Add(item.CreateUserId, users.CnName);
  2005. }
  2006. }
  2007. switch (item.IsAuditGM)
  2008. {
  2009. case 0: item.IsAuditGMStr = "未审核"; break;
  2010. case 1: item.IsAuditGMStr = "已通过"; break;
  2011. case 2: item.IsAuditGMStr = "未通过"; break;
  2012. default: item.IsAuditGMStr = "未知状态"; break;
  2013. }
  2014. }
  2015. var result = new ListViewBase<Fin_GroupExtraCostView>
  2016. {
  2017. CurrPageIndex = dto.PageIndex,
  2018. CurrPageSize = dto.PageSize,
  2019. DataCount = count.DataCount,
  2020. DataList = dataList
  2021. };
  2022. return Ok(JsonView(true, "查询成功", result));
  2023. }
  2024. return Ok(JsonView(false, "查询成功"));
  2025. }
  2026. /// <summary>
  2027. /// 超支费用
  2028. /// 数据集合配置
  2029. /// </summary>
  2030. /// <param name="dto"></param>
  2031. /// <returns></returns>
  2032. [HttpPost]
  2033. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2034. public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
  2035. {
  2036. //支付方式
  2037. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  2038. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  2039. //超支费用类型
  2040. List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
  2041. List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
  2042. //超支费用详细类型
  2043. List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
  2044. PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
  2045. List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
  2046. var data = new
  2047. {
  2048. Payment = _Payment,
  2049. PriceType = _PriceType,
  2050. PriceDetailType = _PriceDetailType
  2051. };
  2052. return Ok(JsonView(true, "", data));
  2053. }
  2054. #endregion
  2055. }
  2056. }