FinancialController.cs 288 KB

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