FinancialController.cs 301 KB

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