FinancialController.cs 283 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099
  1. using Aspose.Cells;
  2. using Aspose.Words;
  3. using Aspose.Words.Drawing;
  4. using EyeSoft.Extensions;
  5. using EyeSoft.IO;
  6. using EyeSoft.Runtime.InteropServices;
  7. using FluentValidation;
  8. using MathNet.Numerics.Distributions;
  9. using Microsoft.EntityFrameworkCore.Query.Internal;
  10. using NPOI.HPSF;
  11. using NPOI.HSSF.UserModel;
  12. using NPOI.SS.Formula.Functions;
  13. using NPOI.SS.Formula.PTG;
  14. using NPOI.SS.UserModel;
  15. using NPOI.Util;
  16. using NPOI.XSSF.UserModel;
  17. using OASystem.API.OAMethodLib;
  18. using OASystem.API.OAMethodLib.File;
  19. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  20. using OASystem.Domain.Dtos.Financial;
  21. using OASystem.Domain.Dtos.Groups;
  22. using OASystem.Domain.Entities.Customer;
  23. using OASystem.Domain.Entities.Financial;
  24. using OASystem.Domain.Entities.Groups;
  25. using OASystem.Domain.ViewModels.Financial;
  26. using OASystem.Domain.ViewModels.Groups;
  27. using OASystem.Infrastructure.Repositories.Financial;
  28. using OASystem.Infrastructure.Repositories.Groups;
  29. using OfficeOpenXml;
  30. using Org.BouncyCastle.Math;
  31. using SqlSugar.Extensions;
  32. using System.Collections;
  33. using System.Data;
  34. using System.Data.OleDb;
  35. using System.Diagnostics;
  36. using System.Globalization;
  37. using System.IO.Compression;
  38. using System.IO.Pipelines;
  39. namespace OASystem.API.Controllers
  40. {
  41. /// <summary>
  42. /// 财务模块
  43. /// </summary>
  44. [Route("api/[controller]/[action]")]
  45. [ApiController]
  46. public class FinancialController : ControllerBase
  47. {
  48. private readonly IMapper _mapper;
  49. private readonly IConfiguration _config;
  50. private readonly SqlSugarClient _sqlSugar;
  51. private readonly HttpClient _httpClient;
  52. private readonly SetDataTypeRepository _setDataTypeRep;
  53. private readonly SetDataRepository _setDataRep;
  54. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  55. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  56. private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
  57. private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
  58. private readonly PaymentRefundAndOtherMoneyRepository _paymentRefundAndOtherMoneyRep; //收款退还与其他款项 仓库
  59. private readonly DelegationInfoRepository _delegationInfoRep; //团组信息 仓库
  60. /// <summary>
  61. /// 初始化
  62. /// </summary>
  63. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
  64. TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
  65. PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient, DelegationInfoRepository delegationInfoRep, SetDataRepository setDataRep)
  66. {
  67. _mapper = mapper;
  68. _config = configuration;
  69. _daiRep = daiRep;
  70. _sqlSugar = sqlSugar;
  71. _setDataTypeRep = setDataTypeRep;
  72. _teamRateRep = teamRateRep;
  73. _ForForeignReceivablesRep = ForForeignReceivablesRep;
  74. _proceedsReceivedRep = proceedsReceivedRep;
  75. _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
  76. _httpClient = httpClient;
  77. _delegationInfoRep = delegationInfoRep;
  78. _setDataRep = setDataRep;
  79. }
  80. #region 日付申请
  81. /// <summary>
  82. /// 获取日付申请 基础数据源
  83. /// </summary>
  84. /// <param name="dto"> 日付申请 分页 dto</param>
  85. /// <returns></returns>
  86. [HttpPost]
  87. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  88. public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
  89. {
  90. var result = await _daiRep.GetPagePriceTypeData(dto);
  91. if (result == null || result.Code != 0)
  92. {
  93. return Ok(JsonView(false, result.Msg));
  94. }
  95. var data = result.Data;
  96. return Ok(JsonView(data));
  97. }
  98. /// <summary>
  99. /// 获取日付申请 基础数据源 - 转账表识
  100. /// </summary>
  101. /// <param name="dto"> 日付申请 分页 dto</param>
  102. /// <returns></returns>
  103. [HttpPost]
  104. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  105. public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
  106. {
  107. var result = await _daiRep.GetPriceTypeAddData(dto);
  108. if (result == null || result.Code != 0)
  109. {
  110. return Ok(JsonView(false, result.Msg));
  111. }
  112. var data = result.Data;
  113. return Ok(JsonView(data));
  114. }
  115. /// <summary>
  116. /// 日付申请 Page Search
  117. /// </summary>
  118. /// <param name="dto"> 日付申请 分页 dto</param>
  119. /// <returns></returns>
  120. [HttpPost]
  121. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  122. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  123. {
  124. var result = await _daiRep.GetPageSearchAll(dto);
  125. if (result == null || result.Code != 0)
  126. {
  127. return Ok(JsonView(false, result.Msg));
  128. }
  129. var data = result.Data;
  130. if (data == null)
  131. {
  132. return Ok(JsonView(false, result.Msg));
  133. }
  134. return Ok(JsonView(data));
  135. }
  136. /// <summary>
  137. /// 日付申请 Single Search By Id
  138. /// </summary>
  139. /// <param name="dto"></param>
  140. /// <returns></returns>
  141. [HttpPost]
  142. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  143. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  144. {
  145. var result = await _daiRep.GetSearchById(dto);
  146. if (result == null || result.Code != 0)
  147. {
  148. return Ok(JsonView(false, result.Msg));
  149. }
  150. return Ok(JsonView(result.Data));
  151. }
  152. /// <summary>
  153. /// 日付申请 添加
  154. /// </summary>
  155. /// <param name="dto"> 日付申请 添加 dto</param>
  156. /// <returns></returns>
  157. [HttpPost]
  158. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  159. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  160. {
  161. var result = await _daiRep.Add(dto);
  162. if (result == null || result.Code != 0)
  163. {
  164. return Ok(JsonView(false, result.Msg));
  165. }
  166. #region 应用推送
  167. try
  168. {
  169. int dailyId = result.Data.GetType().GetProperty("dailyId").GetValue(result.Data, null);
  170. int sign = result.Data.GetType().GetProperty("sign").GetValue(result.Data, null);
  171. await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  172. }
  173. catch (Exception ex)
  174. {
  175. }
  176. #endregion
  177. return Ok(JsonView(true));
  178. }
  179. /// <summary>
  180. /// 日付申请 Update
  181. /// </summary>
  182. /// <param name="dto"> 日付申请 修改 dto</param>
  183. /// <returns></returns>
  184. [HttpPost]
  185. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  186. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  187. {
  188. var result = await _daiRep.Edit(dto);
  189. if (result == null || result.Code != 0)
  190. {
  191. return Ok(JsonView(false, result.Msg));
  192. }
  193. #region 应用推送
  194. try
  195. {
  196. int dailyId = result.Data.GetType().GetProperty("dailyId").GetValue(result.Data, null);
  197. int sign = result.Data.GetType().GetProperty("sign").GetValue(result.Data, null);
  198. await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  199. }
  200. catch (Exception ex)
  201. {
  202. }
  203. #endregion
  204. return Ok(JsonView(true));
  205. }
  206. /// <summary>
  207. /// 日付申请 Del
  208. /// </summary>
  209. /// <param name="dto"> 日付申请 删除 dto</param>
  210. /// <returns></returns>
  211. [HttpPost]
  212. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  213. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  214. {
  215. var result = await _daiRep.Del(dto);
  216. if (result == null || result.Code != 0)
  217. {
  218. return Ok(JsonView(false, result.Msg));
  219. }
  220. return Ok(JsonView(true));
  221. }
  222. /// <summary>
  223. /// 日付申请 财务审核
  224. /// </summary>
  225. /// <param name="dto"> dto </param>
  226. /// <returns></returns>
  227. [HttpPost]
  228. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  229. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  230. {
  231. var result = await _daiRep.DailyPaymentAudit(dto);
  232. if (result == null || result.Code != 0)
  233. {
  234. return Ok(JsonView(false, result.Msg));
  235. }
  236. return Ok(JsonView(true));
  237. }
  238. /// <summary>
  239. /// 日付申请 Single Excel Download
  240. /// </summary>
  241. /// <param name="dto"> dto </param>
  242. /// <returns></returns>
  243. [HttpPost]
  244. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  245. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  246. {
  247. if (dto.PortType == 1 || dto.PortType == 2)
  248. {
  249. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  250. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  251. Where IsDel=0 And Id = {0} ", dto.Id);
  252. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  253. if (feeData == null)
  254. {
  255. return Ok(JsonView(false, "暂无数据!"));
  256. }
  257. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  258. Where IsDel=0 And DFPId = {0} ", dto.Id);
  259. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  260. if (feeData != null)
  261. {
  262. string userName = string.Empty;
  263. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  264. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  265. if (user != null) { userName = user.CnName; }
  266. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  267. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  268. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  269. Dictionary<string, object> pairs = new Dictionary<string, object>();
  270. List<DataTable> datas = new List<DataTable>();
  271. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  272. //{
  273. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  274. // // pairs, datas);
  275. //}
  276. //else //日付常规模板
  277. //{
  278. pairs.Clear();
  279. pairs.Add("Opertor", userName);
  280. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  281. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  282. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  283. pairs.Add("SumPrice", feeData.SumPrice);
  284. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  285. datas.Clear();
  286. datas.Add(data);
  287. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  288. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  289. return Ok(JsonView(true, msg));
  290. //}
  291. }
  292. else
  293. {
  294. return Ok(JsonView(false, "暂无数据!"));
  295. }
  296. }
  297. return Ok(JsonView(true));
  298. }
  299. /// <summary>
  300. /// 日付申请
  301. /// 总经理未审核 日付信息
  302. /// </summary>
  303. /// <param name="dto"> dto </param>
  304. /// <returns></returns>
  305. [HttpGet]
  306. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  307. public async Task<IActionResult> DailyPaymentGMUnAudited()
  308. {
  309. var dailyInfos = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  310. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  311. .Where(dfp => dfp.IsDel == 0 &&
  312. //dfp.FAudit == 1 &&
  313. //dfp.IsPay == 0 &&
  314. dfp.MAudit == 0
  315. )
  316. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  317. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  318. .Select((dfp, u) => new
  319. {
  320. id = dfp.Id,
  321. amountName = dfp.Instructions,
  322. amount = dfp.SumPrice,
  323. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  324. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  325. fAuditDate = dfp.FAuditDate,
  326. applicant = u.CnName,
  327. applicantDate = dfp.CreateTime
  328. })
  329. //.ToListAsync();
  330. .CountAsync();
  331. //int count = dailyInfos.Count;
  332. return Ok(JsonView(true,"查询成功", dailyInfos));
  333. }
  334. #endregion
  335. #region 团组提成
  336. /// <summary>
  337. /// 提成 Page Search
  338. /// </summary>
  339. /// <param name="dto"> 提成 分页 dto</param>
  340. /// <returns></returns>
  341. [HttpPost]
  342. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  343. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  344. {
  345. var data = await GroupCommission.GetCommissionPageList(dto);
  346. return Ok(JsonView(data.Data));
  347. }
  348. #endregion
  349. #region 团组汇率
  350. /// <summary>
  351. /// 团组汇率 Select数据源(团组列,汇率列)
  352. /// </summary>
  353. /// <param name="dto"></param>
  354. /// <returns></returns>
  355. [HttpPost]
  356. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  357. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  358. {
  359. try
  360. {
  361. //迁移数据更新团组汇率
  362. //Result teamRateData1 = await _teamRateRep.GetGroupRateChangeData();
  363. //var data = await _teamRateRep.PostGroupTeamRateHot();
  364. Stopwatch stopwatch = Stopwatch.StartNew();
  365. GroupNameDto groupNameDto = new GroupNameDto() { PortType = dto.PortType };
  366. var groups = await _delegationInfoRep.GetGroupNameList(groupNameDto);
  367. List<CurrencyHot> _currData = new List<CurrencyHot>();
  368. string currData = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("GroupTeamCurrencyData");//string 取
  369. if (!string.IsNullOrEmpty(currData))
  370. {
  371. _currData = JsonConvert.DeserializeObject<List<CurrencyHot>>(currData);
  372. }
  373. else
  374. {
  375. _currData = await _teamRateRep.PostGroupTeamRateHot();
  376. //过期时间 25 Hours
  377. TimeSpan ts = DateTime.Now.AddHours(25).TimeOfDay;
  378. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync("GroupTeamCurrencyData", JsonConvert.SerializeObject(_currData), ts);
  379. }
  380. var _data = new { GroupData = groups.Data, TeamRateData = _currData };
  381. stopwatch.Stop();
  382. return Ok(JsonView(true, $"查询成功!耗时:{stopwatch.ElapsedMilliseconds / 1000}s", _data));
  383. }
  384. catch (Exception ex)
  385. {
  386. return Ok(JsonView(false, ex.Message));
  387. }
  388. }
  389. ///// <summary>
  390. ///// 团组汇率 changge
  391. ///// </summary>
  392. ///// <returns></returns>
  393. //[HttpPost]
  394. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  395. //public async Task<IActionResult> ChangeGroupRateInfo()
  396. //{
  397. // try
  398. // {
  399. // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  400. // if (teamRateData.Code != 0)
  401. // {
  402. // return Ok(JsonView(false, teamRateData.Msg));
  403. // }
  404. // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  405. // }
  406. // catch (Exception ex)
  407. // {
  408. // return Ok(JsonView(false, ex.Message));
  409. // throw;
  410. // }
  411. //}
  412. /// <summary>
  413. /// 团组汇率 Select汇率详情
  414. /// </summary>
  415. /// <param name="dto"></param>
  416. /// <returns></returns>
  417. [HttpPost]
  418. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  419. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  420. {
  421. try
  422. {
  423. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  424. if (teamRateData.Code != 0)
  425. {
  426. return Ok(JsonView(false, teamRateData.Msg));
  427. }
  428. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  429. }
  430. catch (Exception ex)
  431. {
  432. return Ok(JsonView(false, ex.Message));
  433. throw;
  434. }
  435. }
  436. /// <summary>
  437. /// 团组汇率 添加 or 更新
  438. /// </summary>
  439. /// <param name="dto"></param>
  440. /// <returns></returns>
  441. [HttpPost]
  442. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  443. public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
  444. {
  445. try
  446. {
  447. Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
  448. if (teamRateData.Code != 0)
  449. {
  450. return Ok(JsonView(false, teamRateData.Msg));
  451. }
  452. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  453. }
  454. catch (Exception ex)
  455. {
  456. return Ok(JsonView(false, ex.Message));
  457. throw;
  458. }
  459. }
  460. #endregion
  461. #region 对外收款账单 关联已收款项
  462. /// <summary>
  463. /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
  464. /// 关联已收款项
  465. /// </summary>
  466. /// <param name="dto"></param>
  467. /// <returns></returns>
  468. [HttpPost]
  469. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  470. public async Task<IActionResult> GetForeignReceivablesDataSources(ForeignReceivablesDataSourcesDto dto)
  471. {
  472. return Ok(await _ForForeignReceivablesRep.GetDataSource(dto));
  473. }
  474. /// <summary>
  475. /// 对外收款账单
  476. /// 账单详情
  477. /// 关联已收款项
  478. /// </summary>
  479. /// <param name="dto"></param>
  480. /// <returns></returns>
  481. [HttpPost]
  482. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  483. public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  484. {
  485. try
  486. {
  487. Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
  488. if (ffrData.Code != 0)
  489. {
  490. return Ok(JsonView(false, ffrData.Msg));
  491. }
  492. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  493. }
  494. catch (Exception ex)
  495. {
  496. return Ok(JsonView(false, ex.Message));
  497. throw;
  498. }
  499. }
  500. /// <summary>
  501. /// 对外收款账单
  502. /// 账单 删除
  503. /// 关联已收款项
  504. /// </summary>
  505. /// <param name="dto"></param>
  506. /// <returns></returns>
  507. [HttpPost]
  508. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  509. public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
  510. {
  511. try
  512. {
  513. Result ffrData = await _ForForeignReceivablesRep._Del(dto);
  514. if (ffrData.Code != 0)
  515. {
  516. return Ok(JsonView(false, ffrData.Msg));
  517. }
  518. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  519. }
  520. catch (Exception ex)
  521. {
  522. return Ok(JsonView(false, ex.Message));
  523. throw;
  524. }
  525. }
  526. /// <summary>
  527. /// 对外收款账单
  528. /// 添加 And 更新
  529. /// 关联已收款项
  530. /// </summary>
  531. /// <param name="dto"></param>
  532. /// <returns></returns>
  533. [HttpPost]
  534. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  535. public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  536. {
  537. try
  538. {
  539. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
  540. if (ffrData.Code != 0)
  541. {
  542. return Ok(JsonView(false, ffrData.Msg));
  543. }
  544. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  545. }
  546. catch (Exception ex)
  547. {
  548. return Ok(JsonView(false, ex.Message));
  549. throw;
  550. }
  551. }
  552. /// <summary>
  553. /// 已收款项
  554. /// 账单 删除
  555. /// 关联已收款项
  556. /// </summary>
  557. /// <param name="dto"></param>
  558. /// <returns></returns>
  559. [HttpPost]
  560. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  561. public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
  562. {
  563. try
  564. {
  565. Result ffrData = await _proceedsReceivedRep._Del(dto);
  566. if (ffrData.Code != 0)
  567. {
  568. return Ok(JsonView(false, ffrData.Msg));
  569. }
  570. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  571. }
  572. catch (Exception ex)
  573. {
  574. return Ok(JsonView(false, ex.Message));
  575. throw;
  576. }
  577. }
  578. /// <summary>
  579. /// 已收款项
  580. /// 添加 And 更新
  581. /// 关联已收款项
  582. /// </summary>
  583. /// <param name="dto"></param>
  584. /// <returns></returns>
  585. [HttpPost]
  586. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  587. public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
  588. {
  589. try
  590. {
  591. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
  592. if (ffrData.Code != 0)
  593. {
  594. return Ok(JsonView(false, ffrData.Msg));
  595. }
  596. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  597. }
  598. catch (Exception ex)
  599. {
  600. return Ok(JsonView(false, ex.Message));
  601. throw;
  602. }
  603. }
  604. /// <summary>
  605. /// 财务 已收款项
  606. /// 分配已收款项至 应收项下
  607. /// 关联已收款项
  608. /// </summary>
  609. /// <param name="dto"></param>
  610. /// <returns></returns>
  611. [HttpPost]
  612. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  613. public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
  614. {
  615. try
  616. {
  617. Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
  618. if (ffrData.Code != 0)
  619. {
  620. return Ok(JsonView(false, ffrData.Msg));
  621. }
  622. return Ok(JsonView(true));
  623. }
  624. catch (Exception ex)
  625. {
  626. return Ok(JsonView(false, ex.Message));
  627. throw;
  628. }
  629. }
  630. ///// <summary>
  631. ///// 财务 收款账单
  632. ///// 导出Word(北京,四川)
  633. ///// </summary>
  634. ///// <param name="dto"></param>
  635. ///// <returns></returns>
  636. //[HttpPost]
  637. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  638. //public async Task<IActionResult> PostAccountReceivableWordExport(AccountReceivableWordExportDto dto)
  639. //{
  640. // try
  641. // {
  642. // //模板处理
  643. // string typeName = string.Empty;
  644. // if (dto.TemplateType == 1) //四川
  645. // {
  646. // typeName = "四川";
  647. // }
  648. // else if (dto.TemplateType == 2) //北京
  649. // {
  650. // typeName = "北京";
  651. // }
  652. // else return Ok(JsonView(false,"请选择正确的模板类型!"));
  653. // string wordTempName = string.Format("收款账单({0})模板.doc", typeName);
  654. // }
  655. // catch (Exception ex)
  656. // {
  657. // return Ok(JsonView(false, ex.Message));
  658. // }
  659. //}
  660. #endregion
  661. #region 对外收款账单
  662. /// <summary>
  663. /// 对外收款账单
  664. /// 数据源
  665. /// </summary>
  666. /// <param name="dto"></param>
  667. /// <returns></returns>
  668. [HttpPost]
  669. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  670. public async Task<IActionResult> PostGroupReceivablesDataSource(ForeignReceivablesDataSourcesDto dto)
  671. {
  672. return Ok(await _ForForeignReceivablesRep.PostDataSource(dto));
  673. }
  674. /// <summary>
  675. /// 对外收款账单
  676. /// 账单详情
  677. /// </summary>
  678. /// <param name="dto"></param>
  679. /// <returns></returns>
  680. [HttpPost]
  681. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  682. public async Task<IActionResult> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  683. {
  684. return Ok(await _ForForeignReceivablesRep.PostGroupReceivablesInfoByDiId(dto));
  685. }
  686. /// <summary>
  687. /// 对外收款账单
  688. /// 添加 And 更新
  689. /// </summary>
  690. /// <param name="dto"></param>
  691. /// <returns></returns>
  692. [HttpPost]
  693. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  694. public async Task<IActionResult> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  695. {
  696. return Ok(await _ForForeignReceivablesRep.PostReceivablesSave(dto));
  697. }
  698. /// <summary>
  699. /// 对外收款账单
  700. /// 审核
  701. /// </summary>
  702. /// <param name="dto"></param>
  703. /// <returns></returns>
  704. [HttpPost]
  705. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  706. public async Task<IActionResult> PostReceivablesAudit(FeeAuditDto dto)
  707. {
  708. return Ok(await _ForForeignReceivablesRep.FeeAudit(dto));
  709. }
  710. /// <summary>
  711. /// 已收账单
  712. /// 删除
  713. /// </summary>
  714. /// <param name="dto"></param>
  715. /// <returns></returns>
  716. [HttpPost]
  717. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  718. public async Task<IActionResult> PostReceivablesDel(ForeignReceivablesDelDto dto)
  719. {
  720. try
  721. {
  722. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesDel(dto);
  723. if (ffrData.Code != 0)
  724. {
  725. return Ok(JsonView(false, ffrData.Msg));
  726. }
  727. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  728. }
  729. catch (Exception ex)
  730. {
  731. return Ok(JsonView(false, ex.Message));
  732. throw;
  733. }
  734. }
  735. /// <summary>
  736. /// 已收账单
  737. /// File Downloasd
  738. /// Init
  739. /// </summary>
  740. /// <param name="dto"></param>
  741. /// <returns></returns>
  742. [HttpPost]
  743. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  744. public async Task<IActionResult> PostReceivablesFeilDownloadInit()
  745. {
  746. return Ok(JsonView(true, "操作成功!", new List<dynamic> {
  747. new { Id = 1, Name = "生成收款单(四川)" },
  748. new { Id = 2, Name = "生成收款单(北京)" },
  749. new { Id = 3, Name = "汇款账单" }
  750. }
  751. ));
  752. }
  753. /// <summary>
  754. /// 已收账单
  755. /// File Downloasd
  756. /// </summary>
  757. /// <param name="dto"></param>
  758. /// <returns></returns>
  759. [HttpPost]
  760. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  761. public async Task<IActionResult> PostReceivablesFeilDownload(ForeignReceivablesFeilDownloadDto dto)
  762. {
  763. try
  764. {
  765. if (dto.DiId < 1)
  766. {
  767. return Ok(JsonView(false, "请传入有效DiId参数!"));
  768. }
  769. if (dto.FileType < 1 || dto.FileType > 3)
  770. {
  771. return Ok(JsonView(false, "请传入有效FileType参数! 1 生成收款单(四川) 2 生成收款单(北京) 3 汇款账单"));
  772. }
  773. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  774. if (_DelegationInfo == null)
  775. {
  776. return Ok(JsonView(false, "暂无团组信息!!"));
  777. }
  778. if (dto.FileType == 1 || dto.FileType == 2)
  779. {
  780. var _ForeignReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  781. if (_ForeignReceivables.Count < 1)
  782. {
  783. return Ok(JsonView(false, "暂无收款信息!!"));
  784. }
  785. string tempName = "";
  786. if (dto.FileType == 1) tempName = $"收款账单(四川)模板.docx";
  787. else if (dto.FileType == 2) tempName = $"收款账单(北京)模板.docx";
  788. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/{tempName}";
  789. //载入模板
  790. Document doc = new Document(tempPath);
  791. DocumentBuilder builder = new DocumentBuilder(doc);
  792. #region 替换Word模板书签内容
  793. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  794. //付款方
  795. if (doc.Range.Bookmarks["To"] != null)
  796. {
  797. Bookmark mark = doc.Range.Bookmarks["To"];
  798. mark.Text = _ForeignReceivables[0].To == null ? "" : _ForeignReceivables[0].To.ToString();
  799. }
  800. //付款方电话
  801. if (doc.Range.Bookmarks["ToTel"] != null)
  802. {
  803. Bookmark mark = doc.Range.Bookmarks["ToTel"];
  804. mark.Text = _ForeignReceivables[0].ToTel == null ? "" : _ForeignReceivables[0].ToTel.ToString();
  805. }
  806. //导出时间
  807. if (doc.Range.Bookmarks["Date"] != null)
  808. {
  809. Bookmark mark = doc.Range.Bookmarks["Date"];
  810. mark.Text = DateTime.Now.ToString("yyyy-MM-dd");
  811. }
  812. //注
  813. if (doc.Range.Bookmarks["Attention"] != null)
  814. {
  815. Bookmark mark = doc.Range.Bookmarks["Attention"];
  816. mark.Text = _ForeignReceivables[0].Attention == null ? "" : _ForeignReceivables[0].Attention.ToString();
  817. }
  818. //团队名称
  819. if (doc.Range.Bookmarks["Team"] != null)
  820. {
  821. Bookmark mark = doc.Range.Bookmarks["Team"];
  822. mark.Text = _DelegationInfo.VisitCountry == null ? "" : _DelegationInfo.VisitCountry.Replace("|", "、").ToString();
  823. }
  824. //付款日期
  825. if (doc.Range.Bookmarks["PayDate"] != null)
  826. {
  827. Bookmark mark = doc.Range.Bookmarks["PayDate"];
  828. mark.Text = _ForeignReceivables[0].PayDate == null ? "" : Convert.ToDateTime(_ForeignReceivables[0].PayDate).ToString("yyyy年MM月dd日");
  829. }
  830. decimal sumPrice = 0;
  831. //各项费用
  832. if (doc.Range.Bookmarks["PayItemContent"] != null)
  833. {
  834. string items = "";
  835. foreach (var fr in _ForeignReceivables)
  836. {
  837. var currInfo = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == fr.Currency).First();
  838. items += $"{fr.PriceName} {currInfo?.Name} {fr.Price.ToString("#0.00")} * {fr.Count} {fr.Unit} * {fr.Rate}.................. RMB {fr.ItemSumPrice.ToString("#0.00")}\n";
  839. sumPrice += fr.ItemSumPrice;
  840. }
  841. Bookmark mark = doc.Range.Bookmarks["PayItemContent"];
  842. mark.Text = items;
  843. }
  844. //合计
  845. if (doc.Range.Bookmarks["Total"] != null)
  846. {
  847. Bookmark mark = doc.Range.Bookmarks["Total"];
  848. mark.Text = sumPrice.ToString("#0.00");
  849. }
  850. #endregion
  851. //文件名
  852. string strFileName = _DelegationInfo.TeamName + "-收款账单.docx";
  853. //去水印
  854. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  855. doc.Save(AppSettingsHelper.Get("WordBasePath") + "ForeignReceivables/File/" + strFileName);
  856. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/ForeignReceivables/File/" + strFileName;
  857. return Ok(JsonView(true, "成功", new { Url = url }));
  858. }
  859. else if (dto.FileType == 3) //汇款通知
  860. {
  861. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  862. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId && it.NationalTravelFeeId > 0).ToList();
  863. if (_EnterExitCosts == null)
  864. {
  865. return Ok(JsonView(false, "该团组未填写出入境费用;"));
  866. }
  867. var _cityFee = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  868. foreach (var item in _DayAndCosts)
  869. {
  870. var cityInfo = _cityFee.Where(it => it.Id == item.NationalTravelFeeId).FirstOrDefault();
  871. if (cityInfo != null)
  872. {
  873. if (cityInfo.City.Contains("全部城市") || cityInfo.City.Contains("其他城市") || cityInfo.City.Contains("所有城市"))
  874. {
  875. item.Place = cityInfo.Country;
  876. }
  877. else item.Place = cityInfo.City;
  878. }
  879. }
  880. //数据源
  881. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  882. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  883. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  884. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  885. //币种Data
  886. var currData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  887. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  888. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  889. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  890. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  891. .Select((tcl, dc, cc) => new
  892. {
  893. Name = dc.LastName + dc.FirstName,
  894. Sex = dc.Sex,
  895. Birthday = dc.BirthDay,
  896. Company = cc.CompanyFullName.Replace("\n",""),
  897. Job = dc.Job,
  898. AirType = tcl.ShippingSpaceTypeId
  899. })
  900. .ToList();
  901. if (DeleClientList.Count < 1)
  902. {
  903. return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
  904. }
  905. var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
  906. var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
  907. Dictionary<string, string> bookmarkArr = null;
  908. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
  909. //载入模板
  910. Document doc = new Document(tempPath);
  911. DocumentBuilder builder = null;
  912. List<string> filesToZip = new List<string>();
  913. foreach (var ClientItem in _GroupClient) //遍历单位
  914. {
  915. doc = new Document(tempPath);
  916. builder = new DocumentBuilder(doc);
  917. Paragraph paragraph = new Paragraph(doc);
  918. bookmarkArr = new Dictionary<string, string>();
  919. bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
  920. bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
  921. bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
  922. bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
  923. bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry.Replace("|", "、"));//出访国家
  924. bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
  925. var ClientItemList = ClientItem.ToList();
  926. string UsersTop = string.Empty;//word中人员以及金额
  927. decimal WordAllPrice = 0.00M;
  928. //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(),
  929. // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
  930. //遍历人员
  931. for (int i = 0; i < ClientItemList.Count(); i++)
  932. {
  933. Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
  934. var client = ClientItemList[i]; //每个人员
  935. var firstName = ClientItemList[i].Name;
  936. //计算费用总和
  937. decimal airPrice = client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW;
  938. decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
  939. dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
  940. +_EnterExitCosts.YiMiao + _EnterExitCosts.YiMiao + _EnterExitCosts.Ticket + _EnterExitCosts.Service;
  941. WordAllPrice += AllPrice;
  942. UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
  943. TeableBookmarkArr.Add("jp", (client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW).ToString("#0.00") + " 元"); //机票金额
  944. TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
  945. TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
  946. string zsinfo = string.Empty;
  947. string hsinfo = string.Empty;
  948. string gzinfo = string.Empty;
  949. List<string> placeArr = new List<string>();
  950. Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  951. Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
  952. Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
  953. Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
  954. int rowIndex = 0;
  955. foreach (var item in dac1)
  956. {
  957. if (string.IsNullOrWhiteSpace(item.Place))
  958. {
  959. continue;
  960. }
  961. if (placeArr.Contains(item.Place))
  962. {
  963. continue;
  964. }
  965. else
  966. {
  967. placeArr.Add(item.Place);
  968. }
  969. if (!string.IsNullOrWhiteSpace(item.Place))
  970. {
  971. if (rowIndex > ChildTable.Rows.Count - 1)
  972. {
  973. var chitableRow = ChildTable.LastRow.Clone(true);
  974. ChildTable.AppendChild(chitableRow);
  975. }
  976. int days = dac1.FindAll(x => x.Place == item.Place).Count();
  977. SetCells(ChildTable, doc, rowIndex, 0, item.Place);
  978. SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
  979. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  980. SetCells(ChildTable, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/晚");
  981. SetCells(ChildTable, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  982. SetCells(ChildTable, doc, rowIndex, 4, "CNY" + item.SubTotal + "\r\n");
  983. rowIndex++;
  984. zsinfo += item.Place + " " + days + "晚 " + item.Cost.ToString("#0.00") + currencyCode + "/晚" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.0000") + " CNY" + item.SubTotal * days + "\r\n";
  985. }
  986. }
  987. placeArr.Clear();
  988. rowIndex = 0;
  989. foreach (var item in dac2)
  990. {
  991. if (string.IsNullOrWhiteSpace(item.Place))
  992. {
  993. continue;
  994. }
  995. if (placeArr.Contains(item.Place))
  996. {
  997. continue;
  998. }
  999. else
  1000. {
  1001. placeArr.Add(item.Place);
  1002. }
  1003. if (!string.IsNullOrWhiteSpace(item.Place))
  1004. {
  1005. if (rowIndex > ChildTable1.Rows.Count - 1)
  1006. {
  1007. var chitableRow = ChildTable1.LastRow.Clone(true);
  1008. ChildTable1.AppendChild(chitableRow);
  1009. }
  1010. int days = dac2.FindAll(x => x.Place == item.Place).Count();
  1011. SetCells(ChildTable1, doc, rowIndex, 0, item.Place);
  1012. SetCells(ChildTable1, doc, rowIndex, 1, days + "天");
  1013. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  1014. SetCells(ChildTable1, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/天");
  1015. SetCells(ChildTable1, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  1016. SetCells(ChildTable1, doc, rowIndex, 4, "CNY" + item.SubTotal);
  1017. rowIndex++;
  1018. hsinfo += item.Place + " " + days + "天 " + item.Cost.ToString("#0.00") + currencyCode + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.0000") + " CNY" + item.SubTotal * days + "\r\n";
  1019. }
  1020. }
  1021. placeArr.Clear();
  1022. rowIndex = 0;
  1023. foreach (var item in dac3)
  1024. {
  1025. if (string.IsNullOrWhiteSpace(item.Place))
  1026. {
  1027. continue;
  1028. }
  1029. if (placeArr.Contains(item.Place))
  1030. {
  1031. continue;
  1032. }
  1033. else
  1034. {
  1035. placeArr.Add(item.Place);
  1036. }
  1037. if (!string.IsNullOrWhiteSpace(item.Place))
  1038. {
  1039. if (rowIndex > ChildTable2.Rows.Count - 1)
  1040. {
  1041. var chitableRow = ChildTable2.LastRow.Clone(true);
  1042. ChildTable2.AppendChild(chitableRow);
  1043. }
  1044. int days = dac3.FindAll(x => x.Place == item.Place).Count();
  1045. SetCells(ChildTable2, doc, rowIndex, 0, item.Place);
  1046. SetCells(ChildTable2, doc, rowIndex, 1, days + "天");
  1047. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  1048. SetCells(ChildTable2, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/天");
  1049. SetCells(ChildTable2, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  1050. SetCells(ChildTable2, doc, rowIndex, 4, "CNY" + item.SubTotal + "\r\n");
  1051. rowIndex++;
  1052. gzinfo += item.Place + " " + days + "天 " + item.Cost.ToString("#0.00") + currencyCode + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  1053. }
  1054. }
  1055. placeArr.Clear();
  1056. TeableBookmarkArr.Add("zsinfo", zsinfo); //住宿费详情
  1057. TeableBookmarkArr.Add("hs", dac2.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //伙食费
  1058. TeableBookmarkArr.Add("hsinfo", hsinfo); //伙食费详情
  1059. TeableBookmarkArr.Add("gz", dac3.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //公杂费
  1060. TeableBookmarkArr.Add("gzinfo", gzinfo); //公杂费详情
  1061. string otherFeestr = "";
  1062. decimal otherFee = 0.00M;
  1063. if (_EnterExitCosts.Visa > 0.00M)
  1064. {
  1065. otherFee += _EnterExitCosts.Visa;
  1066. otherFeestr += $"签证费{_EnterExitCosts.Visa.ToString("#0.00")}元、";
  1067. }
  1068. if (_EnterExitCosts.YiMiao > 0.00M)
  1069. {
  1070. otherFee += _EnterExitCosts.YiMiao;
  1071. otherFeestr += $"疫苗费{_EnterExitCosts.YiMiao.ToString("#0.00")}元、";
  1072. }
  1073. if (_EnterExitCosts.HeSuan > 0.00M)
  1074. {
  1075. otherFee += _EnterExitCosts.HeSuan;
  1076. otherFeestr += $"核酸检测费{_EnterExitCosts.HeSuan.ToString("#0.00")}元、";
  1077. }
  1078. if (_EnterExitCosts.Safe > 0.00M)
  1079. {
  1080. otherFee += _EnterExitCosts.Safe;
  1081. otherFeestr += $"保险费{_EnterExitCosts.Safe.ToString("#0.00")}元、";
  1082. }
  1083. if (_EnterExitCosts.Ticket > 0.00M)
  1084. {
  1085. otherFee += _EnterExitCosts.Ticket;
  1086. otherFeestr += $"参展门票费{_EnterExitCosts.Ticket.ToString("#0.00")}元、";
  1087. }
  1088. if (otherFeestr.Length > 0)
  1089. {
  1090. otherFeestr = otherFeestr.Substring(0, otherFeestr.Length - 1);
  1091. otherFeestr += "等费用";
  1092. }
  1093. TeableBookmarkArr.Add("qt", otherFee.ToString("#0.00") + " 元");//其他费用
  1094. TeableBookmarkArr.Add("qtinfo", otherFeestr);//其他费用第二列
  1095. TeableBookmarkArr.Add("fw", _EnterExitCosts.Service.ToString("#0.00") + "元/人");//服务费
  1096. TeableBookmarkArr.Add("AllPrice", AllPrice.ToString("#0.00") + "元/人");//表格合计费用
  1097. string airStr = client.AirType == 460 ? "经济舱" : client.AirType == 458 ? "公务舱" : "";
  1098. TeableBookmarkArr.Add("title", $"费用清单-{airStr}({firstName})");
  1099. foreach (var book in TeableBookmarkArr.Keys)
  1100. {
  1101. if (doc.Range.Bookmarks[book] != null)
  1102. {
  1103. Bookmark mark = doc.Range.Bookmarks[book];
  1104. mark.Text = TeableBookmarkArr[book];
  1105. }
  1106. }
  1107. if (i != ClientItemList.Count - 1)
  1108. {
  1109. builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
  1110. Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  1111. table.ParentNode.InsertAfter(paragraph, table);
  1112. var CloneTable = (Aspose.Words.Tables.Table)table.Clone(true);
  1113. table.ParentNode.InsertAfter(CloneTable, paragraph);
  1114. }
  1115. TeableBookmarkArr.Clear();
  1116. }
  1117. bookmarkArr.Add("VisitPrice", WordAllPrice.ToString());//出访费用总额
  1118. bookmarkArr.Add("CnAllPrice", WordAllPrice.ConvertCNYUpper());//出访费用总额中文
  1119. bookmarkArr.Add("namesPrice", UsersTop.TrimEnd('、'));//各人员出访费用 付辰同志出访费用为¥73,604.8元
  1120. foreach (var book in bookmarkArr.Keys)
  1121. {
  1122. if (doc.Range.Bookmarks[book] != null)
  1123. {
  1124. Bookmark mark = doc.Range.Bookmarks[book];
  1125. mark.Text = bookmarkArr[book];
  1126. }
  1127. }
  1128. //MemoryStream outSteam = new MemoryStream();
  1129. string filsPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/File/{ClientItem.Key.Replace("\n", "")}.docx";
  1130. //去水印
  1131. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  1132. doc.Save(filsPath);
  1133. filesToZip.Add(filsPath);
  1134. //streams.Add(ClientItem.Key + ".docx", outSteam.ToArray());
  1135. }
  1136. //文件名
  1137. string zipFileName = _DelegationInfo.TeamName + "-收款账单.zip";
  1138. string zipPath = $"ForeignReceivables/File/{_DelegationInfo.TeamName}-收款账单{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  1139. try
  1140. {
  1141. using (var zip = ZipFile.Open(AppSettingsHelper.Get("WordBasePath") + zipPath, ZipArchiveMode.Create))
  1142. {
  1143. foreach (var file in filesToZip)
  1144. {
  1145. zip.CreateEntryFromFile(file, Path.GetFileName(file));
  1146. }
  1147. }
  1148. }
  1149. catch (Exception ex)
  1150. {
  1151. return Ok(JsonView(false, ex.Message));
  1152. }
  1153. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{zipPath}";
  1154. return Ok(JsonView(true, "成功", new { Url = url }));
  1155. }
  1156. return Ok(JsonView(false, "操作失败!"));
  1157. }
  1158. catch (Exception ex)
  1159. {
  1160. return Ok(JsonView(false, ex.Message));
  1161. }
  1162. }
  1163. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val)
  1164. {
  1165. //获取table中的某个单元格,从0开始
  1166. Aspose.Words.Tables.Cell lshCell = table.Rows[rows].Cells[cells];
  1167. //将单元格中的第一个段落移除
  1168. lshCell.FirstParagraph.Remove();
  1169. //新建一个段落
  1170. Paragraph p = new Paragraph(doc);
  1171. var r = new Run(doc, val);
  1172. r.Font.Size = 8;
  1173. //把设置的值赋给之前新建的段落
  1174. p.AppendChild(r);
  1175. //将此段落加到单元格内
  1176. lshCell.AppendChild(p);
  1177. }
  1178. /// <summary>
  1179. /// 已收账单
  1180. /// 提示导入出入境报价费用
  1181. /// </summary>
  1182. /// <param name="groupId"></param>
  1183. /// <returns></returns>
  1184. [HttpPost]
  1185. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1186. public async Task<IActionResult> PostReceivablesImportFee(int groupId)
  1187. {
  1188. if (groupId < 1) return Ok(JsonView(false, "请传入有效的GroupId参数!"));
  1189. var _EnterExitCosts =await _sqlSugar.Queryable<Grp_EnterExitCost>()
  1190. .Where(it => it.IsDel == 0 && it.DiId == groupId)
  1191. .FirstAsync();
  1192. var _DayAndCosts =await _sqlSugar.Queryable<Grp_DayAndCost>()
  1193. .Where(it => it.IsDel == 0 && it.DiId == groupId)
  1194. .ToListAsync();
  1195. if (_EnterExitCosts == null) return Ok(JsonView(false, "该团组未填写出入境费用;"));
  1196. //数据源
  1197. var stayDatas = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  1198. var mealDatas = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  1199. var miscellaneousDatas = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  1200. var tainDatas = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  1201. //筛选 陪同人员 = 1
  1202. var groupClientList = await _sqlSugar.Queryable<Grp_TourClientList>()
  1203. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id)
  1204. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id)
  1205. .LeftJoin<Sys_SetData>((tcl, dc, cc, sd) => tcl.ShippingSpaceTypeId == sd.Id)
  1206. .Where(tcl => tcl.IsDel == 0 &&
  1207. tcl.DiId == groupId &&
  1208. tcl.IsAccompany == 1
  1209. )
  1210. .Select((tcl, dc, cc, sd) => new
  1211. {
  1212. DiId = tcl.DiId,
  1213. CompanyId = cc.Id,
  1214. CompanyName = cc.CompanyFullName,
  1215. ClienId = dc.Id,
  1216. ClientName = dc.FirstName + dc.LastName,
  1217. SpaceId = tcl.ShippingSpaceTypeId,
  1218. SpaceName = sd.Name
  1219. })
  1220. .ToListAsync();
  1221. if (groupClientList.Count < 1) return Ok(JsonView(false, "该团组未填写接团客户名单;"));
  1222. decimal domesticFeeTotal =0.00M, //境内费用
  1223. economyClassFeeTotal = 0.00M, //经济舱费用
  1224. businessClassFeeTotal = 0.00M, //公务舱费用
  1225. firstClassFeeTotal = 0.00M, //头等舱费用
  1226. stayFeeTotal = 0.00M, //住宿费
  1227. mealsFeeTotal = 0.00M, //餐食费
  1228. miscellaneousFeeTotal = 0.00M, //公杂费
  1229. tainFeeTotal = 0.00M; //培训费
  1230. //境内费用(其他费用)
  1231. if (_EnterExitCosts.ChoiceOne == 1) domesticFeeTotal = _EnterExitCosts.InsidePay;
  1232. //住宿费
  1233. if (_EnterExitCosts.ChoiceThree == 1) stayFeeTotal = stayDatas.Sum(x => x.SubTotal);
  1234. //伙食费
  1235. if (_EnterExitCosts.ChoiceFour == 1) mealsFeeTotal = mealDatas.Sum(x => x.SubTotal);
  1236. //公杂费
  1237. if (_EnterExitCosts.ChoiceFive == 1) miscellaneousFeeTotal = miscellaneousDatas.Sum(x => x.SubTotal);
  1238. //培训费
  1239. if (_EnterExitCosts.ChoiceSix == 1) tainFeeTotal = tainDatas.Sum(x => x.SubTotal);
  1240. decimal otherFeeTotal = domesticFeeTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal;
  1241. //国际旅费合计
  1242. //经济舱
  1243. if (_EnterExitCosts.SumJJC == 1) economyClassFeeTotal = _EnterExitCosts.OutsideJJPay + otherFeeTotal;
  1244. //公务舱
  1245. if (_EnterExitCosts.SumGWC == 1) businessClassFeeTotal = _EnterExitCosts.OutsideGWPay + otherFeeTotal;
  1246. //头等舱
  1247. if (_EnterExitCosts.SumTDC == 1) firstClassFeeTotal = _EnterExitCosts.OutsideTDPay + otherFeeTotal;
  1248. var groupClientListGroup = groupClientList.GroupBy(x => x.CompanyId);
  1249. var _view = new List<ProceedsReceivedNewView>();
  1250. foreach (var item in groupClientListGroup)
  1251. {
  1252. string companyName = item.FirstOrDefault().CompanyName;
  1253. var airTicketGroup = item.GroupBy(x => x.SpaceId);
  1254. foreach (var airTicket in airTicketGroup)
  1255. {
  1256. int quantity = airTicket.Count();
  1257. if (quantity > 0)
  1258. {
  1259. decimal price = 0.00M;
  1260. string spaceName = airTicket.FirstOrDefault()?.SpaceName ?? string.Empty;
  1261. if (spaceName.Equals("经济舱")) price = economyClassFeeTotal;
  1262. else if (spaceName.Equals("公务舱")) price = businessClassFeeTotal;
  1263. else if (spaceName.Equals("头等舱")) price = firstClassFeeTotal;
  1264. if (price > 0)
  1265. {
  1266. decimal itemTotal = price * quantity;
  1267. _view.Add(new ProceedsReceivedNewView()
  1268. {
  1269. Id = 0,
  1270. CreateTime = DateTime.Now,
  1271. Diid = groupId,
  1272. PriceName = $"{companyName}-{spaceName}",
  1273. Price = price,
  1274. Count = quantity,
  1275. Unit = "人",
  1276. ItemSumPrice = itemTotal,
  1277. Currency = 836,
  1278. Rate = 1.0000M,
  1279. AddingWay = 2,
  1280. Remark = "由出入境费用导入费用",
  1281. });
  1282. }
  1283. }
  1284. }
  1285. }
  1286. return Ok(JsonView(true, "操作成功", _view));
  1287. }
  1288. #endregion
  1289. #region 已收款项
  1290. /// <summary>
  1291. /// 已收款项
  1292. /// 查询
  1293. /// </summary>
  1294. /// <param name="dto"></param>
  1295. /// <returns></returns>
  1296. [HttpPost]
  1297. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1298. public async Task<IActionResult> PostAmountReceived(AmountReceivedDto dto)
  1299. {
  1300. try
  1301. {
  1302. if (dto == null)
  1303. {
  1304. return Ok(JsonView(false, "参数不能为空!"));
  1305. }
  1306. Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
  1307. dynamic data = null;
  1308. if (dto.PortType == 1)
  1309. {
  1310. if (ffrData.Code != 0)
  1311. {
  1312. return Ok(JsonView(false, ffrData.Msg));
  1313. }
  1314. data = ffrData.Data;
  1315. }
  1316. else if (dto.PortType == 2)
  1317. {
  1318. if (ffrData.Code != 0)
  1319. {
  1320. return Ok(JsonView(false, ffrData.Msg));
  1321. }
  1322. data = ffrData.Data;
  1323. }
  1324. else if (dto.PortType == 2)
  1325. {
  1326. if (ffrData.Code != 0)
  1327. {
  1328. return Ok(JsonView(false, ffrData.Msg));
  1329. }
  1330. data = ffrData.Data;
  1331. }
  1332. else
  1333. {
  1334. return Ok(JsonView(false, "请选择正确的端口号!"));
  1335. }
  1336. return Ok(JsonView(true, "操作成功!", data));
  1337. }
  1338. catch (Exception ex)
  1339. {
  1340. return Ok(JsonView(false, ex.Message));
  1341. }
  1342. }
  1343. /// <summary>
  1344. /// 已收款项
  1345. /// Add Or Edit
  1346. /// </summary>
  1347. /// <param name="dto"></param>
  1348. /// <returns></returns>
  1349. [HttpPost]
  1350. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1351. public async Task<IActionResult> PostAmountReceivedAddOrEdit(AmountReceivedAddOrEditDto dto)
  1352. {
  1353. try
  1354. {
  1355. if (dto == null)
  1356. {
  1357. return Ok(JsonView(false, "参数不能为空!"));
  1358. }
  1359. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedAddOrEditDto(dto);
  1360. if (dto.PortType == 1)
  1361. {
  1362. if (ffrData.Code != 0)
  1363. {
  1364. return Ok(JsonView(false, ffrData.Msg));
  1365. }
  1366. }
  1367. else if (dto.PortType == 2)
  1368. {
  1369. if (ffrData.Code != 0)
  1370. {
  1371. return Ok(JsonView(false, ffrData.Msg));
  1372. }
  1373. }
  1374. else if (dto.PortType == 2)
  1375. {
  1376. if (ffrData.Code != 0)
  1377. {
  1378. return Ok(JsonView(false, ffrData.Msg));
  1379. }
  1380. }
  1381. else
  1382. {
  1383. return Ok(JsonView(false, "请选择正确的端口号!"));
  1384. }
  1385. return Ok(JsonView(true, "操作成功!"));
  1386. }
  1387. catch (Exception ex)
  1388. {
  1389. return Ok(JsonView(false, ex.Message));
  1390. }
  1391. }
  1392. /// <summary>
  1393. /// 已收款项
  1394. /// Del
  1395. /// </summary>
  1396. /// <param name="dto"></param>
  1397. /// <returns></returns>
  1398. [HttpPost]
  1399. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1400. public async Task<IActionResult> PostAmountReceived_Del(AmountReceivedDelDto dto)
  1401. {
  1402. try
  1403. {
  1404. if (dto == null)
  1405. {
  1406. return Ok(JsonView(false, "参数不能为空!"));
  1407. }
  1408. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedDel(dto);
  1409. if (ffrData.Code != 0)
  1410. {
  1411. return Ok(JsonView(false, ffrData.Msg));
  1412. }
  1413. return Ok(JsonView(true, "操作成功!"));
  1414. }
  1415. catch (Exception ex)
  1416. {
  1417. return Ok(JsonView(false, ex.Message));
  1418. }
  1419. }
  1420. #endregion
  1421. #region 收款退还与其他款项 --> 收款退还
  1422. /// <summary>
  1423. /// 收款退还与其他款项
  1424. /// 查询 根据团组Id
  1425. /// </summary>
  1426. /// <param name="dto"></param>
  1427. /// <returns></returns>
  1428. [HttpPost]
  1429. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1430. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyItemByDiId(PaymentRefundAndOtherMoneyItemByDiIdDto dto)
  1431. {
  1432. try
  1433. {
  1434. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1435. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1436. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1437. #region 页面功能权限处理
  1438. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1439. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1440. if (pageFunAuth.CheckAuth == 0)
  1441. {
  1442. return Ok(JsonView(false, "您没有当前页面查询权限!"));
  1443. }
  1444. #endregion
  1445. Result _result = await _paymentRefundAndOtherMoneyRep._ItemByDiId(dto.DiId);
  1446. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  1447. {
  1448. if (_result.Code != 0)
  1449. {
  1450. return Ok(JsonView(false, _result.Msg));
  1451. }
  1452. var data = new
  1453. {
  1454. PageFuncAuth = pageFunAuth,
  1455. Data = _result.Data
  1456. };
  1457. return Ok(JsonView(true, "操作成功!", data));
  1458. }
  1459. else
  1460. {
  1461. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  1462. }
  1463. }
  1464. catch (Exception ex)
  1465. {
  1466. return Ok(JsonView(false, ex.Message));
  1467. }
  1468. }
  1469. /// <summary>
  1470. /// 收款退还与其他款项
  1471. /// 删除
  1472. /// </summary>
  1473. /// <param name="dto"></param>
  1474. /// <returns></returns>
  1475. [HttpPost]
  1476. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1477. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyDel(PaymentRefundAndOtherMoneyDelDto dto)
  1478. {
  1479. try
  1480. {
  1481. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1482. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1483. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1484. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1485. #region 页面功能权限处理
  1486. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1487. #endregion
  1488. if (pageFunAuth.DeleteAuth == 0)
  1489. {
  1490. return Ok(JsonView(false, "您没有当前页面删除权限!"));
  1491. }
  1492. Result _result = await _paymentRefundAndOtherMoneyRep._Del(dto);
  1493. if (_result.Code != 0)
  1494. {
  1495. return Ok(JsonView(false, _result.Msg));
  1496. }
  1497. return Ok(JsonView(true, "操作成功!"));
  1498. }
  1499. catch (Exception ex)
  1500. {
  1501. return Ok(JsonView(false, ex.Message));
  1502. }
  1503. }
  1504. /// <summary>
  1505. /// 收款退还与其他款项
  1506. /// Info Data Source
  1507. /// </summary>
  1508. /// <param name="dto"></param>
  1509. /// <returns></returns>
  1510. [HttpPost]
  1511. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1512. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfoDataSource(PortDtoBase dto)
  1513. {
  1514. try
  1515. {
  1516. Result _result = await _paymentRefundAndOtherMoneyRep._InfoDataSource(dto);
  1517. if (_result.Code != 0)
  1518. {
  1519. return Ok(JsonView(false, _result.Msg));
  1520. }
  1521. return Ok(JsonView(true, "查询成功!", _result.Data));
  1522. }
  1523. catch (Exception ex)
  1524. {
  1525. return Ok(JsonView(false, ex.Message));
  1526. }
  1527. }
  1528. /// <summary>
  1529. /// 收款退还与其他款项
  1530. /// Info
  1531. /// </summary>
  1532. /// <param name="dto"></param>
  1533. /// <returns></returns>
  1534. [HttpPost]
  1535. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1536. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfo(PaymentRefundAndOtherMoneyInfoDto dto)
  1537. {
  1538. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1539. var view = await _paymentRefundAndOtherMoneyRep._Info(dto);
  1540. return Ok(view);
  1541. }
  1542. /// <summary>
  1543. /// 收款退还与其他款项 --> 收款退还(只保留人名币)
  1544. /// 操作(Add Or Edit)
  1545. /// </summary>
  1546. /// <param name="dto"></param>
  1547. /// <returns></returns>
  1548. [HttpPost]
  1549. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1550. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyAddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
  1551. {
  1552. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1553. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1554. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1555. #region 页面功能权限处理
  1556. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1557. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1558. #endregion
  1559. if (dto.Status == 1) //add
  1560. {
  1561. if (pageFunAuth.AddAuth == 0) return Ok(JsonView(false, "您没有当前页面添加权限!"));
  1562. }
  1563. else if (dto.Status == 2) //edit
  1564. {
  1565. if (pageFunAuth.EditAuth == 0) return Ok(JsonView(false, "您没有当前页面编辑权限!"));
  1566. }
  1567. else return Ok(JsonView(false, "请输入正确的操作状态! 1 添加 2 修改!"));
  1568. return Ok(await _paymentRefundAndOtherMoneyRep._AddOrEdit(dto));
  1569. }
  1570. #endregion
  1571. #region 应收报表
  1572. /// <summary>
  1573. /// 应收报表
  1574. /// 查询 根据日期范围
  1575. /// </summary>
  1576. /// <param name="dto"></param>
  1577. /// <returns></returns>
  1578. [HttpPost]
  1579. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1580. public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
  1581. {
  1582. string sqlWhere = " Where di.IsDel=0 ";
  1583. #region 验证
  1584. if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
  1585. {
  1586. return Ok(JsonView(false, "日期参数至少填写一个!"));
  1587. }
  1588. if (!string.IsNullOrEmpty(dto.beginDt))
  1589. {
  1590. if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1591. {
  1592. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1593. }
  1594. else
  1595. {
  1596. sqlWhere += string.Format(@" And di.VisitDate >= '{0} 00:00:00' ", dto.beginDt);
  1597. }
  1598. }
  1599. if (!string.IsNullOrEmpty(dto.endDt))
  1600. {
  1601. if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1602. {
  1603. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1604. }
  1605. else
  1606. {
  1607. sqlWhere += string.Format(@" And di.VisitDate <= '{0} 23:59:59' ", dto.endDt);
  1608. }
  1609. }
  1610. #endregion
  1611. //已收款项 判断如果是市场部的人员进来的话 只显示自己的 其他的都显示全部的
  1612. string userSqlWhere = "";
  1613. var userInfos = await _sqlSugar.Queryable<Sys_Users>()
  1614. .InnerJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1615. .Where((u, d) => u.IsDel == 0 && d.DepName.Contains("市场部") && u.Id == dto.CurrUserId)
  1616. .ToListAsync();
  1617. if (userInfos.Count > 0) userSqlWhere = string.Format(@$" And JietuanOperator={dto.CurrUserId} ");
  1618. //排序倒序
  1619. 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 {sqlWhere} {userSqlWhere} Order By di.VisitDate Desc");
  1620. List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
  1621. var setData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  1622. decimal sumAll_fr = 0M; //应收
  1623. decimal sumAll_pr = 0M; //已收
  1624. decimal sumAll_balance = 0M; //尾款
  1625. if (list_rst.Count > 0)
  1626. {
  1627. int rowNumber = 1;
  1628. foreach (var item_rst in list_rst)
  1629. {
  1630. DateTime dtTemp;
  1631. bool b = DateTime.TryParse(item_rst.visitDate, out dtTemp);
  1632. if (b)
  1633. {
  1634. item_rst.visitDate = dtTemp.ToString("yyyy-MM-dd");
  1635. }
  1636. item_rst.No = rowNumber;
  1637. rowNumber++;
  1638. int diId = item_rst.diid;
  1639. decimal sum_fr = 0M;
  1640. decimal sum_pr = 0M;
  1641. string str_client = string.Empty;
  1642. decimal sum_refund = 0M; //收款退还
  1643. decimal sum_extra = 0M; //超支费用
  1644. decimal balance = 0M;
  1645. string str_schedule = string.Empty;
  1646. //1.应收
  1647. string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
  1648. List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
  1649. sum_fr = list_fr.Sum(s => s.ItemSumPrice);
  1650. //2.已收
  1651. string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
  1652. List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
  1653. foreach (var item_pr in list_pr)
  1654. {
  1655. sum_pr += item_pr.Price;
  1656. str_client += string.Format(@"{0};", item_pr.Client);
  1657. str_schedule += string.Format(@"{0};", item_pr.Remark);
  1658. }
  1659. if (str_schedule.Length > 0)
  1660. {
  1661. str_schedule = str_schedule.TrimEnd(';');
  1662. }
  1663. if (str_client.Length > 0)
  1664. {
  1665. str_client = str_client.TrimEnd(';');
  1666. }
  1667. //3.收款退还
  1668. string sql_other = string.Format(@"Select * From Fin_PaymentRefundAndOtherMoney prao
  1669. Inner Join Grp_CreditCardPayment ccp On prao.Id = ccp.CId
  1670. Where ccp.CTable = 285 And ccp.IsPay = 1 And prao.IsDel = 0 And ccp.IsDel = 0 And prao.DiId = {0}", diId);
  1671. List<Grp_CreditCardPayment> list_other = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_other).ToList();
  1672. sum_refund = list_other.Sum(s => s.PayMoney * s.DayRate);
  1673. //4.超支
  1674. string sql_extra = string.Format(@" Select c.* From Fin_GroupExtraCost f
  1675. Inner join Grp_CreditCardPayment c On f.Id = c.CId
  1676. Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId = {0} ", diId);
  1677. List<Grp_CreditCardPayment> list_extra = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_extra).ToList();
  1678. sum_extra = list_extra.Sum(s => s.PayMoney * s.DayRate);
  1679. item_rst.frPrice = sum_fr.ToString("#0.00");
  1680. item_rst.extraPrice = sum_extra.ToString("#0.00");
  1681. item_rst.receivableTotal = (sum_fr + sum_extra).ToString("#0.00");
  1682. item_rst.prPrice = sum_pr.ToString("#0.00");
  1683. item_rst.refundAmount = sum_refund.ToString("#0.00");
  1684. item_rst.receivedTotal = (sum_pr - sum_refund).ToString("#0.00");
  1685. item_rst.balPrice = ((sum_fr + sum_extra) - (sum_pr - sum_refund)).ToString("#0.00");
  1686. item_rst.prClient = str_client;
  1687. item_rst.schedule = str_schedule;
  1688. string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
  1689. sumAll_fr += (sum_fr + sum_extra);
  1690. sumAll_pr += (sum_pr - sum_refund);
  1691. sumAll_balance += ((sum_fr + sum_extra) - (sum_pr - sum_refund));
  1692. #region 单位应收已收细项(以应收费用名称为主去(已收费用)匹配) 新增 雷怡 2024-5-08 16:35:28
  1693. List<ClientFeeInfoView> feeDatas = new List<ClientFeeInfoView>();
  1694. //匹配上的数据
  1695. foreach (var item in list_fr)
  1696. {
  1697. var prInfo = list_pr.Find(it => item.PriceName.Contains(it.Client) || item.PriceName.Equals(it.Client));
  1698. decimal _balancePayment = 0.00M;
  1699. if (item.Currency == prInfo?.Currency)
  1700. {
  1701. _balancePayment = item.ItemSumPrice - prInfo?.Price ?? 0.00M;
  1702. }
  1703. feeDatas.Add(new ClientFeeInfoView
  1704. {
  1705. client = item.PriceName,
  1706. frMoney = item.ItemSumPrice.ToString("#0.00"),
  1707. frCurrency = setData.Find(it => it.Id == item.Currency)?.Name ?? "-",
  1708. frRate = item.Rate.ToString("#0.0000"),
  1709. prReceivablesType = setData.Find(it => it.Id == prInfo?.ReceivablesType)?.Name ?? "",
  1710. prTime = prInfo?.SectionTime ?? "-",
  1711. prMoney = prInfo?.Price.ToString("#0.00") ?? "-",
  1712. prCurrency = setData.Find(it => it.Id == prInfo?.Currency)?.Name ?? "",
  1713. balPayment = _balancePayment.ToString("#0.00")
  1714. });
  1715. }
  1716. //未匹配上的数据
  1717. foreach (var item in list_pr)
  1718. {
  1719. var frInfo = list_fr.Find(it => it.PriceName.Contains(item.Client) || it.PriceName.Equals(item.Client));
  1720. if (frInfo == null)
  1721. {
  1722. feeDatas.Add(new ClientFeeInfoView
  1723. {
  1724. client = item.Client + "[未匹配上的已收数据(应收已收公司名称不一致)]",
  1725. frMoney = "0.00",
  1726. frCurrency = "-",
  1727. frRate = "0.0000",
  1728. prReceivablesType = setData.Find(it => it.Id == item?.ReceivablesType)?.Name ?? "",
  1729. prTime = item?.SectionTime ?? "-",
  1730. prMoney = item?.Price.ToString("#0.00") ?? "0.00",
  1731. prCurrency = setData.Find(it => it.Id == item?.Currency)?.Name ?? "",
  1732. balPayment = "0.00"
  1733. });
  1734. }
  1735. }
  1736. item_rst.feeItem = feeDatas;
  1737. #endregion
  1738. }
  1739. PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
  1740. result.total_fr = sumAll_fr.ToString("#0.00");
  1741. result.total_pr = sumAll_pr.ToString("#0.00");
  1742. result.total_balance = sumAll_balance.ToString("#0.00");
  1743. result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
  1744. if (dto.requestType == 1)
  1745. {
  1746. return Ok(JsonView(true, "请求成功", result, list_rst.Count));
  1747. }
  1748. else
  1749. {
  1750. //----------------------------
  1751. List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
  1752. WorkbookDesigner designer = new WorkbookDesigner();
  1753. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
  1754. int excNo = 1;
  1755. foreach (var item in list_rst)
  1756. {
  1757. Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
  1758. exc.No = excNo.ToString();
  1759. excNo++;
  1760. exc.TeamName = item.teamName;
  1761. exc.ClientUnit = item.clientUnit;
  1762. exc.VisitDate = item.visitDate;
  1763. exc.Accounts = item.frPrice;
  1764. exc.Extra = item.extraPrice;
  1765. exc.ReceivableTotal = item.receivableTotal;
  1766. exc.Received = item.prPrice;
  1767. exc.RefundAmount = item.refundAmount;
  1768. exc.ReceivedTotal = item.receivedTotal;
  1769. exc.Balance = item.balPrice;
  1770. exc.Collection = item.schedule;
  1771. DateTime time = Convert.ToDateTime(item.visitDate);
  1772. TimeSpan ts = DateTime.Now - time;
  1773. float SY = float.Parse(item.balPrice);
  1774. if (ts.Days >= 365 && SY > 0)
  1775. {
  1776. exc.Sign = "需收款";
  1777. }
  1778. else
  1779. {
  1780. exc.Sign = "";
  1781. }
  1782. list_Ex.Add(exc);
  1783. }
  1784. var dt = CommonFun.GetDataTableFromIList(list_Ex);
  1785. dt.TableName = "Excel_SyntheticalReceivableByDateRange";
  1786. if (dt != null)
  1787. {
  1788. designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
  1789. //数据源
  1790. designer.SetDataSource(dt);
  1791. //根据数据源处理生成报表内容
  1792. designer.Process();
  1793. string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  1794. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  1795. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  1796. return Ok(JsonView(true, "成功", new { url = rst }));
  1797. }
  1798. }
  1799. }
  1800. return Ok(JsonView(true, "获取成功", "", list_rst.Count));
  1801. }
  1802. #endregion
  1803. #region 付款申请
  1804. /// <summary>
  1805. /// 付款申请
  1806. /// 基础数据
  1807. /// </summary>
  1808. /// <param name="dto"></param>
  1809. /// <returns></returns>
  1810. [HttpPost]
  1811. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1812. public async Task<IActionResult> PostPayRequestInit()
  1813. {
  1814. try
  1815. {
  1816. var conpanyDatas = _sqlSugar.Queryable<Sys_Company>()
  1817. .Where(it => it.IsDel == 0)
  1818. .Select(it => new
  1819. {
  1820. Id = it.Id,
  1821. ConpamyName = it.CompanyName
  1822. }).ToList();
  1823. return Ok(JsonView(true, "操作成功!", new { ConpanyData = conpanyDatas }));
  1824. }
  1825. catch (Exception ex)
  1826. {
  1827. return Ok(JsonView(false, ex.Message));
  1828. }
  1829. }
  1830. /// <summary>
  1831. /// 付款申请 (PageId=51)
  1832. /// 查询 根据日期范围
  1833. /// </summary>
  1834. /// <param name="dto"></param>
  1835. /// <returns></returns>
  1836. [HttpPost]
  1837. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1838. public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
  1839. {
  1840. Stopwatch stopwatch = Stopwatch.StartNew();
  1841. #region 验证
  1842. DateTime beginDt, endDt;
  1843. string format = "yyyy-MM-dd";
  1844. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  1845. {
  1846. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  1847. }
  1848. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  1849. {
  1850. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  1851. }
  1852. #region 页面操作权限验证
  1853. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1854. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1855. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  1856. #endregion
  1857. #endregion
  1858. try
  1859. {
  1860. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  1861. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  1862. if (checkedStr != null)
  1863. {
  1864. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  1865. if (checkedView.GroupIds.Count > 0)
  1866. {
  1867. checkedView.GroupIds = checkedView.GroupIds.OrderBy(x => x).ToList();
  1868. }
  1869. }
  1870. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.Status, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  1871. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(dto.Status, checkedView.GroupIds, checkedView.HotelSubIds, dto.beginDt, dto.endDt);
  1872. stopwatch.Stop();
  1873. return Ok(JsonView(true, $"查询成功!耗时{stopwatch.ElapsedMilliseconds / 1000}s", new { daily = dailyResult, group = groupResult }));
  1874. }
  1875. catch (Exception ex)
  1876. {
  1877. return Ok(JsonView(false, ex.Message));
  1878. }
  1879. }
  1880. /// <summary>
  1881. /// 根据团组类型类型处理团组费用所属公司
  1882. /// </summary>
  1883. /// <param name="teamId"></param>
  1884. /// <returns></returns>
  1885. private CompanyInfo ExpenseCompanyByTeamId(int teamId)
  1886. {
  1887. CompanyInfo _companyInfo = new CompanyInfo();
  1888. List<int> _SiChuan = new List<int>() {
  1889. 38 , // 政府团
  1890. 39 , // 企业团
  1891. 40 , // 散客团
  1892. 102, // 未知
  1893. 248, // 非团组
  1894. 691, // 四川-会务活动
  1895. 762, // 四川-赛事项目收入
  1896. 1048,//高校团
  1897. };
  1898. List<int> _ChengDu = new List<int>() {
  1899. 302, // 成都-会务活动
  1900. 1047, // 成都-赛事项目收入
  1901. };
  1902. if (_SiChuan.Contains(teamId))
  1903. {
  1904. _companyInfo.Id = 2;
  1905. _companyInfo.ConpanyName = "四川泛美交流有限公司";
  1906. }
  1907. if (_ChengDu.Contains(teamId))
  1908. {
  1909. _companyInfo.Id = 1;
  1910. _companyInfo.ConpanyName = "成都泛美商务有限公司";
  1911. }
  1912. return _companyInfo;
  1913. }
  1914. /// <summary>
  1915. /// 付款申请(团组费用申请相关)
  1916. /// 查询 根据日期范围
  1917. /// </summary>
  1918. /// <param name="_groupIds"></param>
  1919. /// <param name="beginDt"></param>
  1920. /// <param name="endDt"></param>
  1921. /// <returns></returns>
  1922. private tree_Group_DailyFeePaymentResult PayRequest_GroupPaymentByDateRange(int status, List<int> _groupIds,List<int> _hotelSubIds, string beginDt, string endDt)
  1923. {
  1924. tree_Group_DailyFeePaymentResult _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
  1925. List<tree_Group_DailyFeePaymentPageListView> dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1926. #region sql条件处理
  1927. string sqlWhere = string.Format(@" And (AuditGMDate Between '{0} 00:00:00' And '{1} 23:59:59') ", beginDt, endDt);
  1928. if (status == 2)
  1929. {
  1930. if (_hotelSubIds.Count > 1)
  1931. {
  1932. var hrIds = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => _hotelSubIds.Contains(it.Id) && it.Price != 0).Select(it => it.HrId).Distinct().ToList();
  1933. var hrIds1 = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.CTable == 76 && hrIds.Contains(it.CId)).Select(it => it.Id).ToList();
  1934. if (hrIds1.Count > 1)
  1935. {
  1936. _groupIds.AddRange(hrIds1);
  1937. }
  1938. }
  1939. if (_groupIds.Count < 1)
  1940. {
  1941. _DailyFeePaymentResult.dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1942. return _DailyFeePaymentResult;
  1943. }
  1944. sqlWhere += string.Format(@" And Id In ({0})", string.Join(",", _groupIds));
  1945. }
  1946. string sql_1 = string.Format(@"Select * From Grp_CreditCardPayment Where IsDel = 0 And IsPay = 0 And (IsAuditGM = 1 Or IsAuditGM = 3 ){0}", sqlWhere);
  1947. #endregion
  1948. var _paymentDatas = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_1).ToList();//付款信息
  1949. _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
  1950. _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
  1951. List<int> groupIds = _paymentDatas.Select(it => it.DIId).Distinct().ToList();
  1952. var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id)).ToList();
  1953. //_groupDatas = (List<Grp_DelegationInfo>)_groupDatas.GroupBy(it => it.TeamDid);
  1954. #region 相关基础数据源
  1955. var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
  1956. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  1957. var countryFeeDatas = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  1958. var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1959. var hotelContentDatas = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && it.IsPay == 0 && it.Price != 0 && groupIds.Contains(it.DiId)).ToList();
  1960. var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1961. var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1962. var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1963. var insureDatas = _sqlSugar.Queryable<Grp_Customers>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1964. var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1965. //var otherMoneyDatas = _sqlSugar.Queryable<Fin_OtherPrice>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Diid)).ToList();
  1966. var otherMoneyDatas = _sqlSugar.Queryable<Grp_DecreasePayments>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1967. var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1968. var ExtraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1969. #endregion
  1970. //Expense company
  1971. foreach (var groupInfo in _groupDatas)
  1972. {
  1973. List<Group_DailyFeePaymentContentInfolView> childList = new List<Group_DailyFeePaymentContentInfolView>();
  1974. var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
  1975. int rouNumber = 1;
  1976. foreach (var payInfo in groupPaymentDatas)
  1977. {
  1978. string priName = "-";
  1979. string orbitalPrivateTransfer = payInfo.OrbitalPrivateTransfer == 0 ? "公转" : payInfo.OrbitalPrivateTransfer == 1 ? "私转" : "-";
  1980. switch (payInfo.CTable)
  1981. {
  1982. case 76: //76 酒店预订
  1983. priName = $"[费用名称:{hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? ""}]";
  1984. break;
  1985. case 79: //79 车/导游地接
  1986. var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
  1987. if (opData != null)
  1988. {
  1989. string area = "";
  1990. bool b = int.TryParse(opData.Area, out int areaId);
  1991. if (b)
  1992. {
  1993. string area1 = countryFeeDatas.Find(it => it.Id == areaId)?.Country ?? "-";
  1994. area = $"{area1}({setDatas.Find(it => it.Id == opData.PriceType)?.Name ?? "-"})";
  1995. }
  1996. else area = opData.Area;
  1997. string opPriName = "-";
  1998. if (!string.IsNullOrEmpty(opData.PriceName)) opPriName = opData.PriceName;
  1999. area += $"({opPriName})";
  2000. if (payInfo.OrbitalPrivateTransfer == 0) //公转
  2001. {
  2002. priName = $"【{orbitalPrivateTransfer}】【导游: {opData.ServiceGuide} 】[费用名称:{area}]";
  2003. }
  2004. else if (payInfo.OrbitalPrivateTransfer == 1) //私转
  2005. {
  2006. priName = $"【{orbitalPrivateTransfer}】【导游:{opData.ServiceGuide}】[费用名称:{area}]";
  2007. }
  2008. }
  2009. break;
  2010. case 80: // 80 签证
  2011. 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);
  2012. List<SimplClientInfo> arr = _sqlSugar.SqlQueryable<SimplClientInfo>(sql).ToList();
  2013. string visaClientName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "";
  2014. string clientName = "-";
  2015. if (Regex.Match(visaClientName, @"\d+,?").Value.Length > 0)
  2016. {
  2017. string[] temparr = visaClientName.Split(',');
  2018. string fistrStr = temparr[0];
  2019. int count = temparr.Count();
  2020. int tempId;
  2021. bool success = int.TryParse(fistrStr, out tempId);
  2022. if (success)
  2023. {
  2024. SimplClientInfo tempInfo = arr.FirstOrDefault(s => s.Id == tempId);
  2025. if (tempInfo != null)
  2026. {
  2027. if (count > 1)
  2028. {
  2029. clientName = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  2030. }
  2031. else
  2032. {
  2033. clientName = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  2034. }
  2035. }
  2036. }
  2037. else
  2038. {
  2039. clientName = fistrStr;
  2040. }
  2041. }
  2042. priName = $"[费用名称:{clientName}]";
  2043. break;
  2044. case 81: // 81 邀请/公务活动
  2045. priName = $"[费用名称:{ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? " -"}]";
  2046. break;
  2047. case 82: // 82 团组客户保险
  2048. priName = $"[费用名称:{insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? " -"}]";
  2049. break;
  2050. case 85: // 85 机票预订
  2051. string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "-";
  2052. string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "-";
  2053. priName = $"{flightsCode}【{airPayType}】";
  2054. break;
  2055. case 98: // 98 其他款项
  2056. priName = $"[费用名称:{otherMoneyDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  2057. break;
  2058. case 285: // 285 收款退还
  2059. priName = $"[费用名称:{refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  2060. break;
  2061. case 1015: // 1015 超支费用
  2062. priName = $"[费用名称:{ExtraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  2063. break;
  2064. default:
  2065. priName = "";
  2066. break;
  2067. }
  2068. bool status1 = false;
  2069. if (_groupIds != null)
  2070. {
  2071. status1 = _groupIds.Contains(payInfo.Id);
  2072. }
  2073. if (payInfo.CTable == 76) //酒店单独处理
  2074. {
  2075. var hotelContents = hotelContentDatas.Where(it => it.HrId == payInfo.CId);
  2076. List<Group_DailyFeePaymentContentInfolView> childInfos = new List<Group_DailyFeePaymentContentInfolView>();
  2077. foreach (var hotelContent in hotelContents)
  2078. {
  2079. string subPriceName = "";
  2080. if (hotelContent.PriceType == 1) subPriceName = "房费";
  2081. else if (hotelContent.PriceType == 2) subPriceName = "早餐";
  2082. else if (hotelContent.PriceType == 3) subPriceName = "地税";
  2083. else if (hotelContent.PriceType == 4) subPriceName = "城市税";
  2084. if (string.IsNullOrEmpty(subPriceName)) subPriceName = priName;
  2085. else subPriceName = $"{priName.Replace("]","")}-{subPriceName}]";
  2086. string payeeStr1 = string.Format(@" {0},开户行:{1},银行卡号:{2} ",
  2087. string.IsNullOrEmpty(hotelContent.Payee) ? "-" : hotelContent.Payee,
  2088. string.IsNullOrEmpty(hotelContent.OtherBankName) ? "-" : hotelContent.OtherBankName,
  2089. string.IsNullOrEmpty(hotelContent.OtherSideNo) ? "-" : hotelContent.OtherSideNo);
  2090. decimal _PaymentAmount1 = hotelContent.Price;//此次付款金额
  2091. decimal _CNYSubTotalAmount1 = _PaymentAmount1 * hotelContent.Rate;//此次付款金额
  2092. _CNYSubTotalAmount1 = Convert.ToDecimal(_CNYSubTotalAmount1.ToString("#0.00"));
  2093. //酒店子项Id选中状态更改
  2094. if (_hotelSubIds != null) status1 = _hotelSubIds.Contains(hotelContent.Id);
  2095. var childInfo1 = new Group_DailyFeePaymentContentInfolView()
  2096. {
  2097. IsChecked = status1,
  2098. Id = payInfo.Id,
  2099. HotelSubId = hotelContent.Id,
  2100. Payee = payeeStr1,
  2101. RowNumber = rouNumber,
  2102. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  2103. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  2104. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  2105. TransferMark = orbitalPrivateTransfer,
  2106. PriceName = subPriceName,
  2107. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  2108. PayCurrCode = setDatas.Find(it => it.Id == hotelContent.Currency)?.Name ?? "",
  2109. PaymentAmount = _PaymentAmount1,
  2110. PayRate = hotelContent.Rate,
  2111. CNYSubTotalAmount = _CNYSubTotalAmount1,
  2112. AuditStatus = payInfo.IsAuditGM
  2113. };
  2114. string remaksDescription1 = $"【{childInfo1.PayType}】【{childInfo1.ModuleName}】{rouNumber}、[申请人:{childInfo1.Applicant}]{subPriceName}[收款方:{childInfo1.Payee}] {childInfo1.PayCurrCode} {_PaymentAmount1.ToString("#0.00")}、CNY:{childInfo1.CNYSubTotalAmount.ToString("#0.00")}(团组:{groupInfo.TeamName})";
  2115. childInfo1.RemaksDescription = remaksDescription1;
  2116. if (status == 2)
  2117. {
  2118. if (status1)
  2119. {
  2120. childInfos.Add(childInfo1);
  2121. }
  2122. }
  2123. else childInfos.Add(childInfo1);
  2124. rouNumber++;
  2125. }
  2126. childList.AddRange(childInfos);
  2127. }
  2128. else
  2129. {
  2130. string payeeStr = string.Format(@" {0},开户行:{1},银行卡号:{2} ",
  2131. string.IsNullOrEmpty(payInfo.Payee) ? "-" : payInfo.Payee,
  2132. string.IsNullOrEmpty(payInfo.OtherBankName) ? "-" : payInfo.OtherBankName,
  2133. string.IsNullOrEmpty(payInfo.OtherSideNo) ? "-" : payInfo.OtherSideNo);
  2134. decimal _PaymentAmount = (payInfo.PayMoney / 100) * payInfo.PayPercentage;//此次付款金额
  2135. decimal _CNYSubTotalAmount = _PaymentAmount * payInfo.DayRate;//此次付款金额
  2136. _CNYSubTotalAmount = Convert.ToDecimal(_CNYSubTotalAmount.ToString("#0.00"));
  2137. var childInfo = new Group_DailyFeePaymentContentInfolView()
  2138. {
  2139. IsChecked = status1,
  2140. Id = payInfo.Id,
  2141. Payee = payeeStr,
  2142. RowNumber = rouNumber,
  2143. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  2144. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  2145. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  2146. TransferMark = orbitalPrivateTransfer,
  2147. PriceName = priName,
  2148. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  2149. PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
  2150. PaymentAmount = _PaymentAmount,
  2151. PayRate = payInfo.DayRate,
  2152. CNYSubTotalAmount = _CNYSubTotalAmount,
  2153. AuditStatus = payInfo.IsAuditGM
  2154. };
  2155. 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})";
  2156. childInfo.RemaksDescription = remaksDescription;
  2157. childList.Add(childInfo);
  2158. rouNumber++;
  2159. }
  2160. }
  2161. CompanyInfo companyInfo = new CompanyInfo();
  2162. companyInfo = ExpenseCompanyByTeamId(groupInfo.TeamDid);
  2163. dataList.Add(new tree_Group_DailyFeePaymentPageListView()
  2164. {
  2165. Id = Guid.NewGuid().ToString("N"),
  2166. GroupName = groupInfo.TeamName,
  2167. CompanyId = companyInfo.Id,
  2168. ConpanyName = companyInfo.ConpanyName,
  2169. CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
  2170. ChildList = childList,
  2171. });
  2172. }
  2173. _DailyFeePaymentResult.dataList = dataList;
  2174. return _DailyFeePaymentResult;
  2175. }
  2176. /// <summary>
  2177. /// 付款申请(日付申请相关)
  2178. /// 查询 根据日期范围
  2179. /// </summary>
  2180. /// <param name="_dailyIds"></param>
  2181. /// <param name="beginDt"></param>
  2182. /// <param name="endDt"></param>
  2183. /// <returns></returns>
  2184. private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(int status, List<int> _dailyIds, string beginDt, string endDt)
  2185. {
  2186. #region sql条件处理
  2187. string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
  2188. if (status == 2)
  2189. {
  2190. if (_dailyIds.Count < 1)
  2191. {
  2192. return new tree_Fin_DailyFeePaymentResult() { childList = new List<Fin_DailyFeePaymentContentInfolView>() };
  2193. }
  2194. sqlWhere += string.Format(@" And dfp.Id In({0}) ", string.Join(",", _dailyIds));
  2195. }
  2196. string sql_1 = string.Format(@"Select * From (
  2197. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  2198. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  2199. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  2200. dfp.PriceTypeId,dfp.TransferTypeId
  2201. From Fin_DailyFeePayment dfp
  2202. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  2203. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  2204. Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1 And dfp.IsPay = 0
  2205. ) temp ", sqlWhere);
  2206. #endregion
  2207. List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
  2208. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  2209. Sys_SetDataType stGZ = _daiRep.Query<Sys_SetDataType>(s => s.Name == "公转").First();
  2210. Sys_SetDataType stSZ = _daiRep.Query<Sys_SetDataType>(s => s.Name == "私转").First();
  2211. foreach (var item in DailyFeePaymentData)
  2212. {
  2213. if (_dailyIds != null)
  2214. {
  2215. item.IsChecked = _dailyIds.Contains(item.Id);
  2216. }
  2217. if (dic_setData.ContainsKey(item.PriceTypeId))
  2218. {
  2219. item.priceTypeStr = dic_setData[item.PriceTypeId];
  2220. }
  2221. else
  2222. {
  2223. Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
  2224. if (sd_priceType != null)
  2225. {
  2226. item.priceTypeStr = sd_priceType.Name;
  2227. dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
  2228. }
  2229. }
  2230. if (dic_setData.ContainsKey(item.transferTypeId))
  2231. {
  2232. item.transferTypeIdStr = dic_setData[item.transferTypeId];
  2233. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  2234. if (sd_transfer != null)
  2235. {
  2236. item.transferParentId = sd_transfer.STid;
  2237. item.transferParentIdStr = sd_transfer.STid == stGZ.Id ? "公转" : sd_transfer.STid == stSZ.Id ? "私转" : "";
  2238. }
  2239. }
  2240. else
  2241. {
  2242. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  2243. if (sd_transfer != null)
  2244. {
  2245. item.transferTypeIdStr = sd_transfer.Name;
  2246. item.transferParentId = sd_transfer.STid;
  2247. item.transferParentIdStr = sd_transfer.STid == stGZ.Id ? "公转" : sd_transfer.STid == stSZ.Id ? "私转" : "";
  2248. dic_setData.Add(item.transferTypeId, sd_transfer.Name);
  2249. }
  2250. }
  2251. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  2252. Where IsDel=0 And DFPId = {0} ", item.Id);
  2253. item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
  2254. int rowNumber = 1;
  2255. foreach (var subItem in item.childList)
  2256. {
  2257. string remaksDescription = $"{rowNumber}、【{item.priceTypeStr}】{item.Instructions}({subItem.PriceName}) CNY:{subItem.ItemTotal.ToString("#0.00")}(单价:{subItem.Price.ToString("#0.00")} * {subItem.Quantity})";
  2258. subItem.RemaksDescription = remaksDescription;
  2259. 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")}】";
  2260. subItem.ExcelRemaksDescription = excelRemaksDescription;
  2261. rowNumber++;
  2262. }
  2263. }
  2264. decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == stGZ.Id).Sum(d => d.SumPrice ?? 0M);
  2265. decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == stSZ.Id).Sum(d => d.SumPrice ?? 0M);
  2266. var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
  2267. return result;
  2268. }
  2269. /// <summary>
  2270. /// 付款申请 (PageId=51)
  2271. /// 团组,日付相关费用 选中状态变更
  2272. /// </summary>
  2273. /// <param name="dto"></param>
  2274. /// <returns></returns>
  2275. [HttpPost]
  2276. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2277. public async Task<IActionResult> PostPayRequestCheckedChange(PayRequestCheckedChangeDto dto)
  2278. {
  2279. #region 验证
  2280. if (dto.Type < 1 || dto.Type > 2)
  2281. {
  2282. return Ok(JsonView(false, "请传入有效的Type参数! 1 checked 2 清除上次勾选"));
  2283. }
  2284. #endregion
  2285. PaymentRequestCheckedView requestCheckedView = new PaymentRequestCheckedView();
  2286. List<int> groupIds = new List<int>();
  2287. List<int> dailyPaymentIds = new List<int>();
  2288. List<int> hotelIds = new List<int>();
  2289. #region 参数处理
  2290. if (!string.IsNullOrEmpty(dto.GroupIds))
  2291. {
  2292. if (dto.GroupIds.Contains(","))
  2293. {
  2294. groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  2295. }
  2296. else
  2297. {
  2298. groupIds.Add(int.Parse(dto.GroupIds));
  2299. }
  2300. }
  2301. if (!string.IsNullOrEmpty(dto.HotelSubIds))
  2302. {
  2303. if (dto.HotelSubIds.Contains(","))
  2304. {
  2305. hotelIds = dto.HotelSubIds.Split(',').Select(int.Parse).ToList();
  2306. }
  2307. else
  2308. {
  2309. hotelIds.Add(int.Parse(dto.HotelSubIds));
  2310. }
  2311. }
  2312. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  2313. {
  2314. if (dto.DailyPaymentIds.Contains(","))
  2315. {
  2316. dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  2317. }
  2318. else
  2319. {
  2320. dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  2321. }
  2322. }
  2323. #endregion
  2324. requestCheckedView.GroupIds = groupIds;
  2325. requestCheckedView.HotelSubIds = hotelIds;
  2326. requestCheckedView.DailyPaymentIds = dailyPaymentIds;
  2327. if (dto.Type == 1)
  2328. {
  2329. TimeSpan ts = DateTime.Now.AddDays(180) - DateTime.Now; //设置redis 过期时间 半年(180)
  2330. var status = await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("paymentRequestCheckedData", JsonConvert.SerializeObject(requestCheckedView), ts);
  2331. if (status)
  2332. {
  2333. return Ok(JsonView(true, "操作成功!"));
  2334. }
  2335. }
  2336. else if (dto.Type == 2)
  2337. {
  2338. var status = await RedisRepository.RedisFactory.CreateRedisRepository().KeyDeleteAsync("paymentRequestCheckedData");
  2339. if (status)
  2340. {
  2341. return Ok(JsonView(true, "操作成功!"));
  2342. }
  2343. }
  2344. return Ok(JsonView(false, "操作失败!"));
  2345. }
  2346. /// <summary>
  2347. /// 付款申请 (PageId=51)
  2348. /// 团组,日付相关费用 汇率变更
  2349. /// </summary>
  2350. /// <param name="dto"></param>
  2351. /// <returns></returns>
  2352. [HttpPost]
  2353. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2354. public async Task<IActionResult> PostPayRequestRateChange(PayRequestRateChangeDto dto)
  2355. {
  2356. #region 验证
  2357. DateTime beginDt, endDt;
  2358. string format = "yyyy-MM-dd";
  2359. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  2360. {
  2361. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  2362. }
  2363. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  2364. {
  2365. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  2366. }
  2367. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2368. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  2369. if (dto.Rate <= 0) return Ok(JsonView(false, "请传入有效的Rate参数!"));
  2370. #endregion
  2371. int hotelSubStatus = 0,status = 0;
  2372. int diid = 0, cTable = 0, currId = 0;
  2373. if (dto.HotelSubId > 0)
  2374. {
  2375. //更改酒店子表汇率
  2376. hotelSubStatus = _sqlSugar.Updateable<Grp_HotelReservationsContent>()
  2377. .SetColumns(it => it.Rate == dto.Rate)
  2378. .Where(it => it.Id == dto.HotelSubId)
  2379. .ExecuteCommand();
  2380. if (hotelSubStatus > 0)
  2381. {
  2382. var hotelSubInfo = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.Id == dto.HotelSubId).First();
  2383. if (hotelSubInfo != null)
  2384. {
  2385. diid = hotelSubInfo.DiId;
  2386. currId = hotelSubInfo.Currency;
  2387. }
  2388. //付款申请汇率更改成功;更改团组汇率对应币种
  2389. string currCode = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == currId).First()?.Name ?? "";
  2390. await _teamRateRep.UpdateGroupRateByDiIdAndCTableId(diid, 76, currCode, dto.Rate);
  2391. }
  2392. }
  2393. if (dto.Id > 0)
  2394. {
  2395. var ccpInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.Id == dto.Id).First();
  2396. decimal cnyMoney = 0.00M;
  2397. if (ccpInfo != null) {
  2398. cnyMoney = ccpInfo.PayMoney * dto.Rate;
  2399. diid = ccpInfo.DIId;
  2400. cTable = ccpInfo.CTable;
  2401. currId = ccpInfo.PaymentCurrency;
  2402. }
  2403. status = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2404. .SetColumns(it => it.DayRate == dto.Rate)
  2405. .SetColumns(it => it.RMBPrice == cnyMoney)
  2406. .Where(it => it.Id == dto.Id)
  2407. .ExecuteCommand();
  2408. if (status > 0)
  2409. {
  2410. //付款申请汇率更改成功;更改团组汇率对应币种
  2411. if (cTable != 76)
  2412. {
  2413. string currCode = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == currId).First()?.Name ?? "";
  2414. await _teamRateRep.UpdateGroupRateByDiIdAndCTableId(diid, cTable, currCode, dto.Rate);
  2415. }
  2416. }
  2417. }
  2418. if (hotelSubStatus > 0 || status > 0)
  2419. {
  2420. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2421. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2422. if (checkedStr != null)
  2423. {
  2424. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2425. }
  2426. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(1, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2427. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(1, checkedView.GroupIds, checkedView.HotelSubIds, dto.beginDt, dto.endDt);
  2428. decimal _gz = dailyResult.gz + groupResult.gz;
  2429. decimal _sz = dailyResult.sz + groupResult.sz;
  2430. return Ok(JsonView(true, "操作成功!", new { gz = dailyResult, sz = groupResult }));
  2431. }
  2432. return Ok(JsonView(false, "该项汇率修改失败!"));
  2433. }
  2434. /// <summary>
  2435. /// 付款申请 (PageId=51)
  2436. /// 团组,日付相关费用 付款状态变更
  2437. /// </summary>
  2438. /// <param name="dto"></param>
  2439. /// <returns></returns>
  2440. [HttpPost]
  2441. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2442. public async Task<IActionResult> PostPayRequestPayChange(PayRequestPayChangeDto dto)
  2443. {
  2444. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2445. //if (string.IsNullOrEmpty(dto.GroupIds))
  2446. //{
  2447. // return Ok(JsonView(false, "请传入有效的GroupIds参数!"));
  2448. //}
  2449. //if (string.IsNullOrEmpty(dto.DailyPaymentIds))
  2450. //{
  2451. // return Ok(JsonView(false, "请传入有效的DailyPaymentIds参数!"));
  2452. //}
  2453. List<int> groupIds = new List<int>();
  2454. List<int> dailyPaymentIds = new List<int>();
  2455. List<int> hotelSubIds = new List<int>();
  2456. #region 参数处理
  2457. if (!string.IsNullOrEmpty(dto.GroupIds))
  2458. {
  2459. if (dto.GroupIds.Contains(",")) groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  2460. else groupIds.Add(int.Parse(dto.GroupIds));
  2461. }
  2462. if (!string.IsNullOrEmpty(dto.HotelSubIds))
  2463. {
  2464. if (dto.HotelSubIds.Contains(",")) hotelSubIds = dto.HotelSubIds.Split(',').Select(int.Parse).ToList();
  2465. else hotelSubIds.Add(int.Parse(dto.HotelSubIds));
  2466. if (hotelSubIds.Count > 0)
  2467. {
  2468. foreach (var item in hotelSubIds)
  2469. {
  2470. if (item < 1)
  2471. {
  2472. hotelSubIds.Remove(item);
  2473. }
  2474. }
  2475. }
  2476. }
  2477. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  2478. {
  2479. if (dto.DailyPaymentIds.Contains(",")) dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  2480. else dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  2481. }
  2482. #endregion
  2483. bool changeStatus = false;
  2484. _sqlSugar.BeginTran();
  2485. if (groupIds.Count > 0)
  2486. {
  2487. var ccpInfos = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id)).ToList();
  2488. var otherTypeCcpIds = ccpInfos.Where(it => it.CTable != 76).Select(it => it.Id).ToList();
  2489. var hotelTyprCcpIds = ccpInfos.Where(it => it.CTable == 76).Select(it => it.Id).ToList();
  2490. int groupStatus = 0;
  2491. if (otherTypeCcpIds.Count > 0) //其他费用类型 正常付款
  2492. {
  2493. groupStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2494. .SetColumns(it => it.IsPay == 1)
  2495. .Where(it => otherTypeCcpIds.Contains(it.Id))
  2496. .ExecuteCommand();
  2497. changeStatus = true;
  2498. }
  2499. if (hotelTyprCcpIds.Count > 0) //酒店费用子项逻辑付款,酒店子项费用全部付完款,c表ispay=1
  2500. {
  2501. if (hotelSubIds.Count > 0)
  2502. {
  2503. List<int> hrPayIds = new List<int>();
  2504. var hrIspayStatus = _sqlSugar.Updateable<Grp_HotelReservationsContent>()
  2505. .SetColumns(it => it.IsPay == 1)
  2506. .Where(it => hotelSubIds.Contains(it.Id))
  2507. .ExecuteCommand();
  2508. changeStatus = true;
  2509. //酒店子项是否全部付完款
  2510. List<int> hrIds = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && hotelSubIds.Contains(it.Id)).Select(it => it.HrId).Distinct().ToList();
  2511. if (hrIds.Count > 0 )
  2512. {
  2513. var hotelSubFeeData = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && hrIds.Contains(it.HrId)).ToList();
  2514. var hotelSubFeeGroupData = hotelSubFeeData.GroupBy(it => it.HrId).ToList();
  2515. foreach (var item in hotelSubFeeGroupData)
  2516. {
  2517. var allTotal = item.Where(it => it.Price > 0).ToList().Count;
  2518. var paymentTotal = item.Where(it => it.Price > 0 && it.IsPay == 1).ToList().Count;
  2519. if (allTotal == paymentTotal)
  2520. {
  2521. hrPayIds.Add(item.Key);
  2522. }
  2523. }
  2524. }
  2525. if (hrPayIds.Count > 0)
  2526. {
  2527. //c表更改全部付款的酒店费用
  2528. groupStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2529. .SetColumns(it => it.IsPay == 1)
  2530. .Where(it => it.CTable == 76 && hrPayIds.Contains(it.CId))
  2531. .ExecuteCommand();
  2532. }
  2533. }
  2534. }
  2535. }
  2536. //if (hotelSubIds.Count > 0)
  2537. //{
  2538. // var groupStatus = _sqlSugar.Updateable<Grp_HotelReservationsContent>()
  2539. // .SetColumns(it => it.IsPay == 1)
  2540. // .Where(it => hotelSubIds.Contains(it.Id))
  2541. // .ExecuteCommand();
  2542. // if (groupStatus > 0)
  2543. // {
  2544. // changeStatus = true;
  2545. // }
  2546. //}
  2547. if (dailyPaymentIds.Count > 0)
  2548. {
  2549. var dailyPaymentStatus = _sqlSugar.Updateable<Fin_DailyFeePayment>()
  2550. .SetColumns(it => it.IsPay == 1)
  2551. .Where(it => dailyPaymentIds.Contains(it.Id))
  2552. .ExecuteCommand();
  2553. if (dailyPaymentStatus > 0)
  2554. {
  2555. changeStatus = true;
  2556. }
  2557. }
  2558. if (changeStatus)
  2559. {
  2560. _sqlSugar.CommitTran();
  2561. #region 应用推送
  2562. try
  2563. {
  2564. foreach (int ccpId in groupIds)
  2565. {
  2566. List<string> tempList = new List<string>() { ccpId.ToString() };
  2567. await AppNoticeLibrary.SendUserMsg_GroupStatus_PayResult(ccpId, tempList);
  2568. }
  2569. foreach (int dailyId in dailyPaymentIds)
  2570. {
  2571. List<string> tempList = new List<string>() { dailyId.ToString() };
  2572. await AppNoticeLibrary.DailyPayReminder_Pay_ToUser(dailyId, tempList);
  2573. }
  2574. }
  2575. catch (Exception ex)
  2576. {
  2577. }
  2578. #endregion
  2579. return Ok(JsonView(true, "操作成功!"));
  2580. }
  2581. _sqlSugar.RollbackTran();
  2582. return Ok(JsonView(false, "付款状态修改失败!"));
  2583. }
  2584. /// <summary>
  2585. /// 付款申请 (PageId=51)
  2586. /// File Download
  2587. /// </summary>
  2588. /// <param name="dto"></param>
  2589. /// <returns></returns>
  2590. [HttpPost]
  2591. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2592. public async Task<IActionResult> PostPayRequestFileDownload(PayRequestFileDownloadDto dto)
  2593. {
  2594. Stopwatch stopwatch = Stopwatch.StartNew();
  2595. #region 参数,权限 验证
  2596. if (dto.PortType < 1)
  2597. {
  2598. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  2599. }
  2600. if (dto.UserId < 1)
  2601. {
  2602. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2603. }
  2604. if (dto.PageId < 1)
  2605. {
  2606. dto.PageId = 51;
  2607. return Ok(JsonView(false, "请传入有效的PageId参数!"));
  2608. }
  2609. if (dto.ConpanyId < 1 || dto.ConpanyId > 4)
  2610. {
  2611. return Ok(JsonView(false, "请传入有效的ConpanyId参数!"));
  2612. }
  2613. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2614. #region 页面操作权限验证
  2615. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  2616. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  2617. #endregion
  2618. #endregion
  2619. try
  2620. {
  2621. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2622. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2623. if (checkedStr != null)
  2624. {
  2625. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2626. }
  2627. if (checkedView == null)
  2628. {
  2629. return Ok(JsonView(false, "没有选中的数据!"));
  2630. }
  2631. if (checkedView.GroupIds == null && checkedView.DailyPaymentIds == null)
  2632. {
  2633. return Ok(JsonView(false, "没有选中的数据!"));
  2634. }
  2635. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(2, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2636. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(2, checkedView.GroupIds, checkedView.HotelSubIds, dto.beginDt, dto.endDt);
  2637. if (dailyResult.childList == null)
  2638. {
  2639. dailyResult.childList = new List<Fin_DailyFeePaymentContentInfolView>();
  2640. }
  2641. List<tree_Group_DailyFeePaymentPageListView> _GroupData = new List<tree_Group_DailyFeePaymentPageListView>();
  2642. List<tree_Fin_DailyFeePaymentPageListView> _DailyData = new List<tree_Fin_DailyFeePaymentPageListView>();
  2643. //1 成都泛美商务有限公司
  2644. if (dto.ConpanyId == 1)
  2645. {
  2646. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2647. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2648. }
  2649. //2 四川泛美交流有限公司
  2650. else if (dto.ConpanyId == 2)
  2651. {
  2652. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2653. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2654. }
  2655. //3 成都纽茵教育科技有限公司
  2656. else if (dto.ConpanyId == 3)
  2657. {
  2658. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2659. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2660. }
  2661. //4 成都鸿企中元科技有限公司
  2662. else if (dto.ConpanyId == 4)
  2663. {
  2664. return Ok(JsonView(false, "暂未开放该类型!"));
  2665. }
  2666. else
  2667. {
  2668. return Ok(JsonView(false, "参数ConpanyId不可使用!"));
  2669. }
  2670. string _requestPaymentDt = DateTime.Now.ToString("yyyy-MM-dd"),//申请付款日期
  2671. _appliedAmount = "", //申请付款金额
  2672. _GZStr = "", //公转价格描述
  2673. _SZStr = ""; //私转价格描述
  2674. decimal groupGZAmout = 0.00M, groupSZAmout = 0.00M;
  2675. decimal dailyGZAmout = 0.00M, dailySZAmout = 0.00M;
  2676. string dailyGZStr = "", dailySZStr = "", groupGZStr = "", groupSZStr = "";
  2677. #region 数据处理
  2678. //团组费用相关
  2679. foreach (var item in _GroupData)
  2680. {
  2681. string groupGZSubStr = "";
  2682. string groupSZSubStr = "";
  2683. foreach (var subItem in item.ChildList)
  2684. {
  2685. if (subItem.TransferMark.Equals("公转"))
  2686. {
  2687. groupGZAmout += subItem.CNYSubTotalAmount;
  2688. groupGZSubStr += $"{subItem.RemaksDescription}\r\n";
  2689. }
  2690. else if (subItem.TransferMark.Equals("私转"))
  2691. {
  2692. groupSZAmout += subItem.CNYSubTotalAmount;
  2693. groupSZSubStr += $"{subItem.RemaksDescription}\r\n";
  2694. }
  2695. //groupGZSubStr += $"\t";
  2696. }
  2697. //if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"团组:{item.GroupName}\r\n{groupGZSubStr}\r\n";
  2698. //if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"团组:{item.GroupName}\r\n{groupSZSubStr}\r\n";
  2699. if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"{groupGZSubStr}\r\n";
  2700. if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"{groupSZSubStr}\r\n";
  2701. }
  2702. //日常费用相关
  2703. foreach (var item in _DailyData)
  2704. {
  2705. foreach (var subItem in item.childList)
  2706. {
  2707. if (item.transferParentId == 62) //公转
  2708. {
  2709. dailyGZAmout += item.SumPrice ?? 0.00M;
  2710. dailyGZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
  2711. }
  2712. else if (item.transferParentId == 63) //私转
  2713. {
  2714. dailySZAmout += item.SumPrice ?? 0.00M;
  2715. dailySZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
  2716. }
  2717. }
  2718. }
  2719. _GZStr = $"【公转】团组相关费用(合计:CNY {groupGZAmout.ToString("#0.00")}):\r\n{groupGZStr}【公转】日常付款费用(合计:CNY {dailyGZAmout.ToString("#0.00")}):\r\n{dailyGZStr}";
  2720. _SZStr = $"【私转】团组相关费用(合计:CNY {groupSZAmout.ToString("#0.00")}):\r\n{groupSZStr}【私转】日常付款费用(合计:CNY {dailySZAmout.ToString("#0.00")}):\r\n{dailySZStr}";
  2721. _appliedAmount = $"公转:CNY {(groupGZAmout + dailyGZAmout).ToString("#0.00")}\r\n私转:CNY {(groupSZAmout + dailySZAmout).ToString("#0.00")}";
  2722. #endregion
  2723. WorkbookDesigner designer = new WorkbookDesigner();
  2724. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/付款申请书.xls");
  2725. designer.SetDataSource("Date", _requestPaymentDt);
  2726. designer.SetDataSource("Price", _appliedAmount);
  2727. designer.SetDataSource("Content", _GZStr);
  2728. designer.SetDataSource("Content1", _SZStr);
  2729. //根据数据源处理生成报表内容
  2730. designer.Process();
  2731. string fileName = ("PayRequest/付款申请(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  2732. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  2733. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  2734. stopwatch.Stop();
  2735. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds / 1000}s", new { url = rst }));
  2736. }
  2737. catch (Exception ex)
  2738. {
  2739. return Ok(JsonView(false, ex.Message));
  2740. }
  2741. }
  2742. #endregion
  2743. #region 超支费用
  2744. /// <summary>
  2745. /// 超支费用
  2746. /// 1增、2改、3删
  2747. /// </summary>
  2748. /// <param name="dto"></param>
  2749. /// <returns></returns>
  2750. [HttpPost]
  2751. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2752. public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  2753. {
  2754. #region 验证
  2755. #endregion
  2756. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  2757. _entity.DiId = dto.diId;
  2758. _entity.PriceName = dto.priceName;
  2759. _entity.Price = dto.price;
  2760. _entity.PriceCurrency = dto.currency;
  2761. _entity.PriceType = dto.priceType;
  2762. _entity.Coefficient = dto.coefficient;
  2763. _entity.PriceDetailType = dto.priceDetailType;
  2764. _entity.FilePath = dto.filePath;
  2765. _entity.Remark = dto.remark;
  2766. _entity.PriceCount = dto.PriceCount;
  2767. _entity.Area = dto.Area;
  2768. DateTime dt_PriceDt;
  2769. bool b_PriceDt = DateTime.TryParse(dto.PriceDt, out dt_PriceDt);
  2770. if (b_PriceDt)
  2771. {
  2772. _entity.PriceDt = dt_PriceDt;
  2773. }
  2774. else
  2775. {
  2776. _entity.PriceDt = DateTime.MinValue;
  2777. }
  2778. _entity.PriceSum = dto.price * dto.PriceCount;
  2779. _daiRep.BeginTran();
  2780. if (dto.editType == 1)
  2781. {
  2782. _entity.CreateUserId = dto.createUser;
  2783. _entity.CreateTime = DateTime.Now;
  2784. _entity.IsDel = 0;
  2785. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  2786. if (returnId > 0)
  2787. {
  2788. dto.Id = returnId;
  2789. }
  2790. }
  2791. else if (dto.editType == 2)
  2792. {
  2793. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2794. {
  2795. PriceName = dto.priceName,
  2796. Price = dto.price,
  2797. PriceCurrency = dto.currency,
  2798. PriceType = dto.priceType,
  2799. PriceDetailType = dto.priceDetailType,
  2800. Coefficient = dto.coefficient,
  2801. FilePath = dto.filePath,
  2802. Remark = dto.remark,
  2803. PriceCount = dto.PriceCount,
  2804. PriceDt = _entity.PriceDt,
  2805. PriceSum = _entity.PriceSum,
  2806. Area = _entity.Area,
  2807. });
  2808. if (!res)
  2809. {
  2810. _daiRep.RollbackTran();
  2811. return Ok(JsonView(false, "2操作失败!"));
  2812. }
  2813. }
  2814. else if (dto.editType == 3)
  2815. {
  2816. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2817. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2818. {
  2819. IsDel = 1,
  2820. DeleteTime = delTime,
  2821. DeleteUserId = dto.createUser
  2822. });
  2823. if (!res)
  2824. {
  2825. _daiRep.RollbackTran();
  2826. return Ok(JsonView(false, "3操作失败!"));
  2827. }
  2828. }
  2829. else
  2830. {
  2831. _daiRep.RollbackTran();
  2832. return Ok(JsonView(false, "未知的editType"));
  2833. }
  2834. if (!extraCost_editCreditCardPayment(dto))
  2835. {
  2836. return Ok(JsonView(false, "ccp操作失败"));
  2837. }
  2838. _daiRep.CommitTran();
  2839. return Ok(JsonView(true, "操作成功"));
  2840. }
  2841. private Result PostCurrencyByDiid_Sync(int diId, int CId, int currencyId)
  2842. {
  2843. if (diId == 0)
  2844. {
  2845. return new Result() { Code = -1, Msg = "请传入团组Id!" };
  2846. }
  2847. if (CId == 0)
  2848. {
  2849. return new Result() { Code = -1, Msg = "请传入类型Id!" };
  2850. }
  2851. if (currencyId == 0)
  2852. {
  2853. return new Result() { Code = -1, Msg = "请传入币种Id!" };
  2854. }
  2855. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == diId && a.IsDel == 0 && a.CTable == CId);
  2856. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  2857. CurrencyInfo CurrencyRate = new CurrencyInfo();
  2858. try
  2859. {
  2860. if (_TeamRate != null)
  2861. {
  2862. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == currencyId);
  2863. if (_SetData != null)
  2864. {
  2865. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  2866. CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  2867. if (CurrencyRate != null)
  2868. {
  2869. return new Result() { Code = 0, Msg = "查询成功!", Data = CurrencyRate };
  2870. }
  2871. else
  2872. {
  2873. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2874. }
  2875. }
  2876. else
  2877. {
  2878. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2879. }
  2880. }
  2881. else
  2882. {
  2883. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2884. }
  2885. }
  2886. catch (Exception)
  2887. {
  2888. return new Result() { Code = -1, Msg = "查询异常!", Data = CurrencyRate };
  2889. }
  2890. }
  2891. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  2892. {
  2893. //设置团组汇率
  2894. decimal dcm_dayrate = 1M;
  2895. decimal dcm_rmbPrice = costDto.price;
  2896. int ispay = costDto.payType == 72 ? 1 : 0;
  2897. if (costDto.costSign != 3)
  2898. {
  2899. //获取新汇率 int diId,int CId, int currencyId
  2900. Result rate = this.PostCurrencyByDiid_Sync(costDto.diId, 1015, costDto.currency);
  2901. if (rate.Code == 0)
  2902. {
  2903. var rateInfo = (rate.Data as CurrencyInfo);
  2904. if (rateInfo is not null)
  2905. {
  2906. dcm_dayrate = rateInfo.Rate;
  2907. dcm_rmbPrice = rateInfo.Rate * dcm_rmbPrice;
  2908. }
  2909. else
  2910. {
  2911. dcm_dayrate = 1;
  2912. }
  2913. }
  2914. }
  2915. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  2916. if (ccp == null)
  2917. {
  2918. ccp = new Grp_CreditCardPayment();
  2919. ccp.PayDId = costDto.payType;// dto
  2920. ccp.ConsumptionPatterns = "";
  2921. ccp.ConsumptionDate = "";
  2922. ccp.CTDId = costDto.payCardId;// dto
  2923. ccp.BankNo = "";
  2924. ccp.CardholderName = "";
  2925. ccp.PayMoney = costDto.price;// dto
  2926. ccp.PaymentCurrency = costDto.currency;// dto
  2927. ccp.CompanyBankNo = "";
  2928. ccp.OtherBankName = "";
  2929. ccp.OtherSideNo = "";
  2930. ccp.OtherSideName = "";
  2931. ccp.Remark = "";
  2932. ccp.CreateUserId = costDto.createUser;
  2933. ccp.CreateTime = DateTime.Now;
  2934. ccp.MFOperator = 0;
  2935. ccp.MFOperatorDate = "";
  2936. ccp.IsAuditDM = 0;
  2937. ccp.AuditDMOperate = 0;
  2938. ccp.AuditDMDate = "";
  2939. ccp.IsAuditMF = 0;
  2940. ccp.AuditMFOperate = 0;
  2941. ccp.AuditMFDate = "";
  2942. ccp.IsAuditGM = 0;
  2943. ccp.AuditGMOperate = 0;
  2944. ccp.AuditGMDate = "";
  2945. ccp.IsPay = ispay; // upd
  2946. ccp.DIId = costDto.diId;// dto
  2947. ccp.CId = costDto.Id;// dto
  2948. ccp.CTable = 1015; //超支费用指向id
  2949. ccp.IsDel = 0;
  2950. ccp.PayPercentage = 100M;
  2951. ccp.PayThenMoney = 0M;
  2952. ccp.PayPercentageOld = 100M;
  2953. ccp.PayThenMoneyOld = 0M;
  2954. ccp.UpdateDate = "";
  2955. ccp.Payee = costDto.payee;// dto
  2956. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  2957. ccp.ExceedBudget = 0;
  2958. ccp.DayRate = dcm_dayrate; //upd
  2959. ccp.RMBPrice = dcm_rmbPrice; //upd
  2960. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  2961. if (ccpInsertId > 0)
  2962. {
  2963. return true;
  2964. }
  2965. }
  2966. else
  2967. {
  2968. if (costDto.editType == 2)
  2969. {
  2970. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  2971. {
  2972. PayDId = costDto.payType,
  2973. CTDId = costDto.payCardId,
  2974. PayMoney = costDto.price,
  2975. PaymentCurrency = costDto.currency,
  2976. IsPay = ispay,
  2977. Payee = costDto.payee,
  2978. OrbitalPrivateTransfer = costDto.costSign,
  2979. DayRate = dcm_dayrate,
  2980. RMBPrice = dcm_rmbPrice
  2981. });
  2982. return res;
  2983. }
  2984. else if (costDto.editType == 3)
  2985. {
  2986. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2987. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  2988. {
  2989. IsDel = 1,
  2990. DeleteTime = delTime,
  2991. DeleteUserId = costDto.createUser
  2992. });
  2993. return res2;
  2994. }
  2995. }
  2996. return false;
  2997. }
  2998. /// <summary>
  2999. /// 超支费用
  3000. /// 详情查询
  3001. /// </summary>
  3002. /// <param name="dto"></param>
  3003. /// <returns></returns>
  3004. [HttpPost]
  3005. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3006. public async Task<IActionResult> PostGroupExtraCost_Detail(Fin_GroupExtraCostDto_Detail dto)
  3007. {
  3008. if (dto.Id < 1)
  3009. {
  3010. return Ok(JsonView(false, "查询失败"));
  3011. }
  3012. string sql = string.Format(@" Select
  3013. f.Id,f.DiId,
  3014. f.PriceName,f.Price,f.PriceCurrency,c.Payee,c.OrbitalPrivateTransfer,c.PayDId,f.area,
  3015. c.CTDId,f.PriceType,f.PriceDetailType,f.Coefficient,f.Remark,f.PriceCount,f.PriceDt
  3016. From Fin_GroupExtraCost f
  3017. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  3018. Left Join Sys_Users u On f.CreateUserId = u.Id
  3019. Where f.IsDel=0 And c.CTable = 1015
  3020. And f.Id = {0} ", dto.Id);
  3021. Fin_GroupExtraCostDetailView detailView = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostDetailView>(sql).FirstAsync();
  3022. if (detailView == null)
  3023. {
  3024. return Ok(JsonView(false, "查询失败"));
  3025. }
  3026. return Ok(JsonView(true, "查询成功", detailView));
  3027. }
  3028. /// <summary>
  3029. /// 超支费用
  3030. /// 列表查询
  3031. /// </summary>
  3032. /// <param name="dto"></param>
  3033. /// <returns></returns>
  3034. [HttpPost]
  3035. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3036. public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
  3037. {
  3038. string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
  3039. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  3040. int endIndex = startIndex + dto.PageSize - 1;
  3041. string sql_data = string.Format(@"Select * From (
  3042. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  3043. 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,
  3044. f.CreateUserId,f.PriceDt,c.IsAuditGM
  3045. From Fin_GroupExtraCost f
  3046. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  3047. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  3048. Left Join Sys_Users u On f.CreateUserId = u.Id
  3049. Where f.IsDel=0 And c.CTable = 1015 {0}
  3050. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  3051. string sql_count = string.Format(@"Select Count(1) as DataCount From (
  3052. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  3053. f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  3054. From Fin_GroupExtraCost f
  3055. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  3056. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  3057. Left Join Sys_Users u On f.CreateUserId = u.Id
  3058. Where f.IsDel=0 And c.CTable = 1015 {0}
  3059. ) temp ", sqlWhere);
  3060. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  3061. {
  3062. //Fin_DailyFeePaymentPageCount
  3063. var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
  3064. List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
  3065. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  3066. Dictionary<int, string> dic_user = new Dictionary<int, string>();
  3067. foreach (var item in dataList)
  3068. {
  3069. DateTime dtTemp_PriceDt;
  3070. bool b_ct = DateTime.TryParse(item.PriceDt, out dtTemp_PriceDt);
  3071. if (b_ct)
  3072. {
  3073. item.PriceDt = dtTemp_PriceDt.ToString("yyyy-MM-dd");
  3074. }
  3075. //费用类型
  3076. if (dic_setData.ContainsKey(item.PriceType))
  3077. {
  3078. item.PriceTypeStr = dic_setData[item.PriceType];
  3079. }
  3080. else
  3081. {
  3082. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
  3083. if (sd_priceTypeDetail != null)
  3084. {
  3085. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  3086. item.PriceTypeStr = tempName;
  3087. dic_setData.Add(item.PriceType, tempName);
  3088. }
  3089. }
  3090. if (item.PriceDetailType > 0)
  3091. {
  3092. if (dic_setData.ContainsKey(item.PriceDetailType))
  3093. {
  3094. item.PriceTypeStr = item.PriceTypeStr + " - " + dic_setData[item.PriceDetailType];
  3095. }
  3096. else
  3097. {
  3098. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceDetailType).First();
  3099. if (sd_priceTypeDetail != null)
  3100. {
  3101. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  3102. item.PriceTypeStr = item.PriceTypeStr + " - " + tempName;
  3103. dic_setData.Add(item.PriceDetailType, tempName);
  3104. }
  3105. }
  3106. }
  3107. //系统用户
  3108. if (dic_user.ContainsKey(item.CreateUserId))
  3109. {
  3110. item.CreateUserIdStr = dic_user[item.CreateUserId];
  3111. }
  3112. else
  3113. {
  3114. Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
  3115. if (users != null)
  3116. {
  3117. item.CreateUserIdStr = users.CnName;
  3118. dic_user.Add(item.CreateUserId, users.CnName);
  3119. }
  3120. }
  3121. switch (item.IsAuditGM)
  3122. {
  3123. case 0: item.IsAuditGMStr = "未审核"; break;
  3124. case 1: item.IsAuditGMStr = "已通过"; break;
  3125. case 2: item.IsAuditGMStr = "未通过"; break;
  3126. default: item.IsAuditGMStr = "未知状态"; break;
  3127. }
  3128. }
  3129. var result = new ListViewBase<Fin_GroupExtraCostView>
  3130. {
  3131. CurrPageIndex = dto.PageIndex,
  3132. CurrPageSize = dto.PageSize,
  3133. DataCount = count.DataCount,
  3134. DataList = dataList
  3135. };
  3136. return Ok(JsonView(true, "查询成功", result));
  3137. }
  3138. return Ok(JsonView(false, "查询失败"));
  3139. }
  3140. /// <summary>
  3141. /// 超支费用
  3142. /// 数据集合配置
  3143. /// </summary>
  3144. /// <param name="dto"></param>
  3145. /// <returns></returns>
  3146. [HttpPost]
  3147. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3148. public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
  3149. {
  3150. //支付方式
  3151. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  3152. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  3153. //信用卡类型
  3154. List<Sys_SetData> Card = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  3155. List<SetDataInfoView> _Card = _mapper.Map<List<SetDataInfoView>>(Card);
  3156. //超支费用类型
  3157. List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
  3158. List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
  3159. //超支费用详细类型
  3160. List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
  3161. PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
  3162. List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
  3163. var data = new
  3164. {
  3165. Payment = _Payment,
  3166. Card = _Card,
  3167. PriceType = _PriceType,
  3168. PriceDetailType = _PriceDetailType
  3169. };
  3170. return Ok(JsonView(true, "", data));
  3171. }
  3172. /// <summary>
  3173. /// 超支费用
  3174. /// 导出团组超支费用Excel
  3175. /// </summary>
  3176. /// <param name="dto"></param>
  3177. /// <returns></returns>
  3178. [HttpPost]
  3179. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3180. public async Task<IActionResult> PostGroupExtraCost_OutputExcel(Fin_GroupExtraCostExcelDto dto)
  3181. {
  3182. string sqlGroup = string.Format(@" Select * From Grp_DelegationInfo WIth(Nolock) where Id = {0} ", dto.diId);
  3183. Grp_DelegationInfo grp_DelegationInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sqlGroup).FirstAsync();
  3184. if (grp_DelegationInfo == null)
  3185. {
  3186. return Ok(JsonView(false, "导出失败,未查询到团组"));
  3187. }
  3188. Workbook workbook = new Workbook();
  3189. Worksheet sheet = workbook.Worksheets[0];
  3190. Cells cells = sheet.Cells;
  3191. //sheet.Protect(Aspose.Cells.ProtectionType.All, "123123", "");//保护工作表
  3192. //sheet.Protection.IsSelectingLockedCellsAllowed = true;//设置只能选择解锁单元格
  3193. //sheet.Protection.IsFormattingColumnsAllowed = true;//设置可以调整列
  3194. //sheet.Protection.IsFormattingRowsAllowed = true;//设置可以调整行
  3195. #region 数据源
  3196. string sqlData = string.Format(@" Select f.PriceType,REPLACE(s2.[Name],'超支费用','') as PriceTypeStr,'('+REPLACE(s3.[Name],'n','')+')' as PriceDetailTypeStr, PriceDt,PriceName,
  3197. Price,PriceCount,s.[Name] as Currency,PriceSum,f.Remark
  3198. From Fin_GroupExtraCost as f With(Nolock)
  3199. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  3200. Inner Join Sys_SetData as s With(Nolock) On f.PriceCurrency = s.Id
  3201. Inner Join Sys_SetData as s2 With(Nolock) On f.PriceType = s2.Id
  3202. Inner Join Sys_SetData as s3 With(Nolock) On f.PriceDetailType = s3.Id
  3203. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  3204. Order by PriceType ASC,PriceDt ASC ", dto.diId);
  3205. string sqlDataCount = string.Format(@" Select f.PriceType,COUNT(f.PriceType) as DataCount
  3206. From Fin_GroupExtraCost as f With(Nolock)
  3207. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  3208. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  3209. Group by PriceType ", dto.diId);
  3210. List<Fin_GroupExtraCost_ExcelView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelView>(sqlData).ToListAsync();
  3211. List<Fin_GroupExtraCost_ExcelCountView> countList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelCountView>(sqlDataCount).ToListAsync();
  3212. if (dataList.Count < 1 || countList.Count < 1)
  3213. {
  3214. return Ok(JsonView(false, "导出失败,未查询到数据"));
  3215. }
  3216. #endregion
  3217. #region 标题
  3218. string cellValue_Header = grp_DelegationInfo.TeamName;
  3219. //Aspose.Cells.Style style1 = workbook.Styles[workbook.Styles.Add()];//新增样式
  3220. Aspose.Cells.Style style_Header = workbook.CreateStyle();
  3221. style_Header.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3222. style_Header.VerticalAlignment = TextAlignmentType.Center;
  3223. style_Header.Font.Name = "微软雅黑";//文字字体
  3224. style_Header.Font.Size = 18;//文字大小
  3225. style_Header.IsLocked = false;//单元格解锁
  3226. style_Header.Font.IsBold = false;//粗体
  3227. style_Header.Font.Color = Color.FromArgb(255, 0, 0);
  3228. //style1.ForegroundColor = Color.FromArgb(0x99, 0xcc, 0xff);//设置背景色
  3229. //style1.Pattern = BackgroundType.Solid; //设置背景样式
  3230. //style1.IsTextWrapped = true;//单元格内容自动换行
  3231. style_Header.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3232. style_Header.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3233. style_Header.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3234. style_Header.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3235. cells.Merge(1, 1, 1, 10);
  3236. Aspose.Cells.Range range_header = cells.CreateRange(1, 1, 1, 10);
  3237. range_header.PutValue(cellValue_Header, false, false);
  3238. range_header.SetStyle(style_Header);
  3239. cells.SetRowHeight(1, 35);
  3240. #endregion
  3241. #region 列名
  3242. Aspose.Cells.Style style_colName = workbook.CreateStyle();
  3243. style_colName.Name = "colName";
  3244. style_colName.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3245. style_colName.VerticalAlignment = TextAlignmentType.Center;
  3246. style_colName.Font.Name = "微软雅黑";//文字字体
  3247. style_colName.Font.Size = 12;//文字大小
  3248. style_colName.IsLocked = false;//单元格解锁
  3249. style_colName.Font.IsBold = true;//粗体
  3250. style_colName.Font.Color = Color.FromArgb(0, 0, 0);
  3251. style_colName.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3252. style_colName.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3253. style_colName.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3254. style_colName.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3255. List<Fin_GroupExtraCostExcelColumnSetting> colNameSettingList = new List<Fin_GroupExtraCostExcelColumnSetting>()
  3256. {
  3257. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 1, columnName="类型", columnWidth= 25},
  3258. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 2, columnName="时间", columnWidth= 16},
  3259. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 3, columnName="内容", columnWidth= 35},
  3260. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 4, columnName="单价", columnWidth= 12},
  3261. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 5, columnName="数量", columnWidth= 12},
  3262. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 6, columnName="货币", columnWidth= 12},
  3263. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 7, columnName="费用", columnWidth= 12},
  3264. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 8, columnName="汇率", columnWidth= 12},
  3265. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 9, columnName="人民币", columnWidth= 12},
  3266. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 10, columnName="备注信息", columnWidth= 24}
  3267. };
  3268. foreach (var col in colNameSettingList)
  3269. {
  3270. cells[2, col.columnIndex].PutValue(col.columnName);
  3271. cells[2, col.columnIndex].SetStyle(style_colName);
  3272. cells.SetColumnWidth(col.columnIndex, col.columnWidth);
  3273. }
  3274. cells.SetRowHeight(2, 25);
  3275. #endregion
  3276. #region 数据填充
  3277. Aspose.Cells.Style style_dataCol = workbook.GetNamedStyle("colName");
  3278. style_dataCol.Font.IsBold = false;
  3279. style_dataCol.Name = "dataCol";
  3280. Aspose.Cells.Style style_dataBlue = workbook.CreateStyle();
  3281. style_dataBlue.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3282. style_dataBlue.VerticalAlignment = TextAlignmentType.Center;
  3283. style_dataBlue.Font.Name = "微软雅黑";//文字字体
  3284. style_dataBlue.Font.Size = 12;//文字大小
  3285. style_dataBlue.IsLocked = false;//单元格解锁
  3286. style_dataBlue.Font.IsBold = false;//粗体
  3287. style_dataBlue.ForegroundColor = Color.FromArgb(189, 215, 238);
  3288. style_dataBlue.Pattern = BackgroundType.Solid;
  3289. style_dataBlue.Font.Color = Color.FromArgb(0, 0, 0);
  3290. style_dataBlue.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3291. style_dataBlue.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3292. style_dataBlue.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3293. style_dataBlue.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3294. Aspose.Cells.Style style_dataYellow = workbook.CreateStyle();
  3295. style_dataYellow.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3296. style_dataYellow.VerticalAlignment = TextAlignmentType.Center;
  3297. style_dataYellow.Font.Name = "微软雅黑";//文字字体
  3298. style_dataYellow.Font.Size = 12;//文字大小
  3299. style_dataYellow.IsLocked = false;//单元格解锁
  3300. style_dataYellow.Font.IsBold = false;//粗体
  3301. style_dataYellow.ForegroundColor = Color.FromArgb(255, 242, 204);
  3302. style_dataYellow.Pattern = BackgroundType.Solid;
  3303. style_dataYellow.Font.Color = Color.FromArgb(0, 0, 0);
  3304. style_dataYellow.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3305. style_dataYellow.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3306. style_dataYellow.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3307. style_dataYellow.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3308. int rowIndex = 4;
  3309. foreach (var d in dataList)
  3310. {
  3311. //内容
  3312. string typeStr = d.PriceDetailTypeStr + d.PriceName;
  3313. cells["B" + rowIndex.ToString()].PutValue(d.PriceTypeStr);
  3314. cells["C" + rowIndex.ToString()].PutValue(d.PriceDtStr);
  3315. cells["D" + rowIndex.ToString()].PutValue(typeStr);
  3316. cells["E" + rowIndex.ToString()].PutValue(d.Price.ToString("#0.00"));
  3317. cells["F" + rowIndex.ToString()].PutValue(d.PriceCount);
  3318. cells["G" + rowIndex.ToString()].PutValue(d.Currency);
  3319. cells["H" + rowIndex.ToString()].PutValue(d.PriceSum.ToString("#0.00"));
  3320. cells["K" + rowIndex.ToString()].PutValue(d.Remark);
  3321. //样式
  3322. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3323. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3324. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3325. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3326. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3327. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3328. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3329. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3330. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3331. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3332. //公式
  3333. cells["H" + rowIndex.ToString()].Formula = string.Format(@"E{0}*F{0}", rowIndex);
  3334. cells["J" + rowIndex.ToString()].Formula = string.Format(@"H{0}*I{0}", rowIndex);
  3335. cells.SetRowHeight(rowIndex - 1, 25);
  3336. rowIndex++;
  3337. }
  3338. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3339. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3340. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3341. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3342. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3343. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3344. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3345. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3346. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3347. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3348. rowIndex++;
  3349. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3350. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3351. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3352. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3353. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3354. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3355. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3356. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3357. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3358. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3359. rowIndex = 3;
  3360. int tempPriceType = 0;
  3361. foreach (var c in dataList)
  3362. {
  3363. if (tempPriceType == c.PriceType)
  3364. {
  3365. continue;
  3366. }
  3367. tempPriceType = c.PriceType;
  3368. int _rowCount = countList.First(s => s.PriceType == tempPriceType).DataCount;
  3369. cells.Merge(rowIndex, 1, _rowCount, 1);
  3370. Aspose.Cells.Range tempRange = cells.CreateRange(rowIndex, 1, _rowCount, 1);
  3371. rowIndex += _rowCount;
  3372. }
  3373. rowIndex = 4 + dataList.Count;
  3374. cells["D" + rowIndex.ToString()].PutValue("合计");
  3375. cells["J" + rowIndex.ToString()].Formula = string.Format(@"SUM(J4,J{0})", rowIndex - 1);
  3376. cells.SetRowHeight(rowIndex - 1, 25);
  3377. rowIndex++;
  3378. cells["D" + rowIndex.ToString()].PutValue("服务费10%开票税金8%");
  3379. cells["J" + rowIndex.ToString()].Formula = string.Format(@"J{0}*1.1*1.08", rowIndex - 1);
  3380. cells.SetRowHeight(rowIndex - 1, 25);
  3381. #endregion
  3382. #region IO
  3383. System.IO.MemoryStream ms = workbook.SaveToStream();//生成数据流
  3384. string fileName = ("GroupExtraCost/超支费用(" + cellValue_Header + ").xlsx");
  3385. byte[] bt = ms.ToArray();
  3386. workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  3387. #endregion
  3388. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  3389. return Ok(JsonView(true, "成功", new { url = rst }));
  3390. }
  3391. /// <summary>
  3392. /// 超支费用Excel导出
  3393. /// </summary>
  3394. /// <param name="dto"></param>
  3395. /// <returns></returns>
  3396. [HttpPost]
  3397. public IActionResult ExportOverspendExcel(Fin_GroupExtraCostExcelDto dto)
  3398. {
  3399. var jw = JsonView(false);
  3400. var grp_DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.diId && x.IsDel == 0);
  3401. if (grp_DelegationInfo == null)
  3402. {
  3403. return Ok(JsonView(false, "团组信息有误!"));
  3404. }
  3405. Dictionary<int, int> dicSoure = new Dictionary<int, int>()
  3406. {
  3407. {1077,1074 },
  3408. {1078,1075 },
  3409. {1079,1076 }
  3410. };
  3411. Dictionary<int, int> mealsDic = new Dictionary<int, int>()
  3412. {
  3413. {988,1074},
  3414. {93,1075},
  3415. {989,1076},
  3416. };
  3417. var checkBoxDataArr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 17).ToList();
  3418. var CurrDataArr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToList();
  3419. var joinTable = _sqlSugar.Queryable<Fin_GroupExtraCost, Grp_CreditCardPayment, Sys_SetData, Grp_NationalTravelFee ,
  3420. Fin_LocalGuideRelevancyOverspend , Grp_CarTouristGuideGroundReservations, Sys_SetData,Grp_DelegationInfo>(
  3421. (f, c, s, g, r ,l, s1,i) => new JoinQueryInfos(
  3422. JoinType.Left, f.Id == c.CId && c.CTable == 1015 && c.IsDel == 0,
  3423. JoinType.Left, c.PaymentCurrency == s.Id && s.IsDel == 0,
  3424. JoinType.Left, g.IsDel == 0 && g.Id == f.Area,
  3425. JoinType.Left, f.Id == r.OverspendId && r.IsDel == 0,
  3426. JoinType.Left, l.Id == r.LocalGuideId && l.IsDel == 0,
  3427. JoinType.Left, s1.Id == l.toCurr && s1.IsDel == 0,
  3428. JoinType.Left, i.Id == l.DiId && i.IsDel == 0
  3429. ))
  3430. .Where((f, c, s, g) => f.IsDel == 0 && f.DiId == dto.diId)
  3431. .Select((f, c, s, g, r, l,s1,i) => new
  3432. {
  3433. c.PaymentCurrency,
  3434. c.DayRate,
  3435. PaymentCurrencyStr = s.Name,
  3436. f.PriceName,
  3437. f.Remark,
  3438. f.PriceCount,
  3439. Price = f.Price * f.Coefficient,
  3440. c.PayMoney,
  3441. RMBPrice = c.RMBPrice * f.Coefficient,
  3442. Offer = c.RMBPrice * f.PriceCount * f.Coefficient,
  3443. c.CTable,
  3444. f.PriceDetailType,
  3445. Area = g.Country ?? "未选择地区!",
  3446. l.toCurr,
  3447. l.Rate,
  3448. toCurrStr = s1.Name,
  3449. g.FoodCost,
  3450. CarParentId = l.Id,
  3451. f.PriceDt,
  3452. i.VisitPNumber,
  3453. f.DiId,
  3454. f.PriceCurrency
  3455. })
  3456. .ToList()
  3457. .Select(x =>
  3458. {
  3459. var costPirce = x.Price;
  3460. decimal costRMBPrice = x.RMBPrice;
  3461. decimal costDayRate = x.DayRate;
  3462. string remake = x.Remark;
  3463. if (x.VisitPNumber > 0 && x.PriceDetailType != 1088)
  3464. {
  3465. decimal.TryParse(x.FoodCost, out decimal cost);
  3466. cost /= 2;
  3467. decimal oldPrice = costPirce;
  3468. costPirce *= x.Rate; //转换币种
  3469. if (x.toCurr != x.PaymentCurrency)
  3470. {
  3471. var rate = _setDataRep.PostCurrencyByDiid(x.DiId, 1015, x.toCurr).Result;
  3472. if (rate.Code == 0)
  3473. {
  3474. var rateData = rate.Data as CurrencyInfo;
  3475. if (rateData != null)
  3476. {
  3477. costDayRate = rateData.Rate;
  3478. }
  3479. }
  3480. }
  3481. if (dicSoure.Keys.Contains(x.PriceDetailType))
  3482. {
  3483. var CarCenter = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(x1 => x1.CTGGRId == x.CarParentId && x1.IsDel == 0
  3484. && x1.SId == mealsDic.First(x2 => x2.Value == dicSoure[x.PriceDetailType]).Key ).ToList().First(x1=> (DateTime.Compare(x1.DatePrice.ObjToDate(), x.PriceDt) == 0));
  3485. costPirce += (CarCenter.Price * CarCenter.Count * x.Rate);
  3486. oldPrice += (CarCenter.Price * CarCenter.Count);
  3487. var costResultPirce = costPirce - x.VisitPNumber * cost;
  3488. costResultPirce = Convert.ToInt32(Math.Round(costResultPirce));
  3489. var findCheck = checkBoxDataArr.Find(s => s.Id == CarCenter.SId);
  3490. if (x.toCurr != x.PaymentCurrency)
  3491. {
  3492. remake += $"{x.PriceDt.ToString("M/d")} {findCheck?.Name} {x.PaymentCurrencyStr} {(int)Math.Round(oldPrice)}( 折算{x.toCurrStr} {(int)Math.Round(costPirce)}) - 财政{cost} * {x.VisitPNumber} = {x.toCurrStr}{costResultPirce}";
  3493. }
  3494. else
  3495. {
  3496. remake += $"{x.PriceDt.ToString("M/d")} {findCheck?.Name}{x.PaymentCurrencyStr} {(int)Math.Round(costPirce)} - 财政{cost} * {x.VisitPNumber} = {x.PaymentCurrencyStr}{costResultPirce}";
  3497. }
  3498. costPirce = costResultPirce;
  3499. }
  3500. else
  3501. {
  3502. costPirce = Convert.ToInt32(Math.Round(costPirce));
  3503. }
  3504. costRMBPrice = Convert.ToInt32(Math.Round(costPirce * costDayRate));
  3505. }
  3506. return new
  3507. {
  3508. x.PaymentCurrency,
  3509. DayRate = costDayRate,
  3510. x.PaymentCurrencyStr,
  3511. x.PriceName,
  3512. Remark = remake,
  3513. x.PriceCount,
  3514. Price = costPirce,
  3515. x.PayMoney,
  3516. RMBPrice = costRMBPrice,
  3517. Offer = costRMBPrice * x.PriceCount,
  3518. x.CTable,
  3519. x.PriceDetailType,
  3520. x.Area,
  3521. x.toCurr,
  3522. x.toCurrStr,
  3523. ItemPrice = costPirce * x.PriceCount,
  3524. };
  3525. })
  3526. .ToList();
  3527. var PriceDetailTypeArr = new int[] { 1088 , 1074, 1075, 1076 };
  3528. var whereArr = joinTable.Where(x => PriceDetailTypeArr.Contains(x.PriceDetailType)).ToList();
  3529. _ = joinTable.RemoveAll(x => PriceDetailTypeArr.Contains(x.PriceDetailType));
  3530. foreach (var item in whereArr)
  3531. {
  3532. joinTable.Insert(0, item);
  3533. }
  3534. var dicClounm = new Dictionary<int, string>()
  3535. {
  3536. { 0,"Area" },
  3537. { 1,"PriceName" },
  3538. { 2,"Remark" },
  3539. { 3,"PriceCount" },
  3540. { 4,"Price" },
  3541. { 5,"ItemPrice" },
  3542. { 6,"DayRate" },
  3543. { 7,"Offer" },
  3544. };
  3545. var rowStartIndex = 2;
  3546. string filePath = AppSettingsHelper.Get("ExcelBasePath") + "\\Template\\超支费用表.xlsx";
  3547. IWorkbook workbook = new XSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
  3548. ISheet sheet = workbook.GetSheetAt(0);
  3549. var initStyleRow = sheet.GetRow(2);
  3550. var clounmCount = dicClounm.Count;
  3551. Action cloneRowFn = () =>
  3552. {
  3553. rowStartIndex++;
  3554. var cloneRow = sheet.CreateRow(rowStartIndex);
  3555. // 复制样式
  3556. for (int i = initStyleRow.FirstCellNum; i < initStyleRow.LastCellNum; i++)
  3557. {
  3558. ICell sourceCell = initStyleRow.GetCell(i);
  3559. ICell targetCell = cloneRow.GetCell(i) ?? cloneRow.CreateCell(i);
  3560. // 确保单元格存在样式
  3561. if (sourceCell.CellStyle != null)
  3562. {
  3563. targetCell.CellStyle = sourceCell.CellStyle;
  3564. }
  3565. }
  3566. };
  3567. sheet.GetRow(0).GetCell(0).SetCellValue($"{grp_DelegationInfo.TeamName}—超支费用");
  3568. foreach (var item in joinTable)
  3569. {
  3570. for (int i = 0; i < clounmCount; i++)
  3571. {
  3572. string property = dicClounm[i];
  3573. string value = item.GetType()!.GetProperty(property)!.GetValue(item)?.ToString() ?? "";
  3574. sheet.GetRow(rowStartIndex).GetCell(i).SetCellValue(value);
  3575. }
  3576. cloneRowFn();
  3577. }
  3578. sheet.GetRow(rowStartIndex).GetCell(2).SetCellValue($"小计:");
  3579. sheet.GetRow(rowStartIndex).GetCell(3).SetCellValue($"{joinTable.Sum(x=>x.RMBPrice)}元");
  3580. var path = $"GroupExtraCost/{grp_DelegationInfo.TeamName}_超支费用.xlsx";
  3581. using (var stream = new MemoryStream())
  3582. {
  3583. workbook.Write(stream, true);
  3584. stream.Flush();
  3585. stream.Seek(0, SeekOrigin.Begin);
  3586. stream.SaveToFile(AppSettingsHelper.Get("ExcelBasePath") + path);
  3587. }
  3588. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + path;
  3589. jw = JsonView(true, "成功", new { url = rst });
  3590. return Ok(jw);
  3591. }
  3592. /// <summary>
  3593. /// 获取超支系数配置
  3594. /// </summary>
  3595. /// <returns></returns>
  3596. [HttpPost]
  3597. public IActionResult QueryCoefficientConfig()
  3598. {
  3599. var arr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 80 && x.IsDel == 0).ToList();
  3600. var carCoefficient = new int[] { 1050 }; //2.4
  3601. var menpiaoCoefficient = new int[] { 1086 }; // 1.2
  3602. var airCoefficient = new int[] { 1035, 1036 }; // 2.0
  3603. var HotelCoefficient = new int[] { 1044, 1045, 1046, 1041, 1042, 1043, 1038 }; // 1.5
  3604. var fanyiCoefficient = new int[] { 1087 }; // 1.5
  3605. var resultArr = new
  3606. ArrayList();
  3607. foreach (var item in arr)
  3608. {
  3609. var a = new { coefficient = 1M, id = 0 };
  3610. if (carCoefficient.Contains(item.Id))
  3611. {
  3612. a = a with
  3613. {
  3614. coefficient = 2.4M,
  3615. id = item.Id
  3616. };
  3617. }
  3618. else if (menpiaoCoefficient.Contains(item.Id))
  3619. {
  3620. a = a with
  3621. {
  3622. coefficient = 1.2M,
  3623. id = item.Id
  3624. };
  3625. }
  3626. else if (airCoefficient.Contains(item.Id))
  3627. {
  3628. a = a with
  3629. {
  3630. coefficient = 2.0M,
  3631. id = item.Id
  3632. };
  3633. }
  3634. else if (HotelCoefficient.Contains(item.Id))
  3635. {
  3636. a = a with
  3637. {
  3638. coefficient = 1.5M,
  3639. id = item.Id
  3640. };
  3641. }
  3642. else if (fanyiCoefficient.Contains(item.Id))
  3643. {
  3644. a = a with
  3645. {
  3646. coefficient = 1.5M,
  3647. id = item.Id
  3648. };
  3649. }
  3650. else
  3651. {
  3652. a = a with
  3653. {
  3654. coefficient = 1M,
  3655. id = item.Id
  3656. };
  3657. }
  3658. resultArr.Add(a);
  3659. }
  3660. return Ok(JsonView(true, "获取成功!", resultArr));
  3661. }
  3662. #endregion
  3663. #region 信用卡对账
  3664. /// <summary>
  3665. ///将指定的Excel的文件转换成DataTable (Excel的第一个sheet)
  3666. /// </summary>
  3667. /// <param name="fullFielPath">文件的绝对路径</param>
  3668. /// <returns></returns>
  3669. private DataTable WorksheetToTable(string fullFielPath, string sheetName = null)
  3670. {
  3671. //如果是“EPPlus”,需要指定LicenseContext。
  3672. //EPPlus.Core 不需要指定。
  3673. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  3674. FileInfo existingFile = new FileInfo(fullFielPath);
  3675. ExcelPackage package = new ExcelPackage(existingFile);
  3676. ExcelWorksheet worksheet = null;
  3677. if (string.IsNullOrEmpty(sheetName))
  3678. {
  3679. //不传入 sheetName 默认取第1个sheet。
  3680. //EPPlus 索引是0
  3681. //EPPlus.Core 索引是1
  3682. worksheet = package.Workbook.Worksheets[0];
  3683. }
  3684. else
  3685. {
  3686. worksheet = package.Workbook.Worksheets[sheetName];
  3687. }
  3688. if (worksheet == null)
  3689. throw new Exception("指定的sheetName不存在");
  3690. return WorksheetToTable(worksheet);
  3691. }
  3692. /// <summary>
  3693. /// 将worksheet转成datatable
  3694. /// </summary>
  3695. /// <param name="worksheet">待处理的worksheet</param>
  3696. /// <returns>返回处理后的datatable</returns>
  3697. private DataTable WorksheetToTable(ExcelWorksheet worksheet)
  3698. {
  3699. //获取worksheet的行数
  3700. int rows = worksheet.Dimension.End.Row;
  3701. //获取worksheet的列数
  3702. int cols = worksheet.Dimension.End.Column;
  3703. DataTable dt = new DataTable(worksheet.Name);
  3704. DataRow dr = null;
  3705. for (int i = 1; i <= rows; i++)
  3706. {
  3707. if (i > 1)
  3708. dr = dt.Rows.Add();
  3709. for (int j = 1; j <= cols; j++)
  3710. {
  3711. //默认将第一行设置为datatable的标题
  3712. if (i == 1)
  3713. dt.Columns.Add(GetString(worksheet.Cells[i, j].Value));
  3714. //剩下的写入datatable
  3715. else
  3716. dr[j - 1] = GetString(worksheet.Cells[i, j].Value);
  3717. }
  3718. }
  3719. return dt;
  3720. }
  3721. private string GetString(object obj)
  3722. {
  3723. if (obj == null)
  3724. return "";
  3725. return obj.ToString();
  3726. }
  3727. private DataTable ExcelFileToDataTable(IFormFile file)
  3728. {
  3729. DataTable dtTest = null;
  3730. using (var stream = new MemoryStream())
  3731. {
  3732. file.CopyTo(stream);
  3733. using (var package = new ExcelPackage(stream))
  3734. {
  3735. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  3736. ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
  3737. dtTest = WorksheetToTable(worksheet);
  3738. }
  3739. }
  3740. return dtTest;
  3741. }
  3742. /// <summary>
  3743. /// 信用卡对账
  3744. /// </summary>
  3745. /// <param name="file"></param>
  3746. /// <param name="cardType"></param>
  3747. /// <param name="beginDt"></param>
  3748. /// <param name="endDt"></param>
  3749. /// <returns></returns>
  3750. [HttpPost]
  3751. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3752. public async Task<IActionResult> PostCreditCardBill(IFormFile file, int cardType, string beginDt, string endDt)
  3753. {
  3754. if (file == null || file.Length < 1)
  3755. {
  3756. return Ok(JsonView(false, "请上传文件!"));
  3757. }
  3758. string fileName = file.FileName;
  3759. if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
  3760. {
  3761. return Ok(JsonView(false, "请上传Excel文件!"));
  3762. }
  3763. if (cardType < 1) return Ok(JsonView(false, "请传入有效的卡类型!"));
  3764. if (string.IsNullOrEmpty(beginDt) || string.IsNullOrEmpty(endDt)) return Ok(JsonView(false, "请输入开始/结束日期!"));
  3765. var beginValid = DateTime.TryParse(beginDt, out _);
  3766. var endValid = DateTime.TryParse(endDt, out _);
  3767. if (!beginValid || !endValid) return Ok(JsonView(false, "请输入正确的日期格式"));
  3768. //读取ExcelFile
  3769. DataTable dt = ExcelFileToDataTable(file);
  3770. dt.TableName = "TB";
  3771. if (dt == null)
  3772. {
  3773. return Ok(JsonView(false, $"您上传的Excel工作表没有内容,请检查!!!"));
  3774. }
  3775. //信用卡信息
  3776. string sql = string.Format($"Select * From Grp_CreditCardPayment Where Isdel = 0 And CTDId = {cardType} And ConsumptionDate between '{beginDt}' and '{endDt}' ");
  3777. var List_ccp = await _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql).ToListAsync();
  3778. if (List_ccp.Count < 1)
  3779. {
  3780. return Ok(JsonView(false, $"未查询到 {beginDt} 至 {endDt} 信用卡账单信息!!!!"));
  3781. }
  3782. //资源信息
  3783. var delegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
  3784. var users = _sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0).ToList();
  3785. string url = string.Empty;
  3786. try
  3787. {
  3788. /*
  3789. * 卡类型
  3790. * 74 美元卡 1
  3791. * 75 欧元卡 1
  3792. * 86 招行卡 1
  3793. * 346 中信卡 1
  3794. * 363 交行卡 1
  3795. *
  3796. */
  3797. var ids = new List<int>();
  3798. if (cardType == 74) //美元卡
  3799. {
  3800. var AirGroupReuslt = List_ccp.Where(x => x.CTable == 85).GroupBy(x => x.DIId).ToList();
  3801. if (AirGroupReuslt != null && AirGroupReuslt.Count > 0)
  3802. {
  3803. foreach (var item in AirGroupReuslt)
  3804. {
  3805. if (item.Count() > 1)
  3806. {
  3807. var obj = item.FirstOrDefault();
  3808. obj.RMBPrice = item.Sum(x => x.PayMoney);//合计币种金额
  3809. obj.Remark = "团组机票总价(虚拟)";
  3810. List_ccp.Add(obj);
  3811. }
  3812. }
  3813. }
  3814. //dt.AcceptChanges(); //提交
  3815. //修改table列名
  3816. dt.Columns[0].ColumnName = "accountType"; // 账户类型
  3817. dt.Columns[1].ColumnName = "tradeDate"; //交易日期
  3818. dt.Columns[2].ColumnName = "BillingDate"; // 记账日期
  3819. dt.Columns[3].ColumnName = "CardNo"; // 卡号
  3820. dt.Columns[4].ColumnName = "deposit"; // 存入金额
  3821. dt.Columns[5].ColumnName = "SpendingAmount"; // 支出金额
  3822. dt.Columns[6].ColumnName = "TransactionDescription"; // 交易描述
  3823. dt.Columns[7].ColumnName = "TeamRemark"; // 团组备注描述
  3824. dt.Columns[8].ColumnName = "Handlers"; // 经手人
  3825. dt.Columns[9].ColumnName = "State"; // 状态
  3826. //删除第一行数据
  3827. if (dt.Rows.Count > 0)
  3828. {
  3829. string accountType = dt.Rows[0]["accountType"].ToString();
  3830. if (dt.Rows[0]["accountType"].ToString().Equals("账户类型"))
  3831. {
  3832. dt.Rows[0].Delete();
  3833. dt.AcceptChanges(); //提交
  3834. }
  3835. }
  3836. foreach (DataRow item in dt.Rows)
  3837. {
  3838. #region 匹配的金额
  3839. decimal ExcelAmount = 0.00M;
  3840. decimal deposit = 0.00M;
  3841. if (!string.IsNullOrEmpty(item["SpendingAmount"].ToString()))
  3842. {
  3843. var isParase = decimal.TryParse(item["SpendingAmount"].ToString(), out ExcelAmount);
  3844. if (isParase)
  3845. {
  3846. var CList = List_ccp.FindAll(x => x.PayMoney == ExcelAmount);
  3847. if (CList != null && CList.Count > 0)
  3848. {
  3849. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3850. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3851. item["State"] = 1;
  3852. }
  3853. }
  3854. }
  3855. if (!string.IsNullOrEmpty(item["deposit"].ToString()))
  3856. {
  3857. var isParse = decimal.TryParse(item["deposit"].ToString(), out deposit);
  3858. if (isParse)
  3859. {
  3860. var CList = List_ccp.FindAll(x => x.PayMoney == deposit);
  3861. if (CList != null && CList.Count > 0)
  3862. {
  3863. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3864. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3865. item["State"] = 1;
  3866. }
  3867. }
  3868. }
  3869. #endregion
  3870. //交易描述
  3871. if (!string.IsNullOrEmpty(item["TransactionDescription"].ToString()))
  3872. {
  3873. string TransactionDescription = item["TransactionDescription"].ToString();
  3874. var startIndex = TransactionDescription.LastIndexOf("[");
  3875. var endIndex = TransactionDescription.LastIndexOf("]");
  3876. if (startIndex != -1 && endIndex != -1)
  3877. {
  3878. var moenyList = TransactionDescription.Substring(startIndex + 1, endIndex - startIndex - 1).Split(' ').
  3879. Where(x => !string.IsNullOrEmpty(x)).ToList();
  3880. decimal money = 0.00M;
  3881. foreach (var itemMoeny in moenyList)
  3882. {
  3883. if (itemMoeny.Contains('.'))
  3884. {
  3885. string itemMoenyStr = itemMoeny.Replace(",", string.Empty);
  3886. bool istrue = decimal.TryParse(itemMoenyStr, out money);
  3887. if (istrue)
  3888. {
  3889. var CList = List_ccp.FindAll(x => x.PayMoney == money);
  3890. if (CList != null && CList.Count > 0)
  3891. {
  3892. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3893. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3894. item["State"] = 1;
  3895. }
  3896. }
  3897. }
  3898. }
  3899. }
  3900. }
  3901. }
  3902. string fileName1 = $"信用卡账单(美元卡){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  3903. Dictionary<string, object> pairs = new Dictionary<string, object>();
  3904. List<DataTable> datas = new List<DataTable>();
  3905. datas.Add(dt);
  3906. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-美元卡.xls", $"CreditCardBill", fileName1, pairs, datas);
  3907. }
  3908. else if (cardType == 75) //欧元卡
  3909. {
  3910. if (dt.Rows.Count > 0)
  3911. {
  3912. string accountType = dt.Rows[0][0].ToString();
  3913. if (accountType.Equals("账户类型"))
  3914. {
  3915. dt.Rows[0].Delete();
  3916. dt.AcceptChanges(); //提交
  3917. }
  3918. }
  3919. //dt.Columns[0].ColumnName = "All";
  3920. DataTable dt1 = new DataTable();
  3921. dt1.TableName = "TB";
  3922. dt1.Columns.Add("TradingDate", Type.GetType("System.String"));//交易日期
  3923. dt1.Columns.Add("TallyDate", Type.GetType("System.String")); //记账日期
  3924. dt1.Columns.Add("TradindDesc", Type.GetType("System.String"));//交易描述
  3925. dt1.Columns.Add("TradindMoney", Type.GetType("System.String"));//交易币种/金额
  3926. dt1.Columns.Add("ClearindMoney", Type.GetType("System.String"));// 清算币种/金额
  3927. dt1.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  3928. dt1.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  3929. dt1.Columns.Add("State", Type.GetType("System.String")); //状态
  3930. for (int i = 0; i < dt.Rows.Count; i++)
  3931. {
  3932. string[] str = dt.Rows[i]["All"].ToString().Split(' ');
  3933. //string[] str = dt.Rows[i];
  3934. DataRow dr = dt1.NewRow();
  3935. dr["TradingDate"] = str[0].ToString();
  3936. dr["TallyDate"] = str[1].ToString();
  3937. dr["TradindDesc"] = str[2].ToString() + " " + str[3].ToString();
  3938. dr["TradindMoney"] = str[4].ToString() + " " + str[5].ToString();
  3939. dr["ClearindMoney"] = str[6].ToString() + " " + str[7].ToString();
  3940. dt1.Rows.Add(dr);
  3941. }
  3942. foreach (DataRow item in dt1.Rows)
  3943. {
  3944. for (int i = 0; i < List_ccp.Count; i++)
  3945. {
  3946. DateTime dtTime1 = Convert.ToDateTime(item["TradingDate"].ToString() == "" ? DateTime.Now.ToString("MM/dd") : item["TradingDate"].ToString()); //交易日期
  3947. string USDPrice = item["TradindMoney"].ToString(); //支出金额
  3948. USDPrice = USDPrice.Split(' ')[1].Trim(); //替换掉非数字
  3949. //USDPrice = USDPrice.Split('/')[1];
  3950. // 经手人 and excel行状态
  3951. if (!string.IsNullOrEmpty(List_ccp[i].ConsumptionDate) && !string.IsNullOrEmpty(USDPrice))
  3952. {
  3953. DateTime dtTime2 = Convert.ToDateTime(List_ccp[i].ConsumptionDate.ToString() == "" ? DateTime.Now.ToString("MM/dd") : List_ccp[i].ConsumptionDate.ToString());
  3954. float price1 = float.Parse(USDPrice);
  3955. float price2 = float.Parse(List_ccp[i].PayMoney.ToString("F2"));
  3956. if (dtTime1 == dtTime2 && price1 == price2)
  3957. {
  3958. item["TeamRemark"] = delegationInfos.Find(it => it.Id == List_ccp[i].DIId)?.TeamName;
  3959. item["Handlers"] = users.Find(it => it.Id == List_ccp[i].CreateUserId)?.CnName;
  3960. item["State"] = "1";
  3961. i = List_ccp.Count - 1;
  3962. }
  3963. else item["State"] = "0";
  3964. }
  3965. else item["State"] = "0";
  3966. }
  3967. if (item["TradindDesc"].ToString().Contains("财付通"))
  3968. item["State"] = "2";
  3969. else if (item["TradindDesc"].ToString().Contains("京东"))
  3970. item["State"] = "2";
  3971. else if (item["TradindDesc"].ToString().Contains("微信支付"))
  3972. item["State"] = "2";
  3973. else if (item["TradindDesc"].ToString().Contains("淘宝"))
  3974. item["State"] = "2";
  3975. }
  3976. string fileName1 = $"信用卡账单(欧元卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
  3977. Dictionary<string, object> pairs = new Dictionary<string, object>();
  3978. List<DataTable> datas = new List<DataTable>();
  3979. datas.Add(dt);
  3980. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-欧元卡.xls", "TB", fileName1, pairs, datas);
  3981. }
  3982. else if (cardType == 86) //招行卡
  3983. {
  3984. var AirGroupReuslt1 = List_ccp.Where(x => x.CTable == 85).GroupBy(x => x.DIId).ToList();
  3985. if (AirGroupReuslt1 != null && AirGroupReuslt1.Count > 0)
  3986. {
  3987. foreach (var item in AirGroupReuslt1)
  3988. {
  3989. if (item.Count() > 1)
  3990. {
  3991. var di = delegationInfos.Find(it => it.Id == item.Key);
  3992. var obj = item.FirstOrDefault();
  3993. obj.Remark = "团组机票总价";
  3994. if (di != null)
  3995. {
  3996. obj.Remark = "团组机票总价(" + di.TeamName + ")";
  3997. }
  3998. obj.RMBPrice = item.Sum(x => x.RMBPrice);//合计人民币
  3999. List_ccp.Add(obj);
  4000. }
  4001. }
  4002. }
  4003. //查询所有刷卡的团组
  4004. //将刷卡团组内刷卡金额的金额存入ccp_list
  4005. //将excel作比较
  4006. //机票刷卡记录
  4007. var AirListAndPayID = List_ccp.Where(x => x.CTable == 85 && x.PayDId == 72).Select(x => x.DIId).Distinct().ToList();
  4008. var AirData = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => AirListAndPayID.Contains(it.DIId) && it.PrePrice != it.Price).ToList();
  4009. foreach (var item in AirData)
  4010. {
  4011. var DBwhere = List_ccp.Find(x => x.PayMoney == item.PrePrice);
  4012. if (DBwhere == null)
  4013. {
  4014. List_ccp.Add(new Grp_CreditCardPayment
  4015. {
  4016. PayMoney = item.PrePrice,
  4017. DIId = item.DIId,
  4018. CreateUserId = item.CreateUserId,
  4019. Remark = "(机票单价价格)",
  4020. });
  4021. }
  4022. }
  4023. var HotelGroupReuslt = List_ccp.Where(x => x.CTable == 76).GroupBy(x => x.DIId).ToList();
  4024. if (HotelGroupReuslt != null && HotelGroupReuslt.Count > 0)
  4025. {
  4026. foreach (var item in HotelGroupReuslt)
  4027. {
  4028. if (item.Count() > 1)
  4029. {
  4030. var di = delegationInfos.Find(it => it.Id == item.Key);
  4031. var obj = item.FirstOrDefault();
  4032. obj.Remark = "团组酒店总价";
  4033. if (di != null)
  4034. {
  4035. obj.Remark = "团组酒店总价(" + di.TeamName + ")";
  4036. }
  4037. obj.RMBPrice = item.Sum(x => x.RMBPrice);//合计人民币
  4038. List_ccp.Add(obj);
  4039. }
  4040. }
  4041. }
  4042. #region
  4043. dt.Rows[0].Delete();//删除列名行
  4044. dt.AcceptChanges();
  4045. DataTable dt1 = new DataTable();
  4046. dt1.TableName = "TB";
  4047. dt1.Columns.Add("TradingDay", Type.GetType("System.String")); // 交易日
  4048. dt1.Columns.Add("TallyDay", Type.GetType("System.String")); // 记账日
  4049. dt1.Columns.Add("TransactionDesc", Type.GetType("System.String")); // 交易描述
  4050. dt1.Columns.Add("RMBMoney", Type.GetType("System.String")); // 人名币金额
  4051. dt1.Columns.Add("CardNo", Type.GetType("System.String")); // 卡号
  4052. dt1.Columns.Add("TradingMoney", Type.GetType("System.String")); // 交易地金额
  4053. dt1.Columns.Add("Currency", Type.GetType("System.String")); // 币种
  4054. dt1.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  4055. dt1.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  4056. dt1.Columns.Add("State", Type.GetType("System.String")); //状态
  4057. for (int j = 0; j < dt.Rows.Count; j++)//遍历行
  4058. {
  4059. DataRow dr = dt1.NewRow(); //获取每一行的数据
  4060. dr["TradingDay"] = dt.Rows[j][0].ToString();
  4061. dr["TallyDay"] = dt.Rows[j][1].ToString();
  4062. dr["TransactionDesc"] = dt.Rows[j][2].ToString();
  4063. dr["RMBMoney"] = dt.Rows[j][3].ToString();
  4064. dr["CardNo"] = dt.Rows[j][4].ToString();
  4065. string currency = "CN";
  4066. string money = dt.Rows[j][5].ToString();
  4067. if (money.Contains('('))
  4068. {
  4069. string[] strs = money.Split('(');
  4070. money = strs[0];
  4071. currency = strs[1].Replace(")", "");
  4072. }
  4073. dr["TradingMoney"] = money;
  4074. dr["Currency"] = currency;
  4075. if (string.IsNullOrEmpty(money))
  4076. {
  4077. continue;
  4078. }
  4079. dt1.Rows.Add(dr);
  4080. }
  4081. //datatable 排序
  4082. dt1.DefaultView.Sort = "TradingDay asc";
  4083. dt1 = dt1.DefaultView.ToTable();
  4084. foreach (DataRow item in dt1.Rows)
  4085. {
  4086. if (item["TradingDay"] == "" && item["RMBMoney"] == "")
  4087. {
  4088. continue;
  4089. }
  4090. //excel获取交易日期
  4091. string ExcelDt = string.Empty;
  4092. //C表交易日期
  4093. string DBDt = string.Empty;
  4094. //excel交易的金额
  4095. decimal TradingMoney = decimal.Parse(item["TradingMoney"].ToString());
  4096. if (item["TradingDay"] != null)
  4097. {
  4098. ExcelDt = DateTime.Parse(item["TradingDay"].ToString()).ToString("MMdd");
  4099. }
  4100. //加一获取金额区间
  4101. decimal MaxTradingMoney = TradingMoney + 1;
  4102. decimal MinTradingMoney = TradingMoney - 1;
  4103. //匹配C表金额相等的值
  4104. var CList = List_ccp.FindAll(x => x.PayMoney < MaxTradingMoney && x.PayMoney > MinTradingMoney);
  4105. if (CList != null && CList.Count > 0)
  4106. {
  4107. #region 日期匹配
  4108. foreach (var Citem in CList)
  4109. {
  4110. if (!string.IsNullOrWhiteSpace(Citem.ConsumptionDate))
  4111. {
  4112. DBDt = DateTime.Parse(Citem.ConsumptionDate).ToString("MMdd");
  4113. if (DBDt == ExcelDt)
  4114. {
  4115. item["TeamRemark"] = delegationInfos.Find(it => it.Id == Citem.DIId)?.TeamName;
  4116. item["Handlers"] = users.Find(it => it.Id == Citem.CreateUserId)?.CnName;
  4117. ids.Add(Citem.Id);
  4118. }
  4119. }
  4120. }
  4121. #endregion
  4122. }
  4123. if (item["TransactionDesc"].ToString().Contains("财付通"))
  4124. item["State"] = "2";
  4125. else if (item["TransactionDesc"].ToString().Contains("京东支付"))
  4126. item["State"] = "2";
  4127. else if (item["TransactionDesc"].ToString().Contains("微信支付"))
  4128. item["State"] = "2";
  4129. else if (item["TransactionDesc"].ToString().Contains("淘宝"))
  4130. item["State"] = "2";
  4131. else if (item["TransactionDesc"].ToString().Contains("支付宝"))
  4132. item["State"] = "2";
  4133. else if (item["TransactionDesc"].ToString().Contains("拼多多"))
  4134. item["State"] = "2";
  4135. else
  4136. item["State"] = "0";
  4137. if (!string.IsNullOrEmpty(item["TeamRemark"].ToString()) && !string.IsNullOrEmpty(item["Handlers"].ToString()))
  4138. item["State"] = "1";
  4139. }
  4140. //更改匹配项状态
  4141. if (ids.Count > 0)
  4142. {
  4143. var _CreditCardPayments = new List<Grp_CreditCardPayment>();
  4144. foreach (var item in ids)
  4145. {
  4146. _CreditCardPayments.Add(new Grp_CreditCardPayment() { Id = item, IsMatchCreditCard = 1.00M });
  4147. }
  4148. var updateStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>(_CreditCardPayments)
  4149. .UpdateColumns(it => new { it.IsMatchCreditCard })
  4150. .Where(it => ids.Contains(it.Id))
  4151. .ExecuteCommand();
  4152. }
  4153. string fileName1 = $"信用卡账单(招行卡){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  4154. Dictionary<string, object> pairs = new Dictionary<string, object>();
  4155. List<DataTable> datas = new List<DataTable>();
  4156. datas.Add(dt1);
  4157. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-招行卡.xls", "CreditCardBill", fileName1, pairs, datas);
  4158. #endregion
  4159. }
  4160. else if (cardType == 346) //中信卡
  4161. {
  4162. dt.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  4163. dt.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  4164. dt.Columns.Add("State", Type.GetType("System.String")); //状态
  4165. //修改table列名
  4166. dt.Columns[0].ColumnName = "TransactionDesc"; // 交易描述
  4167. dt.Columns[1].ColumnName = "TradingCurrencyAndMoney"; // 交易币种和金额
  4168. dt.Columns[2].ColumnName = "TransactionDate"; // 交易日期
  4169. dt.Columns[3].ColumnName = "SettlementCurrencyAndMoney";// 结算币种和金额
  4170. dt.Columns[4].ColumnName = "BookedDate"; // 入账日期
  4171. foreach (DataRow item in dt.Rows)
  4172. {
  4173. for (int i = 0; i < List_ccp.Count; i++)
  4174. {
  4175. if (string.IsNullOrEmpty(item["TransactionDate"].ToString()))
  4176. break;
  4177. DateTime dtTime1 = Convert.ToDateTime(item["TransactionDate"].ToString()); //交易日期
  4178. string USDPrice = item["TradingCurrencyAndMoney"].ToString(); //支出金额
  4179. USDPrice = USDPrice.Split('/')[1];
  4180. //string USDPrice1 = USDPrice.ToString("0.00");
  4181. // 经手人 and excel行状态
  4182. if (!string.IsNullOrEmpty(List_ccp[i].ConsumptionDate) && !string.IsNullOrEmpty(USDPrice))
  4183. {
  4184. DateTime dtTime2 = Convert.ToDateTime(List_ccp[i].ConsumptionDate);
  4185. float price1 = float.Parse(USDPrice);
  4186. float price2 = float.Parse(List_ccp[i].PayMoney.ToString("F2"));
  4187. if (dtTime1 == dtTime2 && price1 == price2)
  4188. {
  4189. item["TeamRemark"] = delegationInfos.Find(it => it.Id == List_ccp[i].DIId)?.TeamName;
  4190. item["Handlers"] = users.Find(it => it.Id == List_ccp[i].CreateUserId)?.CnName;
  4191. item["State"] = "1";
  4192. i = List_ccp.Count - 1;
  4193. }
  4194. else
  4195. item["State"] = "0";
  4196. }
  4197. else
  4198. item["State"] = "0";
  4199. }
  4200. //判断是否是数字
  4201. //if (IsNumber(item["TradingCurrencyAndMoney"].ToString().Split('/')[1]) == false)
  4202. // item["State"] = "0";
  4203. if (item["TransactionDesc"].ToString().Contains("财付通"))
  4204. item["State"] = "2";
  4205. else if (item["TransactionDesc"].ToString().Contains("京东"))
  4206. item["State"] = "2";
  4207. else if (item["TransactionDesc"].ToString().Contains("微信支付"))
  4208. item["State"] = "2";
  4209. else if (item["TransactionDesc"].ToString().Contains("淘宝"))
  4210. item["State"] = "2";
  4211. }
  4212. #region DownExcel
  4213. string fileName1 = $"信用卡账单(中信卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
  4214. Dictionary<string, object> pairs = new Dictionary<string, object>();
  4215. List<DataTable> datas = new List<DataTable>();
  4216. datas.Add(dt);
  4217. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-中信卡.xls", "TB", fileName1, pairs, datas);
  4218. #endregion
  4219. }
  4220. else if (cardType == 363) //交行卡
  4221. {
  4222. dt.Columns[0].ColumnName = "All";
  4223. DataTable dt1 = new DataTable();
  4224. dt1.Columns.Add("TradingDate", Type.GetType("System.String"));//交易日期
  4225. dt1.Columns.Add("TallyDate", Type.GetType("System.String")); //记账日期
  4226. dt1.Columns.Add("TradindDesc", Type.GetType("System.String"));//交易描述
  4227. dt1.Columns.Add("TradindMoney", Type.GetType("System.String"));//交易币种/金额
  4228. dt1.Columns.Add("ClearindMoney", Type.GetType("System.String"));// 清算币种/金额
  4229. dt1.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  4230. dt1.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  4231. dt1.Columns.Add("State", Type.GetType("System.String")); //状态
  4232. for (int i = 0; i < dt.Rows.Count; i++)
  4233. {
  4234. string[] str = dt.Rows[i]["All"].ToString().Split(' ');
  4235. DataRow dr = dt1.NewRow();
  4236. dr["TradingDate"] = str[0].ToString();
  4237. dr["TallyDate"] = str[1].ToString();
  4238. dr["TradindDesc"] = str[2].ToString() + " " + str[3].ToString();
  4239. dr["TradindMoney"] = str[4].ToString() + " " + str[5].ToString();
  4240. dr["ClearindMoney"] = str[6].ToString() + " " + str[7].ToString();
  4241. dt1.Rows.Add(dr);
  4242. }
  4243. foreach (DataRow item in dt1.Rows)
  4244. {
  4245. for (int i = 0; i < List_ccp.Count; i++)
  4246. {
  4247. DateTime dtTime1 = Convert.ToDateTime(item["TradingDate"].ToString() == "" ? DateTime.Now.ToString("MM/dd") : item["TradingDate"].ToString()); //交易日期
  4248. string USDPrice = item["TradindMoney"].ToString(); //支出金额
  4249. USDPrice = USDPrice.Split(' ')[1].Trim(); //替换掉非数字
  4250. //USDPrice = USDPrice.Split('/')[1];
  4251. // 经手人 and excel行状态
  4252. if (!string.IsNullOrEmpty(List_ccp[i].ConsumptionDate) && !string.IsNullOrEmpty(USDPrice))
  4253. {
  4254. DateTime dtTime2 = Convert.ToDateTime(List_ccp[i].ConsumptionDate.ToString() == "" ? DateTime.Now.ToString("MM/dd") : List_ccp[i].ConsumptionDate.ToString());
  4255. float price1 = float.Parse(USDPrice);
  4256. float price2 = float.Parse(List_ccp[i].PayMoney.ToString("F2"));
  4257. if (dtTime1 == dtTime2 && price1 == price2)
  4258. {
  4259. item["TeamRemark"] = delegationInfos.Find(it => it.Id == List_ccp[i].DIId)?.TeamName;
  4260. item["Handlers"] = users.Find(it => it.Id == List_ccp[i].CreateUserId)?.CnName;
  4261. item["State"] = "1";
  4262. i = List_ccp.Count - 1;
  4263. }
  4264. else
  4265. item["State"] = "0";
  4266. }
  4267. else
  4268. item["State"] = "0";
  4269. }
  4270. if (item["TradindDesc"].ToString().Contains("财付通"))
  4271. item["State"] = "2";
  4272. else if (item["TradindDesc"].ToString().Contains("京东"))
  4273. item["State"] = "2";
  4274. else if (item["TradindDesc"].ToString().Contains("微信支付"))
  4275. item["State"] = "2";
  4276. else if (item["TradindDesc"].ToString().Contains("淘宝"))
  4277. item["State"] = "2";
  4278. }
  4279. string fileName1 = $"信用卡账单(交行卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
  4280. Dictionary<string, object> pairs = new Dictionary<string, object>();
  4281. List<DataTable> datas = new List<DataTable>();
  4282. datas.Add(dt);
  4283. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-交行卡.xls", "TB", fileName1, pairs, datas);
  4284. }
  4285. }
  4286. catch (Exception ex)
  4287. {
  4288. return Ok(JsonView(false, $"匹配失败,{ex.Message}!"));
  4289. }
  4290. return Ok(JsonView(true, "操作成功", new { url = url }));
  4291. }
  4292. /// <summary>
  4293. /// 把数据从Excel装载到DataTable
  4294. /// </summary>
  4295. /// <param name="pathName">带路径的Excel文件名</param>
  4296. /// <param name="sheetName">工作表名</param>
  4297. /// <param name="tbContainer">将数据存入的DataTable</param>
  4298. /// <returns></returns>
  4299. public static DataTable ExcelToDataTable(string pathName, string sheetName)
  4300. {
  4301. DataTable tbContainer = new DataTable();
  4302. string strConn = string.Empty;
  4303. if (string.IsNullOrEmpty(sheetName)) { sheetName = "Sheet1"; }
  4304. FileInfo file = new FileInfo(pathName);
  4305. if (!file.Exists) { throw new Exception("文件不存在"); }
  4306. string extension = file.Extension;
  4307. switch (extension)
  4308. {
  4309. case ".xls":
  4310. strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
  4311. break;
  4312. case ".xlsx":
  4313. strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathName + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'";
  4314. break;
  4315. default:
  4316. strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
  4317. break;
  4318. }
  4319. //链接Excel
  4320. OleDbConnection cnnxls = new OleDbConnection(strConn);
  4321. //读取Excel里面有 表Sheet1
  4322. System.Data.OleDb.OleDbDataAdapter oda = new System.Data.OleDb.OleDbDataAdapter(string.Format("select * from [{0}$]", sheetName), cnnxls);
  4323. DataSet ds = new DataSet();
  4324. //将Excel里面有表内容装载到内存表中!
  4325. oda.Fill(tbContainer);
  4326. return tbContainer;
  4327. }
  4328. #endregion
  4329. #region 提成计算
  4330. /// <summary>
  4331. /// 提成计算
  4332. /// </summary>
  4333. /// <param name="dto"></param>
  4334. /// <returns></returns>
  4335. [HttpPost]
  4336. public IActionResult ComputeRoyalties(ComputeRoyaltiesDto dto)
  4337. {
  4338. var jw = JsonView(false);
  4339. var userId = dto.UserId;
  4340. var user = _sqlSugar.Queryable<Sys_Users>().First(x=>x.Id == userId);
  4341. //jw.Data = System.Array.Empty<string>();
  4342. if (user == null)
  4343. {
  4344. jw.Msg = "暂无该用户!";
  4345. return Ok(jw);
  4346. }
  4347. if (!DateTime.TryParse(dto.StartDate,out DateTime StartDateTime))
  4348. {
  4349. jw.Msg = "开始时间格式有误!";
  4350. return Ok(jw);
  4351. }
  4352. if (!DateTime.TryParse(dto.EndDate, out DateTime EndDateTime))
  4353. {
  4354. jw.Msg = "结束时间格式有误!";
  4355. return Ok(jw);
  4356. }
  4357. if (DateTime.Compare(StartDateTime,EndDateTime) > 0)
  4358. {
  4359. jw.Msg = "开始时间大于结束时间!";
  4360. return Ok(jw);
  4361. }
  4362. //机票 职位表id 24
  4363. int[] AirTicket = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 24).Select(x => x.Id).ToArray();
  4364. //酒店 职位表id 25
  4365. int[] Hotel = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 25).Select(x => x.Id).ToArray();
  4366. //OP 职位表id 28
  4367. int [] OP = _sqlSugar.Queryable<Sys_Users>().Where(x=>x.IsDel == 0 && x.JobPostId == 28).Select(x=>x.Id).ToArray();
  4368. //商邀 职位表id 27
  4369. int [] Invitation = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 27).Select(x => x.Id).ToArray();
  4370. //签证 职位表id 26
  4371. int[] Visa = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 26 ).Select(x => x.Id).ToArray();
  4372. //主管职位
  4373. //string[] Manager = { "149", "283" };
  4374. List<ComputeRoyaltiesView> resultArr = new List<ComputeRoyaltiesView>();
  4375. var teamLv = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 56 && x.IsDel == 0).ToList();
  4376. var auditState = new int[] { 1 , 3 };
  4377. if (AirTicket.Contains(userId))
  4378. {
  4379. //提成方式:¥10/人×人数×段数(每个组团涉及的换机次数)
  4380. var listAir = _sqlSugar.Queryable<Grp_AirTicketReservations, Grp_DelegationInfo, Grp_CreditCardPayment>((x, a, b) => new
  4381. JoinQueryInfos(
  4382. JoinType.Left, a.Id == x.DIId ,
  4383. JoinType.Left, b.CTable == 85 && b.CId == x.Id )
  4384. ).Where((x, a, b) => x.IsDel == 0 && x.CreateUserId == userId && (b.IsAuditGM == 1 || b.IsAuditGM == 3)
  4385. && a.IsDel == 0 && a.VisitDate >= StartDateTime && a.VisitDate <= EndDateTime && b.IsDel == 0 && a.IsSure == 1 && auditState.Contains(b.IsAuditGM) )
  4386. .Select((x, a, b) => new
  4387. {
  4388. x.FlightsDescription,
  4389. a.Id,
  4390. a.TeamName,
  4391. a.VisitDate,
  4392. a.TeamLevSId,
  4393. a.VisitPNumber,
  4394. x.Price,
  4395. x.ClientName,
  4396. x.ClientNum,
  4397. x.FlightsCode,
  4398. }).ToList();
  4399. var groupByid = listAir.GroupBy(x => x.Id);
  4400. foreach (var airArr in groupByid)
  4401. {
  4402. var groupAirCount = 0; //团组航段数量
  4403. var infos = new List<string>();
  4404. foreach (var air in airArr)
  4405. {
  4406. var airCount = 0; // 单条航段数量
  4407. if (air.FlightsDescription.IsNullOrWhiteSpace())
  4408. {
  4409. continue;
  4410. }
  4411. if (air.ClientName.Contains("-1") || air.ClientName.Contains("行程单") || air.FlightsCode.Contains("行程单"))
  4412. {
  4413. continue;
  4414. }
  4415. string errMsg = string.Empty;
  4416. if (air.FlightsDescription.Contains("\r\n"))
  4417. {
  4418. var rowCode = Regex.Split(air.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase).Where(x=>!string.IsNullOrWhiteSpace(x)).ToArray();
  4419. for (int i = 0; i < rowCode.Length; i++)
  4420. {
  4421. if (i != 0)
  4422. {
  4423. try
  4424. {
  4425. var columnValue = rowCode[i].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  4426. string day = columnValue[2].Substring(2, 2);//日
  4427. string monthAbbreviations = columnValue[2].Substring(4, 3).ToUpper();//月份
  4428. monthAbbreviations = GeneralMethod.GetLonger(monthAbbreviations);
  4429. string EndHHmm = columnValue[5].Substring(0, 2) + ":" + columnValue[5].Substring(2, 2);
  4430. DateTime EndData = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations}-{day} {EndHHmm}");//当前班次
  4431. var spDotandEmpty1 = rowCode[i - 1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  4432. string day1 = spDotandEmpty1[2].Substring(2, 2);//日
  4433. string monthAbbreviations1 = spDotandEmpty1[2].Substring(4, 3).ToUpper();//月份
  4434. monthAbbreviations1 = GeneralMethod.GetLonger(monthAbbreviations1);
  4435. string HHmm = spDotandEmpty1[6].Substring(0, 2) + ":" + spDotandEmpty1[6].Substring(2, 2);
  4436. DateTime data = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations1}-{day1} {HHmm}");//上个班次
  4437. TimeSpan t3 = EndData - data; //两个时间相减 。默认得到的是 两个时间之间的天数 得到:365.00:00:00
  4438. double getHour = t3.TotalHours;
  4439. if (getHour >= 6)
  4440. {
  4441. if (air.Price > 0)
  4442. {
  4443. airCount += 1;
  4444. }
  4445. else
  4446. {
  4447. airCount -= 1;
  4448. }
  4449. }
  4450. }
  4451. catch (Exception ex)
  4452. {
  4453. errMsg = "机票行程代码格式有误!解析失败!" + $"({ex.Message})";
  4454. break;
  4455. }
  4456. }
  4457. else
  4458. {
  4459. if (air.Price > 0)
  4460. {
  4461. airCount += 1;
  4462. }
  4463. else
  4464. {
  4465. airCount -= 1;
  4466. }
  4467. }
  4468. }
  4469. }
  4470. else
  4471. {
  4472. if (air.Price > 0)
  4473. {
  4474. airCount++;
  4475. }
  4476. else
  4477. {
  4478. airCount--;
  4479. }
  4480. }
  4481. string info = $"航班{air.FlightsCode} {(air.Price > 0 ? "" : "此笔为退费!")} 人数为{air.ClientNum} 有效段数为{airCount} 总段数为{airCount * air.ClientNum}";
  4482. if (!string.IsNullOrWhiteSpace(errMsg))
  4483. {
  4484. info = $"航班{air.FlightsCode} " + errMsg ;
  4485. }
  4486. infos.Add(info);
  4487. groupAirCount += airCount * air.ClientNum;
  4488. }
  4489. var groupinfo = listAir.First(x => x.Id == airArr.Key);
  4490. string temp = "本团人数" + Convert.ToInt32(groupinfo.VisitPNumber) + ",该人员" + user.CnName + "共订航段数" + groupAirCount.ToString() + ",每程航班提成为10元," + user.CnName + "提成共" + (groupAirCount * 10).ToString("#0.00");
  4491. resultArr.Add(new ComputeRoyaltiesView
  4492. {
  4493. TeamName = groupinfo.TeamName,
  4494. TeamId = groupinfo.Id,
  4495. ChiArr = infos,
  4496. TeamLvStr = teamLv.Find(x=>x.Id == groupinfo.TeamLevSId)?.Name,
  4497. VisitDate = groupinfo.VisitDate,
  4498. Temp = temp,
  4499. Price = (groupAirCount * 10),
  4500. }) ;
  4501. }
  4502. }
  4503. else if (Hotel.Contains(userId))
  4504. {
  4505. //标准团组:¥10/间/晚 * 实际订房间数 * 实际订房晚数; setdata id 1001 客人房
  4506. var listHotel = _sqlSugar.Queryable<Grp_HotelReservations, Grp_DelegationInfo, Grp_CreditCardPayment>((x, a, b) => new JoinQueryInfos(
  4507. JoinType.Left,x.DiId == a.Id,
  4508. JoinType.Left,b.CTable == 76 && b.CId == x.Id ))
  4509. .Where((x, a, b) => x.IsDel == 0 && x.CreateUserId == userId && a.VisitDate >= StartDateTime
  4510. && a.VisitDate <= EndDateTime && a.IsDel == 0 && b.IsDel == 0 && x.CardPrice > 0 && a.IsSure == 1 && auditState.Contains(b.IsAuditGM) && x.CheckType == 1001).Select((x,a,b)=> new
  4511. {
  4512. a.Id,
  4513. a.TeamName,
  4514. a.VisitDate,
  4515. a.TeamLevSId,
  4516. a.VisitPNumber,
  4517. x.SingleRoomCount,
  4518. x.SuiteRoomCount,
  4519. x.DoubleRoomCount,
  4520. x.OtherRoomCount,
  4521. x.CheckInDate,
  4522. x.CheckOutDate,
  4523. x.HotelName
  4524. }).ToList();
  4525. var groupByid = listHotel.GroupBy(x => x.Id);
  4526. var propertys = new string[] { "SingleRoomCount", "SuiteRoomCount", "DoubleRoomCount", "OtherRoomCount" };
  4527. foreach (var group in groupByid)
  4528. {
  4529. var infos = new List<string>();
  4530. var totalPrice = 0.00M;
  4531. foreach (var item in group)
  4532. {
  4533. var hotelCount = 0;
  4534. foreach (var property in propertys)
  4535. {
  4536. var value = item.GetType().GetProperty(property).GetValue(item).ObjToInt();
  4537. if (value > 0)
  4538. {
  4539. hotelCount += value;
  4540. }
  4541. }
  4542. if (hotelCount > 0)
  4543. {
  4544. if (DateTime.TryParse(item.CheckInDate, out DateTime checkin) && DateTime.TryParse(item.CheckOutDate, out DateTime checkout))
  4545. {
  4546. var day = checkout - checkin;
  4547. infos.Add($"{item.HotelName} 共有 {hotelCount} 间房 , 入住时间{item.CheckInDate} - {item.CheckOutDate} 共 { day.TotalDays }晚 提成数量:{hotelCount * day.TotalDays} 提成金额:{hotelCount * day.TotalDays * 10}");
  4548. totalPrice += (decimal)(hotelCount * day.TotalDays * 10);
  4549. }
  4550. else
  4551. {
  4552. infos.Add(item.HotelName + " 时间有误!请检查 。");
  4553. }
  4554. }
  4555. }
  4556. var groupinfo = listHotel.First(x => x.Id == group.Key);
  4557. var temp = "本团人数" + groupinfo.VisitPNumber + ",该人员" + user.CnName + "共操作酒店晚数" + totalPrice / 10 + ",每间每晚提成10元," + user.CnName + "提成共" + totalPrice.ToString("#0.00") + "元";
  4558. resultArr.Add(new ComputeRoyaltiesView
  4559. {
  4560. TeamName = groupinfo.TeamName,
  4561. TeamId = groupinfo.Id,
  4562. ChiArr = infos,
  4563. TeamLvStr = teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name,
  4564. VisitDate = groupinfo.VisitDate,
  4565. Temp = temp,
  4566. Price = totalPrice,
  4567. });
  4568. }
  4569. }
  4570. else if (OP.Contains(userId))
  4571. {
  4572. var OPList = _sqlSugar.Queryable<Grp_DelegationInfo>().Where((a) => a.IsDel == 0
  4573. && a.VisitDate >= StartDateTime && a.VisitDate <= EndDateTime && a.IsSure == 1
  4574. ).ToList();
  4575. var LvArr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 70 && x.IsDel == 0).ToList();
  4576. foreach (var groupinfo in OPList)
  4577. {
  4578. var price = LvArr.Find(x => x.Id == groupinfo.OpRoyaltyLv)?.Name.ObjToInt() ?? 0;
  4579. string temp = $"本团等级为{teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name} 提成金额为{price} {(string.IsNullOrWhiteSpace(groupinfo.OpRoyaltyRemark) ? "" : "提成说明:" + groupinfo.OpRoyaltyRemark )}";
  4580. if (price == 0)
  4581. {
  4582. temp = $"本团等级为{teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name} op提成选项未选择!" ;
  4583. }
  4584. resultArr.Add(new ComputeRoyaltiesView
  4585. {
  4586. TeamName = groupinfo.TeamName,
  4587. TeamId = groupinfo.Id,
  4588. ChiArr = new List<string>() { temp },
  4589. TeamLvStr = teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name,
  4590. VisitDate = groupinfo.VisitDate,
  4591. Temp = temp,
  4592. Price = price
  4593. });
  4594. }
  4595. }
  4596. else if (Invitation.Contains(userId))
  4597. {
  4598. //2)付费公务活动部分:¥50 / 团;
  4599. //4)不付费公务活动部分(自己联络)额外奖励:¥200 / 团(若公务活动方与邀请方为同一机构,奖励金额为¥100 / 团);
  4600. //5)只发邀请的团组不付费邀请额外奖励:¥100 / 团;
  4601. //邀请方已授权我司签发的邀请仍按照:¥100 / 团,无额外奖励。
  4602. var officialList = _sqlSugar.Queryable<Res_OfficialActivities, Grp_DelegationInfo>((x,a)=>
  4603. new JoinQueryInfos(JoinType.Left,a.Id == x.DiId)
  4604. ).Where((x,a) => x.IsSubmitApproval == 0 && x.IsDel == 0 && a.IsDel == 0
  4605. && a.VisitDate >= StartDateTime && a.VisitDate <= EndDateTime && a.IsSure == 1
  4606. )
  4607. .Select((x, a) => new
  4608. {
  4609. a.Id,
  4610. a.TeamName,
  4611. a.VisitDate,
  4612. x.CreateUserId,
  4613. x.Type,
  4614. a.TeamLevSId,
  4615. x.Country,
  4616. x.Area,
  4617. x.Date,
  4618. x.Client
  4619. })
  4620. .ToList();
  4621. var groups = officialList.GroupBy(x => x.Id);
  4622. foreach (var group in groups)
  4623. {
  4624. var groupinfo = officialList.First(x => x.Id == group.Key);
  4625. var officialGroupList = group.GroupBy(d => d.CreateUserId);
  4626. int operUserMax = 0, operMaxCount = 0;
  4627. foreach (var item in officialGroupList)
  4628. {
  4629. if (item.Count() > operMaxCount)
  4630. {
  4631. operUserMax = item.Key;
  4632. operMaxCount = item.Count();
  4633. }
  4634. }
  4635. string temp = string.Empty;
  4636. bool isBasics = operUserMax == userId;
  4637. var money = 0;
  4638. var infos = new List<string>();
  4639. foreach (var item in group)
  4640. {
  4641. if (item.CreateUserId != user.Id)
  4642. {
  4643. continue;
  4644. }
  4645. string info = string.Empty;
  4646. if (item.Type == 0)
  4647. {
  4648. money += (100 + 300);
  4649. info = $"{item.Country} - {item.Area} - {item.Client} - {item.Date} 提成金额为 400";
  4650. }
  4651. else if (item.Type == 1)
  4652. {
  4653. money += 300;
  4654. info = $"{item.Country} - {item.Area} - {item.Client} - {item.Date} 提成金额为 300";
  4655. }
  4656. else if (item.Type == 2)
  4657. {
  4658. money += 200;
  4659. info = $"{item.Country} - {item.Area} - {item.Client} - {item.Date} 提成金额为 200";
  4660. }
  4661. infos.Add(info);
  4662. }
  4663. if (isBasics)
  4664. {
  4665. infos.Add($"{groupinfo.TeamName} 该人员{user.CnName}操作场数最多,基本提成为{150}");
  4666. }
  4667. else
  4668. {
  4669. infos.Add($"{groupinfo.TeamName} 操作场数不是最多人员,所以无基本提成");
  4670. }
  4671. resultArr.Add(new ComputeRoyaltiesView
  4672. {
  4673. TeamName = groupinfo.TeamName,
  4674. TeamId = groupinfo.Id,
  4675. ChiArr = infos,
  4676. TeamLvStr = teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name,
  4677. VisitDate = groupinfo.VisitDate,
  4678. Temp = temp,
  4679. Price = money,
  4680. });
  4681. }
  4682. }
  4683. else if (Visa.Contains(userId)) //签证
  4684. {
  4685. // 1)办理英国、加拿大、美国签证¥50元 / 人 / 团;
  4686. // 申根国家及其他所有国家¥30元 / 人 / 团;
  4687. // setdata id 974 客人
  4688. var existsCountry = new string[] { "英国", "加拿大", "美国" };
  4689. var whereExpression = Expressionable.Create<Grp_VisaInfo, Grp_DelegationInfo, Grp_CreditCardPayment>()
  4690. .And(
  4691. (x, a, b) => x.IsDel == 0 && x.CreateUserId == userId && (b.IsAuditGM == 1 || b.IsAuditGM == 3)
  4692. && a.IsDel == 0 && a.VisitDate >= StartDateTime && a.VisitDate <= EndDateTime && b.IsDel == 0 && x.IsThird == 0 && x.PassengerType == 974
  4693. && a.IsSure == 1 && auditState.Contains(b.IsAuditGM)
  4694. );
  4695. var listVisa = _sqlSugar.Queryable<Grp_VisaInfo, Grp_DelegationInfo, Grp_CreditCardPayment>((x, a, b) => new
  4696. JoinQueryInfos(
  4697. JoinType.Left, a.Id == x.DIId,
  4698. JoinType.Left, b.CTable == 80 && b.CId == x.Id)
  4699. )
  4700. .Where(whereExpression.ToExpression())
  4701. .Select((x, a, b) => new
  4702. {
  4703. a.Id,
  4704. a.TeamName,
  4705. a.VisitDate,
  4706. a.TeamLevSId,
  4707. a.VisitPNumber,
  4708. a.VisitCountry,
  4709. x.VisaDescription,
  4710. x.VisaFreeNumber,
  4711. x.VisaNumber,
  4712. x.VisaPrice
  4713. })
  4714. .ToList();
  4715. var groupByid = listVisa.GroupBy(x => x.Id);
  4716. foreach (var visaArr in groupByid)
  4717. {
  4718. var groupinfo = listVisa.First(x => x.Id == visaArr.Key);
  4719. var singlePrice = existsCountry.Where(x => groupinfo.VisitCountry.Contains(x)).Count() > 0 ? 50 : 30;
  4720. int count = 0, money = 0;
  4721. var arr = new List<string>();
  4722. foreach (var visa in visaArr)
  4723. {
  4724. if (visa.VisaPrice > 0)
  4725. {
  4726. count += visa.VisaFreeNumber + visa.VisaNumber;
  4727. money += singlePrice * (visa.VisaFreeNumber + visa.VisaNumber);
  4728. }
  4729. else
  4730. {
  4731. count -= visa.VisaFreeNumber + visa.VisaNumber;
  4732. money -= singlePrice * (visa.VisaFreeNumber + visa.VisaNumber);
  4733. }
  4734. string info = $"签证 {visa.VisaDescription} {(visa.VisaPrice > 0 ? "" : "此笔为退费!")} 人数为{visa.VisaFreeNumber + visa.VisaNumber} 单价为{singlePrice} 金额为{singlePrice * (visa.VisaFreeNumber + visa.VisaNumber)}";
  4735. arr.Add(info);
  4736. }
  4737. string temp = "本团人数" + groupinfo.VisitPNumber + ",该人员" + user.CnName + "共办理英国、加拿大、美国签证" + (singlePrice == 50 ? count : 0).ToString() + "本护照(包含免签人员),申根国家及其他所有国家" + (singlePrice == 30 ? count : 0).ToString() + "本。" + user.CnName + "提成共" + money.ToString("#0.00") + "元";
  4738. resultArr.Add(new ComputeRoyaltiesView
  4739. {
  4740. TeamName = groupinfo.TeamName,
  4741. TeamId = groupinfo.Id,
  4742. ChiArr = arr,
  4743. TeamLvStr = teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name,
  4744. VisitDate = groupinfo.VisitDate,
  4745. Temp = temp,
  4746. Price = money,
  4747. });
  4748. }
  4749. }
  4750. if (resultArr.Count > 0)
  4751. {
  4752. jw.Code = 200;
  4753. jw.Msg = "success!";
  4754. decimal total = 0;
  4755. foreach (var item in resultArr)
  4756. {
  4757. //var number = item.GetType().GetProperty("price")?.GetValue(item)?.ToString();
  4758. //total += decimal.TryParse(number,out decimal numberInt) ? numberInt : 0.00M;
  4759. total += item.Price;
  4760. }
  4761. jw.Data = new
  4762. {
  4763. resultArr,
  4764. totalPrice = total,
  4765. };
  4766. }
  4767. else
  4768. {
  4769. jw.Msg = "暂无数据!";
  4770. }
  4771. return Ok(jw);
  4772. }
  4773. /// <summary>
  4774. /// 导出提成表格
  4775. /// </summary>
  4776. /// <returns></returns>
  4777. [HttpPost]
  4778. public IActionResult ExportRoyaltyExcel(ExportRoyaltyExcelDto dto)
  4779. {
  4780. var jw = JsonView(false);
  4781. var apiResult = ComputeRoyalties(new
  4782. ComputeRoyaltiesDto
  4783. {
  4784. EndDate = dto.EndDate,
  4785. StartDate = dto.StartDate,
  4786. UserId = dto.UserId,
  4787. });
  4788. var parseApiResult = ((apiResult as OkObjectResult)?.Value) as OASystem.Domain.ViewModels.JsonView;
  4789. if (parseApiResult != null && parseApiResult.Code == 200)
  4790. {
  4791. var apiArr = (parseApiResult.Data?.GetType().GetProperty("resultArr")?.GetValue(parseApiResult.Data)) as List<ComputeRoyaltiesView>;
  4792. var user = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == dto.UserId);
  4793. if (apiArr != null && apiArr.Count > 0)
  4794. {
  4795. Dictionary<string, string> dic = new Dictionary<string, string>();
  4796. //dic.Add("Name", "人员:" + user.CnName);
  4797. dic.Add("startTime", dto.StartDate);
  4798. dic.Add("endTime", dto.EndDate);
  4799. dic.Add("operName", user.CnName);
  4800. dic.Add("timeNow", DateTime.Now.ToString("yyyy年MM月dd日"));
  4801. //dic.Add("DowntimeNow", DateTime.Now.ToString("yyyy年MM月dd日"));
  4802. dic.Add("totalPrice",( "总金额:" + parseApiResult.Data?.GetType().GetProperty("totalPrice")?.GetValue(parseApiResult.Data).ObjToDecimal().ToString() ?? "0") +" 元");
  4803. ArrayList ToTableArr = new ArrayList();
  4804. int No = 1;
  4805. //打开excel模板
  4806. foreach (var item in apiArr)
  4807. {
  4808. //载入数据
  4809. ToTableArr.Add(new
  4810. {
  4811. No,
  4812. item.TeamName,
  4813. item.VisitDate,
  4814. item.TeamLvStr,
  4815. item.Temp,
  4816. infos = string.Join("\r\n",item.ChiArr),
  4817. price = item.Price + "元",
  4818. });
  4819. No++;
  4820. }
  4821. DataTable TbData =CommonFun.ToDataTableArray(ToTableArr);
  4822. TbData.TableName = "TbData";
  4823. WorkbookDesigner designer = new WorkbookDesigner();
  4824. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/提成结算template.xlsx");
  4825. foreach (var key in dic.Keys)
  4826. {
  4827. designer.SetDataSource(key, dic[key]);
  4828. }
  4829. //数据源
  4830. designer.SetDataSource(TbData);
  4831. designer.Process();
  4832. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "RoyaltyExcel/" + user.CnName + "_提成结算.xlsx" );
  4833. jw = JsonView(true, "success!", new
  4834. {
  4835. Url = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath")+ "RoyaltyExcel/" + user.CnName + "_提成结算.xlsx",
  4836. });
  4837. }
  4838. }
  4839. else
  4840. {
  4841. jw.Msg = "获取提成信息error " + jw.Msg;
  4842. }
  4843. return Ok(jw);
  4844. }
  4845. /// <summary>
  4846. /// 提成财务确认通知
  4847. /// </summary>
  4848. /// <returns></returns>
  4849. [HttpPost]
  4850. public async Task<IActionResult> RoyaltyConfirmByFin(RoyaltyConfirmDto dto)
  4851. {
  4852. var jw = JsonView(false);
  4853. if (!DateTime.TryParse(dto.StartData, out DateTime StartDateTime))
  4854. {
  4855. jw.Msg = "开始时间格式有误!";
  4856. return Ok(jw);
  4857. }
  4858. if (!DateTime.TryParse(dto.EndData, out DateTime EndDateTime))
  4859. {
  4860. jw.Msg = "结束时间格式有误!";
  4861. return Ok(jw);
  4862. }
  4863. if (DateTime.Compare(StartDateTime, EndDateTime) > 0)
  4864. {
  4865. jw.Msg = "开始时间大于结束时间!";
  4866. return Ok(jw);
  4867. }
  4868. if (dto.ComputeRoyaltiesList.Count != 0)
  4869. {
  4870. var user = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == dto.UserId);
  4871. if (user == null) { return Ok(JsonView(false, "通知失败! 人员信息有误!")); }
  4872. //保存提成信息
  4873. //消息通知对应人员(公司 部门 人员 时间段 团组id 是否确定 )
  4874. List<Fin_RoyaltyConfirm> entitys = dto.ComputeRoyaltiesList.Select(x => new Fin_RoyaltyConfirm
  4875. {
  4876. UserId = dto.UserId,
  4877. ChiArr = JsonConvert.SerializeObject(x.ChiArr),
  4878. CreateTime = DateTime.Now,
  4879. CreateUserId = dto.UserId,
  4880. IsConfirm = 0,
  4881. TeamId = x.TeamId,
  4882. TeamLvStr = x.TeamLvStr,
  4883. Price = x.Price,
  4884. VisitDate = x.VisitDate,
  4885. TeamName = x.TeamName,
  4886. Temp = x.Temp,
  4887. IsSeed = 0
  4888. }).ToList();
  4889. var expressionSoftDeleteWhere = Expressionable.Create<Fin_RoyaltyConfirm>()
  4890. .And(it => it.VisitDate >= StartDateTime)
  4891. .And(it => it.VisitDate <= EndDateTime)
  4892. .And(it => it.IsDel == 0)
  4893. .And(it => it.UserId == dto.UserId)
  4894. .And(it => it.IsSeed == 0)
  4895. .ToExpression();
  4896. var expressionSelectWhere = Expressionable.Create<Fin_RoyaltyConfirm>()
  4897. .And(it => it.VisitDate >= StartDateTime)
  4898. .And(it => it.VisitDate <= EndDateTime)
  4899. .And(it => it.IsDel == 0)
  4900. .And(it => it.UserId == dto.UserId)
  4901. .And(it => it.IsSeed == 1)
  4902. .ToExpression();
  4903. _sqlSugar.BeginTran();
  4904. try
  4905. {
  4906. _ = _sqlSugar.Updateable<Fin_RoyaltyConfirm>().SetColumns(it => new Fin_RoyaltyConfirm() { IsDel = 1, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"), DeleteUserId = dto.UserId })
  4907. .Where(expressionSoftDeleteWhere)
  4908. .ExecuteCommand();
  4909. var confirmYes = _sqlSugar.Queryable<Fin_RoyaltyConfirm>().Where(expressionSelectWhere).Select(x => x.TeamId).ToList();
  4910. entitys = entitys.Where(x => !confirmYes.Contains(x.TeamId)).ToList();
  4911. _ = _sqlSugar.Insertable<Fin_RoyaltyConfirm>(entitys).ExecuteCommand();
  4912. _sqlSugar.CommitTran();
  4913. //调用通知
  4914. var title = "提成确认";
  4915. var center = $"【{dto.StartData}-{dto.EndData}】 提成财务已确认,请尽快查看!";
  4916. //【{dto.StartData}-{dto.EndData}-{dto.CompanyId}-{dto.DeparId}-{dto.UserId}】";
  4917. var ids = new List<int> { 235 , 233 }; //dto.UserId
  4918. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations,title, center, ids);
  4919. jw = JsonView(true, $"人员:{user.CnName} {dto.StartData}-{dto.EndData} 通知成功!");
  4920. }
  4921. catch (Exception ex)
  4922. {
  4923. _sqlSugar.RollbackTran();
  4924. jw = JsonView(false, "保存失败!" + ex.Message);
  4925. }
  4926. }
  4927. else
  4928. {
  4929. jw = JsonView(false,"保存失败! 无提成信息");
  4930. }
  4931. return Ok(jw);
  4932. }
  4933. /// <summary>
  4934. /// 查询提成信息
  4935. /// </summary>
  4936. /// <param name="dto"></param>
  4937. /// <returns></returns>
  4938. [HttpPost]
  4939. public IActionResult QueryRoyaltyInfo(QueryRoyaltyInfoDto dto)
  4940. {
  4941. var jw = JsonView(false);
  4942. var stateArr = new int[] { -1, 0, 1 };
  4943. if (!DateTime.TryParse(dto.StartDate, out DateTime StartDateTime))
  4944. {
  4945. jw.Msg = "开始时间格式有误!";
  4946. return Ok(jw);
  4947. }
  4948. if (!DateTime.TryParse(dto.EndDate, out DateTime EndDateTime))
  4949. {
  4950. jw.Msg = "结束时间格式有误!";
  4951. return Ok(jw);
  4952. }
  4953. if (DateTime.Compare(StartDateTime, EndDateTime) > 0)
  4954. {
  4955. jw.Msg = "开始时间大于结束时间!";
  4956. return Ok(jw);
  4957. }
  4958. if (!stateArr.Contains(dto.Send) || !stateArr.Contains(dto.Confirm))
  4959. {
  4960. jw.Msg = "状态标识有误!";
  4961. return Ok(jw);
  4962. }
  4963. var expressionSelectWhere = Expressionable.Create<Fin_RoyaltyConfirm>()
  4964. .And(it => it.VisitDate >= StartDateTime)
  4965. .And(it => it.VisitDate <= EndDateTime)
  4966. .And(it => it.IsDel == 0)
  4967. .And(it => it.UserId == dto.UserId)
  4968. .AndIF(dto.Confirm != -1,it => it.IsConfirm == dto.Confirm)
  4969. .AndIF(dto.Send != -1, it => it.IsSeed == dto.Send)
  4970. .ToExpression();
  4971. try
  4972. {
  4973. var query = _sqlSugar.Queryable<Fin_RoyaltyConfirm>().Where(expressionSelectWhere).ToList().Select(x => new
  4974. {
  4975. x.Price,
  4976. ChiArr = JsonConvert.DeserializeObject<List<string>>(x.ChiArr),
  4977. x.IsConfirm,
  4978. x.Id,
  4979. x.TeamId,
  4980. x.TeamName,
  4981. x.TeamLvStr,
  4982. x.Temp,
  4983. x.VisitDate,
  4984. x.IsSeed
  4985. });
  4986. jw = JsonView(true, "获取成功!", new
  4987. {
  4988. List = query,
  4989. CostPrice = query.Sum(x=>x.Price),
  4990. ConfirmPrice = query.Where(x=>x.IsConfirm == 1).Sum(x=>x.Price),
  4991. NoConfirmPrice = query.Where(x => x.IsConfirm == 0).Sum(x => x.Price),
  4992. SeedPrice = query.Where(x => x.IsSeed == 1).Sum(x => x.Price),
  4993. NoSeedPrice = query.Where(x => x.IsSeed == 0).Sum(x => x.Price),
  4994. });
  4995. }
  4996. catch (Exception ex)
  4997. {
  4998. jw = JsonView(true, "获取失败!" + ex.Message);
  4999. }
  5000. return Ok(jw);
  5001. }
  5002. /// <summary>
  5003. /// 个人提成确认
  5004. /// </summary>
  5005. /// <param name="dto"></param>
  5006. /// <returns></returns>
  5007. [HttpPost]
  5008. public IActionResult RoyaltyConfirmByUser(RoyaltyConfirmByUserDto dto)
  5009. {
  5010. var jw = JsonView(false);
  5011. var stateArr = new int[] {0 , 1};
  5012. if (!stateArr.Contains(dto.State))
  5013. {
  5014. return Ok(JsonView(false,"状态标识有误!"));
  5015. }
  5016. if (dto.Data != null && dto.Data.Count != 0)
  5017. {
  5018. var expressionUpdateWhere = Expressionable.Create<Fin_RoyaltyConfirm>()
  5019. .And(it => dto.Data.Contains (it.Id))
  5020. .And(it => it.IsDel == 0)
  5021. .ToExpression();
  5022. var count = _sqlSugar.Updateable<Fin_RoyaltyConfirm>().SetColumns(x => new Fin_RoyaltyConfirm
  5023. {
  5024. IsConfirm = dto.State,
  5025. })
  5026. .Where(expressionUpdateWhere).ExecuteCommand();
  5027. jw.Msg = $"{count}个团组确认成功!";
  5028. jw.Code = 200;
  5029. }
  5030. else
  5031. {
  5032. jw.Msg = "Data为空!";
  5033. }
  5034. return Ok(jw);
  5035. }
  5036. /// <summary>
  5037. /// 提成发放
  5038. /// </summary>
  5039. /// <param name="dto"></param>
  5040. /// <returns></returns>
  5041. [HttpPost]
  5042. public IActionResult RoyaltySeed(RoyaltySeedDto dto)
  5043. {
  5044. var jw = JsonView(false);
  5045. if (dto.Data != null && dto.Data.Count > 0)
  5046. {
  5047. var updateCount = _sqlSugar.Updateable<Fin_RoyaltyConfirm>().SetColumns(x => new Fin_RoyaltyConfirm
  5048. { IsSeed = 1 }).Where(x => dto.Data.Contains(x.Id) && x.IsDel == 0 && x.IsConfirm == 1).ExecuteCommand();
  5049. var info = $"{updateCount}个团组提成发放成功!";
  5050. if (dto.Data.Count > updateCount)
  5051. {
  5052. info += $"/r/n{dto.Data.Count - updateCount}个团组未确认!";
  5053. }
  5054. jw = JsonView(true, info);
  5055. }
  5056. else
  5057. {
  5058. jw.Msg = "发放的数据为空!";
  5059. }
  5060. return Ok(jw);
  5061. }
  5062. #endregion
  5063. #region 团组未审核数据
  5064. /// <summary>
  5065. /// 团组未审核费用数据
  5066. /// </summary>
  5067. /// <param name="beginDt"></param>
  5068. /// <param name="endDt"></param>
  5069. /// <returns></returns>
  5070. [HttpGet]
  5071. public async Task<IActionResult> GroupUnAuditFeeList(string beginDt,string endDt)
  5072. {
  5073. var jw = JsonView(false);
  5074. bool beginDtBool = DateTime.TryParse(beginDt, out DateTime _beginDt),
  5075. endDtBool = DateTime.TryParse(endDt, out DateTime _endDt);
  5076. if (!beginDtBool && !endDtBool)
  5077. {
  5078. jw.Msg = $"开始或者结束时间格式不正确!";
  5079. return Ok(jw);
  5080. }
  5081. var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>()
  5082. .Where(x => x.IsDel == 0 &&
  5083. x.VisitDate >= _beginDt &&
  5084. x.VisitDate <= _endDt
  5085. )
  5086. .ToList();
  5087. var _groupIds = _groupDatas.Select(x => x.Id).ToList();
  5088. if (_groupIds.Count < 1)
  5089. {
  5090. jw.Msg = $"该时间段暂无出访的团组!";
  5091. return Ok(jw);
  5092. }
  5093. var _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
  5094. var dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  5095. var _paymentDatas = _sqlSugar.Queryable<Grp_CreditCardPayment>()
  5096. .Where(x => x.IsDel == 0 &&
  5097. _groupIds.Contains(x.DIId) &&
  5098. x.IsAuditGM == 0
  5099. )
  5100. .ToList();
  5101. _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
  5102. _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
  5103. #region 相关基础数据源
  5104. var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
  5105. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  5106. var countryFeeDatas = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  5107. var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>()
  5108. .Where(it => it.IsDel == 0 && _groupIds.Contains(it.DiId))
  5109. .ToList();
  5110. var hotelContentDatas = _sqlSugar.Queryable<Grp_HotelReservationsContent>()
  5111. .Where(it => it.IsDel == 0 &&
  5112. it.IsPay == 0 &&
  5113. it.Price != 0 &&
  5114. _groupIds.Contains(it.DiId)
  5115. )
  5116. .ToList();
  5117. var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  5118. .Where(it => it.IsDel == 0 && _groupIds.Contains(it.DiId))
  5119. .ToList();
  5120. var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>()
  5121. .Where(it => it.IsDel == 0 && _groupIds.Contains(it.DIId))
  5122. .ToList();
  5123. var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>()
  5124. .Where(it => it.IsDel == 0 && _groupIds.Contains(it.DiId))
  5125. .ToList();
  5126. var insureDatas = _sqlSugar.Queryable<Grp_Customers>()
  5127. .Where(it => it.IsDel == 0 && _groupIds.Contains(it.DiId))
  5128. .ToList();
  5129. var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>()
  5130. .Where(it => it.IsDel == 0 && _groupIds.Contains(it.DIId))
  5131. .ToList();
  5132. var otherMoneyDatas = _sqlSugar.Queryable<Grp_DecreasePayments>()
  5133. .Where(it => it.IsDel == 0 && _groupIds.Contains(it.DiId))
  5134. .ToList();
  5135. var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>()
  5136. .Where(it => it.IsDel == 0 && _groupIds.Contains(it.DiId))
  5137. .ToList();
  5138. var extraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>()
  5139. .Where(it => it.IsDel == 0 && _groupIds.Contains(it.DiId))
  5140. .ToList();
  5141. #endregion
  5142. //Expense company
  5143. foreach (var groupInfo in _groupDatas)
  5144. {
  5145. var childList = new List<Group_DailyFeePaymentContentInfolView>();
  5146. var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
  5147. int rouNumber = 1;
  5148. foreach (var payInfo in groupPaymentDatas)
  5149. {
  5150. string priName = "-";
  5151. string orbitalPrivateTransfer = payInfo.OrbitalPrivateTransfer == 0 ? "公转" : payInfo.OrbitalPrivateTransfer == 1 ? "私转" : "-";
  5152. switch (payInfo.CTable)
  5153. {
  5154. case 76: //76 酒店预订
  5155. priName = $"[费用名称:{hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? ""}]";
  5156. break;
  5157. case 79: //79 车/导游地接
  5158. var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
  5159. if (opData != null)
  5160. {
  5161. string area = "";
  5162. bool b = int.TryParse(opData.Area, out int areaId);
  5163. if (b)
  5164. {
  5165. string area1 = countryFeeDatas.Find(it => it.Id == areaId)?.Country ?? "-";
  5166. area = $"{area1}({setDatas.Find(it => it.Id == opData.PriceType)?.Name ?? "-"})";
  5167. }
  5168. else area = opData.Area;
  5169. string opPriName = "-";
  5170. if (!string.IsNullOrEmpty(opData.PriceName)) opPriName = opData.PriceName;
  5171. area += $"({opPriName})";
  5172. if (payInfo.OrbitalPrivateTransfer == 0) //公转
  5173. {
  5174. priName = $"【{orbitalPrivateTransfer}】【导游: {opData.ServiceGuide} 】[费用名称:{area}]";
  5175. }
  5176. else if (payInfo.OrbitalPrivateTransfer == 1) //私转
  5177. {
  5178. priName = $"【{orbitalPrivateTransfer}】【导游:{opData.ServiceGuide}】[费用名称:{area}]";
  5179. }
  5180. }
  5181. break;
  5182. case 80: // 80 签证
  5183. 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);
  5184. List<SimplClientInfo> arr = _sqlSugar.SqlQueryable<SimplClientInfo>(sql).ToList();
  5185. string visaClientName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "";
  5186. string clientName = "-";
  5187. if (Regex.Match(visaClientName, @"\d+,?").Value.Length > 0)
  5188. {
  5189. string[] temparr = visaClientName.Split(',');
  5190. string fistrStr = temparr[0];
  5191. int count = temparr.Count();
  5192. int tempId;
  5193. bool success = int.TryParse(fistrStr, out tempId);
  5194. if (success)
  5195. {
  5196. SimplClientInfo tempInfo = arr.FirstOrDefault(s => s.Id == tempId);
  5197. if (tempInfo != null)
  5198. {
  5199. if (count > 1)
  5200. {
  5201. clientName = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  5202. }
  5203. else
  5204. {
  5205. clientName = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  5206. }
  5207. }
  5208. }
  5209. else
  5210. {
  5211. clientName = fistrStr;
  5212. }
  5213. }
  5214. priName = $"[费用名称:{clientName}]";
  5215. break;
  5216. case 81: // 81 邀请/公务活动
  5217. priName = $"[费用名称:{ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? " -"}]";
  5218. break;
  5219. case 82: // 82 团组客户保险
  5220. priName = $"[费用名称:{insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? " -"}]";
  5221. break;
  5222. case 85: // 85 机票预订
  5223. string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "-";
  5224. string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "-";
  5225. priName = $"{flightsCode}【{airPayType}】";
  5226. break;
  5227. case 98: // 98 其他款项
  5228. priName = $"[费用名称:{otherMoneyDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  5229. break;
  5230. case 285: // 285 收款退还
  5231. priName = $"[费用名称:{refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  5232. break;
  5233. case 1015: // 1015 超支费用
  5234. priName = $"[费用名称:{extraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  5235. break;
  5236. default:
  5237. priName = "";
  5238. break;
  5239. }
  5240. bool status1 = false;
  5241. if (_groupIds != null)
  5242. {
  5243. status1 = _groupIds.Contains(payInfo.Id);
  5244. }
  5245. if (payInfo.CTable == 76) //酒店单独处理
  5246. {
  5247. var hotelContents = hotelContentDatas.Where(it => it.HrId == payInfo.CId);
  5248. List<Group_DailyFeePaymentContentInfolView> childInfos = new List<Group_DailyFeePaymentContentInfolView>();
  5249. foreach (var hotelContent in hotelContents)
  5250. {
  5251. string subPriceName = "";
  5252. if (hotelContent.PriceType == 1) subPriceName = "房费";
  5253. else if (hotelContent.PriceType == 2) subPriceName = "早餐";
  5254. else if (hotelContent.PriceType == 3) subPriceName = "地税";
  5255. else if (hotelContent.PriceType == 4) subPriceName = "城市税";
  5256. if (string.IsNullOrEmpty(subPriceName)) subPriceName = priName;
  5257. else subPriceName = $"{priName.Replace("]", "")}-{subPriceName}]";
  5258. string payeeStr1 = string.Format(@" {0},开户行:{1},银行卡号:{2} ",
  5259. string.IsNullOrEmpty(hotelContent.Payee) ? "-" : hotelContent.Payee,
  5260. string.IsNullOrEmpty(hotelContent.OtherBankName) ? "-" : hotelContent.OtherBankName,
  5261. string.IsNullOrEmpty(hotelContent.OtherSideNo) ? "-" : hotelContent.OtherSideNo);
  5262. decimal _PaymentAmount1 = hotelContent.Price;//此次付款金额
  5263. decimal _CNYSubTotalAmount1 = _PaymentAmount1 * hotelContent.Rate;//此次付款金额
  5264. _CNYSubTotalAmount1 = Convert.ToDecimal(_CNYSubTotalAmount1.ToString("#0.00"));
  5265. var childInfo1 = new Group_DailyFeePaymentContentInfolView()
  5266. {
  5267. IsChecked = status1,
  5268. Id = payInfo.Id,
  5269. HotelSubId = hotelContent.Id,
  5270. Payee = payeeStr1,
  5271. RowNumber = rouNumber,
  5272. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  5273. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  5274. PayType = setDatas.Find(it => it.Id == hotelContent.PayDId)?.Name ?? "",
  5275. TransferMark = orbitalPrivateTransfer,
  5276. PriceName = subPriceName,
  5277. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  5278. PayCurrCode = setDatas.Find(it => it.Id == hotelContent.Currency)?.Name ?? "",
  5279. PaymentAmount = _PaymentAmount1,
  5280. PayRate = hotelContent.Rate,
  5281. CNYSubTotalAmount = _CNYSubTotalAmount1,
  5282. AuditStatus = payInfo.IsAuditGM
  5283. };
  5284. string remaksDescription1 = $"【{childInfo1.PayType}】【{childInfo1.ModuleName}】{rouNumber}、[申请人:{childInfo1.Applicant}]{subPriceName}[收款方:{childInfo1.Payee}] {childInfo1.PayCurrCode} {_PaymentAmount1.ToString("#0.00")}、CNY:{childInfo1.CNYSubTotalAmount.ToString("#0.00")}(团组:{groupInfo.TeamName})";
  5285. childInfo1.RemaksDescription = remaksDescription1;
  5286. childInfos.Add(childInfo1);
  5287. rouNumber++;
  5288. }
  5289. childList.AddRange(childInfos);
  5290. }
  5291. else
  5292. {
  5293. string payeeStr = string.Format(@" {0},开户行:{1},银行卡号:{2} ",
  5294. string.IsNullOrEmpty(payInfo.Payee) ? "-" : payInfo.Payee,
  5295. string.IsNullOrEmpty(payInfo.OtherBankName) ? "-" : payInfo.OtherBankName,
  5296. string.IsNullOrEmpty(payInfo.OtherSideNo) ? "-" : payInfo.OtherSideNo);
  5297. decimal _PaymentAmount = (payInfo.PayMoney / 100) * payInfo.PayPercentage;//此次付款金额
  5298. decimal _CNYSubTotalAmount = _PaymentAmount * payInfo.DayRate;//此次付款金额
  5299. _CNYSubTotalAmount = Convert.ToDecimal(_CNYSubTotalAmount.ToString("#0.00"));
  5300. var childInfo = new Group_DailyFeePaymentContentInfolView()
  5301. {
  5302. IsChecked = status1,
  5303. Id = payInfo.Id,
  5304. Payee = payeeStr,
  5305. RowNumber = rouNumber,
  5306. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  5307. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  5308. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  5309. TransferMark = orbitalPrivateTransfer,
  5310. PriceName = priName,
  5311. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  5312. PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
  5313. PaymentAmount = _PaymentAmount,
  5314. PayRate = payInfo.DayRate,
  5315. CNYSubTotalAmount = _CNYSubTotalAmount,
  5316. AuditStatus = payInfo.IsAuditGM
  5317. };
  5318. 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})";
  5319. childInfo.RemaksDescription = remaksDescription;
  5320. //childList.Add(childInfo);
  5321. rouNumber++;
  5322. }
  5323. }
  5324. CompanyInfo companyInfo = new CompanyInfo();
  5325. companyInfo = ExpenseCompanyByTeamId(groupInfo.TeamDid);
  5326. dataList.Add(new tree_Group_DailyFeePaymentPageListView()
  5327. {
  5328. Id = Guid.NewGuid().ToString("N"),
  5329. GroupName = groupInfo.TeamName,
  5330. CompanyId = companyInfo.Id,
  5331. ConpanyName = companyInfo.ConpanyName,
  5332. CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
  5333. ChildList = childList,
  5334. });
  5335. }
  5336. _DailyFeePaymentResult.dataList = dataList;
  5337. jw.Code = StatusCodes.Status200OK;
  5338. jw.Msg = $"操作成功!";
  5339. jw.Data = _DailyFeePaymentResult;
  5340. return Ok(jw);
  5341. }
  5342. #endregion
  5343. }
  5344. }