FinancialController.cs 289 KB

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