FinancialController.cs 173 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864
  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. using System.Diagnostics;
  34. using System.Security.Cryptography;
  35. using NPOI.POIFS.Crypt.Dsig;
  36. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  37. using Org.BouncyCastle.Asn1.Ocsp;
  38. using FluentValidation;
  39. using AutoMapper;
  40. using NetTaste;
  41. using EyeSoft.Runtime.InteropServices;
  42. using NPOI.HPSF;
  43. using System.Data.OleDb;
  44. namespace OASystem.API.Controllers
  45. {
  46. /// <summary>
  47. /// 财务模块
  48. /// </summary>
  49. [Route("api/[controller]/[action]")]
  50. [ApiController]
  51. public class FinancialController : ControllerBase
  52. {
  53. private readonly IMapper _mapper;
  54. private readonly IConfiguration _config;
  55. private readonly SqlSugarClient _sqlSugar;
  56. private readonly HttpClient _httpClient;
  57. private readonly SetDataTypeRepository _setDataTypeRep;
  58. private readonly SetDataRepository _setDataRep;
  59. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  60. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  61. private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
  62. private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
  63. private readonly PaymentRefundAndOtherMoneyRepository _paymentRefundAndOtherMoneyRep; //收款退还与其他款项 仓库
  64. private readonly DelegationInfoRepository _delegationInfoRep; //团组信息 仓库
  65. /// <summary>
  66. /// 初始化
  67. /// </summary>
  68. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
  69. TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
  70. PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient, DelegationInfoRepository delegationInfoRep)
  71. {
  72. _mapper = mapper;
  73. _config = configuration;
  74. _daiRep = daiRep;
  75. _sqlSugar = sqlSugar;
  76. _setDataTypeRep = setDataTypeRep;
  77. _teamRateRep = teamRateRep;
  78. _ForForeignReceivablesRep = ForForeignReceivablesRep;
  79. _proceedsReceivedRep = proceedsReceivedRep;
  80. _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
  81. _httpClient = httpClient;
  82. _delegationInfoRep = delegationInfoRep;
  83. }
  84. #region 日付申请
  85. /// <summary>
  86. /// 获取日付申请 基础数据源
  87. /// </summary>
  88. /// <param name="dto"> 日付申请 分页 dto</param>
  89. /// <returns></returns>
  90. [HttpPost]
  91. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  92. public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
  93. {
  94. var result = await _daiRep.GetPagePriceTypeData(dto);
  95. if (result == null || result.Code != 0)
  96. {
  97. return Ok(JsonView(false, result.Msg));
  98. }
  99. var data = result.Data;
  100. return Ok(JsonView(data));
  101. }
  102. /// <summary>
  103. /// 获取日付申请 基础数据源 - 转账表识
  104. /// </summary>
  105. /// <param name="dto"> 日付申请 分页 dto</param>
  106. /// <returns></returns>
  107. [HttpPost]
  108. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  109. public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
  110. {
  111. var result = await _daiRep.GetPriceTypeAddData(dto);
  112. if (result == null || result.Code != 0)
  113. {
  114. return Ok(JsonView(false, result.Msg));
  115. }
  116. var data = result.Data;
  117. return Ok(JsonView(data));
  118. }
  119. /// <summary>
  120. /// 日付申请 Page Search
  121. /// </summary>
  122. /// <param name="dto"> 日付申请 分页 dto</param>
  123. /// <returns></returns>
  124. [HttpPost]
  125. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  126. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  127. {
  128. var result = await _daiRep.GetPageSearchAll(dto);
  129. if (result == null || result.Code != 0)
  130. {
  131. return Ok(JsonView(false, result.Msg));
  132. }
  133. var data = result.Data;
  134. if (data == null)
  135. {
  136. return Ok(JsonView(false, result.Msg));
  137. }
  138. return Ok(JsonView(data));
  139. }
  140. /// <summary>
  141. /// 日付申请 Single Search By Id
  142. /// </summary>
  143. /// <param name="dto"></param>
  144. /// <returns></returns>
  145. [HttpPost]
  146. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  147. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  148. {
  149. var result = await _daiRep.GetSearchById(dto);
  150. if (result == null || result.Code != 0)
  151. {
  152. return Ok(JsonView(false, result.Msg));
  153. }
  154. return Ok(JsonView(result.Data));
  155. }
  156. /// <summary>
  157. /// 日付申请 添加
  158. /// </summary>
  159. /// <param name="dto"> 日付申请 添加 dto</param>
  160. /// <returns></returns>
  161. [HttpPost]
  162. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  163. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  164. {
  165. var result = await _daiRep.Add(dto);
  166. if (result == null || result.Code != 0)
  167. {
  168. return Ok(JsonView(false, result.Msg));
  169. }
  170. #region 应用推送
  171. try
  172. {
  173. int dailyId = result.Data.GetType().GetProperty("dailyId").GetValue(result.Data, null);
  174. int sign = result.Data.GetType().GetProperty("sign").GetValue(result.Data, null);
  175. await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  176. }
  177. catch (Exception ex)
  178. {
  179. }
  180. #endregion
  181. return Ok(JsonView(true));
  182. }
  183. /// <summary>
  184. /// 日付申请 Update
  185. /// </summary>
  186. /// <param name="dto"> 日付申请 修改 dto</param>
  187. /// <returns></returns>
  188. [HttpPost]
  189. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  190. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  191. {
  192. var result = await _daiRep.Edit(dto);
  193. if (result == null || result.Code != 0)
  194. {
  195. return Ok(JsonView(false, result.Msg));
  196. }
  197. #region 应用推送
  198. try
  199. {
  200. int dailyId = result.Data.GetType().GetProperty("dailyId").GetValue(result.Data, null);
  201. int sign = result.Data.GetType().GetProperty("sign").GetValue(result.Data, null);
  202. await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  203. }
  204. catch (Exception ex)
  205. {
  206. }
  207. #endregion
  208. return Ok(JsonView(true));
  209. }
  210. /// <summary>
  211. /// 日付申请 Del
  212. /// </summary>
  213. /// <param name="dto"> 日付申请 删除 dto</param>
  214. /// <returns></returns>
  215. [HttpPost]
  216. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  217. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  218. {
  219. var result = await _daiRep.Del(dto);
  220. if (result == null || result.Code != 0)
  221. {
  222. return Ok(JsonView(false, result.Msg));
  223. }
  224. return Ok(JsonView(true));
  225. }
  226. /// <summary>
  227. /// 日付申请 财务审核
  228. /// </summary>
  229. /// <param name="dto"> dto </param>
  230. /// <returns></returns>
  231. [HttpPost]
  232. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  233. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  234. {
  235. var result = await _daiRep.DailyPaymentAudit(dto);
  236. if (result == null || result.Code != 0)
  237. {
  238. return Ok(JsonView(false, result.Msg));
  239. }
  240. return Ok(JsonView(true));
  241. }
  242. /// <summary>
  243. /// 日付申请 Single Excel Download
  244. /// </summary>
  245. /// <param name="dto"> dto </param>
  246. /// <returns></returns>
  247. [HttpPost]
  248. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  249. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  250. {
  251. if (dto.PortType == 1 || dto.PortType == 2)
  252. {
  253. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  254. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  255. Where IsDel=0 And Id = {0} ", dto.Id);
  256. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  257. if (feeData == null)
  258. {
  259. return Ok(JsonView(false, "暂无数据!"));
  260. }
  261. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  262. Where IsDel=0 And DFPId = {0} ", dto.Id);
  263. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  264. if (feeData != null)
  265. {
  266. string userName = string.Empty;
  267. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  268. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  269. if (user != null) { userName = user.CnName; }
  270. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  271. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  272. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  273. Dictionary<string, object> pairs = new Dictionary<string, object>();
  274. List<DataTable> datas = new List<DataTable>();
  275. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  276. //{
  277. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  278. // // pairs, datas);
  279. //}
  280. //else //日付常规模板
  281. //{
  282. pairs.Clear();
  283. pairs.Add("Opertor", userName);
  284. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  285. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  286. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  287. pairs.Add("SumPrice", feeData.SumPrice);
  288. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  289. datas.Clear();
  290. datas.Add(data);
  291. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  292. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  293. return Ok(JsonView(true, msg));
  294. //}
  295. }
  296. else
  297. {
  298. return Ok(JsonView(false, "暂无数据!"));
  299. }
  300. }
  301. return Ok(JsonView(true));
  302. }
  303. #endregion
  304. #region 团组提成
  305. /// <summary>
  306. /// 提成 Page Search
  307. /// </summary>
  308. /// <param name="dto"> 提成 分页 dto</param>
  309. /// <returns></returns>
  310. [HttpPost]
  311. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  312. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  313. {
  314. var data = await GroupCommission.GetCommissionPageList(dto);
  315. return Ok(JsonView(data.Data));
  316. }
  317. #endregion
  318. #region 团组汇率
  319. /// <summary>
  320. /// 团组汇率 Select数据源(团组列,汇率列)
  321. /// </summary>
  322. /// <param name="dto"></param>
  323. /// <returns></returns>
  324. [HttpPost]
  325. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  326. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  327. {
  328. try
  329. {
  330. //迁移数据更新团组汇率
  331. //Result teamRateData1 = await _teamRateRep.GetGroupRateChangeData();
  332. //var data = await _teamRateRep.PostGroupTeamRateHot();
  333. Stopwatch stopwatch = Stopwatch.StartNew();
  334. GroupNameDto groupNameDto = new GroupNameDto() { PortType = dto.PortType };
  335. var groups = await _delegationInfoRep.GetGroupNameList(groupNameDto);
  336. List<CurrencyHot> _currData = new List<CurrencyHot>();
  337. string currData = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("GroupTeamCurrencyData");//string 取
  338. if (!string.IsNullOrEmpty(currData))
  339. {
  340. _currData = JsonConvert.DeserializeObject<List<CurrencyHot>>(currData);
  341. }
  342. else
  343. {
  344. _currData = await _teamRateRep.PostGroupTeamRateHot();
  345. //过期时间 25 Hours
  346. TimeSpan ts = DateTime.Now.AddHours(25).TimeOfDay;
  347. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync("GroupTeamCurrencyData", JsonConvert.SerializeObject(_currData), ts);
  348. }
  349. var _data = new { GroupData = groups.Data, TeamRateData = _currData };
  350. stopwatch.Stop();
  351. return Ok(JsonView(true, $"查询成功!耗时:{stopwatch.ElapsedMilliseconds / 1000}s", _data));
  352. }
  353. catch (Exception ex)
  354. {
  355. return Ok(JsonView(false, ex.Message));
  356. }
  357. }
  358. ///// <summary>
  359. ///// 团组汇率 changge
  360. ///// </summary>
  361. ///// <returns></returns>
  362. //[HttpPost]
  363. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  364. //public async Task<IActionResult> ChangeGroupRateInfo()
  365. //{
  366. // try
  367. // {
  368. // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  369. // if (teamRateData.Code != 0)
  370. // {
  371. // return Ok(JsonView(false, teamRateData.Msg));
  372. // }
  373. // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  374. // }
  375. // catch (Exception ex)
  376. // {
  377. // return Ok(JsonView(false, ex.Message));
  378. // throw;
  379. // }
  380. //}
  381. /// <summary>
  382. /// 团组汇率 Select汇率详情
  383. /// </summary>
  384. /// <param name="dto"></param>
  385. /// <returns></returns>
  386. [HttpPost]
  387. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  388. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  389. {
  390. try
  391. {
  392. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  393. if (teamRateData.Code != 0)
  394. {
  395. return Ok(JsonView(false, teamRateData.Msg));
  396. }
  397. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  398. }
  399. catch (Exception ex)
  400. {
  401. return Ok(JsonView(false, ex.Message));
  402. throw;
  403. }
  404. }
  405. /// <summary>
  406. /// 团组汇率 添加 or 更新
  407. /// </summary>
  408. /// <param name="dto"></param>
  409. /// <returns></returns>
  410. [HttpPost]
  411. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  412. public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
  413. {
  414. try
  415. {
  416. Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
  417. if (teamRateData.Code != 0)
  418. {
  419. return Ok(JsonView(false, teamRateData.Msg));
  420. }
  421. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  422. }
  423. catch (Exception ex)
  424. {
  425. return Ok(JsonView(false, ex.Message));
  426. throw;
  427. }
  428. }
  429. #endregion
  430. #region 对外收款账单 关联已收款项
  431. /// <summary>
  432. /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
  433. /// 关联已收款项
  434. /// </summary>
  435. /// <param name="dto"></param>
  436. /// <returns></returns>
  437. [HttpPost]
  438. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  439. public async Task<IActionResult> GetForeignReceivablesDataSources()
  440. {
  441. try
  442. {
  443. Result ffrData = await _ForForeignReceivablesRep.GetDataSource();
  444. if (ffrData.Code != 0)
  445. {
  446. return Ok(JsonView(false, ffrData.Msg));
  447. }
  448. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  449. }
  450. catch (Exception ex)
  451. {
  452. return Ok(JsonView(false, ex.Message));
  453. throw;
  454. }
  455. }
  456. /// <summary>
  457. /// 对外收款账单
  458. /// 账单详情
  459. /// 关联已收款项
  460. /// </summary>
  461. /// <param name="dto"></param>
  462. /// <returns></returns>
  463. [HttpPost]
  464. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  465. public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  466. {
  467. try
  468. {
  469. Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
  470. if (ffrData.Code != 0)
  471. {
  472. return Ok(JsonView(false, ffrData.Msg));
  473. }
  474. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  475. }
  476. catch (Exception ex)
  477. {
  478. return Ok(JsonView(false, ex.Message));
  479. throw;
  480. }
  481. }
  482. /// <summary>
  483. /// 对外收款账单
  484. /// 账单 删除
  485. /// 关联已收款项
  486. /// </summary>
  487. /// <param name="dto"></param>
  488. /// <returns></returns>
  489. [HttpPost]
  490. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  491. public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
  492. {
  493. try
  494. {
  495. Result ffrData = await _ForForeignReceivablesRep._Del(dto);
  496. if (ffrData.Code != 0)
  497. {
  498. return Ok(JsonView(false, ffrData.Msg));
  499. }
  500. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  501. }
  502. catch (Exception ex)
  503. {
  504. return Ok(JsonView(false, ex.Message));
  505. throw;
  506. }
  507. }
  508. /// <summary>
  509. /// 对外收款账单
  510. /// 添加 And 更新
  511. /// 关联已收款项
  512. /// </summary>
  513. /// <param name="dto"></param>
  514. /// <returns></returns>
  515. [HttpPost]
  516. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  517. public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  518. {
  519. try
  520. {
  521. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
  522. if (ffrData.Code != 0)
  523. {
  524. return Ok(JsonView(false, ffrData.Msg));
  525. }
  526. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  527. }
  528. catch (Exception ex)
  529. {
  530. return Ok(JsonView(false, ex.Message));
  531. throw;
  532. }
  533. }
  534. /// <summary>
  535. /// 已收款项
  536. /// 账单 删除
  537. /// 关联已收款项
  538. /// </summary>
  539. /// <param name="dto"></param>
  540. /// <returns></returns>
  541. [HttpPost]
  542. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  543. public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
  544. {
  545. try
  546. {
  547. Result ffrData = await _proceedsReceivedRep._Del(dto);
  548. if (ffrData.Code != 0)
  549. {
  550. return Ok(JsonView(false, ffrData.Msg));
  551. }
  552. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  553. }
  554. catch (Exception ex)
  555. {
  556. return Ok(JsonView(false, ex.Message));
  557. throw;
  558. }
  559. }
  560. /// <summary>
  561. /// 已收款项
  562. /// 添加 And 更新
  563. /// 关联已收款项
  564. /// </summary>
  565. /// <param name="dto"></param>
  566. /// <returns></returns>
  567. [HttpPost]
  568. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  569. public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
  570. {
  571. try
  572. {
  573. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
  574. if (ffrData.Code != 0)
  575. {
  576. return Ok(JsonView(false, ffrData.Msg));
  577. }
  578. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  579. }
  580. catch (Exception ex)
  581. {
  582. return Ok(JsonView(false, ex.Message));
  583. throw;
  584. }
  585. }
  586. /// <summary>
  587. /// 财务 已收款项
  588. /// 分配已收款项至 应收项下
  589. /// 关联已收款项
  590. /// </summary>
  591. /// <param name="dto"></param>
  592. /// <returns></returns>
  593. [HttpPost]
  594. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  595. public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
  596. {
  597. try
  598. {
  599. Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
  600. if (ffrData.Code != 0)
  601. {
  602. return Ok(JsonView(false, ffrData.Msg));
  603. }
  604. return Ok(JsonView(true));
  605. }
  606. catch (Exception ex)
  607. {
  608. return Ok(JsonView(false, ex.Message));
  609. throw;
  610. }
  611. }
  612. ///// <summary>
  613. ///// 财务 收款账单
  614. ///// 导出Word(北京,四川)
  615. ///// </summary>
  616. ///// <param name="dto"></param>
  617. ///// <returns></returns>
  618. //[HttpPost]
  619. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  620. //public async Task<IActionResult> PostAccountReceivableWordExport(AccountReceivableWordExportDto dto)
  621. //{
  622. // try
  623. // {
  624. // //模板处理
  625. // string typeName = string.Empty;
  626. // if (dto.TemplateType == 1) //四川
  627. // {
  628. // typeName = "四川";
  629. // }
  630. // else if (dto.TemplateType == 2) //北京
  631. // {
  632. // typeName = "北京";
  633. // }
  634. // else return Ok(JsonView(false,"请选择正确的模板类型!"));
  635. // string wordTempName = string.Format("收款账单({0})模板.doc", typeName);
  636. // }
  637. // catch (Exception ex)
  638. // {
  639. // return Ok(JsonView(false, ex.Message));
  640. // }
  641. //}
  642. #endregion
  643. #region 对外收款账单
  644. /// <summary>
  645. /// 对外收款账单
  646. /// 数据源
  647. /// </summary>
  648. /// <param name="dto"></param>
  649. /// <returns></returns>
  650. [HttpPost]
  651. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  652. public async Task<IActionResult> PostGroupReceivablesDataSource()
  653. {
  654. try
  655. {
  656. Result ffrData = await _ForForeignReceivablesRep.PostDataSource();
  657. if (ffrData.Code != 0)
  658. {
  659. return Ok(JsonView(false, ffrData.Msg));
  660. }
  661. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  662. }
  663. catch (Exception ex)
  664. {
  665. return Ok(JsonView(false, ex.Message));
  666. }
  667. }
  668. /// <summary>
  669. /// 对外收款账单
  670. /// 账单详情
  671. /// </summary>
  672. /// <param name="dto"></param>
  673. /// <returns></returns>
  674. [HttpPost]
  675. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  676. public async Task<IActionResult> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  677. {
  678. try
  679. {
  680. Result ffrData = await _ForForeignReceivablesRep.PostGroupReceivablesInfoByDiId(dto);
  681. if (ffrData.Code != 0)
  682. {
  683. return Ok(JsonView(false, ffrData.Msg));
  684. }
  685. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  686. }
  687. catch (Exception ex)
  688. {
  689. return Ok(JsonView(false, ex.Message));
  690. }
  691. }
  692. /// <summary>
  693. /// 对外收款账单
  694. /// 添加 And 更新
  695. /// </summary>
  696. /// <param name="dto"></param>
  697. /// <returns></returns>
  698. [HttpPost]
  699. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  700. public async Task<IActionResult> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  701. {
  702. try
  703. {
  704. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesSave(dto);
  705. if (ffrData.Code != 0)
  706. {
  707. return Ok(JsonView(false, ffrData.Msg));
  708. }
  709. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  710. }
  711. catch (Exception ex)
  712. {
  713. return Ok(JsonView(false, ex.Message));
  714. throw;
  715. }
  716. }
  717. /// <summary>
  718. /// 已收账单
  719. /// 删除
  720. /// </summary>
  721. /// <param name="dto"></param>
  722. /// <returns></returns>
  723. [HttpPost]
  724. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  725. public async Task<IActionResult> PostReceivablesDel(ForeignReceivablesDelDto dto)
  726. {
  727. try
  728. {
  729. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesDel(dto);
  730. if (ffrData.Code != 0)
  731. {
  732. return Ok(JsonView(false, ffrData.Msg));
  733. }
  734. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  735. }
  736. catch (Exception ex)
  737. {
  738. return Ok(JsonView(false, ex.Message));
  739. throw;
  740. }
  741. }
  742. /// <summary>
  743. /// 已收账单
  744. /// File Downloasd
  745. /// Init
  746. /// </summary>
  747. /// <param name="dto"></param>
  748. /// <returns></returns>
  749. [HttpPost]
  750. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  751. public async Task<IActionResult> PostReceivablesFeilDownloadInit()
  752. {
  753. return Ok(JsonView(true, "操作成功!", new List<dynamic> {
  754. new { Id = 1, Name = "生成收款单(四川)" },
  755. new { Id = 2, Name = "生成收款单(北京)" },
  756. new { Id = 3, Name = "汇款账单" }
  757. }
  758. ));
  759. }
  760. /// <summary>
  761. /// 已收账单
  762. /// File Downloasd
  763. /// </summary>
  764. /// <param name="dto"></param>
  765. /// <returns></returns>
  766. [HttpPost]
  767. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  768. public async Task<IActionResult> PostReceivablesFeilDownload(ForeignReceivablesFeilDownloadDto dto)
  769. {
  770. try
  771. {
  772. if (dto.DiId < 1)
  773. {
  774. return Ok(JsonView(false, "请传入有效DiId参数!"));
  775. }
  776. if (dto.FileType < 1 || dto.FileType > 3)
  777. {
  778. return Ok(JsonView(false, "请传入有效FileType参数! 1 生成收款单(四川) 2 生成收款单(北京) 3 汇款账单"));
  779. }
  780. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  781. if (_DelegationInfo == null)
  782. {
  783. return Ok(JsonView(false, "暂无团组信息!!"));
  784. }
  785. if (dto.FileType == 1 || dto.FileType == 2)
  786. {
  787. var _ForeignReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  788. if (_ForeignReceivables.Count < 1)
  789. {
  790. return Ok(JsonView(false, "暂无收款信息!!"));
  791. }
  792. string tempName = "";
  793. if (dto.FileType == 1) tempName = $"收款账单(四川)模板.docx";
  794. else if (dto.FileType == 2) tempName = $"收款账单(北京)模板.docx";
  795. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/{tempName}";
  796. //载入模板
  797. Document doc = new Document(tempPath);
  798. DocumentBuilder builder = new DocumentBuilder(doc);
  799. #region 替换Word模板书签内容
  800. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  801. //付款方
  802. if (doc.Range.Bookmarks["To"] != null)
  803. {
  804. Bookmark mark = doc.Range.Bookmarks["To"];
  805. mark.Text = _ForeignReceivables[0].To == null ? "" : _ForeignReceivables[0].To.ToString();
  806. }
  807. //付款方电话
  808. if (doc.Range.Bookmarks["ToTel"] != null)
  809. {
  810. Bookmark mark = doc.Range.Bookmarks["ToTel"];
  811. mark.Text = _ForeignReceivables[0].ToTel == null ? "" : _ForeignReceivables[0].ToTel.ToString();
  812. }
  813. //导出时间
  814. if (doc.Range.Bookmarks["Date"] != null)
  815. {
  816. Bookmark mark = doc.Range.Bookmarks["Date"];
  817. mark.Text = DateTime.Now.ToString("yyyy-MM-dd");
  818. }
  819. //注
  820. if (doc.Range.Bookmarks["Attention"] != null)
  821. {
  822. Bookmark mark = doc.Range.Bookmarks["Attention"];
  823. mark.Text = _ForeignReceivables[0].Attention == null ? "" : _ForeignReceivables[0].Attention.ToString();
  824. }
  825. //团队名称
  826. if (doc.Range.Bookmarks["Team"] != null)
  827. {
  828. Bookmark mark = doc.Range.Bookmarks["Team"];
  829. mark.Text = _DelegationInfo.VisitCountry == null ? "" : _DelegationInfo.VisitCountry.Replace("|", "、").ToString();
  830. }
  831. //付款日期
  832. if (doc.Range.Bookmarks["PayDate"] != null)
  833. {
  834. Bookmark mark = doc.Range.Bookmarks["PayDate"];
  835. mark.Text = _ForeignReceivables[0].PayDate == null ? "" : Convert.ToDateTime(_ForeignReceivables[0].PayDate).ToString("yyyy年MM月dd日");
  836. }
  837. decimal sumPrice = 0;
  838. //各项费用
  839. if (doc.Range.Bookmarks["PayItemContent"] != null)
  840. {
  841. string items = "";
  842. foreach (var fr in _ForeignReceivables)
  843. {
  844. items += fr.PriceName + " " + fr.Currency + " " + fr.Price.ToString("#0.00") + " * " + fr.Count + " " + fr.Unit + " * " + fr.Rate + ".................. RMB " + fr.ItemSumPrice.ToString("#0.00") + "\n";
  845. sumPrice += fr.ItemSumPrice;
  846. }
  847. Bookmark mark = doc.Range.Bookmarks["PayItemContent"];
  848. mark.Text = items;
  849. }
  850. //合计
  851. if (doc.Range.Bookmarks["Total"] != null)
  852. {
  853. Bookmark mark = doc.Range.Bookmarks["Total"];
  854. mark.Text = sumPrice.ToString("#0.00");
  855. }
  856. #endregion
  857. //文件名
  858. string strFileName = _DelegationInfo.TeamName + "-收款账单.docx";
  859. //去水印
  860. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  861. doc.Save(AppSettingsHelper.Get("WordBasePath") + "ForeignReceivables/File/" + strFileName);
  862. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/ForeignReceivables/File/" + strFileName;
  863. return Ok(JsonView(true, "成功", new { Url = url }));
  864. }
  865. else if (dto.FileType == 3) //汇款通知
  866. {
  867. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  868. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId && it.NationalTravelFeeId > 0).ToList();
  869. if (_EnterExitCosts == null)
  870. {
  871. return Ok(JsonView(false, "该团组未填写出入境费用;"));
  872. }
  873. var _cityFee = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  874. foreach (var item in _DayAndCosts)
  875. {
  876. var cityInfo = _cityFee.Where(it => it.Id == item.NationalTravelFeeId).FirstOrDefault();
  877. if (cityInfo != null)
  878. {
  879. if (cityInfo.City.Contains("全部城市") || cityInfo.City.Contains("其他城市"))
  880. {
  881. item.Place = cityInfo.Country;
  882. }
  883. else item.Place = cityInfo.City;
  884. }
  885. }
  886. //数据源
  887. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  888. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  889. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  890. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  891. //币种Data
  892. var currData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  893. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  894. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  895. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  896. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  897. .Select((tcl, dc, cc) => new
  898. {
  899. Name = dc.LastName + dc.FirstName,
  900. Sex = dc.Sex,
  901. Birthday = dc.BirthDay,
  902. Company = cc.CompanyFullName,
  903. Job = dc.Job,
  904. AirType = tcl.ShippingSpaceTypeId
  905. })
  906. .ToList();
  907. if (DeleClientList.Count < 1)
  908. {
  909. return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
  910. }
  911. var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
  912. var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
  913. Dictionary<string, string> bookmarkArr = null;
  914. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
  915. //载入模板
  916. Document doc = new Document(tempPath);
  917. DocumentBuilder builder = null;
  918. List<string> filesToZip = new List<string>();
  919. foreach (var ClientItem in _GroupClient) //遍历单位
  920. {
  921. doc = new Document(tempPath);
  922. builder = new DocumentBuilder(doc);
  923. Paragraph paragraph = new Paragraph(doc);
  924. bookmarkArr = new Dictionary<string, string>();
  925. bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
  926. bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
  927. bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
  928. bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
  929. bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry.Replace("|", "、"));//出访国家
  930. bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
  931. var ClientItemList = ClientItem.ToList();
  932. string UsersTop = string.Empty;//word中人员以及金额
  933. decimal WordAllPrice = 0.00M;
  934. //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(),
  935. // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
  936. //遍历人员
  937. for (int i = 0; i < ClientItemList.Count(); i++)
  938. {
  939. Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
  940. var client = ClientItemList[i]; //每个人员
  941. var firstName = ClientItemList[i].Name;
  942. //计算费用总和
  943. decimal airPrice = client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW;
  944. decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
  945. dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
  946. +_EnterExitCosts.YiMiao + _EnterExitCosts.YiMiao + _EnterExitCosts.Ticket + _EnterExitCosts.Service;
  947. WordAllPrice += AllPrice;
  948. UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
  949. TeableBookmarkArr.Add("jp", (client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW).ToString("#0.00") + " 元"); //机票金额
  950. TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
  951. TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
  952. string zsinfo = string.Empty;
  953. string hsinfo = string.Empty;
  954. string gzinfo = string.Empty;
  955. List<string> placeArr = new List<string>();
  956. Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  957. Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
  958. Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
  959. Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
  960. int rowIndex = 0;
  961. foreach (var item in dac1)
  962. {
  963. if (string.IsNullOrWhiteSpace(item.Place))
  964. {
  965. continue;
  966. }
  967. if (placeArr.Contains(item.Place))
  968. {
  969. continue;
  970. }
  971. else
  972. {
  973. placeArr.Add(item.Place);
  974. }
  975. if (!string.IsNullOrWhiteSpace(item.Place))
  976. {
  977. if (rowIndex > ChildTable.Rows.Count - 1)
  978. {
  979. var chitableRow = ChildTable.LastRow.Clone(true);
  980. ChildTable.AppendChild(chitableRow);
  981. }
  982. int days = dac1.FindAll(x => x.Place == item.Place).Count();
  983. SetCells(ChildTable, doc, rowIndex, 0, item.Place);
  984. SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
  985. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  986. SetCells(ChildTable, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/晚");
  987. SetCells(ChildTable, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  988. SetCells(ChildTable, doc, rowIndex, 4, "CNY" + item.SubTotal + "\r\n");
  989. rowIndex++;
  990. zsinfo += item.Place + " " + days + "晚 " + item.Cost.ToString("#0.00") + currencyCode + "/晚" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.0000") + " CNY" + item.SubTotal * days + "\r\n";
  991. }
  992. }
  993. placeArr.Clear();
  994. rowIndex = 0;
  995. foreach (var item in dac2)
  996. {
  997. if (string.IsNullOrWhiteSpace(item.Place))
  998. {
  999. continue;
  1000. }
  1001. if (placeArr.Contains(item.Place))
  1002. {
  1003. continue;
  1004. }
  1005. else
  1006. {
  1007. placeArr.Add(item.Place);
  1008. }
  1009. if (!string.IsNullOrWhiteSpace(item.Place))
  1010. {
  1011. if (rowIndex > ChildTable1.Rows.Count - 1)
  1012. {
  1013. var chitableRow = ChildTable1.LastRow.Clone(true);
  1014. ChildTable1.AppendChild(chitableRow);
  1015. }
  1016. int days = dac2.FindAll(x => x.Place == item.Place).Count();
  1017. SetCells(ChildTable1, doc, rowIndex, 0, item.Place);
  1018. SetCells(ChildTable1, doc, rowIndex, 1, days + "天");
  1019. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  1020. SetCells(ChildTable1, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/天");
  1021. SetCells(ChildTable1, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  1022. SetCells(ChildTable1, doc, rowIndex, 4, "CNY" + item.SubTotal);
  1023. rowIndex++;
  1024. hsinfo += item.Place + " " + days + "天 " + item.Cost.ToString("#0.00") + currencyCode + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.0000") + " CNY" + item.SubTotal * days + "\r\n";
  1025. }
  1026. }
  1027. placeArr.Clear();
  1028. rowIndex = 0;
  1029. foreach (var item in dac3)
  1030. {
  1031. if (string.IsNullOrWhiteSpace(item.Place))
  1032. {
  1033. continue;
  1034. }
  1035. if (placeArr.Contains(item.Place))
  1036. {
  1037. continue;
  1038. }
  1039. else
  1040. {
  1041. placeArr.Add(item.Place);
  1042. }
  1043. if (!string.IsNullOrWhiteSpace(item.Place))
  1044. {
  1045. if (rowIndex > ChildTable2.Rows.Count - 1)
  1046. {
  1047. var chitableRow = ChildTable2.LastRow.Clone(true);
  1048. ChildTable2.AppendChild(chitableRow);
  1049. }
  1050. int days = dac3.FindAll(x => x.Place == item.Place).Count();
  1051. SetCells(ChildTable2, doc, rowIndex, 0, item.Place);
  1052. SetCells(ChildTable2, doc, rowIndex, 1, days + "天");
  1053. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  1054. SetCells(ChildTable2, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/天");
  1055. SetCells(ChildTable2, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  1056. SetCells(ChildTable2, doc, rowIndex, 4, "CNY" + item.SubTotal + "\r\n");
  1057. rowIndex++;
  1058. gzinfo += item.Place + " " + days + "天 " + item.Cost.ToString("#0.00") + currencyCode + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  1059. }
  1060. }
  1061. placeArr.Clear();
  1062. TeableBookmarkArr.Add("zsinfo", zsinfo); //住宿费详情
  1063. TeableBookmarkArr.Add("hs", dac2.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //伙食费
  1064. TeableBookmarkArr.Add("hsinfo", hsinfo); //伙食费详情
  1065. TeableBookmarkArr.Add("gz", dac3.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //公杂费
  1066. TeableBookmarkArr.Add("gzinfo", gzinfo); //公杂费详情
  1067. string otherFeestr = "";
  1068. decimal otherFee = 0.00M;
  1069. if (_EnterExitCosts.Visa > 0.00M)
  1070. {
  1071. otherFee += _EnterExitCosts.Visa;
  1072. otherFeestr += $"签证费{_EnterExitCosts.Visa.ToString("#0.00")}元、";
  1073. }
  1074. if (_EnterExitCosts.YiMiao > 0.00M)
  1075. {
  1076. otherFee += _EnterExitCosts.YiMiao;
  1077. otherFeestr += $"疫苗费{_EnterExitCosts.YiMiao.ToString("#0.00")}元、";
  1078. }
  1079. if (_EnterExitCosts.HeSuan > 0.00M)
  1080. {
  1081. otherFee += _EnterExitCosts.HeSuan;
  1082. otherFeestr += $"核酸检测费{_EnterExitCosts.HeSuan.ToString("#0.00")}元、";
  1083. }
  1084. if (_EnterExitCosts.Safe > 0.00M)
  1085. {
  1086. otherFee += _EnterExitCosts.Safe;
  1087. otherFeestr += $"保险费{_EnterExitCosts.Safe.ToString("#0.00")}元、";
  1088. }
  1089. if (_EnterExitCosts.Ticket > 0.00M)
  1090. {
  1091. otherFee += _EnterExitCosts.Ticket;
  1092. otherFeestr += $"参展门票费{_EnterExitCosts.Ticket.ToString("#0.00")}元、";
  1093. }
  1094. if (otherFeestr.Length > 0)
  1095. {
  1096. otherFeestr = otherFeestr.Substring(0, otherFeestr.Length - 1);
  1097. otherFeestr += "等费用";
  1098. }
  1099. TeableBookmarkArr.Add("qt", otherFee.ToString("#0.00") + " 元");//其他费用
  1100. TeableBookmarkArr.Add("qtinfo", otherFeestr);//其他费用第二列
  1101. TeableBookmarkArr.Add("fw", _EnterExitCosts.Service.ToString("#0.00") + "元/人");//服务费
  1102. TeableBookmarkArr.Add("AllPrice", AllPrice.ToString("#0.00") + "元/人");//表格合计费用
  1103. string airStr = client.AirType == 460 ? "经济舱" : client.AirType == 458 ? "公务舱" : "";
  1104. TeableBookmarkArr.Add("title", $"费用清单-{airStr}({firstName})");
  1105. foreach (var book in TeableBookmarkArr.Keys)
  1106. {
  1107. if (doc.Range.Bookmarks[book] != null)
  1108. {
  1109. Bookmark mark = doc.Range.Bookmarks[book];
  1110. mark.Text = TeableBookmarkArr[book];
  1111. }
  1112. }
  1113. if (i != ClientItemList.Count - 1)
  1114. {
  1115. builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
  1116. Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  1117. table.ParentNode.InsertAfter(paragraph, table);
  1118. var CloneTable = (Aspose.Words.Tables.Table)table.Clone(true);
  1119. table.ParentNode.InsertAfter(CloneTable, paragraph);
  1120. }
  1121. TeableBookmarkArr.Clear();
  1122. }
  1123. bookmarkArr.Add("VisitPrice", WordAllPrice.ToString());//出访费用总额
  1124. bookmarkArr.Add("CnAllPrice", WordAllPrice.ConvertCNYUpper());//出访费用总额中文
  1125. bookmarkArr.Add("namesPrice", UsersTop.TrimEnd('、'));//各人员出访费用 付辰同志出访费用为¥73,604.8元
  1126. foreach (var book in bookmarkArr.Keys)
  1127. {
  1128. if (doc.Range.Bookmarks[book] != null)
  1129. {
  1130. Bookmark mark = doc.Range.Bookmarks[book];
  1131. mark.Text = bookmarkArr[book];
  1132. }
  1133. }
  1134. //MemoryStream outSteam = new MemoryStream();
  1135. string filsPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/File/{ClientItem.Key.Replace("\n", "")}.docx";
  1136. //去水印
  1137. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  1138. doc.Save(filsPath);
  1139. filesToZip.Add(filsPath);
  1140. //streams.Add(ClientItem.Key + ".docx", outSteam.ToArray());
  1141. }
  1142. //文件名
  1143. string zipFileName = _DelegationInfo.TeamName + "-收款账单.zip";
  1144. string zipPath = $"ForeignReceivables/File/{_DelegationInfo.TeamName}-收款账单{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  1145. try
  1146. {
  1147. using (var zip = ZipFile.Open(AppSettingsHelper.Get("WordBasePath") + zipPath, ZipArchiveMode.Create))
  1148. {
  1149. foreach (var file in filesToZip)
  1150. {
  1151. zip.CreateEntryFromFile(file, Path.GetFileName(file));
  1152. }
  1153. }
  1154. }
  1155. catch (Exception ex)
  1156. {
  1157. return Ok(JsonView(false, ex.Message));
  1158. }
  1159. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{zipPath}";
  1160. return Ok(JsonView(true, "成功", new { Url = url }));
  1161. }
  1162. return Ok(JsonView(false, "操作失败!"));
  1163. }
  1164. catch (Exception ex)
  1165. {
  1166. return Ok(JsonView(false, ex.Message));
  1167. }
  1168. }
  1169. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val)
  1170. {
  1171. //获取table中的某个单元格,从0开始
  1172. Aspose.Words.Tables.Cell lshCell = table.Rows[rows].Cells[cells];
  1173. //将单元格中的第一个段落移除
  1174. lshCell.FirstParagraph.Remove();
  1175. //新建一个段落
  1176. Paragraph p = new Paragraph(doc);
  1177. var r = new Run(doc, val);
  1178. r.Font.Size = 8;
  1179. //把设置的值赋给之前新建的段落
  1180. p.AppendChild(r);
  1181. //将此段落加到单元格内
  1182. lshCell.AppendChild(p);
  1183. }
  1184. #endregion
  1185. #region 已收款项
  1186. /// <summary>
  1187. /// 已收款项
  1188. /// 查询
  1189. /// </summary>
  1190. /// <param name="dto"></param>
  1191. /// <returns></returns>
  1192. [HttpPost]
  1193. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1194. public async Task<IActionResult> PostAmountReceived(AmountReceivedDto dto)
  1195. {
  1196. try
  1197. {
  1198. if (dto == null)
  1199. {
  1200. return Ok(JsonView(false, "参数不能为空!"));
  1201. }
  1202. Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
  1203. dynamic data = null;
  1204. if (dto.PortType == 1)
  1205. {
  1206. if (ffrData.Code != 0)
  1207. {
  1208. return Ok(JsonView(false, ffrData.Msg));
  1209. }
  1210. data = ffrData.Data;
  1211. }
  1212. else if (dto.PortType == 2)
  1213. {
  1214. if (ffrData.Code != 0)
  1215. {
  1216. return Ok(JsonView(false, ffrData.Msg));
  1217. }
  1218. data = ffrData.Data;
  1219. }
  1220. else if (dto.PortType == 2)
  1221. {
  1222. if (ffrData.Code != 0)
  1223. {
  1224. return Ok(JsonView(false, ffrData.Msg));
  1225. }
  1226. data = ffrData.Data;
  1227. }
  1228. else
  1229. {
  1230. return Ok(JsonView(false, "请选择正确的端口号!"));
  1231. }
  1232. return Ok(JsonView(true, "操作成功!", data));
  1233. }
  1234. catch (Exception ex)
  1235. {
  1236. return Ok(JsonView(false, ex.Message));
  1237. }
  1238. }
  1239. /// <summary>
  1240. /// 已收款项
  1241. /// Add Or Edit
  1242. /// </summary>
  1243. /// <param name="dto"></param>
  1244. /// <returns></returns>
  1245. [HttpPost]
  1246. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1247. public async Task<IActionResult> PostAmountReceivedAddOrEdit(AmountReceivedAddOrEditDto dto)
  1248. {
  1249. try
  1250. {
  1251. if (dto == null)
  1252. {
  1253. return Ok(JsonView(false, "参数不能为空!"));
  1254. }
  1255. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedAddOrEditDto(dto);
  1256. if (dto.PortType == 1)
  1257. {
  1258. if (ffrData.Code != 0)
  1259. {
  1260. return Ok(JsonView(false, ffrData.Msg));
  1261. }
  1262. }
  1263. else if (dto.PortType == 2)
  1264. {
  1265. if (ffrData.Code != 0)
  1266. {
  1267. return Ok(JsonView(false, ffrData.Msg));
  1268. }
  1269. }
  1270. else if (dto.PortType == 2)
  1271. {
  1272. if (ffrData.Code != 0)
  1273. {
  1274. return Ok(JsonView(false, ffrData.Msg));
  1275. }
  1276. }
  1277. else
  1278. {
  1279. return Ok(JsonView(false, "请选择正确的端口号!"));
  1280. }
  1281. return Ok(JsonView(true, "操作成功!"));
  1282. }
  1283. catch (Exception ex)
  1284. {
  1285. return Ok(JsonView(false, ex.Message));
  1286. }
  1287. }
  1288. /// <summary>
  1289. /// 已收款项
  1290. /// Del
  1291. /// </summary>
  1292. /// <param name="dto"></param>
  1293. /// <returns></returns>
  1294. [HttpPost]
  1295. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1296. public async Task<IActionResult> PostAmountReceived_Del(AmountReceivedDelDto dto)
  1297. {
  1298. try
  1299. {
  1300. if (dto == null)
  1301. {
  1302. return Ok(JsonView(false, "参数不能为空!"));
  1303. }
  1304. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedDel(dto);
  1305. if (ffrData.Code != 0)
  1306. {
  1307. return Ok(JsonView(false, ffrData.Msg));
  1308. }
  1309. return Ok(JsonView(true, "操作成功!"));
  1310. }
  1311. catch (Exception ex)
  1312. {
  1313. return Ok(JsonView(false, ex.Message));
  1314. }
  1315. }
  1316. #endregion
  1317. #region 收款退还与其他款项 --> 收款退还
  1318. /// <summary>
  1319. /// 收款退还与其他款项
  1320. /// 查询 根据团组Id
  1321. /// </summary>
  1322. /// <param name="dto"></param>
  1323. /// <returns></returns>
  1324. [HttpPost]
  1325. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1326. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyItemByDiId(PaymentRefundAndOtherMoneyItemByDiIdDto dto)
  1327. {
  1328. try
  1329. {
  1330. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1331. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1332. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1333. #region 页面功能权限处理
  1334. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1335. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1336. if (pageFunAuth.CheckAuth == 0)
  1337. {
  1338. return Ok(JsonView(false, "您没有当前页面查询权限!"));
  1339. }
  1340. #endregion
  1341. Result _result = await _paymentRefundAndOtherMoneyRep._ItemByDiId(dto.DiId);
  1342. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  1343. {
  1344. if (_result.Code != 0)
  1345. {
  1346. return Ok(JsonView(false, _result.Msg));
  1347. }
  1348. var data = new
  1349. {
  1350. PageFuncAuth = pageFunAuth,
  1351. Data = _result.Data
  1352. };
  1353. return Ok(JsonView(true, "操作成功!", data));
  1354. }
  1355. else
  1356. {
  1357. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  1358. }
  1359. }
  1360. catch (Exception ex)
  1361. {
  1362. return Ok(JsonView(false, ex.Message));
  1363. }
  1364. }
  1365. /// <summary>
  1366. /// 收款退还与其他款项
  1367. /// 删除
  1368. /// </summary>
  1369. /// <param name="dto"></param>
  1370. /// <returns></returns>
  1371. [HttpPost]
  1372. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1373. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyDel(PaymentRefundAndOtherMoneyDelDto dto)
  1374. {
  1375. try
  1376. {
  1377. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1378. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1379. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1380. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1381. #region 页面功能权限处理
  1382. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1383. #endregion
  1384. if (pageFunAuth.DeleteAuth == 0)
  1385. {
  1386. return Ok(JsonView(false, "您没有当前页面删除权限!"));
  1387. }
  1388. Result _result = await _paymentRefundAndOtherMoneyRep._Del(dto);
  1389. if (_result.Code != 0)
  1390. {
  1391. return Ok(JsonView(false, _result.Msg));
  1392. }
  1393. return Ok(JsonView(true, "操作成功!"));
  1394. }
  1395. catch (Exception ex)
  1396. {
  1397. return Ok(JsonView(false, ex.Message));
  1398. }
  1399. }
  1400. /// <summary>
  1401. /// 收款退还与其他款项
  1402. /// Info Data Source
  1403. /// </summary>
  1404. /// <param name="dto"></param>
  1405. /// <returns></returns>
  1406. [HttpPost]
  1407. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1408. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfoDataSource(PortDtoBase dto)
  1409. {
  1410. try
  1411. {
  1412. Result _result = await _paymentRefundAndOtherMoneyRep._InfoDataSource(dto);
  1413. if (_result.Code != 0)
  1414. {
  1415. return Ok(JsonView(false, _result.Msg));
  1416. }
  1417. return Ok(JsonView(true, "查询成功!", _result.Data));
  1418. }
  1419. catch (Exception ex)
  1420. {
  1421. return Ok(JsonView(false, ex.Message));
  1422. }
  1423. }
  1424. /// <summary>
  1425. /// 收款退还与其他款项
  1426. /// Info
  1427. /// </summary>
  1428. /// <param name="dto"></param>
  1429. /// <returns></returns>
  1430. [HttpPost]
  1431. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1432. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfo(PaymentRefundAndOtherMoneyInfoDto dto)
  1433. {
  1434. try
  1435. {
  1436. if (dto == null)
  1437. {
  1438. return Ok(JsonView(false, "参数不能为空!"));
  1439. }
  1440. Result _result = await _paymentRefundAndOtherMoneyRep._Info(dto);
  1441. if (_result.Code != 0)
  1442. {
  1443. return Ok(JsonView(false, _result.Msg));
  1444. }
  1445. return Ok(JsonView(true, "查询成功!", _result.Data));
  1446. }
  1447. catch (Exception ex)
  1448. {
  1449. return Ok(JsonView(false, ex.Message));
  1450. }
  1451. }
  1452. /// <summary>
  1453. /// 收款退还与其他款项 --> 收款退还(只保留人名币)
  1454. /// 操作(Add Or Edit)
  1455. /// </summary>
  1456. /// <param name="dto"></param>
  1457. /// <returns></returns>
  1458. [HttpPost]
  1459. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1460. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyAddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
  1461. {
  1462. try
  1463. {
  1464. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1465. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1466. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1467. #region 页面功能权限处理
  1468. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1469. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1470. #endregion
  1471. if (dto.Status == 1) //add
  1472. {
  1473. if (pageFunAuth.AddAuth == 0)
  1474. {
  1475. return Ok(JsonView(false, "您没有当前页面添加权限!"));
  1476. }
  1477. }
  1478. else if (dto.Status == 2) //edit
  1479. {
  1480. if (pageFunAuth.EditAuth == 0)
  1481. {
  1482. return Ok(JsonView(false, "您没有当前页面编辑权限!"));
  1483. }
  1484. }
  1485. else
  1486. {
  1487. return Ok(JsonView(false, "请输入正确的操作状态! 1 添加 2 修改!"));
  1488. }
  1489. Result _result = await _paymentRefundAndOtherMoneyRep._AddOrEdit(dto);
  1490. if (_result.Code != 0)
  1491. {
  1492. return Ok(JsonView(false, _result.Msg));
  1493. }
  1494. return Ok(JsonView(true, "操作成功!"));
  1495. }
  1496. catch (Exception ex)
  1497. {
  1498. return Ok(JsonView(false, ex.Message));
  1499. }
  1500. }
  1501. #endregion
  1502. #region 应收报表
  1503. /// <summary>
  1504. /// 应收报表
  1505. /// 查询 根据日期范围
  1506. /// </summary>
  1507. /// <param name="dto"></param>
  1508. /// <returns></returns>
  1509. [HttpPost]
  1510. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1511. public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
  1512. {
  1513. string sqlWhere = " Where di.IsDel=0 ";
  1514. #region 验证
  1515. if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
  1516. {
  1517. return Ok(JsonView(false, "日期参数至少填写一个!"));
  1518. }
  1519. if (!string.IsNullOrEmpty(dto.beginDt))
  1520. {
  1521. if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1522. {
  1523. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1524. }
  1525. else
  1526. {
  1527. sqlWhere += string.Format(@" And di.VisitDate >= '{0} 00:00:00' ", dto.beginDt);
  1528. }
  1529. }
  1530. if (!string.IsNullOrEmpty(dto.endDt))
  1531. {
  1532. if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1533. {
  1534. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1535. }
  1536. else
  1537. {
  1538. sqlWhere += string.Format(@" And di.VisitDate <= '{0} 23:59:59' ", dto.endDt);
  1539. }
  1540. }
  1541. #endregion
  1542. //排序倒序
  1543. string sql = string.Format(@" select distinct fr.diid,di.TeamName,di.ClientUnit,di.VisitDate,di.CreateTime from Fin_ForeignReceivables fr join Grp_DelegationInfo di on fr.DIID = di.id {0} Order By di.CreateTime Desc", sqlWhere);
  1544. List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
  1545. var setData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  1546. decimal sumAll_fr = 0M; //应收
  1547. decimal sumAll_pr = 0M; //已收
  1548. decimal sumAll_balance = 0M; //尾款
  1549. if (list_rst.Count > 0)
  1550. {
  1551. int rowNumber = 1;
  1552. foreach (var item_rst in list_rst)
  1553. {
  1554. DateTime dtTemp;
  1555. bool b = DateTime.TryParse(item_rst.visitDate, out dtTemp);
  1556. if (b)
  1557. {
  1558. item_rst.visitDate = dtTemp.ToString("yyyy-MM-dd");
  1559. }
  1560. item_rst.No = rowNumber;
  1561. rowNumber++;
  1562. int diId = item_rst.diid;
  1563. decimal sum_fr = 0M;
  1564. decimal sum_pr = 0M;
  1565. string str_client = string.Empty;
  1566. decimal sum_refund = 0M; //收款退还
  1567. decimal sum_extra = 0M; //超支费用
  1568. decimal balance = 0M;
  1569. string str_schedule = string.Empty;
  1570. //1.应收
  1571. string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
  1572. List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
  1573. sum_fr = list_fr.Sum(s => s.ItemSumPrice);
  1574. //2.已收
  1575. string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
  1576. List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
  1577. foreach (var item_pr in list_pr)
  1578. {
  1579. sum_pr += item_pr.Price;
  1580. str_client += string.Format(@"{0};", item_pr.Client);
  1581. str_schedule += string.Format(@"{0};", item_pr.Remark);
  1582. }
  1583. if (str_schedule.Length > 0)
  1584. {
  1585. str_schedule = str_schedule.TrimEnd(';');
  1586. }
  1587. if (str_client.Length > 0)
  1588. {
  1589. str_client = str_client.TrimEnd(';');
  1590. }
  1591. //3.收款退还
  1592. string sql_other = string.Format(@"Select * From Fin_PaymentRefundAndOtherMoney prao
  1593. Inner Join Grp_CreditCardPayment ccp On prao.Id = ccp.CId
  1594. Where ccp.CTable = 285 And ccp.IsPay = 1 And prao.IsDel = 0 And ccp.IsDel = 0 And prao.DiId = {0}", diId);
  1595. List<Grp_CreditCardPayment> list_other = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_other).ToList();
  1596. sum_refund = list_other.Sum(s => s.RMBPrice);
  1597. //4.超支
  1598. string sql_extra = string.Format(@" Select c.* From Fin_GroupExtraCost f
  1599. Inner join Grp_CreditCardPayment c On f.Id = c.CId
  1600. Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId = {0} ", diId);
  1601. List<Grp_CreditCardPayment> list_extra = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_extra).ToList();
  1602. sum_extra = list_extra.Sum(s => s.RMBPrice);
  1603. item_rst.frPrice = sum_fr.ToString("#0.00");
  1604. item_rst.extraPrice = sum_extra.ToString("#0.00");
  1605. item_rst.receivableTotal = (sum_fr + sum_extra).ToString("#0.00");
  1606. item_rst.prPrice = sum_pr.ToString("#0.00");
  1607. item_rst.refundAmount = sum_refund.ToString("#0.00");
  1608. item_rst.receivedTotal = (sum_pr - sum_refund).ToString("#0.00");
  1609. item_rst.balPrice = ((sum_fr + sum_extra) - (sum_pr - sum_refund)).ToString("#0.00");
  1610. item_rst.prClient = str_client;
  1611. item_rst.schedule = str_schedule;
  1612. string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
  1613. sumAll_fr += (sum_fr + sum_extra);
  1614. sumAll_pr += (sum_pr - sum_refund);
  1615. sumAll_balance += ((sum_fr + sum_extra) - (sum_pr - sum_refund));
  1616. #region 单位应收已收细项(以应收费用名称为主去(已收费用)匹配) 新增 雷怡 2024-35-08 16:35:28
  1617. List<ClientFeeInfoView> feeDatas = new List<ClientFeeInfoView>();
  1618. //匹配上的数据
  1619. foreach (var item in list_fr)
  1620. {
  1621. var prInfo = list_pr.Find(it => item.PriceName.Contains(it.Client) || item.PriceName.Equals(it.Client));
  1622. decimal _balancePayment = 0.00M;
  1623. if (item.Currency == prInfo?.Currency)
  1624. {
  1625. _balancePayment = item.ItemSumPrice - prInfo?.Price ?? 0.00M;
  1626. }
  1627. feeDatas.Add(new ClientFeeInfoView
  1628. {
  1629. client = item.PriceName,
  1630. frMoney = item.ItemSumPrice.ToString("#0.00"),
  1631. frCurrency = setData.Find(it => it.Id == item.Currency)?.Name ?? "-",
  1632. frRate = item.Rate.ToString("#0.0000"),
  1633. prReceivablesType = setData.Find(it => it.Id == prInfo?.ReceivablesType)?.Name ?? "",
  1634. prTime = prInfo?.SectionTime ?? "-",
  1635. prMoney = prInfo?.Price.ToString("#0.00") ?? "-",
  1636. prCurrency = setData.Find(it => it.Id == prInfo?.Currency)?.Name ?? "",
  1637. balPayment = _balancePayment.ToString("#0.00")
  1638. });
  1639. }
  1640. //未匹配上的数据
  1641. foreach (var item in list_pr)
  1642. {
  1643. var frInfo = list_fr.Find(it => it.PriceName.Contains(item.Client) || it.PriceName.Equals(item.Client));
  1644. if (frInfo == null)
  1645. {
  1646. feeDatas.Add(new ClientFeeInfoView
  1647. {
  1648. client = item.Client + "[未匹配上的已收数据(应收已收公司名称不一致)]",
  1649. frMoney = "0.00",
  1650. frCurrency = "-",
  1651. frRate = "0.0000",
  1652. prReceivablesType = setData.Find(it => it.Id == item?.ReceivablesType)?.Name ?? "",
  1653. prTime = item?.SectionTime ?? "-",
  1654. prMoney = item?.Price.ToString("#0.00") ?? "0.00",
  1655. prCurrency = setData.Find(it => it.Id == item?.Currency)?.Name ?? "",
  1656. balPayment = "0.00"
  1657. });
  1658. }
  1659. }
  1660. item_rst.feeItem = feeDatas;
  1661. #endregion
  1662. }
  1663. PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
  1664. result.total_fr = sumAll_fr.ToString("#0.00");
  1665. result.total_pr = sumAll_pr.ToString("#0.00");
  1666. result.total_balance = sumAll_balance.ToString("#0.00");
  1667. result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
  1668. if (dto.requestType == 1)
  1669. {
  1670. return Ok(JsonView(true, "请求成功", result, list_rst.Count));
  1671. }
  1672. else
  1673. {
  1674. //----------------------------
  1675. List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
  1676. WorkbookDesigner designer = new WorkbookDesigner();
  1677. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
  1678. int excNo = 1;
  1679. foreach (var item in list_rst)
  1680. {
  1681. Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
  1682. exc.No = excNo.ToString();
  1683. excNo++;
  1684. exc.TeamName = item.teamName;
  1685. exc.ClientUnit = item.clientUnit;
  1686. exc.VisitDate = item.visitDate;
  1687. exc.Accounts = item.frPrice;
  1688. exc.Extra = item.extraPrice;
  1689. exc.ReceivableTotal = item.receivableTotal;
  1690. exc.Received = item.prPrice;
  1691. exc.RefundAmount = item.refundAmount;
  1692. exc.ReceivedTotal = item.receivedTotal;
  1693. exc.Balance = item.balPrice;
  1694. exc.Collection = item.schedule;
  1695. DateTime time = Convert.ToDateTime(item.visitDate);
  1696. TimeSpan ts = DateTime.Now - time;
  1697. float SY = float.Parse(item.balPrice);
  1698. if (ts.Days >= 365 && SY > 0)
  1699. {
  1700. exc.Sign = "需收款";
  1701. }
  1702. else
  1703. {
  1704. exc.Sign = "";
  1705. }
  1706. list_Ex.Add(exc);
  1707. }
  1708. var dt = CommonFun.GetDataTableFromIList(list_Ex);
  1709. dt.TableName = "Excel_SyntheticalReceivableByDateRange";
  1710. if (dt != null)
  1711. {
  1712. designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
  1713. //数据源
  1714. designer.SetDataSource(dt);
  1715. //根据数据源处理生成报表内容
  1716. designer.Process();
  1717. string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  1718. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  1719. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  1720. return Ok(JsonView(true, "成功", new { url = rst }));
  1721. }
  1722. }
  1723. }
  1724. return Ok(JsonView(true, "获取成功", "", list_rst.Count));
  1725. }
  1726. #endregion
  1727. #region 付款申请
  1728. /// <summary>
  1729. /// 付款申请
  1730. /// 基础数据
  1731. /// </summary>
  1732. /// <param name="dto"></param>
  1733. /// <returns></returns>
  1734. [HttpPost]
  1735. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1736. public async Task<IActionResult> PostPayRequestInit()
  1737. {
  1738. try
  1739. {
  1740. var conpanyDatas = _sqlSugar.Queryable<Sys_Company>()
  1741. .Where(it => it.IsDel == 0)
  1742. .Select(it => new
  1743. {
  1744. Id = it.Id,
  1745. ConpamyName = it.CompanyName
  1746. }).ToList();
  1747. return Ok(JsonView(true, "操作成功!", new { ConpanyData = conpanyDatas }));
  1748. }
  1749. catch (Exception ex)
  1750. {
  1751. return Ok(JsonView(false, ex.Message));
  1752. }
  1753. }
  1754. /// <summary>
  1755. /// 付款申请 (PageId=51)
  1756. /// 查询 根据日期范围
  1757. /// </summary>
  1758. /// <param name="dto"></param>
  1759. /// <returns></returns>
  1760. [HttpPost]
  1761. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1762. public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
  1763. {
  1764. Stopwatch stopwatch = Stopwatch.StartNew();
  1765. #region 验证
  1766. DateTime beginDt, endDt;
  1767. string format = "yyyy-MM-dd";
  1768. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  1769. {
  1770. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  1771. }
  1772. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  1773. {
  1774. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  1775. }
  1776. #region 页面操作权限验证
  1777. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1778. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1779. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  1780. #endregion
  1781. #endregion
  1782. try
  1783. {
  1784. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  1785. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  1786. if (checkedStr != null)
  1787. {
  1788. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  1789. }
  1790. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.Status, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  1791. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(dto.Status, checkedView.GroupIds, dto.beginDt, dto.endDt);
  1792. stopwatch.Stop();
  1793. return Ok(JsonView(true, $"查询成功!耗时{stopwatch.ElapsedMilliseconds / 1000}s", new { daily = dailyResult, group = groupResult }));
  1794. }
  1795. catch (Exception ex)
  1796. {
  1797. return Ok(JsonView(false, ex.Message));
  1798. }
  1799. }
  1800. /// <summary>
  1801. /// 根据团组类型类型处理团组费用所属公司
  1802. /// </summary>
  1803. /// <param name="teamId"></param>
  1804. /// <returns></returns>
  1805. private CompanyInfo ExpenseCompanyByTeamId(int teamId)
  1806. {
  1807. CompanyInfo _companyInfo = new CompanyInfo();
  1808. List<int> _SiChuan = new List<int>() {
  1809. 38 , // 政府团
  1810. 39 , // 企业团
  1811. 40 , // 散客团
  1812. 102, // 未知
  1813. 248, // 非团组
  1814. 691, // 四川-会务活动
  1815. 762, // 四川-赛事项目收入
  1816. };
  1817. List<int> _ChengDu = new List<int>() {
  1818. 302, // 成都-会务活动
  1819. 1047, // 成都-赛事项目收入
  1820. };
  1821. if (_SiChuan.Contains(teamId))
  1822. {
  1823. _companyInfo.Id = 2;
  1824. _companyInfo.ConpanyName = "四川泛美交流有限公司";
  1825. }
  1826. if (_ChengDu.Contains(teamId))
  1827. {
  1828. _companyInfo.Id = 1;
  1829. _companyInfo.ConpanyName = "成都泛美商务有限公司";
  1830. }
  1831. return _companyInfo;
  1832. }
  1833. /// <summary>
  1834. /// 付款申请(团组费用申请相关)
  1835. /// 查询 根据日期范围
  1836. /// </summary>
  1837. /// <param name="_groupIds"></param>
  1838. /// <param name="beginDt"></param>
  1839. /// <param name="endDt"></param>
  1840. /// <returns></returns>
  1841. private tree_Group_DailyFeePaymentResult PayRequest_GroupPaymentByDateRange(int status, List<int> _groupIds, string beginDt, string endDt)
  1842. {
  1843. tree_Group_DailyFeePaymentResult _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
  1844. List<tree_Group_DailyFeePaymentPageListView> dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1845. #region sql条件处理
  1846. string sqlWhere = string.Format(@" And (AuditGMDate Between '{0} 00:00:00' And '{1} 23:59:59') ", beginDt, endDt);
  1847. if (status == 2)
  1848. {
  1849. if (_groupIds.Count < 1)
  1850. {
  1851. _DailyFeePaymentResult.dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1852. return _DailyFeePaymentResult;
  1853. }
  1854. sqlWhere += string.Format(@" And Id In ({0})", string.Join(",", _groupIds));
  1855. }
  1856. string sql_1 = string.Format(@"Select * From Grp_CreditCardPayment Where IsDel = 0 And IsPay = 0 And IsAuditGM = 1 {0}", sqlWhere);
  1857. #endregion
  1858. var _paymentDatas = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_1).ToList();//付款信息
  1859. _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
  1860. _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
  1861. List<int> groupIds = _paymentDatas.Select(it => it.DIId).Distinct().ToList();
  1862. var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id)).ToList();
  1863. //_groupDatas = (List<Grp_DelegationInfo>)_groupDatas.GroupBy(it => it.TeamDid);
  1864. #region 相关基础数据源
  1865. var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
  1866. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  1867. var countryFeeDatas = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  1868. var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1869. var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1870. var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1871. var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1872. var insureDatas = _sqlSugar.Queryable<Grp_Customers>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1873. var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1874. //var otherMoneyDatas = _sqlSugar.Queryable<Fin_OtherPrice>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Diid)).ToList();
  1875. var otherMoneyDatas = _sqlSugar.Queryable<Grp_DecreasePayments>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1876. var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1877. var ExtraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1878. #endregion
  1879. //Expense company
  1880. foreach (var groupInfo in _groupDatas)
  1881. {
  1882. List<Group_DailyFeePaymentContentInfolView> childList = new List<Group_DailyFeePaymentContentInfolView>();
  1883. var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
  1884. int rouNumber = 1;
  1885. foreach (var payInfo in groupPaymentDatas)
  1886. {
  1887. string priName = "-";
  1888. string orbitalPrivateTransfer = payInfo.OrbitalPrivateTransfer == 0 ? "公转" : payInfo.OrbitalPrivateTransfer == 1 ? "私转" : "-";
  1889. switch (payInfo.CTable)
  1890. {
  1891. case 76: //76 酒店预订
  1892. priName = $"[费用名称:{hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? ""}]";
  1893. break;
  1894. case 79: //79 车/导游地接
  1895. var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
  1896. if (opData != null)
  1897. {
  1898. string area = "";
  1899. bool b = int.TryParse(opData.Area, out int areaId);
  1900. if (b)
  1901. {
  1902. string area1 = countryFeeDatas.Find(it => it.Id == areaId)?.Country ?? "-";
  1903. area = $"{area1}({setDatas.Find(it => it.Id == opData.PriceType)?.Name ?? "-"})";
  1904. }
  1905. else area = opData.Area;
  1906. string opPriName = "-";
  1907. if (!string.IsNullOrEmpty(opData.PriceName)) opPriName = opData.PriceName;
  1908. area += $"({opPriName})";
  1909. if (payInfo.OrbitalPrivateTransfer == 0) //公转
  1910. {
  1911. priName = $"【{orbitalPrivateTransfer}】【导游: {opData.ServiceGuide} 】[费用名称:{area}]";
  1912. }
  1913. else if (payInfo.OrbitalPrivateTransfer == 1) //私转
  1914. {
  1915. priName = $"【{orbitalPrivateTransfer}】【导游:{opData.ServiceGuide}】[费用名称:{area}]";
  1916. }
  1917. }
  1918. break;
  1919. case 80: // 80 签证
  1920. string sql = string.Format("select b.Id,b.Pinyin,b.lastName,b.firstName,b.phone from Grp_TourClientList a, Crm_DeleClient b where a.clientid = b.id and a.isdel = 0 and a.diid = {0}", groupInfo.Id);
  1921. List<SimplClientInfo> arr = _sqlSugar.SqlQueryable<SimplClientInfo>(sql).ToList();
  1922. string visaClientName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "";
  1923. string clientName = "-";
  1924. if (Regex.Match(visaClientName, @"\d+,?").Value.Length > 0)
  1925. {
  1926. string[] temparr = visaClientName.Split(',');
  1927. string fistrStr = temparr[0];
  1928. int count = temparr.Count();
  1929. int tempId;
  1930. bool success = int.TryParse(fistrStr, out tempId);
  1931. if (success)
  1932. {
  1933. SimplClientInfo tempInfo = arr.FirstOrDefault(s => s.Id == tempId);
  1934. if (tempInfo != null)
  1935. {
  1936. if (count > 1)
  1937. {
  1938. clientName = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  1939. }
  1940. else
  1941. {
  1942. clientName = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  1943. }
  1944. }
  1945. }
  1946. else
  1947. {
  1948. clientName = fistrStr;
  1949. }
  1950. }
  1951. priName = $"[费用名称:{clientName}]";
  1952. break;
  1953. case 81: // 81 邀请/公务活动
  1954. priName = $"[费用名称:{ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? " -"}]";
  1955. break;
  1956. case 82: // 82 团组客户保险
  1957. priName = $"[费用名称:{insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? " -"}]";
  1958. break;
  1959. case 85: // 85 机票预订
  1960. string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "-";
  1961. string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "-";
  1962. priName = $"{flightsCode}【{airPayType}】";
  1963. break;
  1964. case 98: // 98 其他款项
  1965. priName = $"[费用名称:{otherMoneyDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  1966. break;
  1967. case 285: // 285 收款退还
  1968. priName = $"[费用名称:{refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  1969. break;
  1970. case 1015: // 1015 超支费用
  1971. priName = $"[费用名称:{ExtraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  1972. break;
  1973. default:
  1974. priName = "";
  1975. break;
  1976. }
  1977. //
  1978. bool status1 = false;
  1979. if (_groupIds != null)
  1980. {
  1981. status1 = _groupIds.Contains(payInfo.Id);
  1982. }
  1983. string payeeStr = string.Format(@" {0},开户行:{1},银行卡号:{2} ", string.IsNullOrEmpty(payInfo.Payee) ? "-" : payInfo.Payee,
  1984. string.IsNullOrEmpty(payInfo.OtherBankName) ? "-" : payInfo.OtherBankName,
  1985. string.IsNullOrEmpty(payInfo.OtherSideNo) ? "-" : payInfo.OtherSideNo);
  1986. decimal _PaymentAmount = (payInfo.PayMoney / 100) * payInfo.PayPercentage;//此次付款金额
  1987. decimal _CNYSubTotalAmount = _PaymentAmount * payInfo.DayRate;//此次付款金额
  1988. _CNYSubTotalAmount = Convert.ToDecimal(_CNYSubTotalAmount.ToString("#0.00"));
  1989. var childInfo = new Group_DailyFeePaymentContentInfolView()
  1990. {
  1991. IsChecked = status1,
  1992. Id = payInfo.Id,
  1993. Payee = payeeStr,
  1994. RowNumber = rouNumber,
  1995. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  1996. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  1997. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  1998. TransferMark = orbitalPrivateTransfer,
  1999. PriceName = priName,
  2000. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  2001. PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
  2002. PaymentAmount = _PaymentAmount,
  2003. PayRate = payInfo.DayRate,
  2004. CNYSubTotalAmount = _CNYSubTotalAmount
  2005. };
  2006. //string remaksDescription = $"【{childInfo.PayType}】【{childInfo.ModuleName}】{rouNumber}、[申请人:{childInfo.Applicant}][收款方:{childInfo.Payee}]{priName},{payInfo.OtherBankName},{payInfo.OtherSideNo}[{payInfo.ConsumptionPatterns}] {childInfo.PayCurrCode} {payInfo.PayMoney.ToString("#0.00")}、CNY:{childInfo.CNYSubTotalAmount.ToString("#0.00")}(团组:{groupInfo.TeamName})";
  2007. string remaksDescription = $"【{childInfo.PayType}】【{childInfo.ModuleName}】{rouNumber}、[申请人:{childInfo.Applicant}]{priName}[收款方:{childInfo.Payee}] {childInfo.PayCurrCode} {_PaymentAmount.ToString("#0.00")}、CNY:{childInfo.CNYSubTotalAmount.ToString("#0.00")}(团组:{groupInfo.TeamName})";
  2008. childInfo.RemaksDescription = remaksDescription;
  2009. childList.Add(childInfo);
  2010. rouNumber++;
  2011. }
  2012. CompanyInfo companyInfo = new CompanyInfo();
  2013. companyInfo = ExpenseCompanyByTeamId(groupInfo.TeamDid);
  2014. dataList.Add(new tree_Group_DailyFeePaymentPageListView()
  2015. {
  2016. Id = Guid.NewGuid().ToString("N"),
  2017. GroupName = groupInfo.TeamName,
  2018. CompanyId = companyInfo.Id,
  2019. ConpanyName = companyInfo.ConpanyName,
  2020. CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
  2021. ChildList = childList,
  2022. });
  2023. }
  2024. _DailyFeePaymentResult.dataList = dataList;
  2025. return _DailyFeePaymentResult;
  2026. }
  2027. /// <summary>
  2028. /// 付款申请(日付申请相关)
  2029. /// 查询 根据日期范围
  2030. /// </summary>
  2031. /// <param name="_dailyIds"></param>
  2032. /// <param name="beginDt"></param>
  2033. /// <param name="endDt"></param>
  2034. /// <returns></returns>
  2035. private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(int status, List<int> _dailyIds, string beginDt, string endDt)
  2036. {
  2037. #region sql条件处理
  2038. string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
  2039. if (status == 2)
  2040. {
  2041. if (_dailyIds.Count < 1)
  2042. {
  2043. return new tree_Fin_DailyFeePaymentResult() { childList = new List<Fin_DailyFeePaymentContentInfolView>() };
  2044. }
  2045. sqlWhere += string.Format(@" And dfp.Id In({0}) ", string.Join(",", _dailyIds));
  2046. }
  2047. string sql_1 = string.Format(@"Select * From (
  2048. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  2049. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  2050. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  2051. dfp.PriceTypeId,dfp.TransferTypeId
  2052. From Fin_DailyFeePayment dfp
  2053. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  2054. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  2055. Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1 And dfp.IsPay = 0
  2056. ) temp ", sqlWhere);
  2057. #endregion
  2058. List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
  2059. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  2060. Sys_SetDataType stGZ = _daiRep.Query<Sys_SetDataType>(s => s.Name == "公转").First();
  2061. Sys_SetDataType stSZ = _daiRep.Query<Sys_SetDataType>(s => s.Name == "私转").First();
  2062. foreach (var item in DailyFeePaymentData)
  2063. {
  2064. if (_dailyIds != null)
  2065. {
  2066. item.IsChecked = _dailyIds.Contains(item.Id);
  2067. }
  2068. if (dic_setData.ContainsKey(item.PriceTypeId))
  2069. {
  2070. item.priceTypeStr = dic_setData[item.PriceTypeId];
  2071. }
  2072. else
  2073. {
  2074. Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
  2075. if (sd_priceType != null)
  2076. {
  2077. item.priceTypeStr = sd_priceType.Name;
  2078. dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
  2079. }
  2080. }
  2081. if (dic_setData.ContainsKey(item.transferTypeId))
  2082. {
  2083. item.transferTypeIdStr = dic_setData[item.transferTypeId];
  2084. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  2085. if (sd_transfer != null)
  2086. {
  2087. item.transferParentId = sd_transfer.STid;
  2088. item.transferParentIdStr = sd_transfer.STid == stGZ.Id ? "公转" : sd_transfer.STid == stSZ.Id ? "私转" : "";
  2089. }
  2090. }
  2091. else
  2092. {
  2093. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  2094. if (sd_transfer != null)
  2095. {
  2096. item.transferTypeIdStr = sd_transfer.Name;
  2097. item.transferParentId = sd_transfer.STid;
  2098. item.transferParentIdStr = sd_transfer.STid == stGZ.Id ? "公转" : sd_transfer.STid == stSZ.Id ? "私转" : "";
  2099. dic_setData.Add(item.transferTypeId, sd_transfer.Name);
  2100. }
  2101. }
  2102. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  2103. Where IsDel=0 And DFPId = {0} ", item.Id);
  2104. item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
  2105. int rowNumber = 1;
  2106. foreach (var subItem in item.childList)
  2107. {
  2108. string remaksDescription = $"{rowNumber}、【{item.priceTypeStr}】{item.Instructions}({subItem.PriceName}) CNY:{subItem.ItemTotal.ToString("#0.00")}(单价:{subItem.Price.ToString("#0.00")} * {subItem.Quantity})";
  2109. subItem.RemaksDescription = remaksDescription;
  2110. 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")}】";
  2111. subItem.ExcelRemaksDescription = excelRemaksDescription;
  2112. rowNumber++;
  2113. }
  2114. }
  2115. decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == stGZ.Id).Sum(d => d.SumPrice ?? 0M);
  2116. decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == stSZ.Id).Sum(d => d.SumPrice ?? 0M);
  2117. var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
  2118. return result;
  2119. }
  2120. /// <summary>
  2121. /// 付款申请 (PageId=51)
  2122. /// 团组,日付相关费用 选中状态变更
  2123. /// </summary>
  2124. /// <param name="dto"></param>
  2125. /// <returns></returns>
  2126. [HttpPost]
  2127. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2128. public async Task<IActionResult> PostPayRequestCheckedChange(PayRequestCheckedChangeDto dto)
  2129. {
  2130. #region 验证
  2131. if (dto.Type < 1 || dto.Type > 2)
  2132. {
  2133. return Ok(JsonView(false, "请传入有效的Type参数! 1 checked 2 清除上次勾选"));
  2134. }
  2135. #endregion
  2136. try
  2137. {
  2138. PaymentRequestCheckedView requestCheckedView = new PaymentRequestCheckedView();
  2139. List<int> groupIds = new List<int>();
  2140. List<int> dailyPaymentIds = new List<int>();
  2141. #region 参数处理
  2142. if (!string.IsNullOrEmpty(dto.GroupIds))
  2143. {
  2144. if (dto.GroupIds.Contains(","))
  2145. {
  2146. groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  2147. }
  2148. else
  2149. {
  2150. groupIds.Add(int.Parse(dto.GroupIds));
  2151. }
  2152. }
  2153. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  2154. {
  2155. if (dto.DailyPaymentIds.Contains(","))
  2156. {
  2157. dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  2158. }
  2159. else
  2160. {
  2161. dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  2162. }
  2163. }
  2164. #endregion
  2165. requestCheckedView.GroupIds = groupIds;
  2166. requestCheckedView.DailyPaymentIds = dailyPaymentIds;
  2167. if (dto.Type == 1)
  2168. {
  2169. TimeSpan ts = DateTime.Now.AddDays(180) - DateTime.Now; //设置redis 过期时间 半年(180)
  2170. var status = await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("paymentRequestCheckedData", JsonConvert.SerializeObject(requestCheckedView), ts);
  2171. if (status)
  2172. {
  2173. return Ok(JsonView(true, "操作成功!"));
  2174. }
  2175. }
  2176. else if (dto.Type == 2)
  2177. {
  2178. var status = await RedisRepository.RedisFactory.CreateRedisRepository().KeyDeleteAsync("paymentRequestCheckedData");
  2179. if (status)
  2180. {
  2181. return Ok(JsonView(true, "操作成功!"));
  2182. }
  2183. }
  2184. return Ok(JsonView(false, "操作失败!"));
  2185. }
  2186. catch (Exception ex)
  2187. {
  2188. return Ok(JsonView(false, ex.Message));
  2189. }
  2190. }
  2191. /// <summary>
  2192. /// 付款申请 (PageId=51)
  2193. /// 团组,日付相关费用 汇率变更
  2194. /// </summary>
  2195. /// <param name="dto"></param>
  2196. /// <returns></returns>
  2197. [HttpPost]
  2198. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2199. public async Task<IActionResult> PostPayRequestRateChange(PayRequestRateChangeDto dto)
  2200. {
  2201. #region 验证
  2202. DateTime beginDt, endDt;
  2203. string format = "yyyy-MM-dd";
  2204. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  2205. {
  2206. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  2207. }
  2208. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  2209. {
  2210. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  2211. }
  2212. if (dto.UserId < 1)
  2213. {
  2214. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2215. }
  2216. if (dto.Id < 1)
  2217. {
  2218. return Ok(JsonView(false, "请传入有效的Id参数!"));
  2219. }
  2220. if (dto.Rate <= 0)
  2221. {
  2222. return Ok(JsonView(false, "请传入有效的Rate参数!"));
  2223. }
  2224. #endregion
  2225. try
  2226. {
  2227. var status = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2228. .SetColumns(it => it.DayRate == dto.Rate)
  2229. .Where(it => it.Id == dto.Id)
  2230. .ExecuteCommand();
  2231. if (status > 0)
  2232. {
  2233. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2234. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2235. if (checkedStr != null)
  2236. {
  2237. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2238. }
  2239. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(1, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2240. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(1, checkedView.GroupIds, dto.beginDt, dto.endDt);
  2241. decimal _gz = dailyResult.gz + groupResult.gz;
  2242. decimal _sz = dailyResult.sz + groupResult.sz;
  2243. return Ok(JsonView(true, "操作成功!", new { gz = dailyResult, sz = groupResult }));
  2244. }
  2245. return Ok(JsonView(false, "该项汇率修改失败!"));
  2246. }
  2247. catch (Exception ex)
  2248. {
  2249. return Ok(JsonView(false, ex.Message));
  2250. }
  2251. }
  2252. /// <summary>
  2253. /// 付款申请 (PageId=51)
  2254. /// 团组,日付相关费用 付款状态变更
  2255. /// </summary>
  2256. /// <param name="dto"></param>
  2257. /// <returns></returns>
  2258. [HttpPost]
  2259. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2260. public async Task<IActionResult> PostPayRequestPayChange(PayRequestPayChangeDto dto)
  2261. {
  2262. if (dto.UserId < 1)
  2263. {
  2264. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2265. }
  2266. //if (string.IsNullOrEmpty(dto.GroupIds))
  2267. //{
  2268. // return Ok(JsonView(false, "请传入有效的GroupIds参数!"));
  2269. //}
  2270. //if (string.IsNullOrEmpty(dto.DailyPaymentIds))
  2271. //{
  2272. // return Ok(JsonView(false, "请传入有效的DailyPaymentIds参数!"));
  2273. //}
  2274. try
  2275. {
  2276. List<int> groupIds = new List<int>();
  2277. List<int> dailyPaymentIds = new List<int>();
  2278. #region 参数处理
  2279. if (!string.IsNullOrEmpty(dto.GroupIds))
  2280. {
  2281. if (dto.GroupIds.Contains(","))
  2282. {
  2283. groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  2284. }
  2285. else
  2286. {
  2287. groupIds.Add(int.Parse(dto.GroupIds));
  2288. }
  2289. }
  2290. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  2291. {
  2292. if (dto.DailyPaymentIds.Contains(","))
  2293. {
  2294. dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  2295. }
  2296. else
  2297. {
  2298. dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  2299. }
  2300. }
  2301. #endregion
  2302. bool changeStatus = false;
  2303. _sqlSugar.BeginTran();
  2304. if (groupIds.Count > 0)
  2305. {
  2306. var groupStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2307. .SetColumns(it => it.IsPay == 1)
  2308. .Where(it => groupIds.Contains(it.Id))
  2309. .ExecuteCommand();
  2310. if (groupStatus > 0)
  2311. {
  2312. changeStatus = true;
  2313. }
  2314. }
  2315. if (dailyPaymentIds.Count > 0)
  2316. {
  2317. var dailyPaymentStatus = _sqlSugar.Updateable<Fin_DailyFeePayment>()
  2318. .SetColumns(it => it.IsPay == 1)
  2319. .Where(it => dailyPaymentIds.Contains(it.Id))
  2320. .ExecuteCommand();
  2321. if (dailyPaymentStatus > 0)
  2322. {
  2323. changeStatus = true;
  2324. }
  2325. }
  2326. if (changeStatus)
  2327. {
  2328. _sqlSugar.CommitTran();
  2329. #region 应用推送
  2330. try
  2331. {
  2332. foreach (int ccpId in groupIds)
  2333. {
  2334. List<string> tempList = new List<string>() { ccpId.ToString() };
  2335. await AppNoticeLibrary.SendUserMsg_GroupStatus_PayResult(ccpId, tempList);
  2336. }
  2337. foreach (int dailyId in dailyPaymentIds)
  2338. {
  2339. List<string> tempList = new List<string>() { dailyId.ToString() };
  2340. await AppNoticeLibrary.DailyPayReminder_Pay_ToUser(dailyId, tempList);
  2341. }
  2342. }
  2343. catch (Exception ex)
  2344. {
  2345. }
  2346. #endregion
  2347. return Ok(JsonView(true, "操作成功!"));
  2348. }
  2349. _sqlSugar.RollbackTran();
  2350. return Ok(JsonView(false, "付款状态修改失败!"));
  2351. }
  2352. catch (Exception ex)
  2353. {
  2354. _sqlSugar.RollbackTran();
  2355. return Ok(JsonView(false, ex.Message));
  2356. }
  2357. }
  2358. /// <summary>
  2359. /// 付款申请 (PageId=51)
  2360. /// File Download
  2361. /// </summary>
  2362. /// <param name="dto"></param>
  2363. /// <returns></returns>
  2364. [HttpPost]
  2365. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2366. public async Task<IActionResult> PostPayRequestFileDownload(PayRequestFileDownloadDto dto)
  2367. {
  2368. Stopwatch stopwatch = Stopwatch.StartNew();
  2369. #region 参数,权限 验证
  2370. if (dto.PortType < 1)
  2371. {
  2372. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  2373. }
  2374. if (dto.UserId < 1)
  2375. {
  2376. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2377. }
  2378. if (dto.PageId < 1)
  2379. {
  2380. dto.PageId = 51;
  2381. return Ok(JsonView(false, "请传入有效的PageId参数!"));
  2382. }
  2383. if (dto.ConpanyId < 1 || dto.ConpanyId > 4)
  2384. {
  2385. return Ok(JsonView(false, "请传入有效的ConpanyId参数!"));
  2386. }
  2387. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2388. #region 页面操作权限验证
  2389. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  2390. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  2391. #endregion
  2392. #endregion
  2393. try
  2394. {
  2395. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2396. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2397. if (checkedStr != null)
  2398. {
  2399. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2400. }
  2401. if (checkedView == null)
  2402. {
  2403. return Ok(JsonView(false, "没有选中的数据!"));
  2404. }
  2405. if (checkedView.GroupIds == null && checkedView.DailyPaymentIds == null)
  2406. {
  2407. return Ok(JsonView(false, "没有选中的数据!"));
  2408. }
  2409. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(2, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2410. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(2, checkedView.GroupIds, dto.beginDt, dto.endDt);
  2411. if (dailyResult.childList == null)
  2412. {
  2413. dailyResult.childList = new List<Fin_DailyFeePaymentContentInfolView>();
  2414. }
  2415. List<tree_Group_DailyFeePaymentPageListView> _GroupData = new List<tree_Group_DailyFeePaymentPageListView>();
  2416. List<tree_Fin_DailyFeePaymentPageListView> _DailyData = new List<tree_Fin_DailyFeePaymentPageListView>();
  2417. //1 成都泛美商务有限公司
  2418. if (dto.ConpanyId == 1)
  2419. {
  2420. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2421. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2422. }
  2423. //2 四川泛美交流有限公司
  2424. else if (dto.ConpanyId == 2)
  2425. {
  2426. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2427. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2428. }
  2429. //3 成都纽茵教育科技有限公司
  2430. else if (dto.ConpanyId == 3)
  2431. {
  2432. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2433. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2434. }
  2435. //4 成都鸿企中元科技有限公司
  2436. else if (dto.ConpanyId == 4)
  2437. {
  2438. return Ok(JsonView(false, "暂未开放该类型!"));
  2439. }
  2440. else
  2441. {
  2442. return Ok(JsonView(false, "参数ConpanyId不可使用!"));
  2443. }
  2444. string _requestPaymentDt = DateTime.Now.ToString("yyyy-MM-dd"),//申请付款日期
  2445. _appliedAmount = "", //申请付款金额
  2446. _GZStr = "", //公转价格描述
  2447. _SZStr = ""; //私转价格描述
  2448. decimal groupGZAmout = 0.00M, groupSZAmout = 0.00M;
  2449. decimal dailyGZAmout = 0.00M, dailySZAmout = 0.00M;
  2450. string dailyGZStr = "", dailySZStr = "", groupGZStr = "", groupSZStr = "";
  2451. #region 数据处理
  2452. //团组费用相关
  2453. foreach (var item in _GroupData)
  2454. {
  2455. string groupGZSubStr = "";
  2456. string groupSZSubStr = "";
  2457. foreach (var subItem in item.ChildList)
  2458. {
  2459. if (subItem.TransferMark.Equals("公转"))
  2460. {
  2461. groupGZAmout += subItem.CNYSubTotalAmount;
  2462. groupGZSubStr += $"{subItem.RemaksDescription}\r\n";
  2463. }
  2464. else if (subItem.TransferMark.Equals("私转"))
  2465. {
  2466. groupSZAmout += subItem.CNYSubTotalAmount;
  2467. groupSZSubStr += $"{subItem.RemaksDescription}\r\n";
  2468. }
  2469. //groupGZSubStr += $"\t";
  2470. }
  2471. //if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"团组:{item.GroupName}\r\n{groupGZSubStr}\r\n";
  2472. //if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"团组:{item.GroupName}\r\n{groupSZSubStr}\r\n";
  2473. if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"{groupGZSubStr}\r\n";
  2474. if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"{groupSZSubStr}\r\n";
  2475. }
  2476. //日常费用相关
  2477. foreach (var item in _DailyData)
  2478. {
  2479. foreach (var subItem in item.childList)
  2480. {
  2481. if (item.transferParentId == 62) //公转
  2482. {
  2483. dailyGZAmout += item.SumPrice ?? 0.00M;
  2484. dailyGZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
  2485. }
  2486. else if (item.transferParentId == 63) //私转
  2487. {
  2488. dailySZAmout += item.SumPrice ?? 0.00M;
  2489. dailySZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
  2490. }
  2491. }
  2492. }
  2493. _GZStr = $"【公转】团组相关费用(合计:CNY {groupGZAmout.ToString("#0.00")}):\r\n{groupGZStr}【公转】日常付款费用(合计:CNY {dailyGZAmout.ToString("#0.00")}):\r\n{dailyGZStr}";
  2494. _SZStr = $"【私转】团组相关费用(合计:CNY {groupSZAmout.ToString("#0.00")}):\r\n{groupSZStr}【私转】日常付款费用(合计:CNY {dailySZAmout.ToString("#0.00")}):\r\n{dailySZStr}";
  2495. _appliedAmount = $"公转:CNY {(groupGZAmout + dailyGZAmout).ToString("#0.00")}\r\n私转:CNY {(groupSZAmout + dailySZAmout).ToString("#0.00")}";
  2496. #endregion
  2497. WorkbookDesigner designer = new WorkbookDesigner();
  2498. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/付款申请书.xls");
  2499. designer.SetDataSource("Date", _requestPaymentDt);
  2500. designer.SetDataSource("Price", _appliedAmount);
  2501. designer.SetDataSource("Content", _GZStr);
  2502. designer.SetDataSource("Content1", _SZStr);
  2503. //根据数据源处理生成报表内容
  2504. designer.Process();
  2505. string fileName = ("PayRequest/付款申请(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  2506. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  2507. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  2508. stopwatch.Stop();
  2509. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds / 1000}s", new { url = rst }));
  2510. }
  2511. catch (Exception ex)
  2512. {
  2513. return Ok(JsonView(false, ex.Message));
  2514. }
  2515. }
  2516. #endregion
  2517. #region 超支费用
  2518. /// <summary>
  2519. /// 超支费用
  2520. /// 1增、2改、3删
  2521. /// </summary>
  2522. /// <param name="dto"></param>
  2523. /// <returns></returns>
  2524. [HttpPost]
  2525. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2526. public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  2527. {
  2528. #region 验证
  2529. #endregion
  2530. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  2531. _entity.DiId = dto.diId;
  2532. _entity.PriceName = dto.priceName;
  2533. _entity.Price = dto.price;
  2534. _entity.PriceCurrency = dto.currency;
  2535. _entity.PriceType = dto.priceType;
  2536. _entity.Coefficient = dto.coefficient;
  2537. _entity.PriceDetailType = dto.priceDetailType;
  2538. _entity.FilePath = dto.filePath;
  2539. _entity.Remark = dto.remark;
  2540. _entity.PriceCount = dto.PriceCount;
  2541. DateTime dt_PriceDt;
  2542. bool b_PriceDt = DateTime.TryParse(dto.PriceDt, out dt_PriceDt);
  2543. if (b_PriceDt)
  2544. {
  2545. _entity.PriceDt = dt_PriceDt;
  2546. }
  2547. else
  2548. {
  2549. _entity.PriceDt = DateTime.MinValue;
  2550. }
  2551. _entity.PriceSum = dto.price * dto.PriceCount;
  2552. _daiRep.BeginTran();
  2553. if (dto.editType == 1)
  2554. {
  2555. _entity.CreateUserId = dto.createUser;
  2556. _entity.CreateTime = DateTime.Now;
  2557. _entity.IsDel = 0;
  2558. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  2559. if (returnId > 0)
  2560. {
  2561. dto.Id = returnId;
  2562. }
  2563. }
  2564. else if (dto.editType == 2)
  2565. {
  2566. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2567. {
  2568. PriceName = dto.priceName,
  2569. Price = dto.price,
  2570. PriceCurrency = dto.currency,
  2571. PriceType = dto.priceType,
  2572. PriceDetailType = dto.priceDetailType,
  2573. Coefficient = dto.coefficient,
  2574. FilePath = dto.filePath,
  2575. Remark = dto.remark,
  2576. PriceCount = dto.PriceCount,
  2577. PriceDt = _entity.PriceDt,
  2578. PriceSum = _entity.PriceSum
  2579. });
  2580. if (!res)
  2581. {
  2582. _daiRep.RollbackTran();
  2583. return Ok(JsonView(false, "2操作失败!"));
  2584. }
  2585. }
  2586. else if (dto.editType == 3)
  2587. {
  2588. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2589. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2590. {
  2591. IsDel = 1,
  2592. DeleteTime = delTime,
  2593. DeleteUserId = dto.createUser
  2594. });
  2595. if (!res)
  2596. {
  2597. _daiRep.RollbackTran();
  2598. return Ok(JsonView(false, "3操作失败!"));
  2599. }
  2600. }
  2601. else
  2602. {
  2603. _daiRep.RollbackTran();
  2604. return Ok(JsonView(false, "未知的editType"));
  2605. }
  2606. if (!extraCost_editCreditCardPayment(dto))
  2607. {
  2608. return Ok(JsonView(false, "ccp操作失败"));
  2609. }
  2610. _daiRep.CommitTran();
  2611. return Ok(JsonView(true, "操作成功"));
  2612. }
  2613. private Result PostCurrencyByDiid_Sync(int diId, int CId, int currencyId)
  2614. {
  2615. if (diId == 0)
  2616. {
  2617. return new Result() { Code = -1, Msg = "请传入团组Id!" };
  2618. }
  2619. if (CId == 0)
  2620. {
  2621. return new Result() { Code = -1, Msg = "请传入类型Id!" };
  2622. }
  2623. if (currencyId == 0)
  2624. {
  2625. return new Result() { Code = -1, Msg = "请传入币种Id!" };
  2626. }
  2627. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == diId && a.IsDel == 0 && a.CTable == CId);
  2628. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  2629. CurrencyInfo CurrencyRate = new CurrencyInfo();
  2630. try
  2631. {
  2632. if (_TeamRate != null)
  2633. {
  2634. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == currencyId);
  2635. if (_SetData != null)
  2636. {
  2637. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  2638. CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  2639. if (CurrencyRate != null)
  2640. {
  2641. return new Result() { Code = 0, Msg = "查询成功!", Data = CurrencyRate };
  2642. }
  2643. else
  2644. {
  2645. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2646. }
  2647. }
  2648. else
  2649. {
  2650. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2651. }
  2652. }
  2653. else
  2654. {
  2655. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2656. }
  2657. }
  2658. catch (Exception)
  2659. {
  2660. return new Result() { Code = -1, Msg = "查询异常!", Data = CurrencyRate };
  2661. }
  2662. }
  2663. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  2664. {
  2665. //设置团组汇率
  2666. decimal dcm_dayrate = 1M;
  2667. decimal dcm_rmbPrice = costDto.price;
  2668. int ispay = costDto.payType == 72 ? 1 : 0;
  2669. if (costDto.costSign != 3)
  2670. {
  2671. //获取新汇率 int diId,int CId, int currencyId
  2672. Result rate = this.PostCurrencyByDiid_Sync(costDto.diId, 1015, costDto.currency);
  2673. if (rate.Code == 0)
  2674. {
  2675. var rateInfo = (rate.Data as CurrencyInfo);
  2676. if (rateInfo is not null)
  2677. {
  2678. dcm_dayrate = rateInfo.Rate;
  2679. dcm_rmbPrice = rateInfo.Rate * dcm_rmbPrice;
  2680. }
  2681. else
  2682. {
  2683. dcm_dayrate = 1;
  2684. }
  2685. }
  2686. }
  2687. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  2688. if (ccp == null)
  2689. {
  2690. ccp = new Grp_CreditCardPayment();
  2691. ccp.PayDId = costDto.payType;// dto
  2692. ccp.ConsumptionPatterns = "";
  2693. ccp.ConsumptionDate = "";
  2694. ccp.CTDId = costDto.payCardId;// dto
  2695. ccp.BankNo = "";
  2696. ccp.CardholderName = "";
  2697. ccp.PayMoney = costDto.price;// dto
  2698. ccp.PaymentCurrency = costDto.currency;// dto
  2699. ccp.CompanyBankNo = "";
  2700. ccp.OtherBankName = "";
  2701. ccp.OtherSideNo = "";
  2702. ccp.OtherSideName = "";
  2703. ccp.Remark = "";
  2704. ccp.CreateUserId = costDto.createUser;
  2705. ccp.CreateTime = DateTime.Now;
  2706. ccp.MFOperator = 0;
  2707. ccp.MFOperatorDate = "";
  2708. ccp.IsAuditDM = 0;
  2709. ccp.AuditDMOperate = 0;
  2710. ccp.AuditDMDate = "";
  2711. ccp.IsAuditMF = 0;
  2712. ccp.AuditMFOperate = 0;
  2713. ccp.AuditMFDate = "";
  2714. ccp.IsAuditGM = 0;
  2715. ccp.AuditGMOperate = 0;
  2716. ccp.AuditGMDate = "";
  2717. ccp.IsPay = ispay; // upd
  2718. ccp.DIId = costDto.diId;// dto
  2719. ccp.CId = costDto.Id;// dto
  2720. ccp.CTable = 1015; //超支费用指向id
  2721. ccp.IsDel = 0;
  2722. ccp.PayPercentage = 100M;
  2723. ccp.PayThenMoney = 0M;
  2724. ccp.PayPercentageOld = 100M;
  2725. ccp.PayThenMoneyOld = 0M;
  2726. ccp.UpdateDate = "";
  2727. ccp.Payee = costDto.payee;// dto
  2728. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  2729. ccp.ExceedBudget = 0;
  2730. ccp.DayRate = dcm_dayrate; //upd
  2731. ccp.RMBPrice = dcm_rmbPrice; //upd
  2732. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  2733. if (ccpInsertId > 0)
  2734. {
  2735. return true;
  2736. }
  2737. }
  2738. else
  2739. {
  2740. if (costDto.editType == 2)
  2741. {
  2742. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  2743. {
  2744. PayDId = costDto.payType,
  2745. CTDId = costDto.payCardId,
  2746. PayMoney = costDto.price,
  2747. PaymentCurrency = costDto.currency,
  2748. IsPay = ispay,
  2749. Payee = costDto.payee,
  2750. OrbitalPrivateTransfer = costDto.costSign,
  2751. DayRate = dcm_dayrate,
  2752. RMBPrice = dcm_rmbPrice
  2753. });
  2754. return res;
  2755. }
  2756. else if (costDto.editType == 3)
  2757. {
  2758. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2759. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  2760. {
  2761. IsDel = 1,
  2762. DeleteTime = delTime,
  2763. DeleteUserId = costDto.createUser
  2764. });
  2765. return res2;
  2766. }
  2767. }
  2768. return false;
  2769. }
  2770. /// <summary>
  2771. /// 超支费用
  2772. /// 详情查询
  2773. /// </summary>
  2774. /// <param name="dto"></param>
  2775. /// <returns></returns>
  2776. [HttpPost]
  2777. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2778. public async Task<IActionResult> PostGroupExtraCost_Detail(Fin_GroupExtraCostDto_Detail dto)
  2779. {
  2780. if (dto.Id < 1)
  2781. {
  2782. return Ok(JsonView(false, "查询失败"));
  2783. }
  2784. string sql = string.Format(@" Select
  2785. f.Id,f.DiId,
  2786. f.PriceName,f.Price,f.PriceCurrency,c.Payee,c.OrbitalPrivateTransfer,c.PayDId,
  2787. c.CTDId,f.PriceType,f.PriceDetailType,f.Coefficient,f.Remark,f.PriceCount,f.PriceDt
  2788. From Fin_GroupExtraCost f
  2789. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2790. Left Join Sys_Users u On f.CreateUserId = u.Id
  2791. Where f.IsDel=0 And c.CTable = 1015
  2792. And f.Id = {0} ", dto.Id);
  2793. Fin_GroupExtraCostDetailView detailView = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostDetailView>(sql).FirstAsync();
  2794. if (detailView == null)
  2795. {
  2796. return Ok(JsonView(false, "查询失败"));
  2797. }
  2798. return Ok(JsonView(true, "查询成功", detailView));
  2799. }
  2800. /// <summary>
  2801. /// 超支费用
  2802. /// 列表查询
  2803. /// </summary>
  2804. /// <param name="dto"></param>
  2805. /// <returns></returns>
  2806. [HttpPost]
  2807. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2808. public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
  2809. {
  2810. string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
  2811. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  2812. int endIndex = startIndex + dto.PageSize - 1;
  2813. string sql_data = string.Format(@"Select * From (
  2814. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  2815. f.PriceName,f.PriceType,f.PriceDetailType,CAST(f.Price as varchar)+' '+s.[Name] as PriceStr,f.PriceCount,CAST(f.PriceSum as varchar)+' '+s.[Name] as PriceSumStr,
  2816. f.CreateUserId,f.PriceDt,c.IsAuditGM
  2817. From Fin_GroupExtraCost f
  2818. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2819. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  2820. Left Join Sys_Users u On f.CreateUserId = u.Id
  2821. Where f.IsDel=0 And c.CTable = 1015 {0}
  2822. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  2823. string sql_count = string.Format(@"Select Count(1) as DataCount From (
  2824. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  2825. f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  2826. From Fin_GroupExtraCost f
  2827. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2828. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  2829. Left Join Sys_Users u On f.CreateUserId = u.Id
  2830. Where f.IsDel=0 And c.CTable = 1015 {0}
  2831. ) temp ", sqlWhere);
  2832. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  2833. {
  2834. //Fin_DailyFeePaymentPageCount
  2835. var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
  2836. List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
  2837. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  2838. Dictionary<int, string> dic_user = new Dictionary<int, string>();
  2839. foreach (var item in dataList)
  2840. {
  2841. DateTime dtTemp_PriceDt;
  2842. bool b_ct = DateTime.TryParse(item.PriceDt, out dtTemp_PriceDt);
  2843. if (b_ct)
  2844. {
  2845. item.PriceDt = dtTemp_PriceDt.ToString("yyyy-MM-dd");
  2846. }
  2847. //费用类型
  2848. if (dic_setData.ContainsKey(item.PriceType))
  2849. {
  2850. item.PriceTypeStr = dic_setData[item.PriceType];
  2851. }
  2852. else
  2853. {
  2854. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
  2855. if (sd_priceTypeDetail != null)
  2856. {
  2857. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  2858. item.PriceTypeStr = tempName;
  2859. dic_setData.Add(item.PriceType, tempName);
  2860. }
  2861. }
  2862. if (item.PriceDetailType > 0)
  2863. {
  2864. if (dic_setData.ContainsKey(item.PriceDetailType))
  2865. {
  2866. item.PriceTypeStr = item.PriceTypeStr + " - " + dic_setData[item.PriceDetailType];
  2867. }
  2868. else
  2869. {
  2870. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceDetailType).First();
  2871. if (sd_priceTypeDetail != null)
  2872. {
  2873. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  2874. item.PriceTypeStr = item.PriceTypeStr + " - " + tempName;
  2875. dic_setData.Add(item.PriceDetailType, tempName);
  2876. }
  2877. }
  2878. }
  2879. //系统用户
  2880. if (dic_user.ContainsKey(item.CreateUserId))
  2881. {
  2882. item.CreateUserIdStr = dic_user[item.CreateUserId];
  2883. }
  2884. else
  2885. {
  2886. Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
  2887. if (users != null)
  2888. {
  2889. item.CreateUserIdStr = users.CnName;
  2890. dic_user.Add(item.CreateUserId, users.CnName);
  2891. }
  2892. }
  2893. switch (item.IsAuditGM)
  2894. {
  2895. case 0: item.IsAuditGMStr = "未审核"; break;
  2896. case 1: item.IsAuditGMStr = "已通过"; break;
  2897. case 2: item.IsAuditGMStr = "未通过"; break;
  2898. default: item.IsAuditGMStr = "未知状态"; break;
  2899. }
  2900. }
  2901. var result = new ListViewBase<Fin_GroupExtraCostView>
  2902. {
  2903. CurrPageIndex = dto.PageIndex,
  2904. CurrPageSize = dto.PageSize,
  2905. DataCount = count.DataCount,
  2906. DataList = dataList
  2907. };
  2908. return Ok(JsonView(true, "查询成功", result));
  2909. }
  2910. return Ok(JsonView(false, "查询失败"));
  2911. }
  2912. /// <summary>
  2913. /// 超支费用
  2914. /// 数据集合配置
  2915. /// </summary>
  2916. /// <param name="dto"></param>
  2917. /// <returns></returns>
  2918. [HttpPost]
  2919. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2920. public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
  2921. {
  2922. //支付方式
  2923. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  2924. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  2925. //信用卡类型
  2926. List<Sys_SetData> Card = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  2927. List<SetDataInfoView> _Card = _mapper.Map<List<SetDataInfoView>>(Card);
  2928. //超支费用类型
  2929. List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
  2930. List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
  2931. //超支费用详细类型
  2932. List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
  2933. PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
  2934. List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
  2935. var data = new
  2936. {
  2937. Payment = _Payment,
  2938. Card = _Card,
  2939. PriceType = _PriceType,
  2940. PriceDetailType = _PriceDetailType
  2941. };
  2942. return Ok(JsonView(true, "", data));
  2943. }
  2944. /// <summary>
  2945. /// 超支费用
  2946. /// 导出团组超支费用Excel
  2947. /// </summary>
  2948. /// <param name="dto"></param>
  2949. /// <returns></returns>
  2950. [HttpPost]
  2951. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2952. public async Task<IActionResult> PostGroupExtraCost_OutputExcel(Fin_GroupExtraCostExcelDto dto)
  2953. {
  2954. string sqlGroup = string.Format(@" Select * From Grp_DelegationInfo WIth(Nolock) where Id = {0} ", dto.diId);
  2955. Grp_DelegationInfo grp_DelegationInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sqlGroup).FirstAsync();
  2956. if (grp_DelegationInfo == null)
  2957. {
  2958. return Ok(JsonView(false, "导出失败,未查询到团组"));
  2959. }
  2960. Workbook workbook = new Workbook();
  2961. Worksheet sheet = workbook.Worksheets[0];
  2962. Cells cells = sheet.Cells;
  2963. //sheet.Protect(Aspose.Cells.ProtectionType.All, "123123", "");//保护工作表
  2964. //sheet.Protection.IsSelectingLockedCellsAllowed = true;//设置只能选择解锁单元格
  2965. //sheet.Protection.IsFormattingColumnsAllowed = true;//设置可以调整列
  2966. //sheet.Protection.IsFormattingRowsAllowed = true;//设置可以调整行
  2967. #region 数据源
  2968. string sqlData = string.Format(@" Select f.PriceType,REPLACE(s2.[Name],'超支费用','') as PriceTypeStr,'('+REPLACE(s3.[Name],'n','')+')' as PriceDetailTypeStr, PriceDt,PriceName,
  2969. Price,PriceCount,s.[Name] as Currency,PriceSum,f.Remark
  2970. From Fin_GroupExtraCost as f With(Nolock)
  2971. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  2972. Inner Join Sys_SetData as s With(Nolock) On f.PriceCurrency = s.Id
  2973. Inner Join Sys_SetData as s2 With(Nolock) On f.PriceType = s2.Id
  2974. Inner Join Sys_SetData as s3 With(Nolock) On f.PriceDetailType = s3.Id
  2975. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  2976. Order by PriceType ASC,PriceDt ASC ", dto.diId);
  2977. string sqlDataCount = string.Format(@" Select f.PriceType,COUNT(f.PriceType) as DataCount
  2978. From Fin_GroupExtraCost as f With(Nolock)
  2979. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  2980. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  2981. Group by PriceType ", dto.diId);
  2982. List<Fin_GroupExtraCost_ExcelView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelView>(sqlData).ToListAsync();
  2983. List<Fin_GroupExtraCost_ExcelCountView> countList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelCountView>(sqlDataCount).ToListAsync();
  2984. if (dataList.Count < 1 || countList.Count < 1)
  2985. {
  2986. return Ok(JsonView(false, "导出失败,未查询到数据"));
  2987. }
  2988. #endregion
  2989. #region 标题
  2990. string cellValue_Header = grp_DelegationInfo.TeamName;
  2991. //Aspose.Cells.Style style1 = workbook.Styles[workbook.Styles.Add()];//新增样式
  2992. Aspose.Cells.Style style_Header = workbook.CreateStyle();
  2993. style_Header.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  2994. style_Header.VerticalAlignment = TextAlignmentType.Center;
  2995. style_Header.Font.Name = "微软雅黑";//文字字体
  2996. style_Header.Font.Size = 18;//文字大小
  2997. style_Header.IsLocked = false;//单元格解锁
  2998. style_Header.Font.IsBold = false;//粗体
  2999. style_Header.Font.Color = Color.FromArgb(255, 0, 0);
  3000. //style1.ForegroundColor = Color.FromArgb(0x99, 0xcc, 0xff);//设置背景色
  3001. //style1.Pattern = BackgroundType.Solid; //设置背景样式
  3002. //style1.IsTextWrapped = true;//单元格内容自动换行
  3003. style_Header.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3004. style_Header.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3005. style_Header.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3006. style_Header.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3007. cells.Merge(1, 1, 1, 10);
  3008. Aspose.Cells.Range range_header = cells.CreateRange(1, 1, 1, 10);
  3009. range_header.PutValue(cellValue_Header, false, false);
  3010. range_header.SetStyle(style_Header);
  3011. cells.SetRowHeight(1, 35);
  3012. #endregion
  3013. #region 列名
  3014. Aspose.Cells.Style style_colName = workbook.CreateStyle();
  3015. style_colName.Name = "colName";
  3016. style_colName.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3017. style_colName.VerticalAlignment = TextAlignmentType.Center;
  3018. style_colName.Font.Name = "微软雅黑";//文字字体
  3019. style_colName.Font.Size = 12;//文字大小
  3020. style_colName.IsLocked = false;//单元格解锁
  3021. style_colName.Font.IsBold = true;//粗体
  3022. style_colName.Font.Color = Color.FromArgb(0, 0, 0);
  3023. style_colName.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3024. style_colName.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3025. style_colName.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3026. style_colName.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3027. List<Fin_GroupExtraCostExcelColumnSetting> colNameSettingList = new List<Fin_GroupExtraCostExcelColumnSetting>()
  3028. {
  3029. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 1, columnName="类型", columnWidth= 25},
  3030. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 2, columnName="时间", columnWidth= 16},
  3031. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 3, columnName="内容", columnWidth= 35},
  3032. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 4, columnName="单价", columnWidth= 12},
  3033. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 5, columnName="数量", columnWidth= 12},
  3034. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 6, columnName="货币", columnWidth= 12},
  3035. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 7, columnName="费用", columnWidth= 12},
  3036. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 8, columnName="汇率", columnWidth= 12},
  3037. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 9, columnName="人民币", columnWidth= 12},
  3038. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 10, columnName="备注信息", columnWidth= 24}
  3039. };
  3040. foreach (var col in colNameSettingList)
  3041. {
  3042. cells[2, col.columnIndex].PutValue(col.columnName);
  3043. cells[2, col.columnIndex].SetStyle(style_colName);
  3044. cells.SetColumnWidth(col.columnIndex, col.columnWidth);
  3045. }
  3046. cells.SetRowHeight(2, 25);
  3047. #endregion
  3048. #region 数据填充
  3049. Aspose.Cells.Style style_dataCol = workbook.GetNamedStyle("colName");
  3050. style_dataCol.Font.IsBold = false;
  3051. style_dataCol.Name = "dataCol";
  3052. Aspose.Cells.Style style_dataBlue = workbook.CreateStyle();
  3053. style_dataBlue.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3054. style_dataBlue.VerticalAlignment = TextAlignmentType.Center;
  3055. style_dataBlue.Font.Name = "微软雅黑";//文字字体
  3056. style_dataBlue.Font.Size = 12;//文字大小
  3057. style_dataBlue.IsLocked = false;//单元格解锁
  3058. style_dataBlue.Font.IsBold = false;//粗体
  3059. style_dataBlue.ForegroundColor = Color.FromArgb(189, 215, 238);
  3060. style_dataBlue.Pattern = BackgroundType.Solid;
  3061. style_dataBlue.Font.Color = Color.FromArgb(0, 0, 0);
  3062. style_dataBlue.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3063. style_dataBlue.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3064. style_dataBlue.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3065. style_dataBlue.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3066. Aspose.Cells.Style style_dataYellow = workbook.CreateStyle();
  3067. style_dataYellow.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3068. style_dataYellow.VerticalAlignment = TextAlignmentType.Center;
  3069. style_dataYellow.Font.Name = "微软雅黑";//文字字体
  3070. style_dataYellow.Font.Size = 12;//文字大小
  3071. style_dataYellow.IsLocked = false;//单元格解锁
  3072. style_dataYellow.Font.IsBold = false;//粗体
  3073. style_dataYellow.ForegroundColor = Color.FromArgb(255, 242, 204);
  3074. style_dataYellow.Pattern = BackgroundType.Solid;
  3075. style_dataYellow.Font.Color = Color.FromArgb(0, 0, 0);
  3076. style_dataYellow.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3077. style_dataYellow.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3078. style_dataYellow.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3079. style_dataYellow.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3080. int rowIndex = 4;
  3081. foreach (var d in dataList)
  3082. {
  3083. //内容
  3084. string typeStr = d.PriceDetailTypeStr + d.PriceName;
  3085. cells["B" + rowIndex.ToString()].PutValue(d.PriceTypeStr);
  3086. cells["C" + rowIndex.ToString()].PutValue(d.PriceDtStr);
  3087. cells["D" + rowIndex.ToString()].PutValue(typeStr);
  3088. cells["E" + rowIndex.ToString()].PutValue(d.Price.ToString("#0.00"));
  3089. cells["F" + rowIndex.ToString()].PutValue(d.PriceCount);
  3090. cells["G" + rowIndex.ToString()].PutValue(d.Currency);
  3091. cells["H" + rowIndex.ToString()].PutValue(d.PriceSum.ToString("#0.00"));
  3092. cells["K" + rowIndex.ToString()].PutValue(d.Remark);
  3093. //样式
  3094. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3095. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3096. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3097. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3098. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3099. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3100. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3101. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3102. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3103. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3104. //公式
  3105. cells["H" + rowIndex.ToString()].Formula = string.Format(@"E{0}*F{0}", rowIndex);
  3106. cells["J" + rowIndex.ToString()].Formula = string.Format(@"H{0}*I{0}", rowIndex);
  3107. cells.SetRowHeight(rowIndex - 1, 25);
  3108. rowIndex++;
  3109. }
  3110. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3111. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3112. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3113. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3114. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3115. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3116. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3117. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3118. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3119. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3120. rowIndex++;
  3121. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3122. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3123. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3124. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3125. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3126. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3127. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3128. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3129. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3130. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3131. rowIndex = 3;
  3132. int tempPriceType = 0;
  3133. foreach (var c in dataList)
  3134. {
  3135. if (tempPriceType == c.PriceType)
  3136. {
  3137. continue;
  3138. }
  3139. tempPriceType = c.PriceType;
  3140. int _rowCount = countList.First(s => s.PriceType == tempPriceType).DataCount;
  3141. cells.Merge(rowIndex, 1, _rowCount, 1);
  3142. Aspose.Cells.Range tempRange = cells.CreateRange(rowIndex, 1, _rowCount, 1);
  3143. rowIndex += _rowCount;
  3144. }
  3145. rowIndex = 4 + dataList.Count;
  3146. cells["D" + rowIndex.ToString()].PutValue("合计");
  3147. cells["J" + rowIndex.ToString()].Formula = string.Format(@"SUM(J4,J{0})", rowIndex - 1);
  3148. cells.SetRowHeight(rowIndex - 1, 25);
  3149. rowIndex++;
  3150. cells["D" + rowIndex.ToString()].PutValue("服务费10%开票税金8%");
  3151. cells["J" + rowIndex.ToString()].Formula = string.Format(@"J{0}*1.1*1.08", rowIndex - 1);
  3152. cells.SetRowHeight(rowIndex - 1, 25);
  3153. #endregion
  3154. #region IO
  3155. System.IO.MemoryStream ms = workbook.SaveToStream();//生成数据流
  3156. string fileName = ("GroupExtraCost/超支费用(" + cellValue_Header + ").xlsx");
  3157. byte[] bt = ms.ToArray();
  3158. workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  3159. #endregion
  3160. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  3161. return Ok(JsonView(true, "成功", new { url = rst }));
  3162. }
  3163. #endregion
  3164. #region 信用卡对账
  3165. /// <summary>
  3166. /// 信用卡对账
  3167. /// </summary>
  3168. /// <param name="file"></param>
  3169. /// <param name="cardType"></param>
  3170. /// <param name="beginDt"></param>
  3171. /// <param name="endDt"></param>
  3172. /// <returns></returns>
  3173. [HttpPost]
  3174. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3175. public async Task<IActionResult> PostCreditCardBill([FromForm] IFormFile file, int cardType, string beginDt, string endDt)
  3176. {
  3177. if (file == null || file.Length < 1)
  3178. {
  3179. return Ok(JsonView(false, "请上传文件!"));
  3180. }
  3181. string fileName = file.FileName;
  3182. if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
  3183. {
  3184. return Ok(JsonView(false, "请上传Excel文件!"));
  3185. }
  3186. if (cardType < 1) return Ok(JsonView(false, "请传入有效的卡类型!"));
  3187. if (string.IsNullOrEmpty(beginDt) || string.IsNullOrEmpty(endDt )) return Ok(JsonView(false, "请输入开始/结束日期!"));
  3188. var beginValid = DateTime.TryParse(beginDt, out _);
  3189. var endValid = DateTime.TryParse(endDt, out _);
  3190. if (beginValid || endValid) return Ok(JsonView(false, "请输入正确的日期格式"));
  3191. //保存文件
  3192. string filePath = $"{AppSettingsHelper.Get("ExcelBasePath")}/CreditCardBill";
  3193. if (!Directory.Exists(filePath))
  3194. {
  3195. Directory.CreateDirectory(filePath);
  3196. }
  3197. filePath = $"{filePath}/{file.FileName}";
  3198. using (var stream = new FileStream(filePath, FileMode.Create))
  3199. {
  3200. await stream.CopyToAsync(stream);
  3201. }
  3202. //信用卡信息
  3203. string sql = string.Format($"Select * From Grp_CreditCardPayment Where Isdel = 0 And CTDId = {cardType} And ConsumptionDate between '{beginDt}' and '{endDt}' ");
  3204. var List_ccp = await _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql).ToListAsync();
  3205. if (List_ccp.Count < 1)
  3206. {
  3207. return Ok(JsonView(false, $"未查询到 {beginDt} 至 {endDt} 信用卡账单信息!!!!"));
  3208. }
  3209. //资源信息
  3210. var delegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
  3211. var users = _sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0).ToList();
  3212. string cardTempPath = $"{AppSettingsHelper.Get("ExcelBasePath")}/Template";
  3213. string url = string.Empty;
  3214. try
  3215. {
  3216. /*
  3217. * 卡类型
  3218. * 74 美元卡 1
  3219. * 75 欧元卡 1
  3220. * 86 招行卡 1
  3221. * 346 中信卡 1
  3222. * 363 交行卡 1
  3223. *
  3224. */
  3225. switch (cardType)
  3226. {
  3227. case 74:
  3228. cardTempPath = $"{cardTempPath}/信用卡对账模板-美元卡.xls";
  3229. var AirGroupReuslt = List_ccp.Where(x => x.CTable == 85).GroupBy(x => x.DIId).ToList();
  3230. if (AirGroupReuslt != null && AirGroupReuslt.Count > 0)
  3231. {
  3232. foreach (var item in AirGroupReuslt)
  3233. {
  3234. if (item.Count() > 1)
  3235. {
  3236. var obj = item.FirstOrDefault();
  3237. obj.RMBPrice = item.Sum(x => x.PayMoney);//合计币种金额
  3238. obj.Remark = "团组机票总价(虚拟)";
  3239. List_ccp.Add(obj);
  3240. }
  3241. }
  3242. }
  3243. if (Directory.Exists(filePath))
  3244. {
  3245. Workbook wb = new Workbook(filePath);
  3246. WorksheetCollection collection = wb.Worksheets;
  3247. DataTable dt = new DataTable();
  3248. if (collection.Count == 1) dt = ExcelToDataTable(filePath, collection[0].Name);
  3249. else return Ok(JsonView(false, "请检查工作簿页数,请保留一页工作簿页数!!!"));
  3250. if (dt == null) return Ok(JsonView(false, "您上传的Excel工作表没有内容,请检查!!!"));
  3251. dt.AcceptChanges(); //提交
  3252. dt.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  3253. dt.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  3254. dt.Columns.Add("State", Type.GetType("System.String")); //状态
  3255. //修改table列名
  3256. dt.Columns[0].ColumnName = "accountType"; // 账户类型
  3257. dt.Columns[1].ColumnName = "tradeDate"; //交易日期
  3258. dt.Columns[2].ColumnName = "BillingDate"; // 记账日期
  3259. dt.Columns[3].ColumnName = "CardNo"; // 卡号
  3260. dt.Columns[4].ColumnName = "deposit"; // 存入金额
  3261. dt.Columns[5].ColumnName = "SpendingAmount"; // 支出金额
  3262. dt.Columns[6].ColumnName = "TransactionDescription"; // 交易描述
  3263. foreach (DataRow item in dt.Rows)
  3264. {
  3265. #region 匹配的金额
  3266. decimal ExcelAmount = 0.00M;
  3267. decimal deposit = 0.00M;
  3268. if (!string.IsNullOrEmpty(item["SpendingAmount"].ToString()))
  3269. {
  3270. var isParase = decimal.TryParse(item["SpendingAmount"].ToString(), out ExcelAmount);
  3271. if (isParase)
  3272. {
  3273. var CList = List_ccp.FindAll(x => x.PayMoney == ExcelAmount);
  3274. if (CList != null && CList.Count > 0)
  3275. {
  3276. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3277. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3278. item["State"] = 1;
  3279. }
  3280. }
  3281. }
  3282. if (!string.IsNullOrEmpty(item["deposit"].ToString()))
  3283. {
  3284. var isParse = decimal.TryParse(item["deposit"].ToString(), out deposit);
  3285. if (isParse)
  3286. {
  3287. var CList = List_ccp.FindAll(x => x.PayMoney == deposit);
  3288. if (CList != null && CList.Count > 0)
  3289. {
  3290. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3291. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3292. item["State"] = 1;
  3293. }
  3294. }
  3295. }
  3296. #endregion
  3297. //交易描述
  3298. if (!string.IsNullOrEmpty(item["TransactionDescription"].ToString()))
  3299. {
  3300. string TransactionDescription = item["TransactionDescription"].ToString();
  3301. var startIndex = TransactionDescription.LastIndexOf("[");
  3302. var endIndex = TransactionDescription.LastIndexOf("]");
  3303. if (startIndex != -1 && endIndex != -1)
  3304. {
  3305. var moenyList = TransactionDescription.Substring(startIndex + 1, endIndex - startIndex - 1).Split(' ').
  3306. Where(x => !string.IsNullOrEmpty(x)).ToList();
  3307. decimal money = 0.00M;
  3308. foreach (var itemMoeny in moenyList)
  3309. {
  3310. if (itemMoeny.Contains('.'))
  3311. {
  3312. string itemMoenyStr = itemMoeny.Replace(",", string.Empty);
  3313. bool istrue = decimal.TryParse(itemMoenyStr, out money);
  3314. if (istrue)
  3315. {
  3316. var CList = List_ccp.FindAll(x => x.PayMoney == money);
  3317. if (CList != null && CList.Count > 0)
  3318. {
  3319. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3320. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3321. item["State"] = 1;
  3322. }
  3323. }
  3324. }
  3325. }
  3326. }
  3327. }
  3328. }
  3329. string fileName1 = $"信用卡账单(美元卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
  3330. Dictionary<string, object> pairs = new Dictionary<string, object>();
  3331. List<DataTable> datas = new List<DataTable>();
  3332. datas.Add(dt);
  3333. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-美元卡.xls", "TB", fileName1, pairs, datas);
  3334. return Ok(JsonView(true, "操作成功", new { url = "url" }));
  3335. }
  3336. break;
  3337. default:
  3338. return Ok(JsonView(false, "该卡类型对账开发中..."));
  3339. break;
  3340. }
  3341. }
  3342. catch (Exception ex)
  3343. {
  3344. return Ok(JsonView(false, ex.Message));
  3345. }
  3346. return Ok(JsonView(true, "操作成功"));
  3347. }
  3348. /// <summary>
  3349. /// 把数据从Excel装载到DataTable
  3350. /// </summary>
  3351. /// <param name="pathName">带路径的Excel文件名</param>
  3352. /// <param name="sheetName">工作表名</param>
  3353. /// <param name="tbContainer">将数据存入的DataTable</param>
  3354. /// <returns></returns>
  3355. public static DataTable ExcelToDataTable(string pathName, string sheetName)
  3356. {
  3357. DataTable tbContainer = new DataTable();
  3358. string strConn = string.Empty;
  3359. if (string.IsNullOrEmpty(sheetName)) { sheetName = "Sheet1"; }
  3360. FileInfo file = new FileInfo(pathName);
  3361. if (!file.Exists) { throw new Exception("文件不存在"); }
  3362. string extension = file.Extension;
  3363. switch (extension)
  3364. {
  3365. case ".xls":
  3366. strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
  3367. break;
  3368. case ".xlsx":
  3369. strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathName + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'";
  3370. break;
  3371. default:
  3372. strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
  3373. break;
  3374. }
  3375. //链接Excel
  3376. OleDbConnection cnnxls = new OleDbConnection(strConn);
  3377. //读取Excel里面有 表Sheet1
  3378. System.Data.OleDb.OleDbDataAdapter oda = new System.Data.OleDb.OleDbDataAdapter(string.Format("select * from [{0}$]", sheetName), cnnxls);
  3379. DataSet ds = new DataSet();
  3380. //将Excel里面有表内容装载到内存表中!
  3381. oda.Fill(tbContainer);
  3382. return tbContainer;
  3383. }
  3384. #endregion
  3385. }
  3386. }