FinancialController.cs 304 KB

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