FinancialController.cs 123 KB

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