FinancialController.cs 289 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175
  1. using Aspose.Cells;
  2. using Aspose.Words;
  3. using Aspose.Words.Drawing;
  4. using EyeSoft.Extensions;
  5. using EyeSoft.IO;
  6. using EyeSoft.Runtime.InteropServices;
  7. using FluentValidation;
  8. using MathNet.Numerics.Distributions;
  9. using Microsoft.EntityFrameworkCore.Query.Internal;
  10. using NPOI.HPSF;
  11. using NPOI.HSSF.UserModel;
  12. using NPOI.SS.Formula.Functions;
  13. using NPOI.SS.Formula.PTG;
  14. using NPOI.SS.UserModel;
  15. using NPOI.Util;
  16. using NPOI.XSSF.UserModel;
  17. using OASystem.API.OAMethodLib;
  18. using OASystem.API.OAMethodLib.File;
  19. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  20. using OASystem.Domain.Dtos.Financial;
  21. using OASystem.Domain.Dtos.Groups;
  22. using OASystem.Domain.Entities.Customer;
  23. using OASystem.Domain.Entities.Financial;
  24. using OASystem.Domain.Entities.Groups;
  25. using OASystem.Domain.ViewModels.Financial;
  26. using OASystem.Domain.ViewModels.Groups;
  27. using OASystem.Infrastructure.Repositories.Financial;
  28. using OASystem.Infrastructure.Repositories.Groups;
  29. using OfficeOpenXml;
  30. using Org.BouncyCastle.Math;
  31. using SqlSugar.Extensions;
  32. using System.Collections;
  33. using System.Data;
  34. using System.Data.OleDb;
  35. using System.Diagnostics;
  36. using System.Globalization;
  37. using System.IO.Compression;
  38. using System.IO.Pipelines;
  39. namespace OASystem.API.Controllers
  40. {
  41. /// <summary>
  42. /// 财务模块
  43. /// </summary>
  44. [Route("api/[controller]/[action]")]
  45. [ApiController]
  46. public class FinancialController : ControllerBase
  47. {
  48. private readonly IMapper _mapper;
  49. private readonly IConfiguration _config;
  50. private readonly SqlSugarClient _sqlSugar;
  51. private readonly HttpClient _httpClient;
  52. private readonly SetDataTypeRepository _setDataTypeRep;
  53. private readonly SetDataRepository _setDataRep;
  54. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  55. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  56. private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
  57. private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
  58. private readonly PaymentRefundAndOtherMoneyRepository _paymentRefundAndOtherMoneyRep; //收款退还与其他款项 仓库
  59. private readonly DelegationInfoRepository _delegationInfoRep; //团组信息 仓库
  60. /// <summary>
  61. /// 初始化
  62. /// </summary>
  63. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
  64. TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
  65. PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient, DelegationInfoRepository delegationInfoRep, SetDataRepository setDataRep)
  66. {
  67. _mapper = mapper;
  68. _config = configuration;
  69. _daiRep = daiRep;
  70. _sqlSugar = sqlSugar;
  71. _setDataTypeRep = setDataTypeRep;
  72. _teamRateRep = teamRateRep;
  73. _ForForeignReceivablesRep = ForForeignReceivablesRep;
  74. _proceedsReceivedRep = proceedsReceivedRep;
  75. _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
  76. _httpClient = httpClient;
  77. _delegationInfoRep = delegationInfoRep;
  78. _setDataRep = setDataRep;
  79. }
  80. #region 日付申请
  81. /// <summary>
  82. /// 获取日付申请 基础数据源
  83. /// </summary>
  84. /// <param name="dto"> 日付申请 分页 dto</param>
  85. /// <returns></returns>
  86. [HttpPost]
  87. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  88. public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
  89. {
  90. var result = await _daiRep.GetPagePriceTypeData(dto);
  91. if (result == null || result.Code != 0)
  92. {
  93. return Ok(JsonView(false, result.Msg));
  94. }
  95. var data = result.Data;
  96. return Ok(JsonView(data));
  97. }
  98. /// <summary>
  99. /// 获取日付申请 基础数据源 - 转账表识
  100. /// </summary>
  101. /// <param name="dto"> 日付申请 分页 dto</param>
  102. /// <returns></returns>
  103. [HttpPost]
  104. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  105. public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
  106. {
  107. var result = await _daiRep.GetPriceTypeAddData(dto);
  108. if (result == null || result.Code != 0)
  109. {
  110. return Ok(JsonView(false, result.Msg));
  111. }
  112. var data = result.Data;
  113. return Ok(JsonView(data));
  114. }
  115. /// <summary>
  116. /// 日付申请 Page Search
  117. /// </summary>
  118. /// <param name="dto"> 日付申请 分页 dto</param>
  119. /// <returns></returns>
  120. [HttpPost]
  121. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  122. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  123. {
  124. var result = await _daiRep.GetPageSearchAll(dto);
  125. if (result == null || result.Code != 0)
  126. {
  127. return Ok(JsonView(false, result.Msg));
  128. }
  129. var data = result.Data;
  130. if (data == null)
  131. {
  132. return Ok(JsonView(false, result.Msg));
  133. }
  134. return Ok(JsonView(data));
  135. }
  136. /// <summary>
  137. /// 日付申请 Single Search By Id
  138. /// </summary>
  139. /// <param name="dto"></param>
  140. /// <returns></returns>
  141. [HttpPost]
  142. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  143. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  144. {
  145. var result = await _daiRep.GetSearchById(dto);
  146. if (result == null || result.Code != 0)
  147. {
  148. return Ok(JsonView(false, result.Msg));
  149. }
  150. return Ok(JsonView(result.Data));
  151. }
  152. /// <summary>
  153. /// 日付申请 添加
  154. /// </summary>
  155. /// <param name="dto"> 日付申请 添加 dto</param>
  156. /// <returns></returns>
  157. [HttpPost]
  158. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  159. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  160. {
  161. var result = await _daiRep.Add(dto);
  162. if (result == null || result.Code != 0)
  163. {
  164. return Ok(JsonView(false, result.Msg));
  165. }
  166. #region 应用推送
  167. try
  168. {
  169. int dailyId = result.Data.GetType().GetProperty("dailyId").GetValue(result.Data, null);
  170. int sign = result.Data.GetType().GetProperty("sign").GetValue(result.Data, null);
  171. await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  172. }
  173. catch (Exception ex)
  174. {
  175. }
  176. #endregion
  177. return Ok(JsonView(true));
  178. }
  179. /// <summary>
  180. /// 日付申请 Update
  181. /// </summary>
  182. /// <param name="dto"> 日付申请 修改 dto</param>
  183. /// <returns></returns>
  184. [HttpPost]
  185. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  186. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  187. {
  188. var result = await _daiRep.Edit(dto);
  189. if (result == null || result.Code != 0)
  190. {
  191. return Ok(JsonView(false, result.Msg));
  192. }
  193. #region 应用推送
  194. try
  195. {
  196. int dailyId = result.Data.GetType().GetProperty("dailyId").GetValue(result.Data, null);
  197. int sign = result.Data.GetType().GetProperty("sign").GetValue(result.Data, null);
  198. await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  199. }
  200. catch (Exception ex)
  201. {
  202. }
  203. #endregion
  204. return Ok(JsonView(true));
  205. }
  206. /// <summary>
  207. /// 日付申请 Del
  208. /// </summary>
  209. /// <param name="dto"> 日付申请 删除 dto</param>
  210. /// <returns></returns>
  211. [HttpPost]
  212. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  213. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  214. {
  215. var result = await _daiRep.Del(dto);
  216. if (result == null || result.Code != 0)
  217. {
  218. return Ok(JsonView(false, result.Msg));
  219. }
  220. return Ok(JsonView(true));
  221. }
  222. /// <summary>
  223. /// 日付申请 财务审核
  224. /// </summary>
  225. /// <param name="dto"> dto </param>
  226. /// <returns></returns>
  227. [HttpPost]
  228. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  229. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  230. {
  231. var result = await _daiRep.DailyPaymentAudit(dto);
  232. if (result == null || result.Code != 0)
  233. {
  234. return Ok(JsonView(false, result.Msg));
  235. }
  236. return Ok(JsonView(true));
  237. }
  238. /// <summary>
  239. /// 日付申请 Single Excel Download
  240. /// </summary>
  241. /// <param name="dto"> dto </param>
  242. /// <returns></returns>
  243. [HttpPost]
  244. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  245. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  246. {
  247. if (dto.PortType == 1 || dto.PortType == 2)
  248. {
  249. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  250. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  251. Where IsDel=0 And Id = {0} ", dto.Id);
  252. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  253. if (feeData == null)
  254. {
  255. return Ok(JsonView(false, "暂无数据!"));
  256. }
  257. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  258. Where IsDel=0 And DFPId = {0} ", dto.Id);
  259. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  260. if (feeData != null)
  261. {
  262. string userName = string.Empty;
  263. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  264. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  265. if (user != null) { userName = user.CnName; }
  266. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  267. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  268. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  269. Dictionary<string, object> pairs = new Dictionary<string, object>();
  270. List<DataTable> datas = new List<DataTable>();
  271. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  272. //{
  273. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  274. // // pairs, datas);
  275. //}
  276. //else //日付常规模板
  277. //{
  278. pairs.Clear();
  279. pairs.Add("Opertor", userName);
  280. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  281. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  282. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  283. pairs.Add("SumPrice", feeData.SumPrice);
  284. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  285. datas.Clear();
  286. datas.Add(data);
  287. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  288. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  289. return Ok(JsonView(true, msg));
  290. //}
  291. }
  292. else
  293. {
  294. return Ok(JsonView(false, "暂无数据!"));
  295. }
  296. }
  297. return Ok(JsonView(true));
  298. }
  299. /// <summary>
  300. /// 日付申请
  301. /// 总经理未审核 日付信息
  302. /// </summary>
  303. /// <param name="dto"> dto </param>
  304. /// <returns></returns>
  305. [HttpGet]
  306. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  307. public async Task<IActionResult> DailyPaymentGMUnAudited()
  308. {
  309. var dailyInfos = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  310. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  311. .Where(dfp => dfp.IsDel == 0 &&
  312. //dfp.FAudit == 1 &&
  313. //dfp.IsPay == 0 &&
  314. dfp.MAudit == 0
  315. )
  316. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  317. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  318. .Select((dfp, u) => new
  319. {
  320. id = dfp.Id,
  321. amountName = dfp.Instructions,
  322. amount = dfp.SumPrice,
  323. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  324. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  325. fAuditDate = dfp.FAuditDate,
  326. applicant = u.CnName,
  327. applicantDate = dfp.CreateTime
  328. })
  329. //.ToListAsync();
  330. .CountAsync();
  331. //int count = dailyInfos.Count;
  332. return Ok(JsonView(true,"查询成功", dailyInfos));
  333. }
  334. #endregion
  335. #region 团组提成
  336. /// <summary>
  337. /// 提成 Page Search
  338. /// </summary>
  339. /// <param name="dto"> 提成 分页 dto</param>
  340. /// <returns></returns>
  341. [HttpPost]
  342. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  343. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  344. {
  345. var data = await GroupCommission.GetCommissionPageList(dto);
  346. return Ok(JsonView(data.Data));
  347. }
  348. #endregion
  349. #region 团组汇率
  350. /// <summary>
  351. /// 团组汇率 Select数据源(团组列,汇率列)
  352. /// </summary>
  353. /// <param name="dto"></param>
  354. /// <returns></returns>
  355. [HttpPost]
  356. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  357. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  358. {
  359. try
  360. {
  361. //迁移数据更新团组汇率
  362. //Result teamRateData1 = await _teamRateRep.GetGroupRateChangeData();
  363. //var data = await _teamRateRep.PostGroupTeamRateHot();
  364. Stopwatch stopwatch = Stopwatch.StartNew();
  365. GroupNameDto groupNameDto = new GroupNameDto() { PortType = dto.PortType };
  366. var groups = await _delegationInfoRep.GetGroupNameList(groupNameDto);
  367. List<CurrencyHot> _currData = new List<CurrencyHot>();
  368. string currData = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("GroupTeamCurrencyData");//string 取
  369. if (!string.IsNullOrEmpty(currData))
  370. {
  371. _currData = JsonConvert.DeserializeObject<List<CurrencyHot>>(currData);
  372. }
  373. else
  374. {
  375. _currData = await _teamRateRep.PostGroupTeamRateHot();
  376. //过期时间 25 Hours
  377. TimeSpan ts = DateTime.Now.AddHours(25).TimeOfDay;
  378. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync("GroupTeamCurrencyData", JsonConvert.SerializeObject(_currData), ts);
  379. }
  380. var _data = new { GroupData = groups.Data, TeamRateData = _currData };
  381. stopwatch.Stop();
  382. return Ok(JsonView(true, $"查询成功!耗时:{stopwatch.ElapsedMilliseconds / 1000}s", _data));
  383. }
  384. catch (Exception ex)
  385. {
  386. return Ok(JsonView(false, ex.Message));
  387. }
  388. }
  389. ///// <summary>
  390. ///// 团组汇率 changge
  391. ///// </summary>
  392. ///// <returns></returns>
  393. //[HttpPost]
  394. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  395. //public async Task<IActionResult> ChangeGroupRateInfo()
  396. //{
  397. // try
  398. // {
  399. // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  400. // if (teamRateData.Code != 0)
  401. // {
  402. // return Ok(JsonView(false, teamRateData.Msg));
  403. // }
  404. // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  405. // }
  406. // catch (Exception ex)
  407. // {
  408. // return Ok(JsonView(false, ex.Message));
  409. // throw;
  410. // }
  411. //}
  412. /// <summary>
  413. /// 团组汇率 Select汇率详情
  414. /// </summary>
  415. /// <param name="dto"></param>
  416. /// <returns></returns>
  417. [HttpPost]
  418. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  419. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  420. {
  421. try
  422. {
  423. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  424. if (teamRateData.Code != 0)
  425. {
  426. return Ok(JsonView(false, teamRateData.Msg));
  427. }
  428. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  429. }
  430. catch (Exception ex)
  431. {
  432. return Ok(JsonView(false, ex.Message));
  433. throw;
  434. }
  435. }
  436. /// <summary>
  437. /// 团组汇率 添加 or 更新
  438. /// </summary>
  439. /// <param name="dto"></param>
  440. /// <returns></returns>
  441. [HttpPost]
  442. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  443. public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
  444. {
  445. try
  446. {
  447. Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
  448. if (teamRateData.Code != 0)
  449. {
  450. return Ok(JsonView(false, teamRateData.Msg));
  451. }
  452. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  453. }
  454. catch (Exception ex)
  455. {
  456. return Ok(JsonView(false, ex.Message));
  457. throw;
  458. }
  459. }
  460. #endregion
  461. #region 对外收款账单 关联已收款项
  462. /// <summary>
  463. /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
  464. /// 关联已收款项
  465. /// </summary>
  466. /// <param name="dto"></param>
  467. /// <returns></returns>
  468. [HttpPost]
  469. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  470. public async Task<IActionResult> GetForeignReceivablesDataSources(ForeignReceivablesDataSourcesDto dto)
  471. {
  472. return Ok(await _ForForeignReceivablesRep.GetDataSource(dto));
  473. }
  474. /// <summary>
  475. /// 对外收款账单
  476. /// 账单详情
  477. /// 关联已收款项
  478. /// </summary>
  479. /// <param name="dto"></param>
  480. /// <returns></returns>
  481. [HttpPost]
  482. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  483. public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  484. {
  485. try
  486. {
  487. Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
  488. if (ffrData.Code != 0)
  489. {
  490. return Ok(JsonView(false, ffrData.Msg));
  491. }
  492. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  493. }
  494. catch (Exception ex)
  495. {
  496. return Ok(JsonView(false, ex.Message));
  497. throw;
  498. }
  499. }
  500. /// <summary>
  501. /// 对外收款账单
  502. /// 账单 删除
  503. /// 关联已收款项
  504. /// </summary>
  505. /// <param name="dto"></param>
  506. /// <returns></returns>
  507. [HttpPost]
  508. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  509. public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
  510. {
  511. try
  512. {
  513. Result ffrData = await _ForForeignReceivablesRep._Del(dto);
  514. if (ffrData.Code != 0)
  515. {
  516. return Ok(JsonView(false, ffrData.Msg));
  517. }
  518. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  519. }
  520. catch (Exception ex)
  521. {
  522. return Ok(JsonView(false, ex.Message));
  523. throw;
  524. }
  525. }
  526. /// <summary>
  527. /// 对外收款账单
  528. /// 添加 And 更新
  529. /// 关联已收款项
  530. /// </summary>
  531. /// <param name="dto"></param>
  532. /// <returns></returns>
  533. [HttpPost]
  534. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  535. public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  536. {
  537. try
  538. {
  539. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
  540. if (ffrData.Code != 0)
  541. {
  542. return Ok(JsonView(false, ffrData.Msg));
  543. }
  544. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  545. }
  546. catch (Exception ex)
  547. {
  548. return Ok(JsonView(false, ex.Message));
  549. throw;
  550. }
  551. }
  552. /// <summary>
  553. /// 已收款项
  554. /// 账单 删除
  555. /// 关联已收款项
  556. /// </summary>
  557. /// <param name="dto"></param>
  558. /// <returns></returns>
  559. [HttpPost]
  560. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  561. public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
  562. {
  563. try
  564. {
  565. Result ffrData = await _proceedsReceivedRep._Del(dto);
  566. if (ffrData.Code != 0)
  567. {
  568. return Ok(JsonView(false, ffrData.Msg));
  569. }
  570. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  571. }
  572. catch (Exception ex)
  573. {
  574. return Ok(JsonView(false, ex.Message));
  575. throw;
  576. }
  577. }
  578. /// <summary>
  579. /// 已收款项
  580. /// 添加 And 更新
  581. /// 关联已收款项
  582. /// </summary>
  583. /// <param name="dto"></param>
  584. /// <returns></returns>
  585. [HttpPost]
  586. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  587. public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
  588. {
  589. try
  590. {
  591. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
  592. if (ffrData.Code != 0)
  593. {
  594. return Ok(JsonView(false, ffrData.Msg));
  595. }
  596. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  597. }
  598. catch (Exception ex)
  599. {
  600. return Ok(JsonView(false, ex.Message));
  601. throw;
  602. }
  603. }
  604. /// <summary>
  605. /// 财务 已收款项
  606. /// 分配已收款项至 应收项下
  607. /// 关联已收款项
  608. /// </summary>
  609. /// <param name="dto"></param>
  610. /// <returns></returns>
  611. [HttpPost]
  612. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  613. public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
  614. {
  615. try
  616. {
  617. Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
  618. if (ffrData.Code != 0)
  619. {
  620. return Ok(JsonView(false, ffrData.Msg));
  621. }
  622. return Ok(JsonView(true));
  623. }
  624. catch (Exception ex)
  625. {
  626. return Ok(JsonView(false, ex.Message));
  627. throw;
  628. }
  629. }
  630. ///// <summary>
  631. ///// 财务 收款账单
  632. ///// 导出Word(北京,四川)
  633. ///// </summary>
  634. ///// <param name="dto"></param>
  635. ///// <returns></returns>
  636. //[HttpPost]
  637. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  638. //public async Task<IActionResult> PostAccountReceivableWordExport(AccountReceivableWordExportDto dto)
  639. //{
  640. // try
  641. // {
  642. // //模板处理
  643. // string typeName = string.Empty;
  644. // if (dto.TemplateType == 1) //四川
  645. // {
  646. // typeName = "四川";
  647. // }
  648. // else if (dto.TemplateType == 2) //北京
  649. // {
  650. // typeName = "北京";
  651. // }
  652. // else return Ok(JsonView(false,"请选择正确的模板类型!"));
  653. // string wordTempName = string.Format("收款账单({0})模板.doc", typeName);
  654. // }
  655. // catch (Exception ex)
  656. // {
  657. // return Ok(JsonView(false, ex.Message));
  658. // }
  659. //}
  660. #endregion
  661. #region 对外收款账单
  662. /// <summary>
  663. /// 对外收款账单
  664. /// 数据源
  665. /// </summary>
  666. /// <param name="dto"></param>
  667. /// <returns></returns>
  668. [HttpPost]
  669. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  670. public async Task<IActionResult> PostGroupReceivablesDataSource(ForeignReceivablesDataSourcesDto dto)
  671. {
  672. return Ok(await _ForForeignReceivablesRep.PostDataSource(dto));
  673. }
  674. /// <summary>
  675. /// 对外收款账单
  676. /// 账单详情
  677. /// </summary>
  678. /// <param name="dto"></param>
  679. /// <returns></returns>
  680. [HttpPost]
  681. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  682. public async Task<IActionResult> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  683. {
  684. return Ok(await _ForForeignReceivablesRep.PostGroupReceivablesInfoByDiId(dto));
  685. }
  686. /// <summary>
  687. /// 对外收款账单
  688. /// 添加 And 更新
  689. /// </summary>
  690. /// <param name="dto"></param>
  691. /// <returns></returns>
  692. [HttpPost]
  693. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  694. public async Task<IActionResult> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  695. {
  696. return Ok(await _ForForeignReceivablesRep.PostReceivablesSave(dto));
  697. }
  698. /// <summary>
  699. /// 对外收款账单
  700. /// 审核
  701. /// </summary>
  702. /// <param name="dto"></param>
  703. /// <returns></returns>
  704. [HttpPost]
  705. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  706. public async Task<IActionResult> PostReceivablesAudit(FeeAuditDto dto)
  707. {
  708. return Ok(await _ForForeignReceivablesRep.FeeAudit(dto));
  709. }
  710. /// <summary>
  711. /// 已收账单
  712. /// 删除
  713. /// </summary>
  714. /// <param name="dto"></param>
  715. /// <returns></returns>
  716. [HttpPost]
  717. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  718. public async Task<IActionResult> PostReceivablesDel(ForeignReceivablesDelDto dto)
  719. {
  720. try
  721. {
  722. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesDel(dto);
  723. if (ffrData.Code != 0)
  724. {
  725. return Ok(JsonView(false, ffrData.Msg));
  726. }
  727. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  728. }
  729. catch (Exception ex)
  730. {
  731. return Ok(JsonView(false, ex.Message));
  732. throw;
  733. }
  734. }
  735. /// <summary>
  736. /// 已收账单
  737. /// File Downloasd
  738. /// Init
  739. /// </summary>
  740. /// <param name="dto"></param>
  741. /// <returns></returns>
  742. [HttpPost]
  743. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  744. public async Task<IActionResult> PostReceivablesFeilDownloadInit()
  745. {
  746. return Ok(JsonView(true, "操作成功!", new List<dynamic> {
  747. new { Id = 1, Name = "生成收款单(四川)" },
  748. new { Id = 2, Name = "生成收款单(北京)" },
  749. new { Id = 3, Name = "汇款账单" }
  750. }
  751. ));
  752. }
  753. /// <summary>
  754. /// 已收账单
  755. /// File Downloasd
  756. /// </summary>
  757. /// <param name="dto"></param>
  758. /// <returns></returns>
  759. [HttpPost]
  760. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  761. public async Task<IActionResult> PostReceivablesFeilDownload(ForeignReceivablesFeilDownloadDto dto)
  762. {
  763. try
  764. {
  765. if (dto.DiId < 1)
  766. {
  767. return Ok(JsonView(false, "请传入有效DiId参数!"));
  768. }
  769. if (dto.FileType < 1 || dto.FileType > 3)
  770. {
  771. return Ok(JsonView(false, "请传入有效FileType参数! 1 生成收款单(四川) 2 生成收款单(北京) 3 汇款账单"));
  772. }
  773. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  774. if (_DelegationInfo == null)
  775. {
  776. return Ok(JsonView(false, "暂无团组信息!!"));
  777. }
  778. if (dto.FileType == 1 || dto.FileType == 2)
  779. {
  780. var _ForeignReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  781. if (_ForeignReceivables.Count < 1)
  782. {
  783. return Ok(JsonView(false, "暂无收款信息!!"));
  784. }
  785. string tempName = "";
  786. if (dto.FileType == 1) tempName = $"收款账单(四川)模板.docx";
  787. else if (dto.FileType == 2) tempName = $"收款账单(北京)模板.docx";
  788. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/{tempName}";
  789. //载入模板
  790. Document doc = new Document(tempPath);
  791. DocumentBuilder builder = new DocumentBuilder(doc);
  792. #region 替换Word模板书签内容
  793. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  794. //付款方
  795. if (doc.Range.Bookmarks["To"] != null)
  796. {
  797. Bookmark mark = doc.Range.Bookmarks["To"];
  798. mark.Text = _ForeignReceivables[0].To == null ? "" : _ForeignReceivables[0].To.ToString();
  799. }
  800. //付款方电话
  801. if (doc.Range.Bookmarks["ToTel"] != null)
  802. {
  803. Bookmark mark = doc.Range.Bookmarks["ToTel"];
  804. mark.Text = _ForeignReceivables[0].ToTel == null ? "" : _ForeignReceivables[0].ToTel.ToString();
  805. }
  806. //导出时间
  807. if (doc.Range.Bookmarks["Date"] != null)
  808. {
  809. Bookmark mark = doc.Range.Bookmarks["Date"];
  810. mark.Text = DateTime.Now.ToString("yyyy-MM-dd");
  811. }
  812. //注
  813. if (doc.Range.Bookmarks["Attention"] != null)
  814. {
  815. Bookmark mark = doc.Range.Bookmarks["Attention"];
  816. mark.Text = _ForeignReceivables[0].Attention == null ? "" : _ForeignReceivables[0].Attention.ToString();
  817. }
  818. //团队名称
  819. if (doc.Range.Bookmarks["Team"] != null)
  820. {
  821. Bookmark mark = doc.Range.Bookmarks["Team"];
  822. mark.Text = _DelegationInfo.VisitCountry == null ? "" : _DelegationInfo.VisitCountry.Replace("|", "、").ToString();
  823. }
  824. //付款日期
  825. if (doc.Range.Bookmarks["PayDate"] != null)
  826. {
  827. Bookmark mark = doc.Range.Bookmarks["PayDate"];
  828. mark.Text = _ForeignReceivables[0].PayDate == null ? "" : Convert.ToDateTime(_ForeignReceivables[0].PayDate).ToString("yyyy年MM月dd日");
  829. }
  830. decimal sumPrice = 0;
  831. //各项费用
  832. if (doc.Range.Bookmarks["PayItemContent"] != null)
  833. {
  834. string items = "";
  835. foreach (var fr in _ForeignReceivables)
  836. {
  837. var currInfo = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == fr.Currency).First();
  838. items += $"{fr.PriceName} {currInfo?.Name} {fr.Price.ToString("#0.00")} * {fr.Count} {fr.Unit} * {fr.Rate}.................. RMB {fr.ItemSumPrice.ToString("#0.00")}\n";
  839. sumPrice += fr.ItemSumPrice;
  840. }
  841. Bookmark mark = doc.Range.Bookmarks["PayItemContent"];
  842. mark.Text = items;
  843. }
  844. //合计
  845. if (doc.Range.Bookmarks["Total"] != null)
  846. {
  847. Bookmark mark = doc.Range.Bookmarks["Total"];
  848. mark.Text = sumPrice.ToString("#0.00");
  849. }
  850. #endregion
  851. //文件名
  852. string strFileName = _DelegationInfo.TeamName + "-收款账单.docx";
  853. //去水印
  854. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  855. doc.Save(AppSettingsHelper.Get("WordBasePath") + "ForeignReceivables/File/" + strFileName);
  856. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/ForeignReceivables/File/" + strFileName;
  857. return Ok(JsonView(true, "成功", new { Url = url }));
  858. }
  859. else if (dto.FileType == 3) //汇款通知
  860. {
  861. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  862. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId && it.NationalTravelFeeId > 0).ToList();
  863. if (_EnterExitCosts == null)
  864. {
  865. return Ok(JsonView(false, "该团组未填写出入境费用;"));
  866. }
  867. var _cityFee = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  868. foreach (var item in _DayAndCosts)
  869. {
  870. var cityInfo = _cityFee.Where(it => it.Id == item.NationalTravelFeeId).FirstOrDefault();
  871. if (cityInfo != null)
  872. {
  873. if (cityInfo.City.Contains("全部城市") || cityInfo.City.Contains("其他城市") || cityInfo.City.Contains("所有城市"))
  874. {
  875. item.Place = cityInfo.Country;
  876. }
  877. else item.Place = cityInfo.City;
  878. }
  879. }
  880. //数据源
  881. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  882. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  883. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  884. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  885. //币种Data
  886. var currData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  887. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  888. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  889. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  890. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  891. .Select((tcl, dc, cc) => new
  892. {
  893. Name = dc.LastName + dc.FirstName,
  894. Sex = dc.Sex,
  895. Birthday = dc.BirthDay,
  896. Company = cc.CompanyFullName.Replace("\n",""),
  897. Job = dc.Job,
  898. AirType = tcl.ShippingSpaceTypeId
  899. })
  900. .ToList();
  901. if (DeleClientList.Count < 1)
  902. {
  903. return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
  904. }
  905. var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
  906. var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
  907. Dictionary<string, string> bookmarkArr = null;
  908. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
  909. //载入模板
  910. Document doc = new Document(tempPath);
  911. DocumentBuilder builder = null;
  912. List<string> filesToZip = new List<string>();
  913. foreach (var ClientItem in _GroupClient) //遍历单位
  914. {
  915. doc = new Document(tempPath);
  916. builder = new DocumentBuilder(doc);
  917. Paragraph paragraph = new Paragraph(doc);
  918. bookmarkArr = new Dictionary<string, string>();
  919. bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
  920. bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
  921. bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
  922. bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
  923. bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry.Replace("|", "、"));//出访国家
  924. bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
  925. var ClientItemList = ClientItem.ToList();
  926. string UsersTop = string.Empty;//word中人员以及金额
  927. decimal WordAllPrice = 0.00M;
  928. //int[] infoColumn = new int[5] {dac1.Select(x=>x.Place.Length).ToList().Max(),2, dac1.Select(x => x.Cost.Length).Max() + dac1.Select(x => x.Currency.Length).Max(),
  929. // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
  930. //遍历人员
  931. for (int i = 0; i < ClientItemList.Count(); i++)
  932. {
  933. Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
  934. var client = ClientItemList[i]; //每个人员
  935. var firstName = ClientItemList[i].Name;
  936. /*
  937. * 457 头等舱
  938. * 458 公务舱
  939. * 460 经济舱
  940. */
  941. decimal airPrice = 0.00M;
  942. string airName = string.Empty;
  943. if (client.AirType == 457)
  944. {
  945. airName = $"头等舱";
  946. airPrice = _EnterExitCosts.AirTD;
  947. }else if (client.AirType == 458)
  948. {
  949. airName = $"公务舱";
  950. airPrice = _EnterExitCosts.AirGW;
  951. }else if (client.AirType == 460)
  952. {
  953. airName = $"经济舱";
  954. airPrice = _EnterExitCosts.AirJJ;
  955. }
  956. //计算费用总和
  957. decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
  958. dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
  959. +_EnterExitCosts.YiMiao + _EnterExitCosts.YiMiao + _EnterExitCosts.Ticket + _EnterExitCosts.Service;
  960. WordAllPrice += AllPrice;
  961. UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
  962. TeableBookmarkArr.Add("jp", airPrice.ToString("#0.00") + " 元"); //机票金额
  963. TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
  964. TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
  965. string zsinfo = string.Empty;
  966. string hsinfo = string.Empty;
  967. string gzinfo = string.Empty;
  968. List<string> placeArr = new List<string>();
  969. Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  970. Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
  971. Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
  972. Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
  973. int rowIndex = 0;
  974. foreach (var item in dac1)
  975. {
  976. if (string.IsNullOrWhiteSpace(item.Place))
  977. {
  978. continue;
  979. }
  980. if (placeArr.Contains(item.Place))
  981. {
  982. continue;
  983. }
  984. else
  985. {
  986. placeArr.Add(item.Place);
  987. }
  988. if (!string.IsNullOrWhiteSpace(item.Place))
  989. {
  990. if (rowIndex > ChildTable.Rows.Count - 1)
  991. {
  992. var chitableRow = ChildTable.LastRow.Clone(true);
  993. ChildTable.AppendChild(chitableRow);
  994. }
  995. int days = dac1.FindAll(x => x.Place == item.Place).Count();
  996. SetCells(ChildTable, doc, rowIndex, 0, item.Place);
  997. SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
  998. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  999. SetCells(ChildTable, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/晚");
  1000. SetCells(ChildTable, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.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. }