FinancialController.cs 289 KB

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