ReceiptController.php 562 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. // public static $NEW2 = 0;
  10. public $AGENCY = "日常相关费用";
  11. public $TRAVEL = "差旅相关费用";
  12. public $TRAIN = "培训班费用";
  13. public $OTHER = "其他";
  14. public $INTTRAIN='内部培训费用';
  15. private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
  16. private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
  17. private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
  18. private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
  19. private function showCache($path) {
  20. if (file_exists ( $path )) {
  21. echo "<!DOCTYPE html>";
  22. include $path;
  23. die ();
  24. }
  25. }
  26. private function cacheFile($path) {
  27. $content = ob_get_contents ();
  28. $fp = fopen ( $path, "w" );
  29. fwrite ( $fp, $content );
  30. fclose ( $fp );
  31. }
  32. private function collectHtml($receiptCollectList = array(), $itemCategory = "日常相关费用", $classType = "b") {
  33. $collectHtml = "";
  34. $sumPrice = 0.00;
  35. for($i = 1; $i <= 12; $i ++) {
  36. $falg = true;
  37. foreach ( $receiptCollectList as $key => $value ) {
  38. if ($value ['itemCategory'] == $itemCategory && $value ['month'] == $i) {
  39. $sumPrice += $value ['price'];
  40. if ($classType == "b") {
  41. $collectHtml .= '<td class="colGreen taR">¥' . $value ['price'] . '</td>';
  42. $falg = false;
  43. break;
  44. } else {
  45. $collectHtml .= '<td class="taR">¥' . $value ['price'] . '</td>';
  46. $falg = false;
  47. break;
  48. }
  49. }
  50. }
  51. if ($falg)
  52. $collectHtml .= '<td class="taR">-</td>';
  53. }
  54. $collectHtml .= '<td class="taR colGreen">¥' . $sumPrice . '</td>';
  55. return $collectHtml;
  56. }
  57. private function _itineraryDateMin(){
  58. Doo::loadModel ( "itinerary" );
  59. $itinerary = new itinerary ();
  60. $itineraryDetail=$itinerary->getOne(array (
  61. 'where'=>'sid ='.$this->staff [0] ['sid'],
  62. 'desc'=>'itineraryDate',
  63. 'asArray' => true
  64. ));
  65. return date("Y-m-d",strtotime("+1 day",strtotime($itineraryDetail['itineraryDate'])));
  66. }
  67. public function beforeRun($resource, $action) {
  68. Doo::loadClass ( 'XDeode' );
  69. $XDeode = new XDeode ( 5 );
  70. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  71. // 单独判断公司汇总的访问权限
  72. if ($action == 'companyCategoryCollect') {
  73. Doo::loadModel ( "receiptAuthorityManage" );
  74. $invoiceCompanyManage = new receiptAuthorityManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request-statistics' );
  78. }
  79. Doo::loadModel ( 'staff' );
  80. $staff = new staff ();
  81. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  82. $accessModular = 'RECEIPTS';
  83. if (empty ( $detail ['cldAccessArray'] ))
  84. die ( 'illegal request' );
  85. else {
  86. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  87. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  88. $flag = true;
  89. } else {
  90. $flag = false;
  91. }
  92. } else {
  93. die ( 'illegal request' );
  94. }
  95. }
  96. if (! $flag)
  97. die ( 'illegal request' );
  98. }
  99. function __construct() {
  100. if (isset ( $_COOKIE ["staff"] )) {
  101. if (! empty ( $_COOKIE ["staff"] )) {
  102. Doo::loadModel ( 'staff' );
  103. Doo::loadModel ( 'verify' );
  104. $verify = new verify ();
  105. $staff = new staff ();
  106. Doo::loadModel ( "execute" );
  107. $execute = new execute ();
  108. $verifyList = $verify->find ( array (
  109. 'select' => 'staff',
  110. 'asArray' => true
  111. ) );
  112. $list = array ();
  113. // 判断角色的审批权限
  114. foreach ( $verifyList as $key => $value ) {
  115. $ver = json_decode ( $value ['staff'] );
  116. foreach ( $ver as $k => $v ) {
  117. if ($v [1] == 'ROLE') {
  118. $roleList = json_decode ( $v [3] );
  119. foreach ( $roleList as $t => $g ) {
  120. $gList = explode ( "_", $g );
  121. array_push ( $list, $gList [0] );
  122. // print_r($list);
  123. }
  124. } else
  125. array_push ( $list, $v [0] );
  126. }
  127. }
  128. // 判断执行人的审批权限
  129. $executeList = $execute->find ( array (
  130. 'where'=>'mold !="日常收支"',
  131. 'select' => 'staff',
  132. 'asArray' => true
  133. ) );
  134. $list2 = array ();
  135. foreach ( $executeList as $key => $value ) {
  136. $ver = json_decode ( $value ['staff'] );
  137. foreach ( $ver as $k => $v ) {
  138. array_push ( $list2, $v [0] );
  139. }
  140. }
  141. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  142. $eidList = array_filter ( explode ( ",", $eidList ) );
  143. $this->executeId = array_merge ( $list2, $eidList );
  144. //print_r($this->executeId);
  145. $this->verifyId = $list;
  146. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  147. // 检测用户信息完成
  148. $this->data ['isStaffCompleteMsg'] = false;
  149. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  150. if (! empty ( $detail ))
  151. $this->data ['isStaffCompleteMsg'] = true;
  152. return "/";
  153. }
  154. }
  155. Doo::loadCore ( 'uri/DooUriRouter' );
  156. $router = new DooUriRouter ();
  157. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  158. if ($routeRs ['1'] != "login") {
  159. header ( 'Content-Type:text/html;charset=utf-8' );
  160. @header ( "Location: /login" );
  161. }
  162. }
  163. /**
  164. * 费用首页
  165. */
  166. function saeaBorad() {
  167. $travel= $this->get_args ( 'travel' ) ? $this->get_args ( 'travel' ) : "";
  168. Doo::loadModel ( 'receipt' );
  169. $receipt = new receipt ();
  170. Doo::loadModel ( 'verify' );
  171. $verify = new verify ();
  172. Doo::loadModel ( 'L_category' );
  173. $lCategory = new L_category ();
  174. Doo::loadModel ( "role" );
  175. $role = new role ();
  176. Doo::loadModel ( "receiptLog" );
  177. $receiptLog = new receiptLog ();
  178. Doo::loadModel ( 'accountItem' );
  179. $accountItem = new accountItem ();
  180. Doo::loadClass ( 'XDeode' );
  181. $XDeode = new XDeode ( 7 );
  182. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  183. $receiptDetail = $receipt->find ( array (
  184. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  185. 'desc' => 'rid',
  186. 'asArray' => true
  187. ) );
  188. foreach ( $receiptDetail as $key => $value ) {
  189. $receiptDetail [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  190. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  191. $veList = $verify->getOne ( array (
  192. 'where' => 'vid=' . $value ['verify'],
  193. 'asArray' => true
  194. ) );
  195. $v = json_decode ( $veList ['staff'] );
  196. array_push ( $v [0], $veList ['description'] );
  197. foreach ( $v as $n => $m ) {
  198. if ($m ['1'] == 'ROLE') {
  199. $roleInfo = $role->getOne ( array (
  200. 'where' => 'rid=' . $m [0],
  201. 'asArray' => true
  202. ) );
  203. $v [$n] [1] = $roleInfo ['name'];
  204. }
  205. }
  206. $receiptDetail [$key] ['staff'] = $v;
  207. $category = $lCategory->getOne ( array (
  208. 'where' => 'cid=' . $value ['cid'],
  209. 'asArray' => true
  210. ) );
  211. $receiptDetail [$key] ['category'] = $category ['title'];
  212. }
  213. // print_r($receiptLogList);
  214. Doo::loadModel ( 'RAssist' );
  215. $RAssist = new RAssist ();
  216. $receiptExtendList=$RAssist->getRAssistBySid($this->staff[0]['sid']);
  217. //费用项目
  218. $acItem = $accountItem->find ( array ('asArray' => true) );
  219. if ($travel=='success'){
  220. $data ['travel'] =true;
  221. }else{
  222. $data ['travel'] =false;
  223. }
  224. $data ['acItem'] = $acItem;
  225. $data ['receiptExtendList'] = $receiptExtendList;
  226. $data ['receiptLogList'] = $receiptLogList;
  227. $data ['receiptDetail'] = $receiptDetail;
  228. $data ['memu'] = "receipt";
  229. $data ['staff'] = $this->staff;
  230. $data ['receiptMemu'] = 'saeaBorad';
  231. $data ['verifyId'] = $this->verifyId;
  232. $data ['executeId'] = $this->executeId;
  233. $this->render ( "/receipt/receiptFee", $data );
  234. }
  235. /**
  236. * 费用报销单-导流入哪个细分类
  237. */
  238. function receiptFeeDiversion(){
  239. $feeType= $this->get_args ( 'feeType' ) ? $this->get_args ( 'feeType' ) : "";
  240. if($feeType==2){
  241. return '/receipt/feeTravel';
  242. }elseif($feeType==3){
  243. return '/receipt/feeInternalTrain';
  244. }else{
  245. return '/receipt/feeAgency';
  246. }
  247. }
  248. private function _feeData(){
  249. Doo::loadModel ( 'L_category' );
  250. $lCategory = new L_category ();
  251. Doo::loadModel ( 'verify' );
  252. $verify = new verify ();
  253. Doo::loadModel ( 'accountItem' );
  254. $accountItem = new accountItem ();
  255. Doo::loadModel ( "role" );
  256. $role = new role ();
  257. $acItem = $accountItem->find ( array (
  258. 'asArray' => true
  259. ) );
  260. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  261. $data ['category'] = $lCategory->find ( array (
  262. 'asArray' => true
  263. ) );
  264. $data ['itineraryDate'] = $this->_itineraryDateMin();
  265. $data ['veList'] = $veList;
  266. $data ['acItem'] = $acItem;
  267. $data ['memu'] = "receipt";
  268. $data ['staff'] = $this->staff;
  269. $data ['receiptMemu'] = 'saeaBorad';
  270. $data ['verifyId'] = $this->verifyId;
  271. $data ['executeId'] = $this->executeId;
  272. return $data;
  273. }
  274. /**
  275. * 办事处相关费用
  276. */
  277. function feeAgency(){
  278. $data=$this->_feeData();
  279. $this->render ( "/receipt/feeAgency", $data );
  280. }
  281. /**
  282. * 办事处
  283. */
  284. function feeTravel(){
  285. $data=$this->_feeData();
  286. $this->render ( "/receipt/feeTravel", $data );
  287. }
  288. function feeInternalTrain(){
  289. $data=$this->_feeData();
  290. $this->render ( "/receipt/feeInternalTrain", $data );
  291. }
  292. /**
  293. * 添加费用报销单页面
  294. */
  295. function saeaCreate() {
  296. Doo::loadModel ( 'accountItem' );
  297. Doo::loadModel ( 'verify' );
  298. Doo::loadModel ( 'receipt' );
  299. Doo::loadModel ( 'L_category' );
  300. $lCategory = new L_category ();
  301. $receipt = new receipt ();
  302. $verify = new verify ();
  303. $accountItem = new accountItem ();
  304. Doo::loadModel ( "role" );
  305. $role = new role ();
  306. $acItem = $accountItem->find ( array (
  307. 'asArray' => true
  308. ) );
  309. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  310. $data ['category'] = $lCategory->find ( array (
  311. 'asArray' => true
  312. ) );
  313. $data ['veList'] = $veList;
  314. $data ['acItem'] = $acItem;
  315. $data ['memu'] = "receipt";
  316. $data ['staff'] = $this->staff;
  317. $data ['receiptMemu'] = 'saeaBorad';
  318. $data ['verifyId'] = $this->verifyId;
  319. $data ['executeId'] = $this->executeId;
  320. $this->render ( "/admin/saea_create", $data );
  321. }
  322. private function _storageItinerary($itinerary,$rid,$version=2){
  323. $itineraryJson=json_decode($itinerary,true);
  324. Doo::loadModel ( 'itinerary' );
  325. $itinerary = new itinerary ();
  326. $itinerary->delete(array('where' => 'rid=' . $rid ));
  327. if($version==2){
  328. foreach ($itineraryJson as $k=>$v){
  329. foreach ($v as $kk=>$vv){
  330. foreach ($vv as $key=>$value){
  331. if($key==0){
  332. $feeTraveItem=json_encode($value['feeTraveItem']);
  333. $itinerary = new itinerary ();
  334. $itinerary->rid=$rid;
  335. $itinerary->sid=$this->staff [0] ['sid'];
  336. $itinerary->itineraryDate=$value['departuredate'];
  337. $itinerary->itineraryCity=$value['departurecity'];
  338. $itinerary->feeTraveItem='';
  339. $itinerary->itineraryIndex=0;
  340. $itinerary->insert ();
  341. $itinerary = new itinerary ();
  342. $itinerary->rid=$rid;
  343. $itinerary->sid=$this->staff [0] ['sid'];
  344. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  345. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  346. $itinerary->feeTraveItem=$feeTraveItem;
  347. $itinerary->itineraryIndex=1;
  348. $itinerary->insert ();
  349. }else{
  350. $feeTraveItem=json_encode($value['feeTraveItem']);
  351. $itinerary = new itinerary ();
  352. $itinerary->rid=$rid;
  353. $itinerary->sid=$this->staff [0] ['sid'];
  354. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  355. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  356. $itinerary->feeTraveItem=$feeTraveItem;
  357. $itinerary->itineraryIndex=$key+1;
  358. $itinerary->insert ();
  359. }
  360. }
  361. }
  362. }
  363. }elseif($version==1){
  364. foreach ($itineraryJson as $key=>$value){
  365. if($key==0){
  366. $feeTraveItem=json_encode($value['feeTraveItem']);
  367. $itinerary = new itinerary ();
  368. $itinerary->rid=$rid;
  369. $itinerary->sid=$this->staff [0] ['sid'];
  370. $itinerary->itineraryDate=$value['departuredate'];
  371. $itinerary->itineraryCity=$value['departurecity'];
  372. $itinerary->feeTraveItem='';
  373. $itinerary->itineraryIndex=0;
  374. $itinerary->insert ();
  375. $itinerary = new itinerary ();
  376. $itinerary->rid=$rid;
  377. $itinerary->sid=$this->staff [0] ['sid'];
  378. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  379. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  380. $itinerary->feeTraveItem=$feeTraveItem;
  381. $itinerary->itineraryIndex=1;
  382. $itinerary->insert ();
  383. }else{
  384. $feeTraveItem=json_encode($value['feeTraveItem']);
  385. $itinerary = new itinerary ();
  386. $itinerary->rid=$rid;
  387. $itinerary->sid=$this->staff [0] ['sid'];
  388. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  389. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  390. $itinerary->feeTraveItem=$feeTraveItem;
  391. $itinerary->itineraryIndex=$key+1;
  392. $itinerary->insert ();
  393. }
  394. }
  395. }else{
  396. die ( '行程单版本不正确' );
  397. }
  398. }
  399. private function _verificationItinerary($itinerary){
  400. Doo::loadModel ( 'itinerary' );
  401. $itineraryObj = new itinerary ();
  402. if(empty($itinerary)){
  403. header ( 'Content-Type:text/html;charset=utf-8' );
  404. die ( '请填写行程单' );
  405. }
  406. $itineraryJson=json_decode($itinerary,true);
  407. foreach ($itineraryJson as $k=>$v){
  408. foreach ($v as $kk=>$vv){
  409. foreach ($vv as $key=>$value){
  410. if(empty($value['departuredate'])||empty($value['arrivalsdate'])){
  411. header ( 'Content-Type:text/html;charset=utf-8' );
  412. die ( '有行程的日期未设置' );
  413. }
  414. }
  415. }
  416. }
  417. $itineraryDate=array();$sql=array();
  418. foreach ($itineraryJson as $k=>$v){
  419. foreach ($v as $kk=>$vv){
  420. foreach ($vv as $key=>$value){
  421. if($key==0){
  422. array_push($itineraryDate, $value['departuredate']);
  423. array_push($itineraryDate, substr($value['arrivalsdate'],1));
  424. array_push($sql,'?');array_push($sql,'?');
  425. }else{
  426. array_push($itineraryDate, substr($value['arrivalsdate'],1));
  427. array_push($sql,'?');
  428. }
  429. }
  430. }
  431. }
  432. array_push($itineraryDate, $this->staff [0] ['sid']);
  433. $sql=implode(',',$sql);
  434. // $itineraryDate=array();$sql=array();
  435. // foreach ($itineraryJson as $key=>$value){
  436. // if($key==0){
  437. // array_push($itineraryDate, $value['departuredate']);
  438. // array_push($itineraryDate, substr($value['arrivalsdate'],1));
  439. // array_push($sql,'?');array_push($sql,'?');
  440. // }else{
  441. // array_push($itineraryDate, substr($value['arrivalsdate'],1));
  442. // array_push($sql,'?');
  443. // }
  444. // }
  445. // array_push($itineraryDate, $this->staff [0] ['sid']);
  446. // $sql=implode(',',$sql);
  447. if(empty($sql)){
  448. header ( 'Content-Type:text/html;charset=utf-8' );
  449. die ( '请填写行程单-2' );
  450. }
  451. $qualification=array(
  452. 'where' => 'itineraryDate in ('.$sql.') and sid=? ',
  453. 'param' => $itineraryDate,
  454. 'asArray' => TRUE);
  455. $itDateList=$itineraryObj->find($qualification);
  456. if(empty($itDateList)){
  457. return false;
  458. }else{
  459. return true;
  460. }
  461. }
  462. private function _buildFeeData($receiptClass=1,$itinerary=''){
  463. $agency = $this->get_args ( 'agency' );
  464. $travel = $this->get_args ( 'travel' );
  465. $train = $this->get_args ( 'train' );
  466. $other = $this->get_args ( 'other' );
  467. $inttrain = $this->get_args ( 'inttrain' );
  468. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  469. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  470. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  471. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  472. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  473. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  474. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  475. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  476. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  477. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  478. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  479. header ( 'Content-Type:text/html;charset=utf-8' );
  480. die ( '请填写联行号' );
  481. }
  482. if($receiptClass==2){
  483. //TODO 日期检测
  484. if($this->_verificationItinerary($itinerary)){
  485. header ( 'Content-Type:text/html;charset=utf-8' );
  486. die ( '已申请过类此日期的行程' );
  487. }
  488. }
  489. $itinerary=str_replace('\n','<br/>',$itinerary);
  490. Doo::loadModel ( 'receipt' );
  491. Doo::loadModel ( 'receiptDetail' );
  492. Doo::loadModel ( 'accountItem' );
  493. $accountItem = new accountItem ();
  494. $receipt = new receipt ();
  495. Doo::loadModel ( 'enclosur' );
  496. Doo::loadModel ( 'execute' );
  497. $execute = new execute ();
  498. $executeDetail = $execute->getOne ( array (
  499. 'where' => 'mold="报销单执行人"',
  500. 'asArray' => true
  501. ) );
  502. $aItem = $accountItem->find ( array (
  503. 'asArray' => true
  504. ) );
  505. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  506. $ag = $tr = $ta = $ot= $it = 0;
  507. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  508. foreach ( $aItem as $key => $value ) {
  509. if ($value ['category'] == $this->AGENCY) {
  510. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  511. array_push ( $accountJson [$this->AGENCY], array (
  512. 'aid' => $value ['aid'],
  513. 'name' => $value ['name'],
  514. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  515. ) );
  516. $sum += $agency [$ag];
  517. $agencySum += $agency [$ag];
  518. }
  519. $ag ++;
  520. }
  521. if ($value ['category'] == $this->TRAVEL) {
  522. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  523. array_push ( $accountJson [$this->TRAVEL], array (
  524. 'aid' => $value ['aid'],
  525. 'name' => $value ['name'],
  526. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  527. ) );
  528. $sum += $travel [$tr];
  529. $travelSum += $travel [$tr];
  530. }
  531. $tr ++;
  532. }
  533. if ($value ['category'] == $this->TRAIN) {
  534. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  535. array_push ( $accountJson [$this->TRAIN], array (
  536. 'aid' => $value ['aid'],
  537. 'name' => $value ['name'],
  538. 'price' => number_format ( $train [$ta], 2, '.', '' )
  539. ) );
  540. $sum += $train [$ta];
  541. $trainSum += $train [$ta];
  542. }
  543. $ta ++;
  544. }
  545. if ($value ['category'] == $this->INTTRAIN) {
  546. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  547. array_push ( $accountJson [$this->INTTRAIN], array (
  548. 'aid' => $value ['aid'],
  549. 'name' => $value ['name'],
  550. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  551. ) );
  552. $sum += $inttrain [$it];
  553. $inttrainSum += $inttrain [$it];
  554. }
  555. $it ++;
  556. }
  557. if ($value ['category'] == $this->OTHER) {
  558. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  559. array_push ( $accountJson [$this->OTHER], array (
  560. 'aid' => $value ['aid'],
  561. 'name' => $value ['name'],
  562. 'price' => number_format ( $other [$ot], 2, '.', '' )
  563. ) );
  564. $sum += $other [$ot];
  565. $otherSum += $other [$ot];
  566. }
  567. $ot ++;
  568. }
  569. }
  570. $accountJson ['cSum'] = array (
  571. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  572. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  573. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  574. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  575. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  576. );
  577. // 报销单
  578. $receipt->accountItem = json_encode ( $accountJson );
  579. $receipt->staff = $this->staff [0] ['sid'];
  580. $receipt->sum = number_format ( $sum, 2, '.', '' );
  581. $receipt->date = date ( "Y-m-d" );
  582. $receipt->cid = $cid;
  583. $receipt->status = 5;
  584. // 修改审批流程加入角色
  585. $receipt->verify = $verify;
  586. $receipt->executeCopy = $executeDetail ['staff'];
  587. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  588. $order = array (
  589. "\r\n",
  590. "\n",
  591. "\r"
  592. );
  593. $replace = '<br/>';
  594. $explanation = str_replace ( $order, $replace, $explanation );
  595. $receipt->explanation = $explanation;
  596. $receipt->receiptClass = $receiptClass;
  597. $receipt->itinerary2=$itinerary;
  598. $receipt->remittanceName = $remittanceName;
  599. $receipt->bankName = $bankName;
  600. $receipt->bankNumber = $bankNumber;
  601. $receipt->remittanceBankType = $remittanceBankType;
  602. if ($remittanceBankType == 1) {
  603. $receipt->coupletNumber = $coupletNumber;
  604. }
  605. $rid = $receipt->insert ();
  606. //记录行程单
  607. $this->_storageItinerary($itinerary,$rid);
  608. // 附件
  609. if (! empty ( $enclosurName )) {
  610. $enclosurArray = explode ( '-', $enclosurName );
  611. foreach ( $enclosurArray as $value ) {
  612. $enclosur = new enclosur ();
  613. $enclosur->name = $value;
  614. $enclosur->rid = $rid;
  615. $enclosur->insert ();
  616. }
  617. }
  618. // 报销详情
  619. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  620. $receiptDetail = new receiptDetail ();
  621. $receiptDetail->staff = $this->staff [0] ['sid'];
  622. $receiptDetail->item = $value ['name'];
  623. $receiptDetail->itemCategory = $this->AGENCY;
  624. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  625. $receiptDetail->date = date ( "Y-m-d" );
  626. $receiptDetail->cid = $cid;
  627. $receiptDetail->rid = $rid;
  628. $receiptDetail->status = 4;
  629. $receiptDetail->insert ();
  630. }
  631. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  632. $receiptDetail = new receiptDetail ();
  633. $receiptDetail->staff = $this->staff [0] ['sid'];
  634. $receiptDetail->item = $value ['name'];
  635. $receiptDetail->itemCategory = $this->TRAVEL;
  636. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  637. $receiptDetail->date = date ( "Y-m-d" );
  638. $receiptDetail->cid = $cid;
  639. $receiptDetail->rid = $rid;
  640. $receiptDetail->status = 4;
  641. $receiptDetail->insert ();
  642. }
  643. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  644. $receiptDetail = new receiptDetail ();
  645. $receiptDetail->staff = $this->staff [0] ['sid'];
  646. $receiptDetail->item = $value ['name'];
  647. $receiptDetail->itemCategory = $this->TRAIN;
  648. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  649. $receiptDetail->date = date ( "Y-m-d" );
  650. $receiptDetail->cid = $cid;
  651. $receiptDetail->rid = $rid;
  652. $receiptDetail->status = 4;
  653. $receiptDetail->insert ();
  654. }
  655. // 内训
  656. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  657. $receiptDetail = new receiptDetail ();
  658. $receiptDetail->staff = $this->staff [0] ['sid'];
  659. $receiptDetail->item = $value ['name'];
  660. $receiptDetail->itemCategory = $this->INTTRAIN;
  661. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  662. $receiptDetail->date = date ( "Y-m-d" );
  663. $receiptDetail->cid = $cid;
  664. $receiptDetail->rid = $rid;
  665. $receiptDetail->status = 4;
  666. $receiptDetail->insert ();
  667. }
  668. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  669. $receiptDetail = new receiptDetail ();
  670. $receiptDetail->staff = $this->staff [0] ['sid'];
  671. $receiptDetail->item = $value ['name'];
  672. $receiptDetail->itemCategory = $this->OTHER;
  673. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  674. $receiptDetail->date = date ( "Y-m-d" );
  675. $receiptDetail->cid = $cid;
  676. $receiptDetail->rid = $rid;
  677. $receiptDetail->status = 4;
  678. $receiptDetail->insert ();
  679. }
  680. return true;
  681. } else
  682. return false;
  683. }
  684. function addReceipt() {
  685. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  686. if ($this->_buildFeeData(1)) {
  687. return "/saeaBorad";
  688. } else{
  689. die ( 'illegal request' );
  690. }
  691. }
  692. function addFeeTravel(){
  693. $itinerary = $_POST['itinerary'] ? $_POST['itinerary'] : "";
  694. $itineraryList=json_decode($itinerary,true);
  695. // foreach ($itineraryList as $key=>$value){
  696. // if(empty($value['departuredate'])||empty($value['departurecity'])){
  697. // header ( 'Content-Type:text/html;charset=utf-8' );
  698. // die ( '请设置出发地和出发日期' );
  699. // }
  700. // }
  701. if ($this->_buildFeeData(2,$itinerary)) {
  702. return "/saeaBorad?travel=success";
  703. } else{
  704. die ( 'illegal request' );
  705. }
  706. }
  707. function addFeeInternalTrain(){
  708. if ($this->_buildFeeData(3)) {
  709. return "/saeaBorad";
  710. } else{
  711. die ( 'illegal request' );
  712. }
  713. }
  714. function referReceipt() {
  715. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  716. Doo::loadModel ( 'receipt' );
  717. Doo::loadModel ( 'verify' );
  718. $verify = new verify ();
  719. $receipt = new receipt ();
  720. Doo::loadModel ( 'L_category' );
  721. $lCategory = new L_category ();
  722. Doo::loadModel ( "role" );
  723. $role = new role ();
  724. $receiptDetail = $receipt->find ( array (
  725. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  726. 'asArray' => true
  727. ) );
  728. if (empty ( $receiptDetail ))
  729. return "/addReceipt";
  730. foreach ( $receiptDetail as $key => $value ) {
  731. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  732. $veList = $verify->getOne ( array (
  733. 'where' => 'vid=' . $value ['verify'],
  734. 'asArray' => true
  735. ) );
  736. $v = json_decode ( $veList ['staff'] );
  737. array_push ( $v [0], $veList ['description'] );
  738. foreach ( $v as $n => $m ) {
  739. if ($m ['1'] == 'ROLE') {
  740. $roleInfo = $role->getOne ( array (
  741. 'where' => 'rid=' . $m [0],
  742. 'asArray' => true
  743. ) );
  744. $v [$n] [1] = $roleInfo ['name'];
  745. }
  746. }
  747. $receiptDetail [$key] ['staff'] = $v;
  748. $category = $lCategory->getOne ( array (
  749. 'where' => 'cid=' . $value ['cid'],
  750. 'asArray' => true
  751. ) );
  752. $receiptDetail [$key] ['category'] = $category ['title'];
  753. }
  754. // print_r($receiptDetail);
  755. $data ['receiptDetail'] = $receiptDetail;
  756. $data ['memu'] = "receipt";
  757. $data ['staff'] = $this->staff;
  758. $data ['receiptMemu'] = 'saeaCreate';
  759. $data ['verifyId'] = $this->verifyId;
  760. $data ['executeId'] = $this->executeId;
  761. $this->render ( "/admin/saea_confirm", $data );
  762. }
  763. function editReceipt() {
  764. // edit status 4
  765. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  766. Doo::loadClass ( 'XDeode' );
  767. $XDeode = new XDeode ( 7 );
  768. $rid = $XDeode->decode ( $ridKey );
  769. if (empty ( $rid )) {
  770. die ( 'illegal request-id' );
  771. }
  772. // echo $rid.'sd';
  773. Doo::loadModel ( 'accountItem' );
  774. Doo::loadModel ( 'verify' );
  775. Doo::loadModel ( 'receipt' );
  776. $receipt = new receipt ();
  777. $verify = new verify ();
  778. $accountItem = new accountItem ();
  779. Doo::loadModel ( 'L_category' );
  780. $lCategory = new L_category ();
  781. Doo::loadModel ( "role" );
  782. $role = new role ();
  783. Doo::loadModel ( 'enclosur' );
  784. $enclosur = new enclosur ();
  785. $receiptDetail = $receipt->getOne ( array (
  786. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  787. 'asArray' => true
  788. ) );
  789. if (empty ( $receiptDetail )) {
  790. die ( 'illegal request-emptyData' );
  791. }
  792. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  793. $acItem = $accountItem->find ( array (
  794. 'asArray' => true
  795. ) );
  796. $veList = $verify->getVerifyBySubordinate ( 'RECEIPT' );
  797. // 配置编辑信息
  798. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  799. foreach ( $acItem as $key => $value ) {
  800. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  801. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  802. $acItem [$key] ['price'] = $v ['price'];
  803. }
  804. }
  805. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  806. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  807. $acItem [$key] ['price'] = $v ['price'];
  808. }
  809. }
  810. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  811. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  812. $acItem [$key] ['price'] = $v ['price'];
  813. }
  814. }
  815. // 内训
  816. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  817. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  818. $acItem [$key] ['price'] = $v ['price'];
  819. }
  820. }
  821. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  822. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  823. $acItem [$key] ['price'] = $v ['price'];
  824. }
  825. }
  826. }
  827. //$receiptDetail['itinerary']=str_replace('\n','<br/>',$receiptDetail['itinerary']);
  828. //nl2br($receiptDetail['explanation']);
  829. Doo::loadModel ( 'itinerary' );
  830. $itinerary = new itinerary ();
  831. $itinerary->delete(array('where' => 'rid=' . $receiptDetail['rid'] ));
  832. $receiptDetail['explanation']= str_replace('<br/>',"\n",$receiptDetail['explanation']);
  833. $receiptDetail['itinerary']=str_replace('\n','<br/>',$receiptDetail['itinerary']);
  834. $data ['category'] = $lCategory->find ( array (
  835. 'asArray' => true
  836. ) );
  837. $data ['cSum'] = $accountItemList ['cSum'];
  838. $data ['sum'] = $receiptDetail ['sum'];
  839. $data ['enclosurList'] = $enclosurList;
  840. $data ['receiptDetail'] = $receiptDetail;
  841. $data ['veList'] = $veList;
  842. $data ['acItem'] = $acItem;
  843. $data ['memu'] = "receipt";
  844. $data ['staff'] = $this->staff;
  845. $data ['receiptMemu'] = 'saeaBorad';
  846. $data ['verify'] = $receiptDetail ['verify'];
  847. $data ['verifyId'] = $this->verifyId;
  848. $data ['executeId'] = $this->executeId;
  849. $data ['rid'] = $ridKey;
  850. if($receiptDetail['receiptClass']==1){
  851. $this->render ( "/receipt/feeAgencyEdi", $data );
  852. }elseif($receiptDetail['receiptClass']==2){
  853. if(!empty($receiptDetail['itinerary2'])){
  854. //TODO 报销说明
  855. $this->render ( "/receipt/feeTravelEdi2", $data );
  856. }else{
  857. $this->render ( "/receipt/feeTravelEdi", $data );
  858. }
  859. }elseif($receiptDetail['receiptClass']==3){
  860. $this->render ( "/receipt/feeInternalTrainEdi", $data );
  861. }else{
  862. $this->render ( "/admin/saea_edit", $data );
  863. //die ( 'illegal request-renderHtml' );
  864. }
  865. }
  866. function updateReceipt() {
  867. $agency = $this->get_args ( 'agency' );
  868. $travel = $this->get_args ( 'travel' );
  869. $train = $this->get_args ( 'train' );
  870. $other = $this->get_args ( 'other' );
  871. $inttrain = $this->get_args ( 'inttrain' );
  872. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  873. $traveVer = $this->get_args ( 'traveVer' ) ? $this->get_args ( 'traveVer' ) : "trave2";
  874. $itinerary = $_POST['itinerary'];
  875. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  876. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  877. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  878. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  879. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  880. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  881. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  882. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  883. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  884. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  885. Doo::loadClass ( 'XDeode' );
  886. $XDeode = new XDeode ( 7 );
  887. $rid = $XDeode->decode ( $ridKey );
  888. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  889. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  890. header ( 'Content-Type:text/html;charset=utf-8' );
  891. die ( '请填写联行号' );
  892. }
  893. if($traveVer!='trave1'){
  894. if($receiptClass=='trave'){
  895. //TODO 日期检测
  896. if($this->_verificationItinerary($itinerary)){
  897. header ( 'Content-Type:text/html;charset=utf-8' );
  898. die ( '已申请过类此日期的行程' );
  899. }
  900. }
  901. }
  902. Doo::loadModel ( 'receipt' );
  903. Doo::loadModel ( 'receiptDetail' );
  904. Doo::loadModel ( 'accountItem' );
  905. $accountItem = new accountItem ();
  906. $receipt = new receipt ();
  907. Doo::loadModel ( 'enclosur' );
  908. Doo::loadModel ( 'execute' );
  909. $execute = new execute ();
  910. $receiptDetail = $receipt->getOne ( array (
  911. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  912. 'asArray' => true
  913. ) );
  914. if (empty ( $receiptDetail )) {
  915. return "/saeaBorad";
  916. }
  917. //TODO 存储行程单-兼容旧版本的行程单
  918. $itinerary=str_replace('\n','<br/>',$itinerary);
  919. if(!empty($receiptDetail['itinerary2'])){
  920. $this->_storageItinerary($itinerary,$rid);
  921. }else{
  922. $this->_storageItinerary($itinerary,$rid,1);
  923. }
  924. if ($receiptDetail ['Rtype'] == 1) {
  925. $executeDetail = $execute->getOne ( array (
  926. 'where' => 'mold="借款费用执行人"',
  927. 'asArray' => true
  928. ) );
  929. } else {
  930. $executeDetail = $execute->getOne ( array (
  931. 'where' => 'mold="报销单执行人"',
  932. 'asArray' => true
  933. ) );
  934. }
  935. $aItem = $accountItem->find ( array (
  936. 'asArray' => true
  937. ) );
  938. $accountJson [$this->AGENCY] = $accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  939. $ag = $tr = $ta = $ot = $it = 0;
  940. $sum = $agencySum = $travelSum = $trainSum = $inttrainSum = $otherSum = 0;
  941. foreach ( $aItem as $key => $value ) {
  942. if ($value ['category'] == $this->AGENCY) {
  943. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  944. array_push ( $accountJson [$this->AGENCY], array (
  945. 'aid' => $value ['aid'],
  946. 'name' => $value ['name'],
  947. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  948. ) );
  949. $sum += $agency [$ag];
  950. $agencySum += $agency [$ag];
  951. }
  952. $ag ++;
  953. }
  954. if ($value ['category'] == $this->TRAVEL) {
  955. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  956. array_push ( $accountJson [$this->TRAVEL], array (
  957. 'aid' => $value ['aid'],
  958. 'name' => $value ['name'],
  959. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  960. ) );
  961. $sum += $travel [$tr];
  962. $travelSum += $travel [$tr];
  963. }
  964. $tr ++;
  965. }
  966. if ($value ['category'] == $this->TRAIN) {
  967. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  968. array_push ( $accountJson [$this->TRAIN], array (
  969. 'aid' => $value ['aid'],
  970. 'name' => $value ['name'],
  971. 'price' => number_format ( $train [$ta], 2, '.', '' )
  972. ) );
  973. $sum += $train [$ta];
  974. $trainSum += $train [$ta];
  975. }
  976. $ta ++;
  977. }
  978. if ($value ['category'] == $this->INTTRAIN) {
  979. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  980. array_push ( $accountJson [$this->INTTRAIN], array (
  981. 'aid' => $value ['aid'],
  982. 'name' => $value ['name'],
  983. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  984. ) );
  985. $sum += $inttrain [$it];
  986. $inttrainSum += $inttrain [$it];
  987. }
  988. $it ++;
  989. }
  990. if ($value ['category'] == $this->OTHER) {
  991. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  992. array_push ( $accountJson [$this->OTHER], array (
  993. 'aid' => $value ['aid'],
  994. 'name' => $value ['name'],
  995. 'price' => number_format ( $other [$ot], 2, '.', '' )
  996. ) );
  997. $sum += $other [$ot];
  998. $otherSum += $other [$ot];
  999. }
  1000. $ot ++;
  1001. }
  1002. }
  1003. $accountJson ['cSum'] = array (
  1004. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1005. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1006. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1007. 'inttrainSum' => number_format ( $inttrainSum, 2, '.', '' ),
  1008. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1009. );
  1010. // 报销单
  1011. $rid = $receipt->rid = $receiptDetail ['rid'];
  1012. $receipt->accountItem = json_encode ( $accountJson );
  1013. $receipt->staff = $this->staff [0] ['sid'];
  1014. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1015. $receipt->date = date ( "Y-m-d" );
  1016. $receipt->cid = $cid;
  1017. if (($receiptDetail ['status'] != 4)) {
  1018. if ($receiptDetail ['Rtype'] == 1) {
  1019. $receipt->status = 7;
  1020. } else {
  1021. $receipt->status = 5;
  1022. }
  1023. }
  1024. if ($receiptDetail != 4 && ! empty ( $verify ))
  1025. $receipt->verify = $verify;
  1026. $receipt->executeCopy = $executeDetail ['staff'];
  1027. $order = array (
  1028. "\r\n",
  1029. "\n",
  1030. "\r"
  1031. );
  1032. $replace = '<br/>';
  1033. $explanation = str_replace ( $order, $replace, $explanation );
  1034. $receipt->explanation = $explanation;
  1035. if($receiptClass=='trave'){
  1036. if(!empty($receiptDetail['itinerary2'])){//行程单版本
  1037. $receipt->itinerary2=$itinerary;
  1038. }else{
  1039. $receipt->itinerary=$itinerary;
  1040. }
  1041. }
  1042. $receipt->remittanceName = $remittanceName;
  1043. $receipt->bankName = $bankName;
  1044. $receipt->bankNumber = $bankNumber;
  1045. $receipt->remittanceBankType = $remittanceBankType;
  1046. if ($remittanceBankType == 1)
  1047. $receipt->coupletNumber = $coupletNumber;
  1048. $receipt->update ();
  1049. $receiptDetail = new receiptDetail ();
  1050. $receiptDetail->delete ( array (
  1051. 'where' => 'rid=' . $rid
  1052. ) );
  1053. // 报销详情
  1054. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1055. $receiptDetail = new receiptDetail ();
  1056. $receiptDetail->staff = $this->staff [0] ['sid'];
  1057. $receiptDetail->item = $value ['name'];
  1058. $receiptDetail->itemCategory = $this->AGENCY;
  1059. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1060. $receiptDetail->date = date ( "Y-m-d" );
  1061. $receiptDetail->cid = $cid;
  1062. $receiptDetail->rid = $rid;
  1063. $receiptDetail->status = 4;
  1064. $receiptDetail->insert ();
  1065. }
  1066. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1067. $receiptDetail = new receiptDetail ();
  1068. $receiptDetail->staff = $this->staff [0] ['sid'];
  1069. $receiptDetail->item = $value ['name'];
  1070. $receiptDetail->itemCategory = $this->TRAVEL;
  1071. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1072. $receiptDetail->date = date ( "Y-m-d" );
  1073. $receiptDetail->cid = $cid;
  1074. $receiptDetail->rid = $rid;
  1075. $receiptDetail->status = 4;
  1076. $receiptDetail->insert ();
  1077. }
  1078. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1079. $receiptDetail = new receiptDetail ();
  1080. $receiptDetail->staff = $this->staff [0] ['sid'];
  1081. $receiptDetail->item = $value ['name'];
  1082. $receiptDetail->itemCategory = $this->TRAIN;
  1083. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1084. $receiptDetail->date = date ( "Y-m-d" );
  1085. $receiptDetail->cid = $cid;
  1086. $receiptDetail->rid = $rid;
  1087. $receiptDetail->status = 4;
  1088. $receiptDetail->insert ();
  1089. }
  1090. // 内训
  1091. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  1092. $receiptDetail = new receiptDetail ();
  1093. $receiptDetail->staff = $this->staff [0] ['sid'];
  1094. $receiptDetail->item = $value ['name'];
  1095. $receiptDetail->itemCategory = $this->INTTRAIN;
  1096. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1097. $receiptDetail->date = date ( "Y-m-d" );
  1098. $receiptDetail->cid = $cid;
  1099. $receiptDetail->rid = $rid;
  1100. $receiptDetail->status = 4;
  1101. $receiptDetail->insert ();
  1102. }
  1103. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1104. $receiptDetail = new receiptDetail ();
  1105. $receiptDetail->staff = $this->staff [0] ['sid'];
  1106. $receiptDetail->item = $value ['name'];
  1107. $receiptDetail->itemCategory = $this->OTHER;
  1108. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1109. $receiptDetail->date = date ( "Y-m-d" );
  1110. $receiptDetail->cid = $cid;
  1111. $receiptDetail->rid = $rid;
  1112. $receiptDetail->status = 4;
  1113. $receiptDetail->insert ();
  1114. }
  1115. // 附件
  1116. if (! empty ( $enclosurName )) {
  1117. $enclosurArray = explode ( '-', $enclosurName );
  1118. foreach ( $enclosurArray as $value ) {
  1119. $enclosur = new enclosur ();
  1120. $enclosur->name = $value;
  1121. $enclosur->rid = $rid;
  1122. $enclosur->insert ();
  1123. }
  1124. }
  1125. // return "/referReceipt/".$rid;
  1126. }
  1127. return "/saeaBorad";
  1128. }
  1129. function remitAdd() {
  1130. Doo::loadModel ( 'accountItem' );
  1131. Doo::loadModel ( 'verify' );
  1132. Doo::loadModel ( 'receipt' );
  1133. Doo::loadModel ( 'L_category' );
  1134. $lCategory = new L_category ();
  1135. $receipt = new receipt ();
  1136. $verify = new verify ();
  1137. $accountItem = new accountItem ();
  1138. Doo::loadModel ( "role" );
  1139. $role = new role ();
  1140. $acItem = $accountItem->find ( array (
  1141. 'asArray' => true
  1142. ) );
  1143. $veList = $verify->getVerifyBySubordinate('REMIT');
  1144. $data ['category'] = $lCategory->find ( array (
  1145. 'asArray' => true
  1146. ) );
  1147. $data ['veList'] = $veList;
  1148. $data ['acItem'] = $acItem;
  1149. $data ['memu'] = "receipt";
  1150. $data ['staff'] = $this->staff;
  1151. $data ['receiptMemu'] = 'saeaBorad';
  1152. $data ['verifyId'] = $this->verifyId;
  1153. $data ['executeId'] = $this->executeId;
  1154. $this->render ( "/admin/remitAdd", $data );
  1155. }
  1156. function remitAddDo() {
  1157. $agency = $this->get_args ( 'agency' );
  1158. $travel = $this->get_args ( 'travel' );
  1159. $train = $this->get_args ( 'train' );
  1160. $other = $this->get_args ( 'other' );
  1161. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1162. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1163. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1164. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1165. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1166. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1167. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1168. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1169. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1170. // print_r($agency);die;
  1171. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1172. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1173. header ( 'Content-Type:text/html;charset=utf-8' );
  1174. die ( '请填写联行号' );
  1175. }
  1176. Doo::loadModel ( 'receipt' );
  1177. Doo::loadModel ( 'receiptDetail' );
  1178. Doo::loadModel ( 'accountItem' );
  1179. $accountItem = new accountItem ();
  1180. $receipt = new receipt ();
  1181. Doo::loadModel ( 'enclosur' );
  1182. Doo::loadModel ( 'execute' );
  1183. $execute = new execute ();
  1184. $executeDetail = $execute->getOne ( array (
  1185. 'where' => 'mold="对公汇款执行人"',
  1186. 'asArray' => true
  1187. ) );
  1188. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  1189. $aItem = $accountItem->find ( array (
  1190. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  1191. 'asArray' => true
  1192. ) );
  1193. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1194. $ag = $tr = $ta = $ot = 0;
  1195. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1196. print_r($aItem);
  1197. foreach ( $aItem as $key => $value ) {
  1198. if ($value ['category'] == $this->AGENCY) {
  1199. if (isset ( $agency [$ag] )) {
  1200. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1201. array_push ( $accountJson [$this->AGENCY], array (
  1202. 'aid' => $value ['aid'],
  1203. 'name' => $value ['name'],
  1204. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1205. ) );
  1206. $sum += $agency [$ag];
  1207. $agencySum += $agency [$ag];
  1208. }
  1209. }
  1210. $ag ++;
  1211. }
  1212. }
  1213. $accountJson ['cSum'] = array (
  1214. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1215. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1216. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1217. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1218. );
  1219. //die;
  1220. // 报销单
  1221. $receipt->accountItem = json_encode ( $accountJson );
  1222. $receipt->staff = $this->staff [0] ['sid'];
  1223. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1224. $receipt->date = date ( "Y-m-d" );
  1225. $receipt->cid = $cid;
  1226. $receipt->status = 5;
  1227. $receipt->Rtype = 2;
  1228. // 修改审批流程加入角色
  1229. $receipt->verify = $verify;
  1230. $receipt->executeCopy = $executeDetail ['staff'];
  1231. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1232. $order = array (
  1233. "\r\n",
  1234. "\n",
  1235. "\r"
  1236. );
  1237. $replace = '<br/>';
  1238. $explanation = str_replace ( $order, $replace, $explanation );
  1239. $receipt->explanation = $explanation;
  1240. $receipt->remittanceName = $remittanceName;
  1241. $receipt->bankName = $bankName;
  1242. $receipt->bankNumber = $bankNumber;
  1243. $receipt->remittanceBankType = $remittanceBankType;
  1244. if ($remittanceBankType == 1)
  1245. $receipt->coupletNumber = $coupletNumber;
  1246. $rid = $receipt->insert ();
  1247. // 附件
  1248. if (! empty ( $enclosurName )) {
  1249. $enclosurArray = explode ( '-', $enclosurName );
  1250. foreach ( $enclosurArray as $value ) {
  1251. $enclosur = new enclosur ();
  1252. $enclosur->name = $value;
  1253. $enclosur->rid = $rid;
  1254. $enclosur->insert ();
  1255. }
  1256. // print_r($enclosurArray);die;
  1257. }
  1258. // 报销详情
  1259. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1260. $receiptDetail = new receiptDetail ();
  1261. $receiptDetail->staff = $this->staff [0] ['sid'];
  1262. $receiptDetail->item = $value ['name'];
  1263. $receiptDetail->itemCategory = $this->AGENCY;
  1264. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1265. $receiptDetail->date = date ( "Y-m-d" );
  1266. $receiptDetail->cid = $cid;
  1267. $receiptDetail->rid = $rid;
  1268. $receiptDetail->status = 4;
  1269. $receiptDetail->insert ();
  1270. }
  1271. return "/saeaBorad";
  1272. } else
  1273. die ( 'illegal request' );
  1274. }
  1275. function remitEdit() {
  1276. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1277. Doo::loadClass ( 'XDeode' );
  1278. $XDeode = new XDeode ( 7 );
  1279. $rid = $XDeode->decode ( $ridKey );
  1280. if (! is_numeric ( $rid ))
  1281. die ( 'illegal request' );
  1282. Doo::loadModel ( 'accountItem' );
  1283. Doo::loadModel ( 'verify' );
  1284. Doo::loadModel ( 'receipt' );
  1285. $receipt = new receipt ();
  1286. $verify = new verify ();
  1287. $accountItem = new accountItem ();
  1288. Doo::loadModel ( 'L_category' );
  1289. $lCategory = new L_category ();
  1290. Doo::loadModel ( "role" );
  1291. $role = new role ();
  1292. Doo::loadModel ( 'enclosur' );
  1293. $enclosur = new enclosur ();
  1294. $receiptDetail = $receipt->getOne ( array (
  1295. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  1296. 'asArray' => true
  1297. ) );
  1298. if (empty ( $receiptDetail ))
  1299. return "/saeaCreate";
  1300. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  1301. $acItem = $accountItem->find ( array (
  1302. 'asArray' => true
  1303. ) );
  1304. $veList = $verify->getVerifyBySubordinate('REMIT');
  1305. // 配置编辑信息
  1306. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1307. foreach ( $acItem as $key => $value ) {
  1308. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1309. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1310. $acItem [$key] ['price'] = $v ['price'];
  1311. }
  1312. }
  1313. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1314. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1315. $acItem [$key] ['price'] = $v ['price'];
  1316. }
  1317. }
  1318. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1319. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1320. $acItem [$key] ['price'] = $v ['price'];
  1321. }
  1322. }
  1323. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1324. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1325. $acItem [$key] ['price'] = $v ['price'];
  1326. }
  1327. }
  1328. }
  1329. $data ['category'] = $lCategory->find ( array (
  1330. 'asArray' => true
  1331. ) );
  1332. $data ['enclosurList'] = $enclosurList;
  1333. $data ['cSum'] = $accountItemList ['cSum'];
  1334. $data ['sum'] = $receiptDetail ['sum'];
  1335. $data ['receiptDetail'] = $receiptDetail;
  1336. $data ['veList'] = $veList;
  1337. $data ['acItem'] = $acItem;
  1338. $data ['memu'] = "receipt";
  1339. $data ['staff'] = $this->staff;
  1340. $data ['receiptMemu'] = 'saeaBorad';
  1341. $data ['verify'] = $receiptDetail ['verify'];
  1342. $data ['verifyId'] = $this->verifyId;
  1343. $data ['executeId'] = $this->executeId;
  1344. $data ['rid'] = $rid;
  1345. $data ['ridKey'] = $ridKey;
  1346. $this->render ( "/admin/remitEdit", $data );
  1347. }
  1348. function remitEdiDo() {
  1349. $agency = $this->get_args ( 'agency' );
  1350. $travel = $this->get_args ( 'travel' );
  1351. $train = $this->get_args ( 'train' );
  1352. $other = $this->get_args ( 'other' );
  1353. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1354. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1355. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1356. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1357. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1358. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1359. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1360. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1361. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1362. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1363. Doo::loadClass ( 'XDeode' );
  1364. $XDeode = new XDeode ( 7 );
  1365. $rid = $XDeode->decode ( $ridKey );
  1366. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1367. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1368. header ( 'Content-Type:text/html;charset=utf-8' );
  1369. die ( '请填写联行号' );
  1370. }
  1371. Doo::loadModel ( 'receipt' );
  1372. Doo::loadModel ( 'receiptDetail' );
  1373. Doo::loadModel ( 'accountItem' );
  1374. $accountItem = new accountItem ();
  1375. $receipt = new receipt ();
  1376. Doo::loadModel ( 'enclosur' );
  1377. $enclosur = new enclosur ();
  1378. Doo::loadModel ( 'execute' );
  1379. $execute = new execute ();
  1380. $executeDetail = $execute->getOne ( array (
  1381. 'where' => 'mold="对公汇款执行人"',
  1382. 'asArray' => true
  1383. ) );
  1384. $receiptDetail = $receipt->getOne ( array (
  1385. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  1386. 'asArray' => true
  1387. ) );
  1388. if (empty ( $receiptDetail ))
  1389. return "/saeaBorad";
  1390. $aItem = $accountItem->find ( array (
  1391. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  1392. 'asArray' => true
  1393. ) );
  1394. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1395. $ag = $tr = $ta = $ot = 0;
  1396. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1397. foreach ( $aItem as $key => $value ) {
  1398. if ($value ['category'] == $this->AGENCY) {
  1399. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1400. array_push ( $accountJson [$this->AGENCY], array (
  1401. 'aid' => $value ['aid'],
  1402. 'name' => $value ['name'],
  1403. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1404. ) );
  1405. $sum += $agency [$ag];
  1406. $agencySum += $agency [$ag];
  1407. }
  1408. $ag ++;
  1409. }
  1410. }
  1411. $accountJson ['cSum'] = array (
  1412. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1413. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1414. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1415. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1416. );
  1417. // 报销单
  1418. $rid = $receipt->rid = $receiptDetail ['rid'];
  1419. $receipt->accountItem = json_encode ( $accountJson );
  1420. $receipt->staff = $this->staff [0] ['sid'];
  1421. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1422. $receipt->date = date ( "Y-m-d" );
  1423. $receipt->cid = $cid;
  1424. if ($receiptDetail ['Rtype'] == 1)
  1425. $receipt->status = 7;
  1426. else
  1427. $receipt->status = 5;
  1428. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  1429. $receipt->verify = $verify;
  1430. $receipt->executeCopy = $executeDetail ['staff'];
  1431. $order = array (
  1432. "\r\n",
  1433. "\n",
  1434. "\r"
  1435. );
  1436. $replace = '<br/>';
  1437. $explanation = str_replace ( $order, $replace, $explanation );
  1438. $receipt->explanation = $explanation;
  1439. $receipt->remittanceName = $remittanceName;
  1440. $receipt->bankName = $bankName;
  1441. $receipt->bankNumber = $bankNumber;
  1442. $receipt->remittanceBankType = $remittanceBankType;
  1443. if ($remittanceBankType == 1)
  1444. $receipt->coupletNumber = $coupletNumber;
  1445. $receipt->update ();
  1446. $receiptDetail = new receiptDetail ();
  1447. $receiptDetail->delete ( array (
  1448. 'where' => 'rid=' . $rid
  1449. ) );
  1450. // 报销详情
  1451. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1452. $receiptDetail = new receiptDetail ();
  1453. $receiptDetail->staff = $this->staff [0] ['sid'];
  1454. $receiptDetail->item = $value ['name'];
  1455. $receiptDetail->itemCategory = $this->AGENCY;
  1456. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1457. $receiptDetail->date = date ( "Y-m-d" );
  1458. $receiptDetail->cid = $cid;
  1459. $receiptDetail->rid = $rid;
  1460. $receiptDetail->status = 4;
  1461. $receiptDetail->insert ();
  1462. }
  1463. // 附件
  1464. if (! empty ( $enclosurName )) {
  1465. $enclosurArray = explode ( '-', $enclosurName );
  1466. foreach ( $enclosurArray as $value ) {
  1467. $enclosur = new enclosur ();
  1468. $enclosur->name = $value;
  1469. $enclosur->rid = $rid;
  1470. $enclosur->insert ();
  1471. }
  1472. }
  1473. }
  1474. return "/saeaBorad";
  1475. }
  1476. function remitApproval() {
  1477. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1478. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  1479. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  1480. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  1481. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1482. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  1483. if (empty ( $status ))
  1484. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  1485. $vidList = array ();
  1486. $button = 0;
  1487. Doo::loadModel ( 'verify' );
  1488. Doo::loadModel ( 'receipt' );
  1489. Doo::loadModel ( 'staff' );
  1490. $staff = new staff ();
  1491. $receipt = new receipt ();
  1492. $verify = new verify ();
  1493. Doo::loadModel ( 'L_category' );
  1494. $Lcategory = new L_category ();
  1495. Doo::loadModel ( 'enclosur' );
  1496. $enclosur = new enclosur ();
  1497. // user verify ID
  1498. $verifyDetail = $verify->find ( array (
  1499. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  1500. 'asArray' => true
  1501. ) );
  1502. foreach ( $verifyDetail as $key => $value ) {
  1503. array_push ( $vidList, $value ['vid'] );
  1504. }
  1505. $vid = implode ( ",", $vidList );
  1506. if (empty ( $verifyDetail ))
  1507. $vid = 0;
  1508. $categoryList = $Lcategory->find ( array (
  1509. 'asArray' => true
  1510. ) );
  1511. $staffList = $staff->find ( array (
  1512. 'where' => 'cid=' . $cid,
  1513. 'asArray' => true
  1514. ) );
  1515. $ap = "";
  1516. if ($status == 4) {
  1517. $ap = 4;
  1518. $status = 2;
  1519. }
  1520. // get Receipt By verifyID status 2
  1521. $receiptList = $receipt->find ( array (
  1522. 'where' => 'rid =' . $rid . ' and status=2',
  1523. 'desc' => 'rid',
  1524. 'asArray' => true
  1525. ) );
  1526. if (empty ( $receiptList )) {
  1527. die ( 'illegal request' );
  1528. }
  1529. $Locate = 0;
  1530. $roleId = 0;
  1531. if ($ap == 4)
  1532. $status = 4;
  1533. foreach ( $receiptList as $key => $value ) {
  1534. $receiptList [$key] ['Locate'] = $Locate;
  1535. $Locate ++;
  1536. $receiptList [$key] ['reviseDetail'] = array ();
  1537. if (! empty ( $value ['reviseDetail'] ))
  1538. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1539. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1540. $categoryDetil = $Lcategory->getOne ( array (
  1541. 'where' => 'cid=' . $value ['cid'],
  1542. 'asArray' => true
  1543. ) );
  1544. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1545. // 检测编辑状态
  1546. $verifyList = $verify->getOne ( array (
  1547. 'where' => 'vid=' . $value ['verify'],
  1548. 'asArray' => true
  1549. ) );
  1550. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1551. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1552. Doo::loadModel ( 'role' );
  1553. $role = new role ();
  1554. // print_r($verifyList);
  1555. $flag = true;
  1556. $roleKey = 0;
  1557. $endStaffArray = array ();
  1558. $roleArrayCopy = array ();
  1559. foreach ( $verifyList as $k => $v ) {
  1560. // init verifyStaff
  1561. if ($v [1] == 'ROLE') {
  1562. if (! empty ( $verifyStaff )) {
  1563. $endStaffArray = end ( $verifyStaff );
  1564. if ($v [0] == $endStaffArray ['nextStaff']) {
  1565. $roleId = $v [0];
  1566. }
  1567. }
  1568. $roleVerify = json_decode ( $v [3], true );
  1569. $roleKey = $k;
  1570. $roleArray = array ();
  1571. $rolename = $role->getOne ( array (
  1572. 'where' => 'rid=' . $v [0],
  1573. 'asArray' => true
  1574. ) );
  1575. foreach ( $roleVerify as $o => $p ) {
  1576. $staffID = explode ( '_', $p );
  1577. $staffInfo = $staff->getOne ( array (
  1578. 'where' => 'sid=' . $staffID [0],
  1579. 'asArray' => true
  1580. ) );
  1581. // print_r($staffID);
  1582. $exp = array (
  1583. 0 => $staffInfo ['sid'],
  1584. 1 => $staffID [1],
  1585. 2 => $staffInfo ['avatar'],
  1586. 'date' => '',
  1587. 'date' => '',
  1588. 'opinion' => '',
  1589. 'status' => '',
  1590. 'rolename' => $rolename ['name']
  1591. );
  1592. array_push ( $roleArray, $exp );
  1593. }
  1594. $roleArrayCopy [$v [0]] = $roleArray;
  1595. // $verifyList[$k]['roleArray']=$roleArray;
  1596. }
  1597. // print_r($roleArray);
  1598. $verifyList [$k] ['date'] = "";
  1599. $verifyList [$k] ['opinion'] = "";
  1600. $verifyList [$k] ['status'] = "";
  1601. if (empty ( $verifyStaff )) {
  1602. $verifyList [$k] ['date'] = "";
  1603. $verifyList [$k] ['opinion'] = "";
  1604. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1605. $verifyList [$k] ['status'] = 4;
  1606. $button = 4;
  1607. $flag = false;
  1608. }
  1609. } else {
  1610. foreach ( $verifyStaff as $m => $u ) {
  1611. if ($v [0] == $m) {
  1612. $verifyList [$k] ['date'] = $u ['date'];
  1613. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1614. $verifyList [$k] ['status'] = $u ['status'];
  1615. $flag = false;
  1616. break;
  1617. }
  1618. }
  1619. $endStaffArray = end ( $verifyStaff );
  1620. if (isset ( $endStaffArray ['ROLE'] )) {
  1621. } else {
  1622. $endKey = key ( $verifyStaff );
  1623. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  1624. $button = 4;
  1625. $verifyList [$k] ['status'] = 4;
  1626. }
  1627. }
  1628. }
  1629. }
  1630. $rolename ['name'] = '';
  1631. if (! empty ( $roleId )) {
  1632. Doo::loadModel ( 'role' );
  1633. $role = new role ();
  1634. $rolename = $role->getOne ( array (
  1635. 'where' => 'rid=' . $roleId,
  1636. 'asArray' => true
  1637. ) );
  1638. }
  1639. if (! empty ( $verifyStaff ))
  1640. $endStaffArray = end ( $verifyStaff );
  1641. $KOP = false;
  1642. foreach ( $roleArrayCopy as $P => $A ) {
  1643. foreach ( $A as $MKI => $AVL ) {
  1644. if (! empty ( $verifyStaff )) {
  1645. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1646. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1647. $button = 4;
  1648. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1649. }
  1650. foreach ( $verifyStaff as $m => $u ) {
  1651. $AVLFK = $AVL [0] . '_R';
  1652. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1653. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1654. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1655. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1656. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1657. break;
  1658. }
  1659. }
  1660. } else {
  1661. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1662. $button = 4;
  1663. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1664. }
  1665. }
  1666. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1667. $KOP = true;
  1668. }
  1669. }
  1670. foreach ( $roleArrayCopy as $k => $v ) {
  1671. foreach ( $verifyList as $m => $n ) {
  1672. if ($n [0] == $k) {
  1673. array_splice ( $verifyList, $m, 1, $v );
  1674. }
  1675. }
  1676. }
  1677. $receiptList [$key] ['verifyList'] = $verifyList;
  1678. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1679. 'where' => 'sid=' . $value ['staff'],
  1680. 'asArray' => true
  1681. ) );
  1682. $receiptList [$key] ['button'] = $button;
  1683. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1684. }
  1685. $mothHtml = "";
  1686. for($i = 1; $i <= 12; $i ++) {
  1687. if ($month == $i)
  1688. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  1689. else
  1690. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  1691. }
  1692. // 获取审批日志
  1693. Doo::loadModel ( 'receiptLog' );
  1694. $receiptLog = new receiptLog ();
  1695. $rlList = array ();
  1696. $rlInfo = $receiptLog->getOne ( array (
  1697. 'where' => 'rid=' . $rid . ' and status=4',
  1698. 'asArray' => true
  1699. ) );
  1700. $tijdate = $receiptLog->getOne ( array (
  1701. 'where' => 'rid=' . $rid . ' and status=2',
  1702. 'asc' => 'rlid',
  1703. 'asArray' => true
  1704. ) );
  1705. if (! empty ( $rlInfo )) {
  1706. $rlList = $receiptLog->find ( array (
  1707. 'where' => 'rid=' . $rid,
  1708. 'asc' => 'rlid',
  1709. 'asArray' => true
  1710. ) );
  1711. }
  1712. $receiptList [0] ['rlList'] = $rlList;
  1713. $enclosurList = $enclosur->find ( array (
  1714. 'where' => 'rid=' . $rid,
  1715. 'asArray' => true
  1716. ) );
  1717. $enclosurHtml = '';
  1718. foreach ( $enclosurList as $value ) {
  1719. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  1720. }
  1721. // print_r($receiptList);
  1722. $data ['enclosurHtml'] = $enclosurHtml;
  1723. $data ['rolename'] = $rolename ['name'];
  1724. $data ['datetij'] = $tijdate ['date'];
  1725. $data ['mothHtml'] = $mothHtml;
  1726. $data ['rid'] = $rid;
  1727. $data ['receiptList'] = $receiptList;
  1728. $data ['receiptApprovalCount'] = count ( $receiptList );
  1729. $data ['status'] = $status;
  1730. $data ['year'] = $year;
  1731. $data ['categoryList'] = $categoryList;
  1732. $data ['staffList'] = $staffList;
  1733. $data ['cid'] = $cid;
  1734. $data ['sid'] = $sid;
  1735. $data ['ap'] = $ap;
  1736. $data ['memu'] = "receipt";
  1737. $data ['staff'] = $this->staff;
  1738. $data ['receiptMemu'] = 'approvalExpenses';
  1739. $data ['verifyId'] = $this->verifyId;
  1740. $data ['executeId'] = $this->executeId;
  1741. $this->render ( "/admin/remitApproval", $data );
  1742. }
  1743. function saeaLoanAdd() {
  1744. Doo::loadModel ( 'verify' );
  1745. $verify = new verify ();
  1746. Doo::loadModel ( "role" );
  1747. $role = new role ();
  1748. Doo::loadModel ( 'L_category' );
  1749. $lCategory = new L_category ();
  1750. $veList = $verify->getVerifyBySubordinate('LOAN');
  1751. $data ['category'] = $lCategory->find ( array (
  1752. 'asArray' => true
  1753. ) );
  1754. $data ['veList'] = $veList;
  1755. $data ['memu'] = "receipt";
  1756. $data ['staff'] = $this->staff;
  1757. $data ['receiptMemu'] = 'saeaBorad';
  1758. $data ['verifyId'] = $this->verifyId;
  1759. $data ['executeId'] = $this->executeId;
  1760. $this->render ( "/admin/saeaLoanAdd", $data );
  1761. }
  1762. function saeaLoanAddDo() {
  1763. $agency = $this->get_args ( 'agency' );
  1764. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1765. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1766. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1767. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1768. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1769. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1770. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1771. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1772. // die;
  1773. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1774. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1775. header ( 'Content-Type:text/html;charset=utf-8' );
  1776. die ( '请填写联行号' );
  1777. }
  1778. Doo::loadModel ( 'receipt' );
  1779. Doo::loadModel ( 'receiptDetail' );
  1780. Doo::loadModel ( 'accountItem' );
  1781. $accountItem = new accountItem ();
  1782. $receipt = new receipt ();
  1783. Doo::loadModel ( 'loanReceipt' );
  1784. $loanReceipt = new loanReceipt ();
  1785. Doo::loadModel ( 'execute' );
  1786. $execute = new execute ();
  1787. Doo::loadModel ( 'enclosur' );
  1788. $executeDetail = $execute->getOne ( array (
  1789. 'where' => 'mold="借款执行人"',
  1790. 'asArray' => true
  1791. ) );
  1792. $aItem = $accountItem->find ( array (
  1793. 'asArray' => true
  1794. ) );
  1795. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1796. $ag = $tr = $ta = $ot = 0;
  1797. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1798. array_push ( $accountJson ['借款费用'], array (
  1799. 'aid' => 0,
  1800. 'name' => '申请金额',
  1801. 'price' => number_format ( $agency, 2, '.', '' )
  1802. ) );
  1803. $sum += $agency;
  1804. $agencySum += $agency;
  1805. $accountJson ['cSum'] = array (
  1806. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1807. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1808. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1809. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1810. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1811. );
  1812. // 借款数据备份
  1813. $loanReceipt->loanItem = json_encode ( $accountJson );
  1814. $loanReceipt->staff = $this->staff [0] ['sid'];
  1815. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1816. $loanReceipt->date = date ( "Y-m-d" );
  1817. $loanReceipt->cid = $cid;
  1818. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1819. $loanReceipt->status = 5;
  1820. $loanReceipt->Rtype = 1;
  1821. $loanReceipt->verify = $verify;
  1822. $receipt->receiptOrder = $receipt->receiptOrder;
  1823. // 添加HTML换行符
  1824. // var_dump($explanation);
  1825. $order = array (
  1826. "\r\n",
  1827. "\n",
  1828. "\r"
  1829. );
  1830. $replace = '<br/>';
  1831. $explanation = str_replace ( $order, $replace, $explanation );
  1832. // $explanation=str_replace('\r',"<br/>",$explanation);
  1833. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  1834. $loanReceipt->explanation = $explanation;
  1835. $loanRid = $loanReceipt->insert ();
  1836. // 报销单
  1837. $receipt->loanItem = json_encode ( $accountJson );
  1838. $receipt->staff = $this->staff [0] ['sid'];
  1839. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1840. $receipt->date = date ( "Y-m-d" );
  1841. $receipt->cid = $cid;
  1842. // 特殊状态
  1843. $receipt->status = 5;
  1844. $receipt->Rtype = 1;
  1845. $receipt->loanRid = $loanRid;
  1846. // 修改审批流程加入角色
  1847. $receipt->verify = $verify;
  1848. $receipt->executeCopy = $executeDetail ['staff'];
  1849. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  1850. $receipt->explanation = $explanation;
  1851. $receipt->remittanceName = $remittanceName;
  1852. $receipt->bankName = $bankName;
  1853. $receipt->bankNumber = $bankNumber;
  1854. $receipt->remittanceBankType = $remittanceBankType;
  1855. if ($remittanceBankType == 1)
  1856. $receipt->coupletNumber = $coupletNumber;
  1857. $rid = $receipt->insert ();
  1858. return "/saeaBorad";
  1859. } else
  1860. die ( 'illegal request' );
  1861. }
  1862. function saeaLoanEdi() {
  1863. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1864. Doo::loadClass ( 'XDeode' );
  1865. $XDeode = new XDeode ( 7 );
  1866. $rid = $XDeode->decode ( $ridKey );
  1867. if (! is_numeric ( $rid ))
  1868. die ( 'illegal request' );
  1869. Doo::loadModel ( 'verify' );
  1870. $verify = new verify ();
  1871. Doo::loadModel ( "role" );
  1872. $role = new role ();
  1873. Doo::loadModel ( 'L_category' );
  1874. $lCategory = new L_category ();
  1875. Doo::loadModel ( 'receipt' );
  1876. $receipt = new receipt ();
  1877. $receiptInfo = $receipt->getOne ( array (
  1878. 'where' => 'rid=' . $rid,
  1879. 'asArray' => true
  1880. ) );
  1881. $veList = $verify->find ( array (
  1882. 'where'=>'subordinate like "%LOAN%"',
  1883. 'asArray' => true
  1884. ) );
  1885. foreach ( $veList as $key => $value ) {
  1886. $v = json_decode ( $value ['staff'] );
  1887. $list = array ();
  1888. foreach ( $v as $n => $m ) {
  1889. if ($m ['1'] == 'ROLE') {
  1890. $roleInfo = $role->getOne ( array (
  1891. 'where' => 'rid=' . $m [0],
  1892. 'asArray' => true
  1893. ) );
  1894. $v [$n] [1] = $roleInfo ['name'];
  1895. array_push ( $list, $roleInfo ['name'] );
  1896. } else {
  1897. array_push ( $list, $v [$n] [1] );
  1898. }
  1899. }
  1900. $veList [$key] ['staff'] = implode ( '>', $list );
  1901. }
  1902. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  1903. // print_r($receiptInfo);
  1904. $data ['receiptInfo'] = $receiptInfo;
  1905. $data ['category'] = $lCategory->find ( array (
  1906. 'asArray' => true
  1907. ) );
  1908. $data ['veList'] = $veList;
  1909. $data ['ridKey'] = $ridKey;
  1910. $data ['memu'] = "receipt";
  1911. $data ['staff'] = $this->staff;
  1912. $data ['receiptMemu'] = 'saeaBorad';
  1913. $data ['verifyId'] = $this->verifyId;
  1914. $data ['executeId'] = $this->executeId;
  1915. $this->render ( "/admin/saeaLoanEdi", $data );
  1916. }
  1917. function saeaLoanEdiDo() {
  1918. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1919. $agency = $this->get_args ( 'agency' );
  1920. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1921. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1922. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1923. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1924. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1925. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1926. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1927. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1928. // die;
  1929. Doo::loadClass ( 'XDeode' );
  1930. $XDeode = new XDeode ( 7 );
  1931. $rid = $XDeode->decode ( $ridKey );
  1932. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1933. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1934. header ( 'Content-Type:text/html;charset=utf-8' );
  1935. die ( '请填写联行号' );
  1936. }
  1937. Doo::loadModel ( 'receipt' );
  1938. Doo::loadModel ( 'receiptDetail' );
  1939. Doo::loadModel ( 'accountItem' );
  1940. $accountItem = new accountItem ();
  1941. $receipt = new receipt ();
  1942. Doo::loadModel ( 'loanReceipt' );
  1943. $loanReceipt = new loanReceipt ();
  1944. Doo::loadModel ( 'enclosur' );
  1945. Doo::loadModel ( 'execute' );
  1946. $execute = new execute ();
  1947. $executeDetail = $execute->getOne ( array (
  1948. 'where' => 'mold="借款执行人"',
  1949. 'asArray' => true
  1950. ) );
  1951. $receiptDetail = $receipt->getOne ( array (
  1952. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1953. 'asArray' => true
  1954. ) );
  1955. if (empty ( $receiptDetail ))
  1956. die ( '参数错误' );
  1957. $aItem = $accountItem->find ( array (
  1958. 'asArray' => true
  1959. ) );
  1960. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1961. $ag = $tr = $ta = $ot = 0;
  1962. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1963. array_push ( $accountJson ['借款费用'], array (
  1964. 'aid' => 0,
  1965. 'name' => '申请金额',
  1966. 'price' => number_format ( $agency, 2, '.', '' )
  1967. ) );
  1968. $sum += $agency;
  1969. $agencySum += $agency;
  1970. $accountJson ['cSum'] = array (
  1971. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1972. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1973. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1974. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1975. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1976. );
  1977. // 报销单
  1978. $receipt->loanItem = json_encode ( $accountJson );
  1979. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1980. $receipt->cid = $cid;
  1981. // 特殊状态
  1982. // 修改审批流程加入角色
  1983. if ($receiptDetail ['status'] != 4)
  1984. $receipt->verify = $verify;
  1985. $order = array (
  1986. "\r\n",
  1987. "\n",
  1988. "\r"
  1989. );
  1990. $replace = '<br/>';
  1991. $explanation = str_replace ( $order, $replace, $explanation );
  1992. $receipt->explanation = $explanation;
  1993. $receipt->remittanceName = $remittanceName;
  1994. $receipt->bankName = $bankName;
  1995. $receipt->bankNumber = $bankNumber;
  1996. $receipt->remittanceBankType = $remittanceBankType;
  1997. if ($remittanceBankType == 1)
  1998. $receipt->coupletNumber = $coupletNumber;
  1999. $receipt->update ( array (
  2000. 'where' => 'rid=' . $rid
  2001. ) );
  2002. // 借款数据更新
  2003. $loanReceipt->loanItem = json_encode ( $accountJson );
  2004. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  2005. $loanReceipt->cid = $cid;
  2006. if ($receiptDetail ['status'] != 4)
  2007. $loanReceipt->verify = $verify;
  2008. $loanReceipt->explanation = $explanation;
  2009. $receipt->executeCopy = $executeDetail ['staff'];
  2010. $loanReceipt->update ( array (
  2011. 'where' => 'rid=' . $receiptDetail ['loanRid']
  2012. ) );
  2013. }
  2014. return "/saeaBorad";
  2015. }
  2016. function saeaLoanReceiptAdd() {
  2017. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2018. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  2019. Doo::loadModel ( 'receipt' );
  2020. $receipt = new receipt ();
  2021. Doo::loadModel ( 'loanReceipt' );
  2022. $loanReceipt = new loanReceipt ();
  2023. Doo::loadModel ( 'L_category' );
  2024. $Lcategory = new L_category ();
  2025. Doo::loadModel ( 'verify' );
  2026. Doo::loadModel ( 'statistics' );
  2027. $statistics = new statistics ();
  2028. $verify = new verify ();
  2029. Doo::loadModel ( 'staff' );
  2030. $staff = new staff ();
  2031. $receiptDetail = $receipt->getOne ( array (
  2032. 'where' => 'rid=' . $rid,
  2033. 'desc' => 'rid',
  2034. 'asArray' => true
  2035. ) );
  2036. $receiptList = $loanReceipt->find ( array (
  2037. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  2038. 'desc' => 'rid',
  2039. 'asArray' => true
  2040. ) );
  2041. $Locate = 0;
  2042. $roleId = 0;
  2043. $button = 0;
  2044. foreach ( $receiptList as $key => $value ) {
  2045. $receiptList [$key] ['Locate'] = $Locate;
  2046. $Locate ++;
  2047. $receiptList [$key] ['reviseDetail'] = array ();
  2048. if (! empty ( $value ['reviseDetail'] ))
  2049. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2050. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2051. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2052. $categoryDetil = $Lcategory->getOne ( array (
  2053. 'where' => 'cid=' . $value ['cid'],
  2054. 'asArray' => true
  2055. ) );
  2056. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2057. // 检测编辑状态
  2058. $verifyList = $verify->getOne ( array (
  2059. 'where' => 'vid=' . $value ['verify'],
  2060. 'asArray' => true
  2061. ) );
  2062. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2063. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2064. Doo::loadModel ( 'role' );
  2065. $role = new role ();
  2066. $flag = true;
  2067. $roleKey = 0;
  2068. $endStaffArray = array ();
  2069. $roleArrayCopy = array ();
  2070. foreach ( $verifyList as $k => $v ) {
  2071. // init verifyStaff
  2072. if ($v [1] == 'ROLE') {
  2073. if (! empty ( $verifyStaff )) {
  2074. $endStaffArray = end ( $verifyStaff );
  2075. // if ($v[0]==$endStaffArray['nextStaff']){
  2076. // $roleId=$v[0];
  2077. // }
  2078. }
  2079. $roleVerify = json_decode ( $v [3], true );
  2080. $roleKey = $k;
  2081. $roleArray = array ();
  2082. $rolename = $role->getOne ( array (
  2083. 'where' => 'rid=' . $v [0],
  2084. 'asArray' => true
  2085. ) );
  2086. foreach ( $roleVerify as $o => $p ) {
  2087. $staffID = explode ( '_', $p );
  2088. $staffInfo = $staff->getOne ( array (
  2089. 'where' => 'sid=' . $staffID [0],
  2090. 'asArray' => true
  2091. ) );
  2092. // print_r($staffID);
  2093. $exp = array (
  2094. 0 => $staffInfo ['sid'],
  2095. 1 => $staffID [1],
  2096. 2 => $staffInfo ['avatar'],
  2097. 'date' => '',
  2098. 'date' => '',
  2099. 'opinion' => '',
  2100. 'status' => '',
  2101. 'rolename' => $rolename ['name']
  2102. );
  2103. array_push ( $roleArray, $exp );
  2104. }
  2105. $roleArrayCopy [$v [0]] = $roleArray;
  2106. // $verifyList[$k]['roleArray']=$roleArray;
  2107. }
  2108. $verifyList [$k] ['date'] = "";
  2109. $verifyList [$k] ['opinion'] = "";
  2110. $verifyList [$k] ['status'] = "";
  2111. if (empty ( $verifyStaff )) {
  2112. $verifyList [$k] ['date'] = "";
  2113. $verifyList [$k] ['opinion'] = "";
  2114. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2115. $verifyList [$k] ['status'] = 4;
  2116. $flag = false;
  2117. }
  2118. } else {
  2119. foreach ( $verifyStaff as $m => $u ) {
  2120. if ($v [0] == $m) {
  2121. $verifyList [$k] ['date'] = $u ['date'];
  2122. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2123. $verifyList [$k] ['status'] = $u ['status'];
  2124. $flag = false;
  2125. break;
  2126. }
  2127. }
  2128. $endStaffArray = end ( $verifyStaff );
  2129. if (isset ( $endStaffArray ['ROLE'] )) {
  2130. } else {
  2131. // $endKey=key($verifyStaff);
  2132. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2133. // $button=4;
  2134. // $verifyList[$k]['status']=4;
  2135. // }
  2136. }
  2137. }
  2138. }
  2139. $rolename ['name'] = '';
  2140. if (! empty ( $roleId )) {
  2141. Doo::loadModel ( 'role' );
  2142. $role = new role ();
  2143. $rolename = $role->getOne ( array (
  2144. 'where' => 'rid=' . $roleId,
  2145. 'asArray' => true
  2146. ) );
  2147. }
  2148. if (! empty ( $verifyStaff ))
  2149. $endStaffArray = end ( $verifyStaff );
  2150. $KOP = false;
  2151. foreach ( $roleArrayCopy as $P => $A ) {
  2152. foreach ( $A as $MKI => $AVL ) {
  2153. if (! empty ( $verifyStaff )) {
  2154. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2155. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2156. $button = 4;
  2157. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2158. }
  2159. foreach ( $verifyStaff as $m => $u ) {
  2160. $AVLFK = $AVL [0] . '_R';
  2161. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2162. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2163. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2164. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2165. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2166. break;
  2167. }
  2168. }
  2169. } else {
  2170. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2171. $button = 4;
  2172. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2173. }
  2174. }
  2175. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2176. $KOP = true;
  2177. }
  2178. }
  2179. foreach ( $roleArrayCopy as $k => $v ) {
  2180. foreach ( $verifyList as $m => $n ) {
  2181. if ($n [0] == $k) {
  2182. array_splice ( $verifyList, $m, 1, $v );
  2183. }
  2184. }
  2185. }
  2186. $receiptList [$key] ['verifyList'] = $verifyList;
  2187. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2188. 'where' => 'sid=' . $value ['staff'],
  2189. 'asArray' => true
  2190. ) );
  2191. $receiptList [$key] ['button'] = $button;
  2192. //
  2193. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  2194. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  2195. }
  2196. $data ['receiptList'] = $receiptList;
  2197. $data ['receiptDetail'] = $receiptDetail;
  2198. Doo::loadModel ( 'L_category' );
  2199. $lCategory = new L_category ();
  2200. Doo::loadModel ( 'accountItem' );
  2201. $accountItem = new accountItem ();
  2202. $acItem = $accountItem->find ( array (
  2203. 'asArray' => true
  2204. ) );
  2205. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  2206. $data ['rid'] = $rid;
  2207. $data ['category'] = $lCategory->find ( array (
  2208. 'asArray' => true
  2209. ) );
  2210. $data ['veList'] = $veList;
  2211. $data ['acItem'] = $acItem;
  2212. $data['itineraryDate']=$this->_itineraryDateMin();
  2213. $data ['memu'] = "receipt";
  2214. $data ['staff'] = $this->staff;
  2215. $data ['receiptMemu'] = 'saeaBorad';
  2216. $data ['verifyId'] = $this->verifyId;
  2217. $data ['executeId'] = $this->executeId;
  2218. $data['receiptClass']=$receiptClass;
  2219. if($receiptClass=='trave'){
  2220. $this->render ( "/receipt/feeLoanReceiptTrave", $data );
  2221. }else{
  2222. $this->render ( "/receipt/feeLoanReceipt", $data );
  2223. }
  2224. }
  2225. function saeaLoanReceiptAddDo() {
  2226. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  2227. $agency = $this->get_args ( 'agency' );
  2228. $travel = $this->get_args ( 'travel' );
  2229. $train = $this->get_args ( 'train' );
  2230. $other = $this->get_args ( 'other' );
  2231. $inttrain = $this->get_args ( 'inttrain' );
  2232. $itinerary = $_POST['itinerary'];//$this->get_args ( 'itinerary' ) ? $this->get_args ( 'itinerary' ) : "";
  2233. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  2234. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2235. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  2236. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  2237. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  2238. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2239. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2240. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2241. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2242. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2243. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  2244. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2245. header ( 'Content-Type:text/html;charset=utf-8' );
  2246. die ( '请填写联行号' );
  2247. }
  2248. if($receiptClass=='agency'){
  2249. $receiptClass=1;
  2250. }elseif($receiptClass=='trave'){
  2251. $receiptClass=2;
  2252. if($this->_verificationItinerary($itinerary)){
  2253. header ( 'Content-Type:text/html;charset=utf-8' );
  2254. die ( '已申请过类此日期的行程' );
  2255. }
  2256. }elseif($receiptClass=='internalTrain'){
  2257. $receiptClass=3;
  2258. }else{
  2259. header ( 'Content-Type:text/html;charset=utf-8' );
  2260. die ( '借款报销单分类不正确' );
  2261. }
  2262. Doo::loadModel ( 'receipt' );
  2263. Doo::loadModel ( 'receiptDetail' );
  2264. Doo::loadModel ( 'accountItem' );
  2265. $accountItem = new accountItem ();
  2266. $receipt = new receipt ();
  2267. Doo::loadModel ( 'enclosur' );
  2268. Doo::loadModel ( 'execute' );
  2269. $execute = new execute ();
  2270. $executeDetail = $execute->getOne ( array (
  2271. 'where' => 'mold="借款费用执行人"',
  2272. 'asArray' => true
  2273. ) );
  2274. $receiptDet = $receipt->getOne ( array (
  2275. 'where' => 'rid=' . $rid,
  2276. 'asArray' => true
  2277. ) );
  2278. // if(!empty($receiptDetail))
  2279. // return "/referReceipt/".$receiptDetail['rid'];
  2280. $aItem = $accountItem->find ( array (
  2281. 'asArray' => true
  2282. ) );
  2283. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2284. $ag = $tr = $ta = $ot =$it = 0;
  2285. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  2286. foreach ( $aItem as $key => $value ) {
  2287. if ($value ['category'] == $this->AGENCY) {
  2288. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  2289. array_push ( $accountJson [$this->AGENCY], array (
  2290. 'aid' => $value ['aid'],
  2291. 'name' => $value ['name'],
  2292. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  2293. ) );
  2294. $sum += $agency [$ag];
  2295. $agencySum += $agency [$ag];
  2296. }
  2297. $ag ++;
  2298. }
  2299. if ($value ['category'] == $this->TRAVEL) {
  2300. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  2301. array_push ( $accountJson [$this->TRAVEL], array (
  2302. 'aid' => $value ['aid'],
  2303. 'name' => $value ['name'],
  2304. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  2305. ) );
  2306. $sum += $travel [$tr];
  2307. $travelSum += $travel [$tr];
  2308. }
  2309. $tr ++;
  2310. }
  2311. if ($value ['category'] == $this->INTTRAIN) {
  2312. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  2313. array_push ( $accountJson [$this->INTTRAIN], array (
  2314. 'aid' => $value ['aid'],
  2315. 'name' => $value ['name'],
  2316. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  2317. ) );
  2318. $sum += $inttrain [$it];
  2319. $inttrainSum += $inttrain [$it];
  2320. }
  2321. $it ++;
  2322. }
  2323. if ($value ['category'] == $this->TRAIN) {
  2324. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  2325. array_push ( $accountJson [$this->TRAIN], array (
  2326. 'aid' => $value ['aid'],
  2327. 'name' => $value ['name'],
  2328. 'price' => number_format ( $train [$ta], 2, '.', '' )
  2329. ) );
  2330. $sum += $train [$ta];
  2331. $trainSum += $train [$ta];
  2332. }
  2333. $ta ++;
  2334. }
  2335. if ($value ['category'] == $this->OTHER) {
  2336. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  2337. array_push ( $accountJson [$this->OTHER], array (
  2338. 'aid' => $value ['aid'],
  2339. 'name' => $value ['name'],
  2340. 'price' => number_format ( $other [$ot], 2, '.', '' )
  2341. ) );
  2342. $sum += $other [$ot];
  2343. $otherSum += $other [$ot];
  2344. }
  2345. $ot ++;
  2346. }
  2347. }
  2348. $accountJson ['cSum'] = array (
  2349. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2350. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2351. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2352. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  2353. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2354. );
  2355. // 报销单
  2356. $receipt->accountItem = json_encode ( $accountJson );
  2357. $receipt->staff = $this->staff [0] ['sid'];
  2358. $receipt->loanSum = $receiptDet ['sum'];
  2359. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2360. $receipt->date = date ( "Y-m-d" );
  2361. $receipt->pastDate = '0000-00-00';
  2362. $receipt->cid = $cid;
  2363. $receipt->status = 7;
  2364. $receipt->receiptClass=$receiptClass;
  2365. if($receiptClass==2){
  2366. $receipt->itinerary2=$itinerary;
  2367. $this->_storageItinerary($itinerary, $rid);
  2368. }
  2369. // 修改审批流程加入角色
  2370. $receipt->verify = $verify;
  2371. $receipt->verifyStaff = '';
  2372. $receipt->executeStaff = '';
  2373. $receipt->executeCopy = $executeDetail ['staff'];
  2374. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  2375. $receipt->explanation = $explanation;
  2376. $receipt->remittanceName = $remittanceName;
  2377. $receipt->bankName = $bankName;
  2378. $receipt->bankNumber = $bankNumber;
  2379. $receipt->remittanceBankType = $remittanceBankType;
  2380. if ($remittanceBankType == 1)
  2381. $receipt->coupletNumber = $coupletNumber;
  2382. $receipt->update ( array (
  2383. 'where' => 'rid=' . $rid
  2384. ) );
  2385. // 附件
  2386. if (! empty ( $enclosurName )) {
  2387. $enclosurArray = explode ( '-', $enclosurName );
  2388. foreach ( $enclosurArray as $value ) {
  2389. $enclosur = new enclosur ();
  2390. $enclosur->name = $value;
  2391. $enclosur->rid = $rid;
  2392. $enclosur->insert ();
  2393. }
  2394. // print_r($enclosurArray);die;
  2395. }
  2396. // 报销详情
  2397. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  2398. $receiptDetail = new receiptDetail ();
  2399. $receiptDetail->staff = $this->staff [0] ['sid'];
  2400. $receiptDetail->item = $value ['name'];
  2401. $receiptDetail->itemCategory = $this->AGENCY;
  2402. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2403. $receiptDetail->date = date ( "Y-m-d" );
  2404. $receiptDetail->cid = $cid;
  2405. $receiptDetail->rid = $rid;
  2406. $receiptDetail->status = 4;
  2407. $receiptDetail->insert ();
  2408. }
  2409. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  2410. $receiptDetail = new receiptDetail ();
  2411. $receiptDetail->staff = $this->staff [0] ['sid'];
  2412. $receiptDetail->item = $value ['name'];
  2413. $receiptDetail->itemCategory = $this->TRAVEL;
  2414. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2415. $receiptDetail->date = date ( "Y-m-d" );
  2416. $receiptDetail->cid = $cid;
  2417. $receiptDetail->rid = $rid;
  2418. $receiptDetail->status = 4;
  2419. $receiptDetail->insert ();
  2420. }
  2421. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  2422. $receiptDetail = new receiptDetail ();
  2423. $receiptDetail->staff = $this->staff [0] ['sid'];
  2424. $receiptDetail->item = $value ['name'];
  2425. $receiptDetail->itemCategory = $this->TRAIN;
  2426. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2427. $receiptDetail->date = date ( "Y-m-d" );
  2428. $receiptDetail->cid = $cid;
  2429. $receiptDetail->rid = $rid;
  2430. $receiptDetail->status = 4;
  2431. $receiptDetail->insert ();
  2432. }
  2433. //内训
  2434. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  2435. $receiptDetail = new receiptDetail ();
  2436. $receiptDetail->staff = $this->staff [0] ['sid'];
  2437. $receiptDetail->item = $value ['name'];
  2438. $receiptDetail->itemCategory = $this->INTTRAIN;
  2439. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2440. $receiptDetail->date = date ( "Y-m-d" );
  2441. $receiptDetail->cid = $cid;
  2442. $receiptDetail->rid = $rid;
  2443. $receiptDetail->status = 4;
  2444. $receiptDetail->insert ();
  2445. }
  2446. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  2447. $receiptDetail = new receiptDetail ();
  2448. $receiptDetail->staff = $this->staff [0] ['sid'];
  2449. $receiptDetail->item = $value ['name'];
  2450. $receiptDetail->itemCategory = $this->OTHER;
  2451. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2452. $receiptDetail->date = date ( "Y-m-d" );
  2453. $receiptDetail->cid = $cid;
  2454. $receiptDetail->rid = $rid;
  2455. $receiptDetail->status = 4;
  2456. $receiptDetail->insert ();
  2457. }
  2458. return "/saeaBorad";
  2459. }
  2460. return "/saeaLoanReceiptAdd/" . $rid;
  2461. }
  2462. function saeaLoanReceiptEdi() {
  2463. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2464. Doo::loadClass ( 'XDeode' );
  2465. $XDeode = new XDeode ( 7 );
  2466. $rid = $XDeode->decode ( $ridKey );
  2467. if (! is_numeric ( $rid ))
  2468. die ( 'illegal request' );
  2469. Doo::loadModel ( 'accountItem' );
  2470. Doo::loadModel ( 'verify' );
  2471. Doo::loadModel ( 'receipt' );
  2472. $receipt = new receipt ();
  2473. $verify = new verify ();
  2474. $accountItem = new accountItem ();
  2475. Doo::loadModel ( 'L_category' );
  2476. $Lcategory = new L_category ();
  2477. Doo::loadModel ( "role" );
  2478. $role = new role ();
  2479. Doo::loadModel ( 'loanReceipt' );
  2480. $loanReceipt = new loanReceipt ();
  2481. Doo::loadModel ( 'staff' );
  2482. $staff = new staff ();
  2483. $receiptDetail = $receipt->getOne ( array (
  2484. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  2485. 'asArray' => true
  2486. ) );
  2487. if (empty ( $receiptDetail ))
  2488. return "/saeaBorad";
  2489. $receiptList = $loanReceipt->find ( array (
  2490. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  2491. 'desc' => 'rid',
  2492. 'asArray' => true
  2493. ) );
  2494. $Locate = 0;
  2495. $roleId = 0;
  2496. $button = 0;
  2497. foreach ( $receiptList as $key => $value ) {
  2498. $receiptList [$key] ['Locate'] = $Locate;
  2499. $Locate ++;
  2500. $receiptList [$key] ['reviseDetail'] = array ();
  2501. if (! empty ( $value ['reviseDetail'] ))
  2502. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2503. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2504. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2505. $categoryDetil = $Lcategory->getOne ( array (
  2506. 'where' => 'cid=' . $value ['cid'],
  2507. 'asArray' => true
  2508. ) );
  2509. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2510. // 检测编辑状态
  2511. $verifyList = $verify->getOne ( array (
  2512. 'where' => 'vid=' . $value ['verify'],
  2513. 'asArray' => true
  2514. ) );
  2515. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2516. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2517. Doo::loadModel ( 'role' );
  2518. $role = new role ();
  2519. $flag = true;
  2520. $roleKey = 0;
  2521. $endStaffArray = array ();
  2522. $roleArrayCopy = array ();
  2523. foreach ( $verifyList as $k => $v ) {
  2524. // init verifyStaff
  2525. if ($v [1] == 'ROLE') {
  2526. if (! empty ( $verifyStaff )) {
  2527. $endStaffArray = end ( $verifyStaff );
  2528. // if ($v[0]==$endStaffArray['nextStaff']){
  2529. // $roleId=$v[0];
  2530. // }
  2531. }
  2532. $roleVerify = json_decode ( $v [3], true );
  2533. $roleKey = $k;
  2534. $roleArray = array ();
  2535. $rolename = $role->getOne ( array (
  2536. 'where' => 'rid=' . $v [0],
  2537. 'asArray' => true
  2538. ) );
  2539. foreach ( $roleVerify as $o => $p ) {
  2540. $staffID = explode ( '_', $p );
  2541. $staffInfo = $staff->getOne ( array (
  2542. 'where' => 'sid=' . $staffID [0],
  2543. 'asArray' => true
  2544. ) );
  2545. // print_r($staffID);
  2546. $exp = array (
  2547. 0 => $staffInfo ['sid'],
  2548. 1 => $staffID [1],
  2549. 2 => $staffInfo ['avatar'],
  2550. 'date' => '',
  2551. 'date' => '',
  2552. 'opinion' => '',
  2553. 'status' => '',
  2554. 'rolename' => $rolename ['name']
  2555. );
  2556. array_push ( $roleArray, $exp );
  2557. }
  2558. $roleArrayCopy [$v [0]] = $roleArray;
  2559. // $verifyList[$k]['roleArray']=$roleArray;
  2560. }
  2561. $verifyList [$k] ['date'] = "";
  2562. $verifyList [$k] ['opinion'] = "";
  2563. $verifyList [$k] ['status'] = "";
  2564. if (empty ( $verifyStaff )) {
  2565. $verifyList [$k] ['date'] = "";
  2566. $verifyList [$k] ['opinion'] = "";
  2567. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2568. $verifyList [$k] ['status'] = 4;
  2569. $flag = false;
  2570. }
  2571. } else {
  2572. foreach ( $verifyStaff as $m => $u ) {
  2573. if ($v [0] == $m) {
  2574. $verifyList [$k] ['date'] = $u ['date'];
  2575. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2576. $verifyList [$k] ['status'] = $u ['status'];
  2577. $flag = false;
  2578. break;
  2579. }
  2580. }
  2581. $endStaffArray = end ( $verifyStaff );
  2582. if (isset ( $endStaffArray ['ROLE'] )) {
  2583. } else {
  2584. // $endKey=key($verifyStaff);
  2585. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2586. // $button=4;
  2587. // $verifyList[$k]['status']=4;
  2588. // }
  2589. }
  2590. }
  2591. }
  2592. $rolename ['name'] = '';
  2593. if (! empty ( $roleId )) {
  2594. Doo::loadModel ( 'role' );
  2595. $role = new role ();
  2596. $rolename = $role->getOne ( array (
  2597. 'where' => 'rid=' . $roleId,
  2598. 'asArray' => true
  2599. ) );
  2600. }
  2601. if (! empty ( $verifyStaff ))
  2602. $endStaffArray = end ( $verifyStaff );
  2603. $KOP = false;
  2604. foreach ( $roleArrayCopy as $P => $A ) {
  2605. foreach ( $A as $MKI => $AVL ) {
  2606. if (! empty ( $verifyStaff )) {
  2607. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2608. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2609. $button = 4;
  2610. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2611. }
  2612. foreach ( $verifyStaff as $m => $u ) {
  2613. $AVLFK = $AVL [0] . '_R';
  2614. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2615. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2616. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2617. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2618. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2619. break;
  2620. }
  2621. }
  2622. } else {
  2623. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2624. $button = 4;
  2625. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2626. }
  2627. }
  2628. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2629. $KOP = true;
  2630. }
  2631. }
  2632. foreach ( $roleArrayCopy as $k => $v ) {
  2633. foreach ( $verifyList as $m => $n ) {
  2634. if ($n [0] == $k) {
  2635. array_splice ( $verifyList, $m, 1, $v );
  2636. }
  2637. }
  2638. }
  2639. $receiptList [$key] ['verifyList'] = $verifyList;
  2640. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2641. 'where' => 'sid=' . $value ['staff'],
  2642. 'asArray' => true
  2643. ) );
  2644. $receiptList [$key] ['button'] = $button;
  2645. //
  2646. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  2647. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  2648. }
  2649. $data ['receiptList'] = $receiptList;
  2650. $acItem = $accountItem->find ( array (
  2651. 'asArray' => true
  2652. ) );
  2653. $veList = $verify->find ( array (
  2654. 'asArray' => true
  2655. ) );
  2656. foreach ( $veList as $key => $value ) {
  2657. $v = json_decode ( $value ['staff'] );
  2658. $list = array ();
  2659. foreach ( $v as $n => $m ) {
  2660. if ($m ['1'] == 'ROLE') {
  2661. $roleInfo = $role->getOne ( array (
  2662. 'where' => 'rid=' . $m [0],
  2663. 'asArray' => true
  2664. ) );
  2665. $v [$n] [1] = $roleInfo ['name'];
  2666. array_push ( $list, $roleInfo ['name'] );
  2667. } else {
  2668. array_push ( $list, $v [$n] [1] );
  2669. }
  2670. }
  2671. $veList [$key] ['staff'] = implode ( '>', $list );
  2672. }
  2673. // 配置编辑信息
  2674. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  2675. foreach ( $acItem as $key => $value ) {
  2676. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  2677. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  2678. $acItem [$key] ['price'] = $v ['price'];
  2679. }
  2680. }
  2681. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  2682. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  2683. $acItem [$key] ['price'] = $v ['price'];
  2684. }
  2685. }
  2686. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  2687. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  2688. $acItem [$key] ['price'] = $v ['price'];
  2689. }
  2690. }
  2691. //内训
  2692. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  2693. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  2694. $acItem [$key] ['price'] = $v ['price'];
  2695. }
  2696. }
  2697. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  2698. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  2699. $acItem [$key] ['price'] = $v ['price'];
  2700. }
  2701. }
  2702. }
  2703. $data ['category'] = $Lcategory->find ( array (
  2704. 'asArray' => true
  2705. ) );
  2706. $data ['ridKey'] = $ridKey;
  2707. $data ['cSum'] = $accountItemList ['cSum'];
  2708. $data ['sum'] = $receiptDetail ['sum'];
  2709. $data ['receiptDetail'] = $receiptDetail;
  2710. $data ['veList'] = $veList;
  2711. $data ['acItem'] = $acItem;
  2712. $data ['memu'] = "receipt";
  2713. $data ['staff'] = $this->staff;
  2714. $data ['receiptMemu'] = 'saeaBorad';
  2715. $data ['verify'] = $receiptDetail ['verify'];
  2716. $data ['verifyId'] = $this->verifyId;
  2717. $data ['executeId'] = $this->executeId;
  2718. $data ['rid'] = $rid;
  2719. if($receiptDetail['receiptClass']==1){
  2720. $this->render ( "/receipt/feeLoanReceiptAgencyEdi", $data );
  2721. }elseif($receiptDetail['receiptClass']==2){
  2722. Doo::loadModel ( 'itinerary' );
  2723. $itinerary = new itinerary ();
  2724. $itinerary->delete(array('where' => 'rid=' . $receiptDetail['rid'] ));
  2725. $this->render ( "/receipt/feeLoanReceiptTraveEdi", $data );
  2726. }elseif($receiptDetail['receiptClass']==3){
  2727. $this->render ( "/receipt/feeLoanReceiptITEdi", $data );
  2728. }else{
  2729. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  2730. }
  2731. }
  2732. /**
  2733. * 培训班结算
  2734. */
  2735. function receiptTrainAdd() {
  2736. Doo::loadModel ( 'accountItem' );
  2737. $accountItem = new accountItem ();
  2738. $acItem = $accountItem->find ( array (
  2739. 'asArray' => true
  2740. ) );
  2741. // 审批组
  2742. Doo::loadModel ( 'verify' );
  2743. $verify = new verify ();
  2744. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2745. // 办事处
  2746. Doo::loadModel ( 'L_category' );
  2747. $lCategory = new L_category ();
  2748. $data ['category'] = $lCategory->getCategory ();
  2749. $data ['veList'] = $veList;
  2750. $data ['memu'] = "receipt";
  2751. $data ['staff'] = $this->staff;
  2752. $data ['acItem'] = $acItem;
  2753. $data ['receiptMemu'] = 'saeaBorad';
  2754. $data ['verifyId'] = $this->verifyId;
  2755. $data ['executeId'] = $this->executeId;
  2756. $this->render ( "/receipt/receiptTrainAdd", $data );
  2757. }
  2758. /**
  2759. * 添加培训班结算
  2760. */
  2761. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  2762. // 培训班信息
  2763. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2764. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2765. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2766. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2767. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  2768. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2769. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2770. // 发票信息
  2771. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2772. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2773. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2774. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2775. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2776. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2777. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2778. //&&! empty ( $participants )
  2779. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  2780. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2781. header ( 'Content-Type:text/html;charset=utf-8' );
  2782. die ( '请填写联行号' );
  2783. }
  2784. Doo::loadModel ( 'execute' );
  2785. $execute = new execute ();
  2786. $executeDetail = $execute->getOne ( array (
  2787. 'where' => 'mold="培训班结算"',
  2788. 'asArray' => true
  2789. ) );
  2790. if (empty ( $executeDetail )) {
  2791. header ( 'Content-Type:text/html;charset=utf-8' );
  2792. die ( '未设置执行人' );
  2793. }
  2794. Doo::loadClass ( 'XDeode' );
  2795. $XDeode = new XDeode ( 5 );
  2796. $cid = $XDeode->decode ( $cid );
  2797. Doo::loadModel ( 'receipt' );
  2798. $receipt = new receipt ();
  2799. Doo::loadModel ( 'receiptTraining' );
  2800. $receiptTraining = new receiptTraining ();
  2801. // 创建费用培训班
  2802. $item = array (
  2803. 'cid' => $this->staff [0] ['cid'],
  2804. 'categoryName' => $this->staff [0] ['category'],
  2805. 'trainName' => $trainName,
  2806. 'trainStartDate' => $trainStartDate,
  2807. 'trainEndDate' => $trainEndDate,
  2808. 'participants' => $participants,
  2809. 'freeParticipants'=>$freeParticipants,
  2810. 'trainAddress' => $trainAddress,
  2811. 'trainRemarks' => $trainRemarks,
  2812. 'creator' => $this->staff [0] ['sid'],
  2813. 'creatorDate' => date ( "Y-m-d H:i:s" )
  2814. );
  2815. $irid = $receiptTraining->addReceiptTraining ( $item );
  2816. // 报销单
  2817. $receipt->status = 5;
  2818. $receipt->trainId = $irid;
  2819. $receipt->Rtype = 3;
  2820. $receipt->staff = $this->staff [0] ['sid'];
  2821. $receipt->cid = $cid;
  2822. $receipt->verify = $verify;
  2823. $receipt->date = date ( "Y-m-d" );
  2824. $receipt->executeCopy = $executeDetail ['staff'];
  2825. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2826. $receipt->remittanceName = $remittanceName;
  2827. $receipt->bankName = $bankName;
  2828. $receipt->bankNumber = $bankNumber;
  2829. $receipt->remittanceBankType = $remittanceBankType;
  2830. if ($remittanceBankType == 1)
  2831. $receipt->coupletNumber = $coupletNumber;
  2832. $rid = $receipt->insert ();
  2833. $XDeode = new XDeode ( 7 );
  2834. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  2835. } else
  2836. die ( 'illegal request' );
  2837. }
  2838. /**
  2839. * 培训班编辑
  2840. */
  2841. function receiptTrainEdi() {
  2842. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2843. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  2844. Doo::loadClass ( 'XDeode' );
  2845. $XDeode = new XDeode ( 7 );
  2846. $rid = $XDeode->decode ( $ridKey );
  2847. if (! is_numeric ( $rid ))
  2848. die ( 'illegal request' );
  2849. Doo::loadModel ( 'receipt' );
  2850. $receipt = new receipt ();
  2851. Doo::loadModel ( 'receiptTraining' );
  2852. $receiptTraining = new receiptTraining ();
  2853. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2854. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  2855. die ('illegal request--status');
  2856. }
  2857. //如有已入账已收款的发票,自动取消办事处已收款
  2858. // Doo::loadModel ( 'RIExtend' );
  2859. // $RIExtend = new RIExtend ();
  2860. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  2861. // if (!empty($RIExtendList)){
  2862. // foreach ($RIExtendList as $key=>$value){
  2863. // $RIExtend = new RIExtend ();
  2864. // $RIExtend->delete(array (
  2865. // 'where' => 'iid=' . $value['iid'],
  2866. // 'limit' => 1
  2867. // ));
  2868. // }
  2869. // }
  2870. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2871. // 汇总表合计
  2872. // 收入合计--加入开票合计
  2873. Doo::loadModel ( 'invoiceTraining' );
  2874. $invoiceTraining = new invoiceTraining ();
  2875. $invoiceTrainingDetail = array (
  2876. 'invoiceArriveAmount' => 0,
  2877. 'RIAmount' => 0,
  2878. 'invoiceTotalAmount' => 0,
  2879. 'invoiceCompanyAmount'=>0
  2880. );
  2881. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2882. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2883. }
  2884. // print_r($invoiceTrainingDetail);
  2885. $invoiceArriveAmount = $RIAmount = 0;
  2886. if (! empty ( $invoiceTrainingDetail )) {
  2887. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  2888. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  2889. }
  2890. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2891. //print_r($invoiceTrainingDetail);
  2892. // 支出项目
  2893. Doo::loadModel ( 'accountItem' );
  2894. $accountItem = new accountItem ();
  2895. // 项目金额合计
  2896. Doo::loadModel ( 'RItem' );
  2897. $RItem = new RItem ();
  2898. // 讲师获得
  2899. Doo::loadModel ( 'RILecturer' );
  2900. $RILecturer = new RILecturer ();
  2901. $RItemList = $RItem->getRItemByRid ( $rid );
  2902. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2903. // 支出项金额详情
  2904. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  2905. // print_r($aiData);
  2906. // 利润
  2907. $profit=$invoiceArriveAmount - $aiData ['total'];
  2908. $companyProfit=$profit * 0.6;
  2909. $categoryProfit=$profit * 0.4;
  2910. $data ['profit'] = sprintf("%.2f",$profit);
  2911. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  2912. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  2913. //发票利润
  2914. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  2915. //发票公司利润
  2916. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  2917. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  2918. //办事处利润
  2919. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  2920. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  2921. // print_r($aiData['dataList']);
  2922. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  2923. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  2924. // 备用金
  2925. $sum = 0;
  2926. $data ['receiptLoanDetail'] = array (
  2927. 'sum' => '0.00'
  2928. );
  2929. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2930. //$data ['receiptLoanDetail'] = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2931. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2932. $sum=0;
  2933. foreach ($receiptLoanList as $key=>$value){
  2934. $sum+=$value['sum'];
  2935. }
  2936. $data ['receiptLoanDetail'] = array (
  2937. 'sum' => $sum
  2938. );
  2939. //$sum = $data ['receiptLoanDetail'] ['sum'];
  2940. }
  2941. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  2942. $data ['payment'] = sprintf("%.2f",$payment);
  2943. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  2944. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  2945. $data ['aiList'] = $aiData ['dataList'];
  2946. // 占比计算
  2947. if ($invoiceArriveAmount != 0) {
  2948. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  2949. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  2950. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  2951. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  2952. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  2953. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  2954. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  2955. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  2956. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  2957. } else {
  2958. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  2959. }
  2960. //发票金额占比计算
  2961. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  2962. //支出
  2963. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2964. //利润
  2965. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2966. //公司利润
  2967. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2968. //办事处利润
  2969. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2970. //公司收款
  2971. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2972. //备用金
  2973. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2974. //办事处收款
  2975. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2976. //办事处实际支出
  2977. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2978. //付总部款
  2979. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2980. }else{
  2981. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2982. }
  2983. //讲师人数
  2984. Doo::loadModel ( 'RILecturer' );
  2985. $RILecturer = new RILecturer ();
  2986. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2987. $data['lectureCount']=count($RILecturerList);
  2988. // 审批组
  2989. Doo::loadModel ( 'verify' );
  2990. $verify = new verify ();
  2991. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2992. // 办事处
  2993. Doo::loadModel ( 'L_category' );
  2994. $lCategory = new L_category ();
  2995. $data ['category'] = $lCategory->getCategory ();
  2996. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2997. $data ['receiptDetail'] = $receiptDetail;
  2998. $data ['veList'] = $veList;
  2999. $data ['trainEdiType'] = $trainEdiType;
  3000. $data ['ridKey'] = $ridKey;
  3001. $data ['memu'] = "receipt";
  3002. $data ['staff'] = $this->staff;
  3003. $data ['receiptMemu'] = 'saeaBorad';
  3004. $data ['verifyId'] = $this->verifyId;
  3005. $data ['executeId'] = $this->executeId;
  3006. $this->render ( "/receipt/receiptTrainEdi", $data );
  3007. }
  3008. /**
  3009. * 培训班借款编辑
  3010. */
  3011. function receiptTrainLoanEdi() {
  3012. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3013. Doo::loadClass ( 'XDeode' );
  3014. $XDeode = new XDeode ( 7 );
  3015. $rid = $XDeode->decode ( $ridKey );
  3016. if (! is_numeric ( $rid ))
  3017. die ( 'illegal request' );
  3018. Doo::loadModel ( 'receipt' );
  3019. $receipt = new receipt ();
  3020. Doo::loadModel ( 'receiptTraining' );
  3021. $receiptTraining = new receiptTraining ();
  3022. Doo::loadModel ( 'verify' );
  3023. $verify = new verify ();
  3024. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3025. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  3026. die ();
  3027. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3028. // 借款详情HTML
  3029. // 获得借款信息
  3030. $receiptLoanHtml = '';
  3031. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  3032. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  3033. foreach ($receiptLoanList as $key=>$value){
  3034. // 获得某费用单审批信息
  3035. $verifylist = $verify->getVerifyByRid ( $value ['rid'] );
  3036. Doo::loadClass ( 'receipt.func' );
  3037. $extendHtml = '<p><a class="button"
  3038. href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $value ['ridKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  3039. $receiptLoanHtml .= _getReceiptLoanHtml ( $value, $verifylist, $extendHtml );
  3040. }
  3041. }
  3042. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  3043. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3044. $data ['receiptDetail'] = $receiptDetail;
  3045. $data ['trainEdiType'] = "LOAN";
  3046. $data ['ridKey'] = $ridKey;
  3047. $data ['memu'] = "receipt";
  3048. $data ['staff'] = $this->staff;
  3049. $data ['receiptMemu'] = 'saeaBorad';
  3050. $data ['verifyId'] = $this->verifyId;
  3051. $data ['executeId'] = $this->executeId;
  3052. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  3053. }
  3054. /**
  3055. * 更新培训班结算基本信息
  3056. */
  3057. function receiptTrainInfoEdiDo() {
  3058. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  3059. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  3060. // 培训班信息
  3061. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  3062. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  3063. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  3064. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  3065. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  3066. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  3067. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  3068. // 发票信息
  3069. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  3070. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3071. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  3072. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3073. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  3074. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  3075. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  3076. //&& ! empty ( $participants )
  3077. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  3078. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  3079. header ( 'Content-Type:text/html;charset=utf-8' );
  3080. die ( '请填写联行号' );
  3081. }
  3082. Doo::loadClass ( 'XDeode' );
  3083. $XDeode = new XDeode ( 5 );
  3084. $cid = $XDeode->decode ( $cid );
  3085. $rtid = $XDeode->decode ( $rtid );
  3086. $rid = $XDeode->decode ( $rid );
  3087. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  3088. die ( 'illegal request-IdError' );
  3089. }
  3090. Doo::loadModel ( 'receipt' );
  3091. $receipt = new receipt ();
  3092. Doo::loadModel ( 'receiptTraining' );
  3093. $receiptTraining = new receiptTraining ();
  3094. // 更新费用培训班
  3095. $item = array (
  3096. 'rtid' => $rtid,
  3097. 'trainName' => $trainName,
  3098. 'trainStartDate' => $trainStartDate,
  3099. 'trainEndDate' => $trainEndDate,
  3100. 'participants' => $participants,
  3101. 'freeParticipants'=>$freeParticipants,
  3102. 'trainAddress' => $trainAddress,
  3103. 'trainRemarks' => $trainRemarks
  3104. );
  3105. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  3106. // 报销单
  3107. $receipt->rid = $rid;
  3108. $receipt->cid = $cid;
  3109. $receipt->verify = $verify;
  3110. $receipt->remittanceName = $remittanceName;
  3111. $receipt->bankName = $bankName;
  3112. $receipt->bankNumber = $bankNumber;
  3113. $receipt->remittanceBankType = $remittanceBankType;
  3114. if ($remittanceBankType == 1)
  3115. $receipt->coupletNumber = $coupletNumber;
  3116. $receipt->update ();
  3117. $XDeode = new XDeode ( 7 );
  3118. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  3119. } else
  3120. die ( 'illegal request' );
  3121. }
  3122. /**
  3123. * 编辑培训班结算---更新借款
  3124. */
  3125. function receiptTrainLoanEdiDo() {
  3126. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3127. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  3128. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  3129. Doo::loadModel ( 'receipt' );
  3130. $receipt = new receipt ();
  3131. Doo::loadClass ( 'XDeode' );
  3132. $XDeode = new XDeode ( 5 );
  3133. $rid = $XDeode->decode ( $ridKey );
  3134. $ridLoan = $XDeode->decode ( $ridLoanKey );
  3135. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  3136. die ( 'illegal request-ridError' );
  3137. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3138. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  3139. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3140. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3141. die ( 'illegal request-receiptError' );
  3142. }
  3143. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  3144. die ( 'illegal request-receipLoantError' );
  3145. }
  3146. // 培训班结算挂钩借款
  3147. $receipt = new receipt ();
  3148. $trainLoanRid=$ridLoan;
  3149. if (!empty($receiptDetail['trainLoanRid'])){
  3150. $trainLoanRid=$receiptDetail['trainLoanRid'].','.$ridLoan;
  3151. }
  3152. $item = array (
  3153. 'rid' => $rid,
  3154. 'trainLoanRid' => $trainLoanRid
  3155. );
  3156. $receipt->setReceiptByCondition ( $item );
  3157. // 更新借款状态变成已挂钩
  3158. $receipt = new receipt ();
  3159. $item = array (
  3160. 'rid' => $ridLoan,
  3161. 'status' => 10,
  3162. 'statusTrain' => 1
  3163. );
  3164. $receipt->setReceiptByCondition ( $item );
  3165. $XDeode = new XDeode ( 7 );
  3166. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  3167. } else
  3168. die ( 'illegal request' );
  3169. }
  3170. /**
  3171. * 编辑培训班结算--移除借款
  3172. */
  3173. function receiptTrainLoanRemoveDo() {
  3174. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  3175. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  3176. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  3177. Doo::loadModel ( 'receipt' );
  3178. $receipt = new receipt ();
  3179. Doo::loadClass ( 'XDeode' );
  3180. $XDeode = new XDeode ( 5 );
  3181. $rid = $XDeode->decode ( $ridKey );
  3182. $ridLoan = $XDeode->decode ( $ridLoanKey );
  3183. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  3184. die ( 'illegal request-ridError' );
  3185. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3186. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  3187. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  3188. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3189. die ( 'illegal request-receiptError' );
  3190. }
  3191. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  3192. die ( 'illegal request-receipLoantError' );
  3193. }
  3194. // 培训班结算挂钩借款
  3195. $receipt = new receipt ();
  3196. $trainLoanRidArray=explode(",", $receiptDetail['trainLoanRid']);
  3197. foreach ($trainLoanRidArray as $key=>$value){
  3198. if($value==$ridLoan){
  3199. unset($trainLoanRidArray[$key]);
  3200. }
  3201. }
  3202. $trainLoanRidString=implode(",", $trainLoanRidArray);
  3203. $item = array (
  3204. 'rid' => $rid,
  3205. 'trainLoanRid' => $trainLoanRidString
  3206. );
  3207. $receipt->setReceiptByCondition ( $item );
  3208. // 更新借款状态变成已挂钩
  3209. $receipt = new receipt ();
  3210. $item = array (
  3211. 'rid' => $ridLoan,
  3212. 'status' => 8,
  3213. 'statusTrain' => 0
  3214. );
  3215. $receipt->setReceiptByCondition ( $item );
  3216. $XDeode = new XDeode ( 7 );
  3217. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  3218. } else
  3219. die ( 'illegal request' );
  3220. }
  3221. /**
  3222. * 编辑培训班结算 ---开票
  3223. */
  3224. function receiptTrainInvoiceEdi() {
  3225. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3226. Doo::loadClass ( 'XDeode' );
  3227. $XDeode = new XDeode ( 7 );
  3228. $rid = $XDeode->decode ( $ridKey );
  3229. if (! is_numeric ( $rid ))
  3230. die ( 'illegal request' );
  3231. Doo::loadModel ( 'receipt' );
  3232. $receipt = new receipt ();
  3233. Doo::loadModel ( 'receiptTraining' );
  3234. $receiptTraining = new receiptTraining ();
  3235. Doo::loadModel ( 'invoice' );
  3236. $invoice = new invoice ();
  3237. Doo::loadModel ( 'invoiceTraining' );
  3238. $invoiceTraining = new invoiceTraining ();
  3239. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3240. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  3241. die ();
  3242. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3243. $invoiceList = $invoiceTrainingDetail = array ();
  3244. if ($receiptDetail ['invoiceTrainId'] != 0) {
  3245. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  3246. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  3247. }
  3248. //print_r($invoiceList);
  3249. $data ['invoiceList'] = $invoiceList;
  3250. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  3251. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3252. $data ['receiptDetail'] = $receiptDetail;
  3253. $data ['trainEdiType'] = "INVOICE";
  3254. $data ['ridKey'] = $ridKey;
  3255. $data ['memu'] = "receipt";
  3256. $data ['staff'] = $this->staff;
  3257. $data ['receiptMemu'] = 'saeaBorad';
  3258. $data ['verifyId'] = $this->verifyId;
  3259. $data ['executeId'] = $this->executeId;
  3260. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  3261. }
  3262. /**
  3263. * 编辑培训班结算---更新开票
  3264. */
  3265. function receiptTrainInvoiceEdiDo() {
  3266. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3267. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  3268. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  3269. Doo::loadModel ( 'receipt' );
  3270. $receipt = new receipt ();
  3271. Doo::loadModel ( 'invoiceTraining' );
  3272. $invoiceTraining = new invoiceTraining ();
  3273. Doo::loadClass ( 'XDeode' );
  3274. $XDeode = new XDeode ( 5 );
  3275. $rid = $XDeode->decode ( $ridKey );
  3276. $itid = $XDeode->decode ( $itidKey );
  3277. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  3278. die ( 'illegal request-idError' );
  3279. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3280. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  3281. // 不合法的数据
  3282. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3283. die ( 'illegal request-receiptError' );
  3284. }
  3285. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  3286. die ( 'illegal request-receipLoantError' );
  3287. }
  3288. // 培训班结算挂钩借款
  3289. $receipt = new receipt ();
  3290. $item = array (
  3291. 'rid' => $rid,
  3292. 'invoiceTrainId' => $itid
  3293. );
  3294. $receipt->setReceiptByCondition ( $item );
  3295. $invoiceTraining = new invoiceTraining ();
  3296. $item = array (
  3297. 'bindReceipt' => 1,
  3298. 'itid' => $itid
  3299. );
  3300. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  3301. $XDeode = new XDeode ( 7 );
  3302. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  3303. } else
  3304. die ( 'illegal request' );
  3305. }
  3306. /**
  3307. * 更新培训班结算 收款和取消收款
  3308. */
  3309. function receiptTrainReceivables() {
  3310. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  3311. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3312. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3313. Doo::loadClass ( 'XDeode' );
  3314. $XDeode = new XDeode ( 5 );
  3315. $rid = $XDeode->decode ( $ridKey );
  3316. $iid = $XDeode->decode ( $iidKey );
  3317. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  3318. die ( 'illegal request-iid' );
  3319. Doo::loadModel ( 'RIExtend' );
  3320. $RIExtend = new RIExtend ();
  3321. if ($doType == 'CONFIRM') {
  3322. $RIExtend->rid = $rid;
  3323. $RIExtend->iid = $iid;
  3324. $RIExtend->RIstatus = 1;
  3325. $RIExtend->insert ();
  3326. echo json_encode ( array (
  3327. 'status' => 1,
  3328. ) );
  3329. die ( );
  3330. } elseif ($doType == 'CANCEL') {
  3331. $RIExtend->delete ( array (
  3332. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  3333. 'limit' => 1
  3334. ) );
  3335. echo json_encode ( array (
  3336. 'status' => 1,
  3337. ) );
  3338. die ( );
  3339. } else {
  3340. echo json_encode ( array (
  3341. 'status' => 2,
  3342. ) );
  3343. die ( );
  3344. }
  3345. }
  3346. /**
  3347. * 移除挂钩的培训班发票
  3348. */
  3349. function receiptTrainReceivablesDelDo() {
  3350. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  3351. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  3352. Doo::loadModel ( 'receipt' );
  3353. $receipt = new receipt ();
  3354. Doo::loadModel ( 'RIExtend' );
  3355. $RIExtend = new RIExtend ();
  3356. Doo::loadClass ( 'XDeode' );
  3357. $XDeode = new XDeode ( 5 );
  3358. $rid = $XDeode->decode ( $ridKey );
  3359. $itid = $XDeode->decode ( $itidKey );
  3360. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  3361. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3362. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  3363. die ( 'illegal request-status' );
  3364. }
  3365. $receipt = new receipt ();
  3366. $receipt->rid = $rid;
  3367. $receipt->invoiceTrainId = 0;
  3368. $receipt->update ();
  3369. Doo::loadModel ( 'invoiceTraining' );
  3370. $invoiceTraining = new invoiceTraining ();
  3371. $item = array (
  3372. 'bindReceipt' => 0,
  3373. 'itid' => $itid
  3374. );
  3375. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  3376. $RIExtend->delete ( array (
  3377. 'where' => 'rid=' . $rid
  3378. ) );
  3379. $XDeode = new XDeode ( 7 );
  3380. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  3381. } else
  3382. die ( 'illegal request-iid' );
  3383. }
  3384. /**
  3385. * 编辑培训班结算
  3386. */
  3387. function receiptTrainItemEdi() {
  3388. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3389. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3390. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  3391. Doo::loadClass ( 'XDeode' );
  3392. $XDeode = new XDeode ( 7 );
  3393. $rid = $XDeode->decode ( $ridKey );
  3394. if (! is_numeric ( $rid ))
  3395. die ( 'illegal request' );
  3396. Doo::loadModel ( 'receipt' );
  3397. $receipt = new receipt ();
  3398. Doo::loadModel ( 'receiptTraining' );
  3399. $receiptTraining = new receiptTraining ();
  3400. Doo::loadModel ( 'RItem' );
  3401. $RItem = new RItem ();
  3402. Doo::loadModel ( 'accountItem' );
  3403. $accountItem = new accountItem ();
  3404. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3405. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3406. die ();
  3407. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3408. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  3409. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  3410. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  3411. // if($value['name']=='税款'){
  3412. // unset($aiList[$key]);break;
  3413. // }
  3414. // }
  3415. //print_r($RItemList);
  3416. $data ['name'] = $name;
  3417. $data ['RItemList'] = $RItemList;
  3418. $data ['aiList'] = $aiList;
  3419. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3420. $data ['receiptDetail'] = $receiptDetail;
  3421. $data ['trainEdiType'] = "ITEM";
  3422. $data ['ridKey'] = $ridKey;
  3423. $data ['memu'] = "receipt";
  3424. $data ['staff'] = $this->staff;
  3425. $data ['receiptMemu'] = 'saeaBorad';
  3426. $data ['verifyId'] = $this->verifyId;
  3427. $data ['executeId'] = $this->executeId;
  3428. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  3429. }
  3430. /**
  3431. * 添加支出项 需要修改 费用金额合计
  3432. */
  3433. function receiptTrainItemAddDo() {
  3434. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3435. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  3436. // 支出项信息
  3437. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  3438. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  3439. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3440. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  3441. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  3442. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  3443. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  3444. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  3445. Doo::loadClass ( 'XDeode' );
  3446. $XDeode = new XDeode ( 5 );
  3447. Doo::loadModel ( 'RItem' );
  3448. $RItem = new RItem ();
  3449. $rid = $XDeode->decode ( $ridKey );
  3450. $rtid= $XDeode->decode ( $rtidKey );
  3451. if (! is_numeric ( $rid )){
  3452. die ( 'illegal request' );
  3453. }
  3454. Doo::loadModel ( 'receiptDetail' );
  3455. $receiptDetail = new receiptDetail ();
  3456. Doo::loadModel ( 'receipt' );
  3457. $receipt = new receipt ();
  3458. Doo::loadModel ( 'receiptTraining' );
  3459. $receiptTraining = new receiptTraining ();
  3460. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  3461. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  3462. $order = array (
  3463. "\r\n",
  3464. "\n",
  3465. "\r"
  3466. );
  3467. $replace = '<br/>';
  3468. $describe = str_replace ( $order, $replace, $describe );
  3469. $itemData = array (
  3470. 'rid' => $rid,
  3471. 'item' => $item,
  3472. 'price' => $price,
  3473. 'date' => $date,
  3474. 'inputer' => $inputer,
  3475. 'describe' => $describe,
  3476. 'creater' => $this->staff['0']['username'],
  3477. 'createrId' => $this->staff['0']['sid'],
  3478. 'creatDate' => date ( "Y-m-d H:i:s" ),
  3479. 'identifying'=>$identifyingTotal
  3480. );
  3481. if($payType=='company'){
  3482. $itemData += array (
  3483. 'payType' => 1
  3484. );
  3485. }
  3486. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  3487. //更新支出项标识总数
  3488. $itemData = array (
  3489. 'rtid'=>$rtid,
  3490. 'identifyingTotal'=>$identifyingTotal
  3491. );
  3492. $receiptTraining->setReceiptTrainByCondition($itemData);
  3493. $XDeode = new XDeode ( 7 );
  3494. if($payType=='company'){
  3495. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  3496. }else{
  3497. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  3498. }
  3499. } else
  3500. die ( 'illegal request-dataError' );
  3501. }
  3502. /**
  3503. * 培训班结算-讲师
  3504. */
  3505. function receiptTrainLecturerEdi() {
  3506. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3507. Doo::loadClass ( 'XDeode' );
  3508. $XDeode = new XDeode ( 7 );
  3509. $rid = $XDeode->decode ( $ridKey );
  3510. if (! is_numeric ( $rid ))
  3511. die ( 'illegal request' );
  3512. Doo::loadModel ( 'receipt' );
  3513. $receipt = new receipt ();
  3514. Doo::loadModel ( 'receiptTraining' );
  3515. $receiptTraining = new receiptTraining ();
  3516. Doo::loadModel ( 'RILecturer' );
  3517. $RILecturer = new RILecturer ();
  3518. Doo::loadModel ( 'lecturer' );
  3519. $lecturer = new lecturer ();
  3520. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3521. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3522. die ();
  3523. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3524. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  3525. $lecturerList = $lecturer->getLecturerAll ();
  3526. $INSIDEhtml = $OUTSIDEhtml = '';
  3527. foreach ( $lecturerList as $key => $value ) {
  3528. if ($value ['ltype'] == 'INSIDE') {
  3529. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  3530. } elseif ($value ['ltype'] == 'OUTSIDE') {
  3531. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  3532. }
  3533. }
  3534. $data ['INSIDEhtml'] = $INSIDEhtml;
  3535. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  3536. // print_r($RItemList);
  3537. $data ['RILecturerList'] = $RILecturerList;
  3538. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3539. $data ['receiptDetail'] = $receiptDetail;
  3540. $data ['trainEdiType'] = "LECTURER";
  3541. $data ['ridKey'] = $ridKey;
  3542. $data ['memu'] = "receipt";
  3543. $data ['staff'] = $this->staff;
  3544. $data ['receiptMemu'] = 'saeaBorad';
  3545. $data ['verifyId'] = $this->verifyId;
  3546. $data ['executeId'] = $this->executeId;
  3547. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  3548. }
  3549. /**
  3550. * 添加讲师
  3551. */
  3552. function receiptTrainLecturerAddDo() {
  3553. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3554. // 支出项信息
  3555. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  3556. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  3557. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  3558. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  3559. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  3560. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  3561. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  3562. Doo::loadClass ( 'XDeode' );
  3563. $XDeode = new XDeode ( 5 );
  3564. Doo::loadModel ( 'RILecturer' );
  3565. $RILecturer = new RILecturer ();
  3566. $rid = $XDeode->decode ( $ridKey );
  3567. if (! is_numeric ( $rid ))
  3568. die ( 'illegal request' );
  3569. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  3570. die ( 'illegal request-taxationError' );
  3571. $RILecturer->rid = $rid;
  3572. $RILecturer->ltype = $ltype;
  3573. if ($ltype == 'OUTSIDE') {
  3574. if ($taxation == 'TAXATION') {
  3575. $RILecturer->taxation = 1;
  3576. } elseif ($taxation == 'NOTAXATION') {
  3577. $RILecturer->taxation = 0;
  3578. }
  3579. }
  3580. $RILecturer->lecturerName = $lecturerName;
  3581. $RILecturer->schoolDay = $schoolDay;
  3582. $RILecturer->price = $price;
  3583. $RILecturer->fees=$fees;
  3584. $RILecturer->insert ();
  3585. // 添加公司汇总
  3586. // 报销详情
  3587. Doo::loadModel ( 'receiptDetail' );
  3588. $receiptDetail = new receiptDetail ();
  3589. Doo::loadModel ( 'receipt' );
  3590. $receipt = new receipt ();
  3591. // 金额总计
  3592. $price = $price * $schoolDay;
  3593. $rInfo = $receipt->getReceiptByRid ( $rid );
  3594. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  3595. if (empty ( $rdInfo )) {
  3596. $receiptDetail = new receiptDetail ();
  3597. $receiptDetail->staff = $rInfo ['staff'];
  3598. $receiptDetail->item = '讲课费';
  3599. $receiptDetail->itemCategory = '培训班费用';
  3600. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  3601. $receiptDetail->date = date ( "Y-m-d" );
  3602. $receiptDetail->cid = $rInfo ['cid'];
  3603. $receiptDetail->rid = $rid;
  3604. $receiptDetail->status = 4;
  3605. $receiptDetail->insert ();
  3606. } else {
  3607. $receiptDetail = new receiptDetail ();
  3608. $rdInfo ['price'] += $fees;
  3609. $receiptDetail->price = $rdInfo ['price'];
  3610. $receiptDetail->update ( array (
  3611. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  3612. ) );
  3613. }
  3614. $receipt = new receipt ();
  3615. $receipt->sum=$rInfo['sum']+$fees;
  3616. $receipt->update ( array (
  3617. 'where' => 'rid=' . $rid
  3618. ) );
  3619. $XDeode = new XDeode ( 7 );
  3620. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  3621. } else
  3622. die ( 'illegal request' );
  3623. }
  3624. /**
  3625. * 移除讲师
  3626. */
  3627. function receiptTrainLecturerDelDo() {
  3628. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  3629. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  3630. Doo::loadModel ( 'receipt' );
  3631. $receipt = new receipt ();
  3632. Doo::loadModel ( 'RILecturer' );
  3633. $RILecturer = new RILecturer ();
  3634. Doo::loadClass ( 'XDeode' );
  3635. $XDeode = new XDeode ( 5 );
  3636. $rid = $XDeode->decode ( $ridKey );
  3637. $rlid = $XDeode->decode ( $rlidKey );
  3638. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  3639. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3640. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  3641. die ( 'illegal request-status' );
  3642. }
  3643. $detail=$RILecturer->getRILecturerByRlid($rlid);
  3644. if (empty($detail)){
  3645. die ( 'illegal request-data' );
  3646. }
  3647. $RILecturer->delete ( array (
  3648. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  3649. ) );
  3650. //更新费用合计金额
  3651. $rInfo = $receipt->getReceiptByRid ( $rid );
  3652. $receipt = new receipt ();
  3653. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  3654. $receipt->update ( array (
  3655. 'where' => 'rid=' . $rid
  3656. ) );
  3657. Doo::loadModel ( 'receiptDetail' );
  3658. $receiptDetail = new receiptDetail ();
  3659. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  3660. $receiptDetail = new receiptDetail ();
  3661. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  3662. $receiptDetail->price = $rdInfo ['price'];
  3663. $receiptDetail->update ( array (
  3664. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  3665. ) );
  3666. $XDeode = new XDeode ( 7 );
  3667. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  3668. } else
  3669. die ( 'illegal request-iid' );
  3670. }
  3671. /**
  3672. * 培训班提交审批
  3673. */
  3674. function receiptTrainDo() {
  3675. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3676. Doo::loadClass ( 'XDeode' );
  3677. $XDeode = new XDeode ( 7 );
  3678. $rid = $XDeode->decode ( $ridKey );
  3679. Doo::loadModel ( 'receipt' );
  3680. $receipt = new receipt ();
  3681. Doo::loadModel ( 'receiptDetail' );
  3682. $receiptDetail = new receiptDetail ();
  3683. Doo::loadModel ( 'statistics' );
  3684. $statistics = new statistics ();
  3685. Doo::loadModel ( "verify" );
  3686. $verify = new verify ();
  3687. // 审批状态的判定
  3688. $receiptDetailList = $receipt->getOne ( array (
  3689. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  3690. 'asArray' => true
  3691. ) );
  3692. if (empty ( $receiptDetailList ))
  3693. return "/saeaBorad";
  3694. $verifyDetail = $verify->getOne ( array (
  3695. 'where' => ' vid =' . $receiptDetailList ['verify'],
  3696. 'asArray' => true
  3697. ) );
  3698. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3699. if (empty ( $receiptDetailList ['nowStaff'] )) {
  3700. $nowStaff = "";
  3701. $nowStaffList = array ();
  3702. if ($verifyDetail [0] [1] == 'ROLE') {
  3703. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3704. foreach ( $vStaffString as $key => $value ) {
  3705. $staffK = explode ( "_", $value );
  3706. array_push ( $nowStaffList, $staffK [0] );
  3707. }
  3708. $nowStaff = implode ( ',', $nowStaffList );
  3709. } else {
  3710. $nowStaff = $verifyDetail [0] [0];
  3711. }
  3712. $receipt->nowStaff = $nowStaff;
  3713. }
  3714. // echo $nowStaff;
  3715. // print_r($verifyDetail);die;
  3716. $receipt->rid = $receiptDetailList ['rid'];
  3717. $receipt->date = date ( "Y-m-d" );
  3718. $receipt->status = 2;
  3719. $receipt->update ();
  3720. $receiptDetail->status = 2;
  3721. $receiptDetail->update ( array (
  3722. 'where' => 'rid=' . $receiptDetailList ['rid']
  3723. ) );
  3724. Doo::loadModel ( "receiptLog" );
  3725. $receiptLog = new receiptLog ();
  3726. Doo::loadModel ( "verify" );
  3727. $verify = new verify ();
  3728. $vr = $verify->getOne ( array (
  3729. 'where' => 'vid=' . $receiptDetailList ['verify'],
  3730. 'asArray' => true
  3731. ) );
  3732. $jd = json_decode ( $vr ['staff'] );
  3733. $roleId = 0;
  3734. foreach ( $jd as $key => $value ) {
  3735. if ($value [1] == 'ROLE') {
  3736. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  3737. if ($pos !== false) {
  3738. $roleId = $value [0];
  3739. }
  3740. }
  3741. }
  3742. // 审批日志
  3743. // echo $roleId;die;
  3744. if (! empty ( $roleId )) {
  3745. Doo::loadModel ( "role" );
  3746. $role = new role ();
  3747. $roleInfo = $role->getOne ( array (
  3748. 'where' => 'rid=' . $roleId,
  3749. 'asArray' => true
  3750. ) );
  3751. // $receiptLog->rolename = $roleInfo ['name'];
  3752. }
  3753. $receiptLog->username = $this->staff [0] ['username'];
  3754. $receiptLog->uid = $this->staff [0] ['sid'];
  3755. $receiptLog->date = date ( "Y-m-d" );
  3756. $receiptLog->opinion = '提交审批';
  3757. $receiptLog->img = $this->staff [0] ['avatar'];
  3758. $receiptLog->status = 2;
  3759. $receiptLog->rid = $rid;
  3760. $receiptLog->insert ();
  3761. // 写入列表项
  3762. Doo::loadModel ( 'accountItem' );
  3763. $accountItem = new accountItem ();
  3764. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  3765. // 项目金额合计
  3766. Doo::loadModel ( 'RItem' );
  3767. $RItem = new RItem ();
  3768. // 讲师获得
  3769. Doo::loadModel ( 'RILecturer' );
  3770. $RILecturer = new RILecturer ();
  3771. $RItemList = $RItem->getRItemByRid ( $rid );
  3772. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  3773. // 支出项金额详情
  3774. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  3775. // print_r($aItem);
  3776. // print_r($aiData);
  3777. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  3778. $ag = $tr = $ta = $ot = 0;
  3779. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  3780. foreach ( $aItem as $key => $value ) {
  3781. if ($value ['category'] == $this->TRAIN) {
  3782. foreach ( $aiData ['dataList'] as $k => $v ) {
  3783. if ($value ['name'] == $v ['name']) {
  3784. array_push ( $accountJson [$this->TRAIN], array (
  3785. 'aid' => $value ['aid'],
  3786. 'name' => $value ['name'],
  3787. 'price' => number_format ( $v ['price'], 2, '.', '' )
  3788. ) );
  3789. $sum += $v ['price'];
  3790. $trainSum += $v ['price'];
  3791. unset ( $aiData ['dataList'] [$k] );
  3792. break;
  3793. }
  3794. }
  3795. }
  3796. }
  3797. $accountJson ['cSum'] = array (
  3798. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  3799. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  3800. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  3801. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  3802. );
  3803. // 报销单
  3804. $receipt = new receipt ();
  3805. $receipt->accountItem = json_encode ( $accountJson );
  3806. $receipt->sum = number_format ( $sum, 2, '.', '' );
  3807. $receipt->update ( array (
  3808. 'where' => 'rid=' . $rid
  3809. ) );
  3810. // print_r($accountJson);
  3811. // statistics item 统计写入
  3812. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  3813. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  3814. $accountItem = $accountJson;
  3815. $stat = $statistics->getOne ( array (
  3816. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  3817. 'asArray' => true
  3818. ) );
  3819. if (empty ( $stat )) {
  3820. $statistics->date = date ( "Y-m-d" );
  3821. $statistics->cid = $this->staff [0] ['cid'];
  3822. $statistics->staff = $this->staff [0] ['sid'];
  3823. $statistics->agPrice = 0;
  3824. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  3825. $statistics->insert ();
  3826. } else {
  3827. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  3828. $statistics->update ( array (
  3829. 'where' => 'sid=' . $stat ['sid']
  3830. ) );
  3831. }
  3832. return "/saeaBorad";
  3833. }
  3834. function confirmation() {
  3835. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3836. Doo::loadModel ( 'receipt' );
  3837. Doo::loadModel ( 'receiptDetail' );
  3838. $receipt = new receipt ();
  3839. $receiptDetail = new receiptDetail ();
  3840. Doo::loadModel ( 'statistics' );
  3841. Doo::loadModel ( 'itemStatistics' );
  3842. $statistics = new statistics ();
  3843. $itemStatistics = new itemStatistics ();
  3844. Doo::loadModel ( "verify" );
  3845. $verify = new verify ();
  3846. $receiptDetailList = $receipt->getOne ( array (
  3847. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  3848. 'asArray' => true
  3849. ) );
  3850. if (empty ( $receiptDetailList ))
  3851. return "/saeaBorad";
  3852. $verifyDetail = $verify->getOne ( array (
  3853. 'where' => ' vid =' . $receiptDetailList ['verify'],
  3854. 'asArray' => true
  3855. ) );
  3856. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3857. if (empty ( $receiptDetailList ['nowStaff'] )) {
  3858. $nowStaff = "";
  3859. $nowStaffList = array ();
  3860. if ($verifyDetail [0] [1] == 'ROLE') {
  3861. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3862. foreach ( $vStaffString as $key => $value ) {
  3863. $staffK = explode ( "_", $value );
  3864. array_push ( $nowStaffList, $staffK [0] );
  3865. }
  3866. $nowStaff = implode ( ',', $nowStaffList );
  3867. } else {
  3868. $nowStaff = $verifyDetail [0] [0];
  3869. }
  3870. $receipt->nowStaff = $nowStaff;
  3871. }
  3872. // echo $nowStaff;
  3873. // print_r($verifyDetail);die;
  3874. $receipt->rid = $receiptDetailList ['rid'];
  3875. $receipt->status = 2;
  3876. $receipt->update ();
  3877. // 操作日志
  3878. Doo::loadModel ( "receiptLog" );
  3879. $receiptLog = new receiptLog ();
  3880. $verify = new verify ();
  3881. $receiptInfo = $receipt->getOne ( array (
  3882. 'where' => 'rid=' . $rid,
  3883. 'asArray' => true
  3884. ) );
  3885. $vr = $verify->getOne ( array (
  3886. 'where' => 'vid=' . $receiptInfo ['verify'],
  3887. 'asArray' => true
  3888. ) );
  3889. $jd = json_decode ( $vr ['staff'] );
  3890. $roleId = 0;
  3891. foreach ( $jd as $key => $value ) {
  3892. if ($value [1] == 'ROLE') {
  3893. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  3894. if ($pos !== false) {
  3895. $roleId = $value [0];
  3896. }
  3897. }
  3898. }
  3899. // 审批日志
  3900. // echo $roleId;die;
  3901. if (! empty ( $roleId )) {
  3902. Doo::loadModel ( "role" );
  3903. $role = new role ();
  3904. $roleInfo = $role->getOne ( array (
  3905. 'where' => 'rid=' . $roleId,
  3906. 'asArray' => true
  3907. ) );
  3908. // $receiptLog->rolename = $roleInfo ['name'];
  3909. }
  3910. $receiptLog->username = $this->staff [0] ['username'];
  3911. $receiptLog->uid = $this->staff [0] ['sid'];
  3912. $receiptLog->date = date ( "Y-m-d" );
  3913. $receiptLog->opinion = '提交审批';
  3914. $receiptLog->img = $this->staff [0] ['avatar'];
  3915. $receiptLog->status = 2;
  3916. $receiptLog->rid = $rid;
  3917. $receiptLog->insert ();
  3918. return "/expenses";
  3919. }
  3920. function expenses() {
  3921. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  3922. if (empty ( $item ))
  3923. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  3924. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3925. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  3926. Doo::loadClass ( 'XDeode' );
  3927. $XDeode = new XDeode ( 7 );
  3928. Doo::loadModel ( 'receipt' );
  3929. $receipt = new receipt ();
  3930. Doo::loadModel ( 'L_category' );
  3931. $Lcategory = new L_category ();
  3932. Doo::loadModel ( 'verify' );
  3933. Doo::loadModel ( 'statistics' );
  3934. $statistics = new statistics ();
  3935. $verify = new verify ();
  3936. Doo::loadModel ( 'staff' );
  3937. $staff = new staff ();
  3938. $condition = "";
  3939. if ($item == "expenses")
  3940. $condition = " and Rtype=1 ";
  3941. elseif ($item == "receipts")
  3942. $condition = " and Rtype=0 ";
  3943. elseif ($item == "remits")
  3944. $condition = " and Rtype=2 ";
  3945. elseif ($item == "train")
  3946. $condition = " and Rtype=3 ";
  3947. $dateCondition = " and Year(date) =" . $year;
  3948. if (! empty ( $moth )) {
  3949. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  3950. $stList = $statistics->getOne ( array (
  3951. 'select' => 'rePrice ,agPrice',
  3952. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  3953. 'asArray' => true
  3954. ) );
  3955. } else
  3956. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  3957. if (empty ( $stList ))
  3958. $stList = array (
  3959. 'rePrice' => 0,
  3960. 'agPrice' => 0
  3961. );
  3962. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  3963. if (! isset ( $noPassSum ['sum'] ))
  3964. $noPassSum ['sum'] = 0;
  3965. $data ['stList'] = array (
  3966. 'rePrice' => $stList ['rePrice'],
  3967. 'agPrice' => $stList ['agPrice'],
  3968. 'skPrice' => ($noPassSum ['sum'])
  3969. );
  3970. $receiptList = $receipt->find ( array (
  3971. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  3972. 'desc' => 'rid',
  3973. 'asArray' => true
  3974. ) );
  3975. $Locate = 0;
  3976. $roleId = 0;
  3977. $button = 0;
  3978. foreach ( $receiptList as $key => $value ) {
  3979. $receiptList[$key]['balance']='';
  3980. if($value['Rtype']==1){
  3981. $receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
  3982. $receiptList[$key]['balanceABS']=abs($receiptList[$key]['balance']);
  3983. }elseif($value['Rtype']==3){
  3984. $payment=$this->_getReceiptTrainPayment($value['invoiceTrainId'],$value['trainLoanRid'],$value['rid']);
  3985. $receiptList[$key]['payment']=$payment;
  3986. $receiptList[$key]['paymentABS']=abs($payment);
  3987. }
  3988. $receiptList [$key] ['Locate'] = $Locate;
  3989. $Locate ++;
  3990. $receiptList [$key] ['reviseDetail'] = array ();
  3991. if (! empty ( $value ['reviseDetail'] ))
  3992. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3993. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3994. $categoryDetil = $Lcategory->getOne ( array (
  3995. 'where' => 'cid=' . $value ['cid'],
  3996. 'asArray' => true
  3997. ) );
  3998. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3999. // 检测编辑状态
  4000. $verifyList = $verify->getOne ( array (
  4001. 'where' => 'vid=' . $value ['verify'],
  4002. 'asArray' => true
  4003. ) );
  4004. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4005. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4006. Doo::loadModel ( 'role' );
  4007. $role = new role ();
  4008. $flag = true;
  4009. $roleKey = 0;
  4010. $endStaffArray = array ();
  4011. $roleArrayCopy = array ();
  4012. foreach ( $verifyList as $k => $v ) {
  4013. // init verifyStaff
  4014. if ($v [1] == 'ROLE') {
  4015. if (! empty ( $verifyStaff )) {
  4016. $endStaffArray = end ( $verifyStaff );
  4017. // if ($v[0]==$endStaffArray['nextStaff']){
  4018. // $roleId=$v[0];
  4019. // }
  4020. }
  4021. $roleVerify = json_decode ( $v [3], true );
  4022. $roleKey = $k;
  4023. $roleArray = array ();
  4024. $rolename = $role->getOne ( array (
  4025. 'where' => 'rid=' . $v [0],
  4026. 'asArray' => true
  4027. ) );
  4028. foreach ( $roleVerify as $o => $p ) {
  4029. $staffID = explode ( '_', $p );
  4030. $staffInfo = $staff->getOne ( array (
  4031. 'where' => 'sid=' . $staffID [0],
  4032. 'asArray' => true
  4033. ) );
  4034. // print_r($staffID);
  4035. $exp = array (
  4036. 0 => $staffInfo ['sid'],
  4037. 1 => $staffID [1],
  4038. 2 => $staffInfo ['avatar'],
  4039. 'date' => '',
  4040. 'date' => '',
  4041. 'opinion' => '',
  4042. 'status' => '',
  4043. 'rolename' => $rolename ['name']
  4044. );
  4045. array_push ( $roleArray, $exp );
  4046. }
  4047. $roleArrayCopy [$v [0]] = $roleArray;
  4048. // $verifyList[$k]['roleArray']=$roleArray;
  4049. }
  4050. $verifyList [$k] ['date'] = "";
  4051. $verifyList [$k] ['opinion'] = "";
  4052. $verifyList [$k] ['status'] = "";
  4053. if (empty ( $verifyStaff )) {
  4054. $verifyList [$k] ['date'] = "";
  4055. $verifyList [$k] ['opinion'] = "";
  4056. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4057. $verifyList [$k] ['status'] = 4;
  4058. $flag = false;
  4059. }
  4060. } else {
  4061. foreach ( $verifyStaff as $m => $u ) {
  4062. if ($v [0] == $m) {
  4063. $verifyList [$k] ['date'] = $u ['date'];
  4064. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4065. $verifyList [$k] ['status'] = $u ['status'];
  4066. $flag = false;
  4067. break;
  4068. }
  4069. }
  4070. $endStaffArray = end ( $verifyStaff );
  4071. if (isset ( $endStaffArray ['ROLE'] )) {
  4072. } else {
  4073. // $endKey=key($verifyStaff);
  4074. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4075. // $button=4;
  4076. // $verifyList[$k]['status']=4;
  4077. // }
  4078. }
  4079. }
  4080. }
  4081. $rolename ['name'] = '';
  4082. if (! empty ( $roleId )) {
  4083. Doo::loadModel ( 'role' );
  4084. $role = new role ();
  4085. $rolename = $role->getOne ( array (
  4086. 'where' => 'rid=' . $roleId,
  4087. 'asArray' => true
  4088. ) );
  4089. }
  4090. if (! empty ( $verifyStaff ))
  4091. $endStaffArray = end ( $verifyStaff );
  4092. $KOP = false;
  4093. foreach ( $roleArrayCopy as $P => $A ) {
  4094. foreach ( $A as $MKI => $AVL ) {
  4095. if (! empty ( $verifyStaff )) {
  4096. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4097. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4098. $button = 4;
  4099. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4100. }
  4101. foreach ( $verifyStaff as $m => $u ) {
  4102. $AVLFK = $AVL [0] . '_R';
  4103. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4104. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4105. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4106. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4107. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4108. break;
  4109. }
  4110. }
  4111. } else {
  4112. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4113. $button = 4;
  4114. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4115. }
  4116. }
  4117. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4118. $KOP = true;
  4119. }
  4120. }
  4121. foreach ( $roleArrayCopy as $k => $v ) {
  4122. foreach ( $verifyList as $m => $n ) {
  4123. if ($n [0] == $k) {
  4124. array_splice ( $verifyList, $m, 1, $v );
  4125. }
  4126. }
  4127. }
  4128. $receiptList [$key] ['verifyList'] = $verifyList;
  4129. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4130. 'where' => 'sid=' . $value ['staff'],
  4131. 'asArray' => true
  4132. ) );
  4133. $receiptList [$key] ['button'] = $button;
  4134. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  4135. }
  4136. // print_r($receiptList);die;
  4137. $mothHtml = "";
  4138. for($i = 1; $i <= 12; $i ++) {
  4139. if ($moth == $i)
  4140. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4141. else
  4142. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4143. }
  4144. $dateHtml = "";
  4145. $now = date ( "Y" );
  4146. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  4147. if ($YEARD <= $now) {
  4148. $dateHtml .= '<option ';
  4149. if ($year == $YEARD) {
  4150. $dateHtml .= 'selected ';
  4151. }
  4152. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  4153. }
  4154. }
  4155. $data ['dateHtml'] = $dateHtml;
  4156. $data ['mothHtml'] = $mothHtml;
  4157. $data ['receiptList'] = $receiptList;
  4158. $data ['memu'] = "receipt";
  4159. $data ['staff'] = $this->staff;
  4160. $data ['receiptMemu'] = 'expenses';
  4161. $data ['verifyId'] = $this->verifyId;
  4162. $data ['executeId'] = $this->executeId;
  4163. $data ['item'] = $item;
  4164. $data ['year'] = $year;
  4165. $this->render ( "/admin/expenses", $data );
  4166. }
  4167. function expensesCollect() {
  4168. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4169. Doo::loadModel ( 'receipt' );
  4170. $receipt = new receipt ();
  4171. Doo::loadModel ( 'L_category' );
  4172. $Lcategory = new L_category ();
  4173. Doo::loadModel ( 'verify' );
  4174. Doo::loadModel ( 'statistics' );
  4175. $statistics = new statistics ();
  4176. $verify = new verify ();
  4177. Doo::loadModel ( 'staff' );
  4178. $staff = new staff ();
  4179. Doo::loadModel ( 'loanReceipt' );
  4180. $loanReceipt = new loanReceipt ();
  4181. $receiptList = $receipt->find ( array (//去掉
  4182. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  4183. 'desc' => 'rid',
  4184. 'asArray' => true
  4185. ) );
  4186. $loanList = $loanReceipt->find ( array (
  4187. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4188. 'desc' => 'rid',
  4189. 'asArray' => true
  4190. ) );
  4191. /*
  4192. * $Locate=0;$roleId=0;$button=0; foreach ($loanList as $key=>$value){ $loanList[$key]['Locate']=$Locate;$Locate++; $loanList[$key]['reviseDetail']=array(); if (!empty($value['reviseDetail'])) $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true); $loanList[$key]['accountItem']=json_decode($value['accountItem'],true); $loanList[$key]['loanItem']=json_decode($value['loanItem'],true); $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true)); $loanList[$key]['category']=$categoryDetil['title']; //检测编辑状态 if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9) $verifyList['staff']=$value['verifyBreakup']; else $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true)); $verifyList=json_decode($verifyList['staff'],true);//status opinion $verifyStaff=json_decode($value['verifyStaff'],true); Doo::loadModel('role'); $role=new role(); $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array(); foreach ($verifyList as $k=>$v){ //init verifyStaff if ($v[1]=='ROLE'){ if (!empty($verifyStaff)){ $endStaffArray=end($verifyStaff); // if ($v[0]==$endStaffArray['nextStaff']){ // $roleId=$v[0]; // } } $roleVerify=json_decode($v[3],true); $roleKey=$k;$roleArray=array(); $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true)); foreach ($roleVerify as $o=>$p){ $staffID=explode ('_',$p); $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true)); //print_r($staffID); $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']); array_push($roleArray, $exp); } $roleArrayCopy[$v[0]]=$roleArray; //$verifyList[$k]['roleArray']=$roleArray; } $verifyList[$k]['date']=""; $verifyList[$k]['opinion']=""; $verifyList[$k]['status']=""; if (empty($verifyStaff)){ $verifyList[$k]['date']=""; $verifyList[$k]['opinion']=""; if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){ $verifyList[$k]['status']=4; $flag=false; } }else{ foreach ($verifyStaff as $m=>$u){ if ($v[0]==$m){ $verifyList[$k]['date']=$u['date']; $verifyList[$k]['opinion']=$u['opinion']; $verifyList[$k]['status']=$u['status']; $flag=false; break; } } $endStaffArray=end($verifyStaff); if (isset($endStaffArray['ROLE'])){ }else{ // $endKey=key($verifyStaff); // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){ // $button=4; // $verifyList[$k]['status']=4; // } } } } $rolename['name']=''; if (!empty($roleId)){ Doo::loadModel('role'); $role=new role(); $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true)); } if (!empty($verifyStaff)) $endStaffArray=end($verifyStaff); $KOP=false; foreach ($roleArrayCopy as $P=>$A){ foreach ( $A as $MKI=>$AVL){ if (!empty($verifyStaff)){ //&&$rolename['rid']==$endStaffArray['nextStaff'] if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){ $button=4; $roleArrayCopy[$P][$MKI]['status']=4; } foreach ($verifyStaff as $m=>$u){ $AVLFK=$AVL[0].'_R'; //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>'; if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1 $roleArrayCopy[$P][$MKI]['date']=$u['date']; $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion']; $roleArrayCopy[$P][$MKI]['status']=$u['status']; break; } } }else{ if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){ $button=4; $roleArrayCopy[$P][$MKI]['status']=4; } } //$roleArray[$MKI]['rolename']=$rolename['name']; $KOP=true; } } foreach ($roleArrayCopy as $k=>$v){ foreach ($verifyList as $m=>$n){ if ($n[0]==$k){ array_splice($verifyList,$m,1,$v); } } } $loanList[$key]['verifyList']=$verifyList; $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true)); $loanList[$key]['button']=$button; //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']); } $data['loanList']=$loanList;
  4193. */
  4194. $data ['explanation'] = '';
  4195. if (! empty ( $loanList ))
  4196. $data ['explanation'] = $loanList [0] ['explanation'];
  4197. $Locate = 0;
  4198. $roleId = 0;
  4199. $button = 0;
  4200. foreach ( $receiptList as $key => $value ) {
  4201. $receiptList [$key] ['Locate'] = $Locate;
  4202. $Locate ++;
  4203. $receiptList [$key] ['reviseDetail'] = array ();
  4204. if (! empty ( $value ['reviseDetail'] ))
  4205. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4206. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4207. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4208. $categoryDetil = $Lcategory->getOne ( array (
  4209. 'where' => 'cid=' . $value ['cid'],
  4210. 'asArray' => true
  4211. ) );
  4212. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4213. // 检测编辑状态
  4214. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  4215. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  4216. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  4217. else
  4218. $verifyList ['staff'] = $value ['verifyBreakup'];
  4219. } else
  4220. $verifyList = $verify->getOne ( array (
  4221. 'where' => 'vid=' . $value ['verify'],
  4222. 'asArray' => true
  4223. ) );
  4224. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4225. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4226. Doo::loadModel ( 'role' );
  4227. $role = new role ();
  4228. $flag = true;
  4229. $roleKey = 0;
  4230. $endStaffArray = array ();
  4231. $roleArrayCopy = array ();
  4232. foreach ( $verifyList as $k => $v ) {
  4233. // init verifyStaff
  4234. if ($v [1] == 'ROLE') {
  4235. if (! empty ( $verifyStaff )) {
  4236. $endStaffArray = end ( $verifyStaff );
  4237. // if ($v[0]==$endStaffArray['nextStaff']){
  4238. // $roleId=$v[0];
  4239. // }
  4240. }
  4241. $roleVerify = json_decode ( $v [3], true );
  4242. $roleKey = $k;
  4243. $roleArray = array ();
  4244. $rolename = $role->getOne ( array (
  4245. 'where' => 'rid=' . $v [0],
  4246. 'asArray' => true
  4247. ) );
  4248. foreach ( $roleVerify as $o => $p ) {
  4249. $staffID = explode ( '_', $p );
  4250. $staffInfo = $staff->getOne ( array (
  4251. 'where' => 'sid=' . $staffID [0],
  4252. 'asArray' => true
  4253. ) );
  4254. // print_r($staffID);
  4255. $exp = array (
  4256. 0 => $staffInfo ['sid'],
  4257. 1 => $staffID [1],
  4258. 2 => $staffInfo ['avatar'],
  4259. 'date' => '',
  4260. 'date' => '',
  4261. 'opinion' => '',
  4262. 'status' => '',
  4263. 'rolename' => $rolename ['name']
  4264. );
  4265. array_push ( $roleArray, $exp );
  4266. }
  4267. $roleArrayCopy [$v [0]] = $roleArray;
  4268. // $verifyList[$k]['roleArray']=$roleArray;
  4269. }
  4270. $verifyList [$k] ['date'] = "";
  4271. $verifyList [$k] ['opinion'] = "";
  4272. $verifyList [$k] ['status'] = "";
  4273. if (empty ( $verifyStaff )) {
  4274. $verifyList [$k] ['date'] = "";
  4275. $verifyList [$k] ['opinion'] = "";
  4276. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4277. $verifyList [$k] ['status'] = 4;
  4278. $flag = false;
  4279. }
  4280. } else {
  4281. foreach ( $verifyStaff as $m => $u ) {
  4282. if ($v [0] == $m) {
  4283. $verifyList [$k] ['date'] = $u ['date'];
  4284. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4285. $verifyList [$k] ['status'] = $u ['status'];
  4286. $flag = false;
  4287. break;
  4288. }
  4289. }
  4290. $endStaffArray = end ( $verifyStaff );
  4291. if (isset ( $endStaffArray ['ROLE'] )) {
  4292. } else {
  4293. // $endKey=key($verifyStaff);
  4294. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4295. // $button=4;
  4296. // $verifyList[$k]['status']=4;
  4297. // }
  4298. }
  4299. }
  4300. }
  4301. $rolename ['name'] = '';
  4302. if (! empty ( $roleId )) {
  4303. Doo::loadModel ( 'role' );
  4304. $role = new role ();
  4305. $rolename = $role->getOne ( array (
  4306. 'where' => 'rid=' . $roleId,
  4307. 'asArray' => true
  4308. ) );
  4309. }
  4310. if (! empty ( $verifyStaff ))
  4311. $endStaffArray = end ( $verifyStaff );
  4312. $KOP = false;
  4313. foreach ( $roleArrayCopy as $P => $A ) {
  4314. foreach ( $A as $MKI => $AVL ) {
  4315. if (! empty ( $verifyStaff )) {
  4316. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4317. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4318. $button = 4;
  4319. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4320. }
  4321. foreach ( $verifyStaff as $m => $u ) {
  4322. $AVLFK = $AVL [0] . '_R';
  4323. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4324. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4325. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4326. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4327. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4328. break;
  4329. }
  4330. }
  4331. } else {
  4332. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4333. $button = 4;
  4334. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4335. }
  4336. }
  4337. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4338. $KOP = true;
  4339. }
  4340. }
  4341. foreach ( $roleArrayCopy as $k => $v ) {
  4342. foreach ( $verifyList as $m => $n ) {
  4343. if ($n [0] == $k) {
  4344. array_splice ( $verifyList, $m, 1, $v );
  4345. }
  4346. }
  4347. }
  4348. // 费用执行人相关数据
  4349. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4350. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4351. foreach ( $executeCopy as $k => $v ) {
  4352. $executeCopy [$k] ['date'] = '';
  4353. $executeCopy [$k] ['opinion'] = '';
  4354. $executeCopy [$k] ['status'] = '';
  4355. if (! empty ( $executeStaff ))
  4356. foreach ( $executeStaff as $m => $u ) {
  4357. if ($v [0] == $m) {
  4358. $executeCopy [$k] ['date'] = $u ['date'];
  4359. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4360. $executeCopy [$k] ['status'] = $u ['status'];
  4361. break;
  4362. }
  4363. }
  4364. }
  4365. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4366. $receiptList [$key] ['verifyList'] = $verifyList;
  4367. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4368. 'where' => 'sid=' . $value ['staff'],
  4369. 'asArray' => true
  4370. ) );
  4371. $receiptList [$key] ['button'] = $button;
  4372. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4373. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4374. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4375. $receiptList [$key] ['relust'] = $relust;
  4376. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4377. }
  4378. Doo::loadModel ( 'enclosur' );
  4379. $enclosur = new enclosur ();
  4380. $enclosurList = $enclosur->find ( array (
  4381. 'where' => 'rid=' . $rid,
  4382. 'asArray' => true
  4383. ) );
  4384. $enclosurHtml = '';
  4385. foreach ( $enclosurList as $value ) {
  4386. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4387. }
  4388. $receiptList[0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  4389. $data ['enclosurHtml'] = $enclosurHtml;
  4390. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  4391. $data ['receiptList'] = $receiptList;
  4392. $data ['memu'] = "receipt";
  4393. $data ['staff'] = $this->staff;
  4394. $data ['receiptMemu'] = 'expenses';
  4395. $data ['verifyId'] = $this->verifyId;
  4396. $data ['executeId'] = $this->executeId;
  4397. if($receiptList[0]['receiptClass']==2){
  4398. if(!empty($receiptList[0]['itinerary2'])){
  4399. $this->render ( "/receipt/feeTraveDetail2", $data );
  4400. }else{
  4401. $this->render ( "/receipt/feeTraveDetail", $data );
  4402. }
  4403. }else{
  4404. $this->render ( "/admin/expensesCollect", $data );
  4405. }
  4406. }
  4407. function approvalExpenses() {
  4408. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  4409. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4410. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4411. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4412. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4413. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  4414. // echo $rdate;
  4415. if (empty ( $status ))
  4416. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4417. $page_size = 8;
  4418. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4419. $vidList = array ();
  4420. $button = 0;
  4421. Doo::loadModel ( 'verify' );
  4422. $verify = new verify ();
  4423. Doo::loadModel ( 'receipt' );
  4424. $receipt = new receipt ();
  4425. Doo::loadModel ( 'staff' );
  4426. $staff = new staff ();
  4427. Doo::loadModel ( 'L_category' );
  4428. $Lcategory = new L_category ();
  4429. // user verify ID
  4430. $verifyDetail = $verify->find ( array (
  4431. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4432. 'asArray' => true
  4433. ) );
  4434. foreach ( $verifyDetail as $key => $value ) {
  4435. array_push ( $vidList, $value ['vid'] );
  4436. }
  4437. $vid = implode ( ",", $vidList );
  4438. if (empty ( $verifyDetail )){
  4439. $vid = 0;
  4440. }
  4441. $dateCondition = " ";
  4442. // if (! empty ( $month ))
  4443. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  4444. if ($status == 'done' || $status == 'termination') {
  4445. if (! empty ( $year )) {
  4446. $dateCondition = " and Year(pastDate) =" . $year;
  4447. if (! empty ( $month ))
  4448. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  4449. }
  4450. } elseif ($status == 'finish') {
  4451. if (! empty ( $year )) {
  4452. $dateCondition = " and Year(pastDate) =" . $year;
  4453. if (! empty ( $month ))
  4454. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  4455. }
  4456. }
  4457. // date ( 'Y-m' )
  4458. // if (! empty ( $rdate ) && $status == 'done')
  4459. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  4460. // elseif (! empty ( $rdate ))
  4461. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  4462. $categoryList = $Lcategory->find ( array (
  4463. 'asArray' => true
  4464. ) );
  4465. $staffList = $staff->find ( array (
  4466. 'where' => 'cid=' . $cid,
  4467. 'asArray' => true
  4468. ) );
  4469. $cateCondition = "";
  4470. $staffCondition = "";
  4471. $approvalCondition = "";
  4472. if (! empty ( $cid )) {
  4473. $cateCondition = ' and cid=' . $cid;
  4474. }
  4475. if (! empty ( $sid )) {
  4476. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  4477. $cateCondition = "";
  4478. }
  4479. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  4480. if ($status == 'pendApproval') {
  4481. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4482. }
  4483. if ($status == 'ongoing') {
  4484. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  4485. }
  4486. if ($status == 'done') {
  4487. $approvalCondition = ' and (status=8 or status=9 ) ';
  4488. }
  4489. if ($status == 'termination') {
  4490. $approvalCondition = " and status=3";
  4491. }
  4492. if ($status == 'finish') {
  4493. $approvalCondition = " and (status=1 or status=8 or status=9 or status=10)";
  4494. }
  4495. if($status == 'loan'){
  4496. $approvalCondition = " and (status=8 or status=7) and Rtype=1";
  4497. }
  4498. $pageinfo ['page'] = array (
  4499. 'previous' => ''
  4500. );
  4501. if(!empty($receiptOrder)){
  4502. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  4503. $receiptList = $receipt->find ( array ( // $dateCondition
  4504. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  4505. 'desc' => 'rid',
  4506. 'asArray' => true
  4507. ) );
  4508. }else{
  4509. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  4510. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  4511. $receiptList = $receipt->find ( array ( // $dateCondition.
  4512. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  4513. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  4514. 'desc' => 'rid',
  4515. 'asArray' => true
  4516. ) );
  4517. } else {
  4518. $receiptList = $receipt->find ( array ( // $dateCondition
  4519. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  4520. 'desc' => 'rid',
  4521. 'asArray' => true
  4522. ) );
  4523. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  4524. }
  4525. }
  4526. $rLRes = $receipt->find ( array (
  4527. 'where' => 'status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )' . $cateCondition . $staffCondition . ' and verify in (' . $vid . ')',
  4528. 'desc' => 'rid',
  4529. 'asArray' => true
  4530. ) );
  4531. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  4532. // print_r($receiptList);
  4533. Doo::loadClass ( 'XDeode' );
  4534. $XDeode = new XDeode ( 7 );
  4535. $Locate = 0;
  4536. //
  4537. $reportList = $reportCateList = array ();
  4538. foreach ( $receiptList as $key => $value ) {
  4539. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  4540. $receiptList [$key] ['Locate'] = $Locate;
  4541. $Locate ++;
  4542. $receiptList [$key] ['reviseDetail'] = array ();
  4543. if (! empty ( $value ['reviseDetail'] ))
  4544. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4545. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4546. $categoryDetil = $Lcategory->getOne ( array (
  4547. 'where' => 'cid=' . $value ['cid'],
  4548. 'asArray' => true
  4549. ) );
  4550. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4551. $verifyList = $verify->getOne ( array (
  4552. 'where' => 'vid=' . $value ['verify'],
  4553. 'asArray' => true
  4554. ) );
  4555. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4556. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4557. foreach ( $verifyList as $k => $v ) {
  4558. // init verifyStaff
  4559. $verifyList [$k] ['date'] = "";
  4560. $verifyList [$k] ['opinion'] = "";
  4561. $verifyList [$k] ['status'] = "";
  4562. if (empty ( $verifyStaff )) {
  4563. $verifyList [$k] ['date'] = "";
  4564. $verifyList [$k] ['opinion'] = "";
  4565. if ($v [0] == $this->staff [0] ['sid']) {
  4566. $verifyList [$k] ['status'] = 4;
  4567. $button = 4;
  4568. }
  4569. } else {
  4570. $flag = true;
  4571. foreach ( $verifyStaff as $m => $u ) {
  4572. if ($v [0] == $m) {
  4573. $verifyList [$k] ['date'] = $u ['date'];
  4574. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4575. $verifyList [$k] ['status'] = $u ['status'];
  4576. $flag = false;
  4577. break;
  4578. }
  4579. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4580. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4581. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4582. }
  4583. if ($flag) { // 检测可编辑
  4584. if ($v [0] == $this->staff [0] ['sid']) {
  4585. $verifyList [$k] ['status'] = 4;
  4586. $button = 4;
  4587. }
  4588. }
  4589. }
  4590. }
  4591. $receiptList [$key] ['verifyList'] = $verifyList;
  4592. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4593. 'where' => 'sid=' . $value ['staff'],
  4594. 'asArray' => true
  4595. ) );
  4596. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  4597. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  4598. $receiptList [$key] ['button'] = $button;
  4599. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  4600. //获得培训班结算RID 借款费用--已经锁定
  4601. if($value['status']==10){
  4602. $trainRD=$receipt->getReceiptByTrainLoanRid($value['rid']);
  4603. $receiptList [$key]['trainRidKey7']=$trainRD['ridKey7'];
  4604. }
  4605. }
  4606. $reportList = array_unique ( $reportList );
  4607. $reportHtml = '';
  4608. foreach ( $reportList as $key => $value ) {
  4609. $v = explode ( "-", $value );
  4610. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  4611. }
  4612. // print_r($reportList)
  4613. $data ['reportHtml'] = $reportHtml;
  4614. $reportCateList = array_unique ( $reportCateList );
  4615. $reportCateHtml = '';
  4616. foreach ( $reportCateList as $key => $value ) {
  4617. $v = explode ( "-", $value );
  4618. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  4619. }
  4620. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  4621. $data ['reportCateHtml'] = $reportCateHtml;
  4622. // print_r($receiptList);die;
  4623. // $data['verifyDetail']=$verifyDetail;
  4624. $mothHtml = "";
  4625. for($i = 1; $i <= 12; $i ++) {
  4626. if ($month == $i)
  4627. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  4628. else
  4629. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  4630. }
  4631. $data ['mothHtml'] = $mothHtml;
  4632. $dateHtml = "";
  4633. $now = date ( "Y" );
  4634. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  4635. if ($YEARD <= $now) {
  4636. $dateHtml .= '<option ';
  4637. if ($year == $YEARD) {
  4638. $dateHtml .= 'selected ';
  4639. }
  4640. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  4641. }
  4642. }
  4643. $data ['dateHtml'] = $dateHtml;
  4644. $data ['page'] = $pageinfo;
  4645. $data ['receiptList'] = $receiptList;
  4646. $data ['receiptApprovalCount'] = count ( $rLRes );
  4647. $data ['status'] = $status;
  4648. $data ['year'] = $year;
  4649. $data ['month'] = $month;
  4650. $data ['categoryList'] = $categoryList;
  4651. $data ['staffList'] = $staffList;
  4652. $data ['cid'] = $cid;
  4653. $data ['sid'] = $sid;
  4654. // print_r($receiptList);
  4655. $data['receiptOrder']=$receiptOrder;
  4656. $data ['memu'] = "receipt";
  4657. $data ['staff'] = $this->staff;
  4658. $data ['receiptMemu'] = 'approvalExpenses';
  4659. $data ['verifyId'] = $this->verifyId;
  4660. $data ['executeId'] = $this->executeId;
  4661. $this->render ( "/admin/approvalExpenses", $data );
  4662. }
  4663. private function _expensesDoc(){
  4664. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  4665. Doo::loadClass ( 'XDeode' );
  4666. $XDeode = new XDeode ( 5 );
  4667. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  4668. $rid = $XDeode->decode ( $rid );
  4669. if (! is_numeric ( $rid ))
  4670. die ( 'illegal request' );
  4671. Doo::loadModel ( 'receipt' );
  4672. $receipt = new receipt ();
  4673. Doo::loadModel ( 'L_category' );
  4674. $Lcategory = new L_category ();
  4675. Doo::loadModel ( 'verify' );
  4676. Doo::loadModel ( 'statistics' );
  4677. $statistics = new statistics ();
  4678. $verify = new verify ();
  4679. Doo::loadModel ( 'staff' );
  4680. $staff = new staff ();
  4681. Doo::loadModel ( 'loanReceipt' );
  4682. $loanReceipt = new loanReceipt ();
  4683. $receiptList = $receipt->find ( array (
  4684. 'where' => ' rid=' . $rid,
  4685. 'desc' => 'rid',
  4686. 'asArray' => true
  4687. ) );
  4688. $loanList = array ();
  4689. if (! empty ( $receiptList ))
  4690. $loanList = $loanReceipt->find ( array (
  4691. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4692. 'desc' => 'rid',
  4693. 'asArray' => true
  4694. ) );
  4695. $Locate = 0;
  4696. $roleId = 0;
  4697. $button = 0;
  4698. foreach ( $loanList as $key => $value ) {
  4699. $loanList [$key] ['Locate'] = $Locate;
  4700. $Locate ++;
  4701. $loanList [$key] ['reviseDetail'] = array ();
  4702. if (! empty ( $value ['reviseDetail'] ))
  4703. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4704. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4705. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4706. $categoryDetil = $Lcategory->getOne ( array (
  4707. 'where' => 'cid=' . $value ['cid'],
  4708. 'asArray' => true
  4709. ) );
  4710. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4711. // 检测编辑状态
  4712. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  4713. $verifyList ['staff'] = $value ['verifyBreakup'];
  4714. else
  4715. $verifyList = $verify->getOne ( array (
  4716. 'where' => 'vid=' . $value ['verify'],
  4717. 'asArray' => true
  4718. ) );
  4719. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4720. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4721. Doo::loadModel ( 'role' );
  4722. $role = new role ();
  4723. $flag = true;
  4724. $roleKey = 0;
  4725. $endStaffArray = array ();
  4726. $roleArrayCopy = array ();
  4727. foreach ( $verifyList as $k => $v ) {
  4728. // init verifyStaff
  4729. if ($v [1] == 'ROLE') {
  4730. if (! empty ( $verifyStaff )) {
  4731. $endStaffArray = end ( $verifyStaff );
  4732. // if ($v[0]==$endStaffArray['nextStaff']){
  4733. // $roleId=$v[0];
  4734. // }
  4735. }
  4736. $roleVerify = json_decode ( $v [3], true );
  4737. $roleKey = $k;
  4738. $roleArray = array ();
  4739. $rolename = $role->getOne ( array (
  4740. 'where' => 'rid=' . $v [0],
  4741. 'asArray' => true
  4742. ) );
  4743. foreach ( $roleVerify as $o => $p ) {
  4744. $staffID = explode ( '_', $p );
  4745. $staffInfo = $staff->getOne ( array (
  4746. 'where' => 'sid=' . $staffID [0],
  4747. 'asArray' => true
  4748. ) );
  4749. // print_r($staffID);
  4750. $exp = array (
  4751. 0 => $staffInfo ['sid'],
  4752. 1 => $staffID [1],
  4753. 2 => $staffInfo ['avatar'],
  4754. 'date' => '',
  4755. 'date' => '',
  4756. 'opinion' => '',
  4757. 'status' => '',
  4758. 'rolename' => $rolename ['name']
  4759. );
  4760. array_push ( $roleArray, $exp );
  4761. }
  4762. $roleArrayCopy [$v [0]] = $roleArray;
  4763. // $verifyList[$k]['roleArray']=$roleArray;
  4764. }
  4765. $verifyList [$k] ['date'] = "";
  4766. $verifyList [$k] ['opinion'] = "";
  4767. $verifyList [$k] ['status'] = "";
  4768. if (empty ( $verifyStaff )) {
  4769. $verifyList [$k] ['date'] = "";
  4770. $verifyList [$k] ['opinion'] = "";
  4771. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4772. $verifyList [$k] ['status'] = 4;
  4773. $flag = false;
  4774. }
  4775. } else {
  4776. foreach ( $verifyStaff as $m => $u ) {
  4777. if ($v [0] == $m) {
  4778. $verifyList [$k] ['date'] = $u ['date'];
  4779. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4780. $verifyList [$k] ['status'] = $u ['status'];
  4781. $flag = false;
  4782. break;
  4783. }
  4784. }
  4785. $endStaffArray = end ( $verifyStaff );
  4786. if (isset ( $endStaffArray ['ROLE'] )) {
  4787. } else {
  4788. // $endKey=key($verifyStaff);
  4789. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4790. // $button=4;
  4791. // $verifyList[$k]['status']=4;
  4792. // }
  4793. }
  4794. }
  4795. }
  4796. $rolename ['name'] = '';
  4797. if (! empty ( $roleId )) {
  4798. Doo::loadModel ( 'role' );
  4799. $role = new role ();
  4800. $rolename = $role->getOne ( array (
  4801. 'where' => 'rid=' . $roleId,
  4802. 'asArray' => true
  4803. ) );
  4804. }
  4805. if (! empty ( $verifyStaff ))
  4806. $endStaffArray = end ( $verifyStaff );
  4807. $KOP = false;
  4808. foreach ( $roleArrayCopy as $P => $A ) {
  4809. foreach ( $A as $MKI => $AVL ) {
  4810. if (! empty ( $verifyStaff )) {
  4811. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4812. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4813. $button = 4;
  4814. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4815. }
  4816. foreach ( $verifyStaff as $m => $u ) {
  4817. $AVLFK = $AVL [0] . '_R';
  4818. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4819. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4820. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4821. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4822. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4823. break;
  4824. }
  4825. }
  4826. } else {
  4827. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4828. $button = 4;
  4829. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4830. }
  4831. }
  4832. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4833. $KOP = true;
  4834. }
  4835. }
  4836. foreach ( $roleArrayCopy as $k => $v ) {
  4837. foreach ( $verifyList as $m => $n ) {
  4838. if ($n [0] == $k) {
  4839. array_splice ( $verifyList, $m, 1, $v );
  4840. }
  4841. }
  4842. }
  4843. $loanList [$key] ['verifyList'] = $verifyList;
  4844. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4845. 'where' => 'sid=' . $value ['staff'],
  4846. 'asArray' => true
  4847. ) );
  4848. $loanList [$key] ['button'] = $button;
  4849. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  4850. }
  4851. $data ['loanList'] = $loanList;
  4852. //print_r($loanList);
  4853. $Locate = 0;
  4854. $roleId = 0;
  4855. $button = 0;
  4856. foreach ( $receiptList as $key => $value ) {
  4857. $receiptList [$key] ['Locate'] = $Locate;
  4858. $Locate ++;
  4859. $receiptList [$key] ['reviseDetail'] = array ();
  4860. if (! empty ( $value ['reviseDetail'] ))
  4861. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4862. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4863. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4864. $categoryDetil = $Lcategory->getOne ( array (
  4865. 'where' => 'cid=' . $value ['cid'],
  4866. 'asArray' => true
  4867. ) );
  4868. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4869. // 检测编辑状态
  4870. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  4871. $verifyList ['staff'] = $value ['verifyBreakup'];
  4872. } else
  4873. $verifyList = $verify->getOne ( array (
  4874. 'where' => 'vid=' . $value ['verify'],
  4875. 'asArray' => true
  4876. ) );
  4877. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4878. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4879. Doo::loadModel ( 'role' );
  4880. $role = new role ();
  4881. if ($verifyList == NULL)
  4882. $verifyList = array ();
  4883. $flag = true;
  4884. $roleKey = 0;
  4885. $endStaffArray = array ();
  4886. $roleArrayCopy = array ();
  4887. foreach ( $verifyList as $k => $v ) {
  4888. // init verifyStaff
  4889. if ($v [1] == 'ROLE') {
  4890. if (! empty ( $verifyStaff )) {
  4891. $endStaffArray = end ( $verifyStaff );
  4892. // if ($v[0]==$endStaffArray['nextStaff']){
  4893. // $roleId=$v[0];
  4894. // }
  4895. }
  4896. $roleVerify = json_decode ( $v [3], true );
  4897. $roleKey = $k;
  4898. $roleArray = array ();
  4899. $rolename = $role->getOne ( array (
  4900. 'where' => 'rid=' . $v [0],
  4901. 'asArray' => true
  4902. ) );
  4903. foreach ( $roleVerify as $o => $p ) {
  4904. $staffID = explode ( '_', $p );
  4905. $staffInfo = $staff->getOne ( array (
  4906. 'where' => 'sid=' . $staffID [0],
  4907. 'asArray' => true
  4908. ) );
  4909. // print_r($staffID);
  4910. $exp = array (
  4911. 0 => $staffInfo ['sid'],
  4912. 1 => $staffID [1],
  4913. 2 => $staffInfo ['avatar'],
  4914. 'date' => '',
  4915. 'date' => '',
  4916. 'opinion' => '',
  4917. 'status' => '',
  4918. 'rolename' => $rolename ['name']
  4919. );
  4920. array_push ( $roleArray, $exp );
  4921. }
  4922. $roleArrayCopy [$v [0]] = $roleArray;
  4923. // $verifyList[$k]['roleArray']=$roleArray;
  4924. }
  4925. $verifyList [$k] ['date'] = "";
  4926. $verifyList [$k] ['opinion'] = "";
  4927. $verifyList [$k] ['status'] = "";
  4928. if (empty ( $verifyStaff )) {
  4929. $verifyList [$k] ['date'] = "";
  4930. $verifyList [$k] ['opinion'] = "";
  4931. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4932. $verifyList [$k] ['status'] = 4;
  4933. $flag = false;
  4934. }
  4935. } else {
  4936. foreach ( $verifyStaff as $m => $u ) {
  4937. if ($v [0] == $m) {
  4938. $verifyList [$k] ['date'] = $u ['date'];
  4939. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4940. $verifyList [$k] ['status'] = $u ['status'];
  4941. $flag = false;
  4942. break;
  4943. }
  4944. }
  4945. $endStaffArray = end ( $verifyStaff );
  4946. if (isset ( $endStaffArray ['ROLE'] )) {
  4947. } else {
  4948. // $endKey=key($verifyStaff);
  4949. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4950. // $button=4;
  4951. // $verifyList[$k]['status']=4;
  4952. // }
  4953. }
  4954. }
  4955. }
  4956. $FC = @$rolename ['name'];
  4957. $rolename ['name'] = '';
  4958. if (! empty ( $roleId )) {
  4959. Doo::loadModel ( 'role' );
  4960. $role = new role ();
  4961. $rolename = $role->getOne ( array (
  4962. 'where' => 'rid=' . $roleId,
  4963. 'asArray' => true
  4964. ) );
  4965. }
  4966. if (! empty ( $verifyStaff ))
  4967. $endStaffArray = end ( $verifyStaff );
  4968. $KOP = false;
  4969. foreach ( $roleArrayCopy as $P => $A ) {
  4970. foreach ( $A as $MKI => $AVL ) {
  4971. if (! empty ( $verifyStaff )) {
  4972. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4973. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4974. $button = 4;
  4975. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4976. }
  4977. foreach ( $verifyStaff as $m => $u ) {
  4978. $AVLFK = $AVL [0] . '_R';
  4979. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4980. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4981. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4982. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4983. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4984. break;
  4985. }
  4986. }
  4987. } else {
  4988. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4989. $button = 4;
  4990. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4991. }
  4992. }
  4993. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4994. $KOP = true;
  4995. }
  4996. }
  4997. foreach ( $roleArrayCopy as $k => $v ) {
  4998. foreach ( $verifyList as $m => $n ) {
  4999. if ($n [0] == $k) {
  5000. array_splice ( $verifyList, $m, 1, $v );
  5001. }
  5002. }
  5003. }
  5004. // 费用执行人相关数据
  5005. $executeCopy = json_decode ( $value ['executeCopy'], true );
  5006. $executeStaff = json_decode ( $value ['executeStaff'], true );
  5007. foreach ( $executeCopy as $k => $v ) {
  5008. $executeCopy [$k] ['date'] = '';
  5009. $executeCopy [$k] ['opinion'] = '';
  5010. $executeCopy [$k] ['status'] = '';
  5011. if (! empty ( $executeStaff ))
  5012. foreach ( $executeStaff as $m => $u ) {
  5013. if ($v [0] == $m) {
  5014. $executeCopy [$k] ['date'] = $u ['date'];
  5015. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  5016. $executeCopy [$k] ['status'] = $u ['status'];
  5017. break;
  5018. }
  5019. }
  5020. }
  5021. $receiptList [$key] ['executeCopy'] = $executeCopy;
  5022. // print_r($verifyList);
  5023. $receiptList [$key] ['verifyList'] = $verifyList;
  5024. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5025. 'where' => 'sid=' . $value ['staff'],
  5026. 'asArray' => true
  5027. ) );
  5028. $receiptList [$key] ['button'] = $button;
  5029. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5030. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5031. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5032. $receiptList [$key] ['relust'] = $relust;
  5033. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5034. }
  5035. // print_r($receiptList);
  5036. // 获取审批日志
  5037. Doo::loadModel ( 'receiptLog' );
  5038. $receiptLog = new receiptLog ();
  5039. $rlList = array ();
  5040. $rlInfo = $receiptLog->getOne ( array (
  5041. 'where' => 'rid=' . $rid . ' and status=4',
  5042. 'asArray' => true
  5043. ) );
  5044. // $tijdate = $receiptLog->getOne ( array (
  5045. // 'where' => 'rid=' . $rid . ' and status=2',
  5046. // 'asc' => 'rlid',
  5047. // 'asArray' => true
  5048. // ) );
  5049. if (! empty ( $rlInfo )) {
  5050. $rlList = $receiptLog->find ( array (
  5051. 'where' => 'rid=' . $rid,
  5052. 'asc' => 'rlid',
  5053. 'asArray' => true
  5054. ) );
  5055. }
  5056. $RN=array();
  5057. if (!empty( $rolename ['staff'])){
  5058. $RN = @json_decode ( $rolename ['staff'] );
  5059. }
  5060. //
  5061. foreach ( $rlList as $key => $value ) {
  5062. $rlList [$key] ['rolename'] = '';
  5063. foreach ( $RN as $k => $v ) {
  5064. $id = explode ( "_", $v );
  5065. if ($id [0] == $value ['uid']) {
  5066. $rlList [$key] ['rolename'] = $FC;
  5067. break;
  5068. }
  5069. }
  5070. }
  5071. Doo::loadModel ( 'enclosur' );
  5072. $enclosur = new enclosur ();
  5073. $enclosurList = $enclosur->find ( array (
  5074. 'where' => 'rid=' . $rid,
  5075. 'asArray' => true
  5076. ) );
  5077. $enclosurHtml = '';
  5078. foreach ( $enclosurList as $value ) {
  5079. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5080. }
  5081. $data ['enclosurHtml'] = $enclosurHtml;
  5082. $receiptList [0] ['rlList'] = $rlList;
  5083. $data ['receiptList'] = $receiptList;
  5084. $data ['receiptList'][0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  5085. // print_r($receiptList);
  5086. $data ['memu'] = "receipt";
  5087. $data ['staff'] = $this->staff;
  5088. $data ['receiptMemu'] = 'approvalExpenses';
  5089. $data ['verifyId'] = $this->verifyId;
  5090. $data ['executeId'] = $this->executeId;
  5091. return $data;
  5092. }
  5093. function expensesDoc() {
  5094. $data=$this->_expensesDoc();
  5095. if(!empty($data['receiptList'][0]['itinerary2'])){
  5096. $this->render ( "/receipt/feeTraveView", $data );
  5097. }else{
  5098. $this->render ( "/admin/expensesDoc", $data );
  5099. }
  5100. }
  5101. function expensesDocPrint(){
  5102. $data=$this->_expensesDoc();
  5103. $this->render ( "/receipt/expensesDocPrint", $data );
  5104. }
  5105. function expensesEdi() {
  5106. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5107. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5108. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5109. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5110. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5111. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5112. if (empty ( $status ))
  5113. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5114. $vidList = array ();
  5115. $button = 0;
  5116. Doo::loadModel ( 'verify' );
  5117. Doo::loadModel ( 'receipt' );
  5118. Doo::loadModel ( 'staff' );
  5119. $staff = new staff ();
  5120. $receipt = new receipt ();
  5121. $verify = new verify ();
  5122. Doo::loadModel ( 'L_category' );
  5123. $Lcategory = new L_category ();
  5124. Doo::loadModel ( 'enclosur' );
  5125. $enclosur = new enclosur ();
  5126. // user verify ID
  5127. $verifyDetail = $verify->find ( array (
  5128. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5129. 'asArray' => true
  5130. ) );
  5131. foreach ( $verifyDetail as $key => $value ) {
  5132. array_push ( $vidList, $value ['vid'] );
  5133. }
  5134. $vid = implode ( ",", $vidList );
  5135. if (empty ( $verifyDetail ))
  5136. $vid = 0;
  5137. $categoryList = $Lcategory->find ( array (
  5138. 'asArray' => true
  5139. ) );
  5140. $staffList = $staff->find ( array (
  5141. 'where' => 'cid=' . $cid,
  5142. 'asArray' => true
  5143. ) );
  5144. $ap = "";
  5145. if ($status == 4) {
  5146. $ap = 4;
  5147. $status = 2;
  5148. }
  5149. // get Receipt By verifyID status 2
  5150. $receiptList = $receipt->find ( array (
  5151. 'where' => 'rid =' . $rid . ' and status=2',
  5152. 'desc' => 'rid',
  5153. 'asArray' => true
  5154. ) );
  5155. if (empty ( $receiptList )) {
  5156. die ( 'illegal request' );
  5157. }
  5158. $Locate = 0;
  5159. $roleId = 0;
  5160. if ($ap == 4)
  5161. $status = 4;
  5162. foreach ( $receiptList as $key => $value ) {
  5163. $receiptList [$key] ['Locate'] = $Locate;
  5164. $Locate ++;
  5165. $receiptList [$key] ['reviseDetail'] = array ();
  5166. if (! empty ( $value ['reviseDetail'] ))
  5167. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5168. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5169. $categoryDetil = $Lcategory->getOne ( array (
  5170. 'where' => 'cid=' . $value ['cid'],
  5171. 'asArray' => true
  5172. ) );
  5173. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5174. // 检测编辑状态
  5175. $verifyList = $verify->getOne ( array (
  5176. 'where' => 'vid=' . $value ['verify'],
  5177. 'asArray' => true
  5178. ) );
  5179. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5180. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5181. Doo::loadModel ( 'role' );
  5182. $role = new role ();
  5183. // print_r($verifyList);
  5184. $flag = true;
  5185. $roleKey = 0;
  5186. $endStaffArray = array ();
  5187. $roleArrayCopy = array ();
  5188. foreach ( $verifyList as $k => $v ) {
  5189. // init verifyStaff
  5190. if ($v [1] == 'ROLE') {
  5191. if (! empty ( $verifyStaff )) {
  5192. $endStaffArray = end ( $verifyStaff );
  5193. if ($v [0] == $endStaffArray ['nextStaff']) {
  5194. $roleId = $v [0];
  5195. }
  5196. }
  5197. $roleVerify = json_decode ( $v [3], true );
  5198. $roleKey = $k;
  5199. $roleArray = array ();
  5200. $rolename = $role->getOne ( array (
  5201. 'where' => 'rid=' . $v [0],
  5202. 'asArray' => true
  5203. ) );
  5204. foreach ( $roleVerify as $o => $p ) {
  5205. $staffID = explode ( '_', $p );
  5206. $staffInfo = $staff->getOne ( array (
  5207. 'where' => 'sid=' . $staffID [0],
  5208. 'asArray' => true
  5209. ) );
  5210. // print_r($staffID);
  5211. $exp = array (
  5212. 0 => $staffInfo ['sid'],
  5213. 1 => $staffID [1],
  5214. 2 => $staffInfo ['avatar'],
  5215. 'date' => '',
  5216. 'date' => '',
  5217. 'opinion' => '',
  5218. 'status' => '',
  5219. 'rolename' => $rolename ['name']
  5220. );
  5221. array_push ( $roleArray, $exp );
  5222. }
  5223. $roleArrayCopy [$v [0]] = $roleArray;
  5224. // $verifyList[$k]['roleArray']=$roleArray;
  5225. }
  5226. // print_r($roleArray);
  5227. $verifyList [$k] ['date'] = "";
  5228. $verifyList [$k] ['opinion'] = "";
  5229. $verifyList [$k] ['status'] = "";
  5230. if (empty ( $verifyStaff )) {
  5231. $verifyList [$k] ['date'] = "";
  5232. $verifyList [$k] ['opinion'] = "";
  5233. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5234. $verifyList [$k] ['status'] = 4;
  5235. $button = 4;
  5236. $flag = false;
  5237. }
  5238. } else {
  5239. foreach ( $verifyStaff as $m => $u ) {
  5240. if ($v [0] == $m) {
  5241. $verifyList [$k] ['date'] = $u ['date'];
  5242. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5243. $verifyList [$k] ['status'] = $u ['status'];
  5244. $flag = false;
  5245. break;
  5246. }
  5247. }
  5248. $endStaffArray = end ( $verifyStaff );
  5249. if (isset ( $endStaffArray ['ROLE'] )) {
  5250. } else {
  5251. $endKey = key ( $verifyStaff );
  5252. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5253. $button = 4;
  5254. $verifyList [$k] ['status'] = 4;
  5255. }
  5256. }
  5257. }
  5258. }
  5259. $rolename ['name'] = '';
  5260. if (! empty ( $roleId )) {
  5261. Doo::loadModel ( 'role' );
  5262. $role = new role ();
  5263. $rolename = $role->getOne ( array (
  5264. 'where' => 'rid=' . $roleId,
  5265. 'asArray' => true
  5266. ) );
  5267. }
  5268. if (! empty ( $verifyStaff ))
  5269. $endStaffArray = end ( $verifyStaff );
  5270. $KOP = false;
  5271. foreach ( $roleArrayCopy as $P => $A ) {
  5272. foreach ( $A as $MKI => $AVL ) {
  5273. if (! empty ( $verifyStaff )) {
  5274. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5275. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5276. $button = 4;
  5277. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5278. }
  5279. foreach ( $verifyStaff as $m => $u ) {
  5280. $AVLFK = $AVL [0] . '_R';
  5281. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5282. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5283. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5284. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5285. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5286. break;
  5287. }
  5288. }
  5289. } else {
  5290. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5291. $button = 4;
  5292. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5293. }
  5294. }
  5295. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5296. $KOP = true;
  5297. }
  5298. }
  5299. // print_r($roleArrayCopy);
  5300. // echo $roleKey;
  5301. foreach ( $roleArrayCopy as $k => $v ) {
  5302. foreach ( $verifyList as $m => $n ) {
  5303. if ($n [0] == $k) {
  5304. array_splice ( $verifyList, $m, 1, $v );
  5305. }
  5306. }
  5307. }
  5308. $receiptList [$key] ['verifyList'] = $verifyList;
  5309. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5310. 'where' => 'sid=' . $value ['staff'],
  5311. 'asArray' => true
  5312. ) );
  5313. $receiptList [$key] ['button'] = $button;
  5314. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  5315. }
  5316. // $data['verifyDetail']=$verifyDetail;
  5317. $mothHtml = "";
  5318. for($i = 1; $i <= 12; $i ++) {
  5319. if ($month == $i)
  5320. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5321. else
  5322. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5323. }
  5324. // 获取审批日志
  5325. Doo::loadModel ( 'receiptLog' );
  5326. $receiptLog = new receiptLog ();
  5327. $rlList = array ();
  5328. $rlInfo = $receiptLog->getOne ( array (
  5329. 'where' => 'rid=' . $rid . ' and status=4',
  5330. 'asArray' => true
  5331. ) );
  5332. $tijdate = $receiptLog->getOne ( array (
  5333. 'where' => 'rid=' . $rid . ' and status=2',
  5334. 'asc' => 'rlid',
  5335. 'asArray' => true
  5336. ) );
  5337. if (! empty ( $rlInfo )) {
  5338. $rlList = $receiptLog->find ( array (
  5339. 'where' => 'rid=' . $rid,
  5340. 'asc' => 'rlid',
  5341. 'asArray' => true
  5342. ) );
  5343. }
  5344. $receiptList [0] ['rlList'] = $rlList;
  5345. $enclosurList = $enclosur->find ( array (
  5346. 'where' => 'rid=' . $rid,
  5347. 'asArray' => true
  5348. ) );
  5349. $enclosurHtml = '';
  5350. foreach ( $enclosurList as $value ) {
  5351. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5352. }
  5353. // print_r($receiptList);
  5354. $data ['rid'] = $rid;
  5355. $data ['enclosurHtml'] = $enclosurHtml;
  5356. $data ['rolename'] = $rolename ['name'];
  5357. $data ['datetij'] = $tijdate ['date'];
  5358. $data ['mothHtml'] = $mothHtml;
  5359. $data ['receiptList'] = $receiptList;
  5360. $data ['receiptApprovalCount'] = count ( $receiptList );
  5361. $data ['status'] = $status;
  5362. $data ['year'] = $year;
  5363. $data ['categoryList'] = $categoryList;
  5364. $data ['staffList'] = $staffList;
  5365. $data ['cid'] = $cid;
  5366. $data ['sid'] = $sid;
  5367. $data ['ap'] = $ap;
  5368. $data ['memu'] = "receipt";
  5369. $data ['staff'] = $this->staff;
  5370. $data ['receiptMemu'] = 'approvalExpenses';
  5371. $data ['verifyId'] = $this->verifyId;
  5372. $data ['executeId'] = $this->executeId;
  5373. $this->render ( "/admin/expensesEdi", $data );
  5374. }
  5375. function expensesDefray() {
  5376. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5377. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  5378. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5379. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  5380. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  5381. if (! empty ( $rid )) {
  5382. Doo::loadModel ( "verify" );
  5383. $verify = new verify ();
  5384. Doo::loadModel ( "receiptDetail" );
  5385. $receiptDetailObj = new receiptDetail ();
  5386. Doo::loadModel ( "itemStatistics" );
  5387. Doo::loadModel ( "statistics" );
  5388. $statistics = new statistics ();
  5389. $itemStatistics = new itemStatistics ();
  5390. Doo::loadModel ( "receipt" );
  5391. $receipt = new receipt ();
  5392. Doo::loadModel ( "loanReceipt" );
  5393. $loanReceipt = new loanReceipt ();
  5394. $receiptDetail = $receipt->getOne ( array (
  5395. 'where' => 'rid=' . $rid . ' and status=2 ',
  5396. 'asArray' => true
  5397. ) );
  5398. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  5399. $nsflag = true;
  5400. foreach ( $nslist as $value ) {
  5401. if ($value == $this->staff ['0'] ['sid']) {
  5402. $nsflag = false;
  5403. break;
  5404. }
  5405. }
  5406. // print_r($nslist);die;
  5407. if (empty ( $receiptDetail ) || $nsflag)
  5408. return "/approvalExpenses/pendApproval";
  5409. $verifyDetail = $verify->getOne ( array (
  5410. 'where' => ' vid =' . $receiptDetail ['verify'],
  5411. 'asArray' => true
  5412. ) );
  5413. $verifyString = $verifyDetail ['staff'];
  5414. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  5415. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  5416. if (empty ( $opinion )) {
  5417. if ($status == 3)
  5418. $opinion = "终止";
  5419. else
  5420. $opinion = "同意支付";
  5421. }
  5422. $nowStaff = 0;
  5423. $nowStaffList = array ();
  5424. if (empty ( $verifyStaff )) {
  5425. // 还需加入是否已经进入角色审批
  5426. if ($verifyDetail [0] [1] == 'ROLE') {
  5427. // print_r($verifyDetail);echo "ddd";
  5428. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  5429. foreach ( $vStaffString as $key => $value ) {
  5430. $staffK = explode ( "_", $value );
  5431. if ($staffK [0] != $this->staff [0] ['sid'])
  5432. array_push ( $nowStaffList, $staffK [0] );
  5433. }
  5434. // print_r($verifyDetail);
  5435. // die;
  5436. if (! empty ( $nowStaffList )) {
  5437. $nowStaff = implode ( ',', $nowStaffList );
  5438. $verifyStaff = array (
  5439. $this->staff [0] ['sid'] . "_R" => array (
  5440. 'date' => date ( 'Y-m-d' ),
  5441. 'opinion' => $opinion,
  5442. 'status' => $status,
  5443. 'nextStaff' => $verifyDetail [0] [0],
  5444. 'ROLE' => 1
  5445. )
  5446. );
  5447. } else {
  5448. $nowStaff = $verifyDetail [1] [0];
  5449. $verifyStaff = array (
  5450. $this->staff [0] ['sid'] . "_R" => array (
  5451. 'date' => date ( 'Y-m-d' ),
  5452. 'opinion' => $opinion,
  5453. 'status' => $status,
  5454. 'nextStaff' => $verifyDetail [1] [0]
  5455. )
  5456. );
  5457. }
  5458. } else {
  5459. if ($verifyDetail [1] [1] == 'ROLE') {
  5460. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  5461. // echo "dd";
  5462. foreach ( $vStaffString as $key => $value ) {
  5463. $staffK = explode ( "_", $value );
  5464. array_push ( $nowStaffList, $staffK [0] );
  5465. }
  5466. $nowStaff = implode ( ',', $nowStaffList );
  5467. $verifyStaff = array (
  5468. $this->staff [0] ['sid'] => array (
  5469. 'date' => date ( 'Y-m-d' ),
  5470. 'opinion' => $opinion,
  5471. 'status' => $status,
  5472. 'nextStaff' => $verifyDetail [1] [0],
  5473. 'ROLE' => 1
  5474. )
  5475. );
  5476. } else {
  5477. $nowStaff = $verifyDetail [1] [0];
  5478. $verifyStaff = array (
  5479. $this->staff [0] ['sid'] => array (
  5480. 'date' => date ( 'Y-m-d' ),
  5481. 'opinion' => $opinion,
  5482. 'status' => $status,
  5483. 'nextStaff' => $verifyDetail [1] [0]
  5484. )
  5485. );
  5486. }
  5487. }
  5488. if ($status == 3)
  5489. $verifyStaff = array (
  5490. 'final' => $status,
  5491. $this->staff [0] ['sid'] => array (
  5492. 'date' => date ( 'Y-m-d' ),
  5493. 'opinion' => $opinion,
  5494. 'status' => $status
  5495. )
  5496. );
  5497. $vStaffString = json_encode ( $verifyStaff );
  5498. $receipt->nowStaff = $nowStaff;
  5499. $receipt->verifyStaff = $vStaffString;
  5500. $loanReceipt->nowStaff = $nowStaff;
  5501. $loanReceipt->verifyStaff = $vStaffString;
  5502. } else {
  5503. $VS = end ( $verifyStaff );
  5504. // 非角色审批
  5505. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  5506. $nextStaff = 0;
  5507. $roleSTF = false;
  5508. foreach ( $verifyDetail as $key => $value ) {
  5509. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  5510. if (isset ( $verifyDetail [$key + 1] )) {
  5511. $nextStaff = $verifyDetail [$key + 1] [0];
  5512. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  5513. $roleSTF = true;
  5514. }
  5515. break;
  5516. }
  5517. }
  5518. if (! $roleSTF) {
  5519. $nowStaff = $nextStaff;
  5520. $verifyStaff [$this->staff [0] ['sid']] = array (
  5521. 'date' => date ( 'Y-m-d' ),
  5522. 'opinion' => $opinion,
  5523. 'status' => $status,
  5524. 'nextStaff' => $nextStaff
  5525. );
  5526. } else {
  5527. // 获取角色下的所有用户ID
  5528. $nowStaffList = array ();
  5529. foreach ( $verifyDetail as $vfk ) {
  5530. if ($vfk [1] == 'ROLE') {
  5531. $vStaffString = json_decode ( $vfk [3] );
  5532. foreach ( $vStaffString as $key => $value ) {
  5533. $staffK = explode ( "_", $value );
  5534. array_push ( $nowStaffList, $staffK [0] );
  5535. }
  5536. }
  5537. }
  5538. $nowStaff = implode ( ',', $nowStaffList );
  5539. $verifyStaff [$this->staff [0] ['sid']] = array (
  5540. 'date' => date ( 'Y-m-d' ),
  5541. 'opinion' => $opinion,
  5542. 'status' => $status,
  5543. 'nextStaff' => $nextStaff,
  5544. 'ROLE' => 0
  5545. );
  5546. }
  5547. if ($status == 3) {
  5548. $verifyStaff ['final'] = $status;
  5549. $verifyStaff [$this->staff [0] ['sid']] = array (
  5550. 'date' => date ( 'Y-m-d' ),
  5551. 'opinion' => $opinion,
  5552. 'status' => $status
  5553. );
  5554. }
  5555. $vStaffString = json_encode ( $verifyStaff );
  5556. $receipt->nowStaff = $nowStaff;
  5557. $receipt->verifyStaff = $vStaffString;
  5558. $loanReceipt->nowStaff = $nowStaff;
  5559. $loanReceipt->verifyStaff = $vStaffString;
  5560. }
  5561. // 角色审批
  5562. if (isset ( $VS ['ROLE'] )) {
  5563. // 找出角色人 当前审批角色组
  5564. $verifyJSStaff = array ();
  5565. $nowStaffList2 = array ();
  5566. foreach ( $verifyDetail as $key => $value ) {
  5567. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  5568. $verifyJSStaff = json_decode ( $value [3] );
  5569. foreach ( $verifyJSStaff as $m ) {
  5570. $staffK = explode ( "_", $m );
  5571. array_push ( $nowStaffList2, $staffK [0] );
  5572. }
  5573. // print_r($nowStaffList2);
  5574. }
  5575. }
  5576. $RoleVerifyStaff = array ();
  5577. foreach ( $verifyStaff as $key => $value ) {
  5578. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  5579. foreach ( $nowStaffList2 as $m ) {
  5580. if ($key == $m . "_R")
  5581. $RoleVerifyStaff [$key] = $value;
  5582. }
  5583. }
  5584. }
  5585. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  5586. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  5587. // 下一个审批人ID
  5588. $nextStaff = 0;
  5589. $falg = false;
  5590. foreach ( $verifyDetail as $key => $value ) {
  5591. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  5592. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  5593. $falg = true;
  5594. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  5595. $nowStaffList = array ();
  5596. foreach ( $vStaffString as $v ) {
  5597. $staffK = explode ( "_", $v );
  5598. array_push ( $nowStaffList, $staffK [0] );
  5599. }
  5600. $nowStaff = implode ( ',', $nowStaffList );
  5601. $nextStaff = $verifyDetail [$key + 1] [0];
  5602. } elseif (isset ( $verifyDetail [$key + 1] )) {
  5603. $nextStaff = $verifyDetail [$key + 1] [0];
  5604. $nowStaff = $nextStaff;
  5605. } else
  5606. $nowStaff = '';
  5607. break;
  5608. }
  5609. }
  5610. if ($falg)
  5611. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5612. 'date' => date ( 'Y-m-d' ),
  5613. 'opinion' => $opinion,
  5614. 'status' => $status,
  5615. 'nextStaff' => $nextStaff,
  5616. 'ROLE' => 1
  5617. );
  5618. else
  5619. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5620. 'date' => date ( 'Y-m-d' ),
  5621. 'opinion' => $opinion,
  5622. 'status' => $status,
  5623. 'nextStaff' => $nextStaff
  5624. );
  5625. // print_r($verifyStaff);
  5626. // echo $nowStaff;die;
  5627. } else { // 进入下一个角色或者审批人
  5628. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  5629. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5630. 'date' => date ( 'Y-m-d' ),
  5631. 'opinion' => $opinion,
  5632. 'status' => $status,
  5633. 'nextStaff' => $VS ['nextStaff'],
  5634. 'ROLE' => 1
  5635. );
  5636. }
  5637. if ($status == 3) {
  5638. $verifyStaff ['final'] = $status;
  5639. $verifyStaff [$this->staff [0] ['sid']] = array (
  5640. 'date' => date ( 'Y-m-d' ),
  5641. 'opinion' => $opinion,
  5642. 'status' => $status
  5643. );
  5644. }
  5645. $vStaffString = json_encode ( $verifyStaff );
  5646. $receipt->verifyStaff = $vStaffString;
  5647. $receipt->nowStaff = $nowStaff;
  5648. $loanReceipt->nowStaff = $nowStaff;
  5649. $loanReceipt->verifyStaff = $vStaffString;
  5650. }
  5651. // print_r($verifyStaff);die;
  5652. }
  5653. $roleKey = 0;
  5654. $roleId = 0;
  5655. $verifyDetailCopy = array ();
  5656. foreach ( $verifyDetail as $k => $v ) {
  5657. if ($v [1] == 'ROLE') {
  5658. $roleId = $v [0];
  5659. $roleVerify = json_decode ( $v [3], true );
  5660. $roleKey = $k;
  5661. $roleArray = array ();
  5662. foreach ( $roleVerify as $o => $p ) {
  5663. $staffID = explode ( '_', $p );
  5664. $exp = array (
  5665. 0 => $staffID [0],
  5666. 1 => $staffID [1]
  5667. );
  5668. array_push ( $roleArray, $exp );
  5669. }
  5670. $verifyDetailCopy [$v [0]] = $roleArray;
  5671. }
  5672. }
  5673. // print_r($verifyDetail);
  5674. foreach ( $verifyDetailCopy as $k => $v ) {
  5675. foreach ( $verifyDetail as $m => $n ) {
  5676. if ($n [0] == $k) {
  5677. array_splice ( $verifyDetail, $m, 1, $v );
  5678. }
  5679. }
  5680. }
  5681. // 审批日志
  5682. if (! isset ( $verifyStaff ['final'] )) {
  5683. Doo::loadModel ( "receiptLog" );
  5684. $receiptLog = new receiptLog ();
  5685. if (! empty ( $roleId )) {
  5686. Doo::loadModel ( "role" );
  5687. $role = new role ();
  5688. $roleInfo = $role->getOne ( array (
  5689. 'where' => 'rid=' . $roleId,
  5690. 'asArray' => true
  5691. ) );
  5692. $receiptLog->rolename = $roleInfo ['name'];
  5693. }
  5694. $receiptLog->username = $this->staff [0] ['username'];
  5695. $receiptLog->uid = $this->staff [0] ['sid'];
  5696. $receiptLog->date = date ( "Y-m-d" );
  5697. $receiptLog->opinion = $opinion;
  5698. $receiptLog->img = $this->staff [0] ['avatar'];
  5699. $receiptLog->status = 1;
  5700. $receiptLog->rid = $rid;
  5701. $receiptLog->insert ();
  5702. }
  5703. if (isset ( $verifyStaff ['final'] )) { // rDetail
  5704. $receipt->status = 3;
  5705. $receipt->verifyBreakup = $verifyString;
  5706. $receiptDetailObj->status = 3;
  5707. $receiptDetailObj->update ( array (
  5708. 'where' => 'rid=' . $rid
  5709. ) );
  5710. // 微信企业号通知
  5711. $this->setWXMsg ( $rid, 3 );
  5712. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  5713. $receipt->status = 6;
  5714. $receipt->pastDate = date ( "Y-m-d" );
  5715. $receipt->isBK = 1;
  5716. $loanReceipt->verifyBreakup = $verifyString;
  5717. $loanReceipt->status = 1;
  5718. $loanReceipt->pastDate = date ( "Y-m-d" );
  5719. //生成流水后 不更新汇款金额
  5720. Doo::loadModel ( 'wasteBook' );
  5721. $wasteBook = new wasteBook ();
  5722. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  5723. if (empty($wbDetail)){
  5724. $loanReceipt->amount = $receiptDetail ['amount'];
  5725. }
  5726. $loanReceipt->update ( array (
  5727. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  5728. ) );
  5729. // 微信企业号通知
  5730. $this->setWXMsg ( $rid, 1 );
  5731. }
  5732. $receipt->amount = $receiptDetail['sum'];
  5733. $receipt->update ( array (
  5734. 'where' => ' rid = ' . $rid
  5735. ) );
  5736. // 进入下一条审批费用新加需求
  5737. $vidList = array ();
  5738. $verifyDetail = $verify->find ( array (
  5739. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  5740. 'asArray' => true
  5741. ) );
  5742. foreach ( $verifyDetail as $key => $value ) {
  5743. array_push ( $vidList, $value ['vid'] );
  5744. }
  5745. $vid = implode ( ",", $vidList );
  5746. if (empty ( $verifyDetail ))
  5747. $vid = 0;
  5748. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  5749. $receipt = new receipt ();
  5750. $rd = $receipt->getOne ( array (
  5751. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  5752. 'asc' => 'rid',
  5753. 'asArray' => true
  5754. ) );
  5755. if (empty ( $rd )) {
  5756. return '/approvalExpenses/pendApproval';
  5757. }
  5758. if ($rd ['Rtype'] == 1) {
  5759. if ($rd ['isBK'] == 1) {
  5760. return '/receiptburEdi/' . $rd ['rid'];
  5761. } else {
  5762. return '/expensesEdi/' . $rd ['rid'];
  5763. }
  5764. } elseif ($rd ['Rtype'] == 2) {
  5765. return '/remitApproval/' . $rd ['rid'];
  5766. } else {
  5767. return '/receiptburEdi/' . $rd ['rid'];
  5768. }
  5769. // return "/approvalExpenses/pendApproval";
  5770. }
  5771. }
  5772. function ajaxExamineExe() {
  5773. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5774. Doo::loadModel ( 'receipt' );
  5775. $receipt = new receipt ();
  5776. Doo::loadClass ( 'XDeode' );
  5777. $XDeode = new XDeode ( 5 );
  5778. if (! empty ( $rid )) {
  5779. $rLRes = $receipt->find ( array (
  5780. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  5781. 'asArray' => true
  5782. ) );
  5783. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  5784. echo json_encode ( array (
  5785. 'status' => 1,
  5786. 'receipt' => $rLRes [0]
  5787. ) );
  5788. die ();
  5789. }
  5790. echo json_encode ( array (
  5791. 'status' => 0,
  5792. 'receipt' => array ()
  5793. ) );
  5794. die ();
  5795. }
  5796. function implement() {
  5797. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5798. $Rtype = isset ( $this->params ['Rtype'] ) ? $this->params ['Rtype'] : '';
  5799. Doo::loadClass ( 'XDeode' );
  5800. $XDeode = new XDeode ( 5 );
  5801. Doo::loadModel ( 'receipt' );
  5802. $receipt = new receipt ();
  5803. Doo::loadModel ( 'L_category' );
  5804. $Lcategory = new L_category ();
  5805. Doo::loadModel ( 'verify' );
  5806. $verify = new verify ();
  5807. Doo::loadModel ( 'staff' );
  5808. $staff = new staff ();
  5809. Doo::loadModel ( "execute" );
  5810. $execute = new execute ();
  5811. $rid = $XDeode->decode ( $rid );
  5812. $receiptList = $receipt->find ( array (
  5813. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  5814. 'desc' => 'rid',
  5815. 'asArray' => true
  5816. ) );
  5817. Doo::loadModel ( 'loanReceipt' );
  5818. $loanReceipt = new loanReceipt ();
  5819. // print_r($receiptList);
  5820. $loanList = array ();
  5821. if (! isset ( $receiptList ))
  5822. $loanList = $loanReceipt->find ( array (
  5823. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5824. 'desc' => 'rid',
  5825. 'asArray' => true
  5826. ) );
  5827. $Locate = 0;
  5828. $roleId = 0;
  5829. $button = 0;
  5830. foreach ( $loanList as $key => $value ) {
  5831. $loanList [$key] ['Locate'] = $Locate;
  5832. $Locate ++;
  5833. $loanList [$key] ['reviseDetail'] = array ();
  5834. if (! empty ( $value ['reviseDetail'] ))
  5835. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5836. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5837. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5838. $categoryDetil = $Lcategory->getOne ( array (
  5839. 'where' => 'cid=' . $value ['cid'],
  5840. 'asArray' => true
  5841. ) );
  5842. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5843. // 检测编辑状态
  5844. $verifyList = $verify->getOne ( array (
  5845. 'where' => 'vid=' . $value ['verify'],
  5846. 'asArray' => true
  5847. ) );
  5848. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5849. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5850. Doo::loadModel ( 'role' );
  5851. $role = new role ();
  5852. $flag = true;
  5853. $roleKey = 0;
  5854. $endStaffArray = array ();
  5855. $roleArrayCopy = array ();
  5856. foreach ( $verifyList as $k => $v ) {
  5857. // init verifyStaff
  5858. if ($v [1] == 'ROLE') {
  5859. if (! empty ( $verifyStaff )) {
  5860. $endStaffArray = end ( $verifyStaff );
  5861. // if ($v[0]==$endStaffArray['nextStaff']){
  5862. // $roleId=$v[0];
  5863. // }
  5864. }
  5865. $roleVerify = json_decode ( $v [3], true );
  5866. $roleKey = $k;
  5867. $roleArray = array ();
  5868. $rolename = $role->getOne ( array (
  5869. 'where' => 'rid=' . $v [0],
  5870. 'asArray' => true
  5871. ) );
  5872. foreach ( $roleVerify as $o => $p ) {
  5873. $staffID = explode ( '_', $p );
  5874. $staffInfo = $staff->getOne ( array (
  5875. 'where' => 'sid=' . $staffID [0],
  5876. 'asArray' => true
  5877. ) );
  5878. // print_r($staffID);
  5879. $exp = array (
  5880. 0 => $staffInfo ['sid'],
  5881. 1 => $staffID [1],
  5882. 2 => $staffInfo ['avatar'],
  5883. 'date' => '',
  5884. 'date' => '',
  5885. 'opinion' => '',
  5886. 'status' => '',
  5887. 'rolename' => $rolename ['name']
  5888. );
  5889. array_push ( $roleArray, $exp );
  5890. }
  5891. $roleArrayCopy [$v [0]] = $roleArray;
  5892. // $verifyList[$k]['roleArray']=$roleArray;
  5893. }
  5894. $verifyList [$k] ['date'] = "";
  5895. $verifyList [$k] ['opinion'] = "";
  5896. $verifyList [$k] ['status'] = "";
  5897. if (empty ( $verifyStaff )) {
  5898. $verifyList [$k] ['date'] = "";
  5899. $verifyList [$k] ['opinion'] = "";
  5900. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5901. $verifyList [$k] ['status'] = 4;
  5902. $flag = false;
  5903. }
  5904. } else {
  5905. foreach ( $verifyStaff as $m => $u ) {
  5906. if ($v [0] == $m) {
  5907. $verifyList [$k] ['date'] = $u ['date'];
  5908. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5909. $verifyList [$k] ['status'] = $u ['status'];
  5910. $flag = false;
  5911. break;
  5912. }
  5913. }
  5914. $endStaffArray = end ( $verifyStaff );
  5915. if (isset ( $endStaffArray ['ROLE'] )) {
  5916. } else {
  5917. // $endKey=key($verifyStaff);
  5918. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5919. // $button=4;
  5920. // $verifyList[$k]['status']=4;
  5921. // }
  5922. }
  5923. }
  5924. }
  5925. $rolename ['name'] = '';
  5926. if (! empty ( $roleId )) {
  5927. Doo::loadModel ( 'role' );
  5928. $role = new role ();
  5929. $rolename = $role->getOne ( array (
  5930. 'where' => 'rid=' . $roleId,
  5931. 'asArray' => true
  5932. ) );
  5933. }
  5934. if (! empty ( $verifyStaff ))
  5935. $endStaffArray = end ( $verifyStaff );
  5936. $KOP = false;
  5937. foreach ( $roleArrayCopy as $P => $A ) {
  5938. foreach ( $A as $MKI => $AVL ) {
  5939. if (! empty ( $verifyStaff )) {
  5940. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5941. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5942. $button = 4;
  5943. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5944. }
  5945. foreach ( $verifyStaff as $m => $u ) {
  5946. $AVLFK = $AVL [0] . '_R';
  5947. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5948. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5949. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5950. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5951. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5952. break;
  5953. }
  5954. }
  5955. } else {
  5956. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5957. $button = 4;
  5958. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5959. }
  5960. }
  5961. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5962. $KOP = true;
  5963. }
  5964. }
  5965. foreach ( $roleArrayCopy as $k => $v ) {
  5966. foreach ( $verifyList as $m => $n ) {
  5967. if ($n [0] == $k) {
  5968. array_splice ( $verifyList, $m, 1, $v );
  5969. }
  5970. }
  5971. }
  5972. $loanList [$key] ['verifyList'] = $verifyList;
  5973. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  5974. 'where' => 'sid=' . $value ['staff'],
  5975. 'asArray' => true
  5976. ) );
  5977. }
  5978. $data ['loanList'] = $loanList;
  5979. $Locate = 0;
  5980. $roleId = 0;
  5981. $button = 0;
  5982. Doo::loadClass ( 'XDeode' );
  5983. $XDeode = new XDeode ( 5 );
  5984. foreach ( $receiptList as $key => $value ) {
  5985. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  5986. $button2 = 0;
  5987. $receiptList [$key] ['Locate'] = $Locate;
  5988. $Locate ++;
  5989. $receiptList [$key] ['reviseDetail'] = array ();
  5990. if (! empty ( $value ['reviseDetail'] ))
  5991. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5992. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5993. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5994. $categoryDetil = $Lcategory->getOne ( array (
  5995. 'where' => 'cid=' . $value ['cid'],
  5996. 'asArray' => true
  5997. ) );
  5998. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5999. $executeList = json_decode ( $value ['executeCopy'], true );
  6000. $executeStaff = array ();
  6001. if (! empty ( $value ['executeStaff'] ))
  6002. $executeStaff = json_decode ( $value ['executeStaff'], true );
  6003. if (isset ( $executeList )) {
  6004. foreach ( $executeList as $op => $lo ) {
  6005. $executeList [$op] ['date'] = "";
  6006. $executeList [$op] ['opinion'] = "";
  6007. $executeList [$op] ['status'] = "";
  6008. foreach ( $executeStaff as $m => $u ) {
  6009. if ($lo [0] == $m) {
  6010. $executeList [$op] ['date'] = $u ['date'];
  6011. $executeList [$op] ['opinion'] = $u ['opinion'];
  6012. $executeList [$op] ['status'] = $u ['status'];
  6013. break;
  6014. }
  6015. }
  6016. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  6017. $button2 = 1;
  6018. $executeList [$op] ['status'] = 4;
  6019. }
  6020. }
  6021. }
  6022. // 检测编辑状态
  6023. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  6024. $verifyList ['staff'] = $value ['verifyBreakup'];
  6025. } else
  6026. $verifyList = $verify->getOne ( array (
  6027. 'where' => 'vid=' . $value ['verify'],
  6028. 'asArray' => true
  6029. ) );
  6030. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6031. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6032. Doo::loadModel ( 'role' );
  6033. $role = new role ();
  6034. if ($verifyList == NULL)
  6035. $verifyList = array ();
  6036. $flag = true;
  6037. $roleKey = 0;
  6038. $endStaffArray = array ();
  6039. $roleArrayCopy = array ();
  6040. foreach ( $verifyList as $k => $v ) {
  6041. // init verifyStaff
  6042. if ($v [1] == 'ROLE') {
  6043. if (! empty ( $verifyStaff )) {
  6044. $endStaffArray = end ( $verifyStaff );
  6045. // if ($v[0]==$endStaffArray['nextStaff']){
  6046. // $roleId=$v[0];
  6047. // }
  6048. }
  6049. $roleVerify = json_decode ( $v [3], true );
  6050. $roleKey = $k;
  6051. $roleArray = array ();
  6052. $rolename = $role->getOne ( array (
  6053. 'where' => 'rid=' . $v [0],
  6054. 'asArray' => true
  6055. ) );
  6056. foreach ( $roleVerify as $o => $p ) {
  6057. $staffID = explode ( '_', $p );
  6058. $staffInfo = $staff->getOne ( array (
  6059. 'where' => 'sid=' . $staffID [0],
  6060. 'asArray' => true
  6061. ) );
  6062. // print_r($staffID);
  6063. $exp = array (
  6064. 0 => $staffInfo ['sid'],
  6065. 1 => $staffID [1],
  6066. 2 => $staffInfo ['avatar'],
  6067. 'date' => '',
  6068. 'date' => '',
  6069. 'opinion' => '',
  6070. 'status' => '',
  6071. 'rolename' => $rolename ['name']
  6072. );
  6073. array_push ( $roleArray, $exp );
  6074. }
  6075. $roleArrayCopy [$v [0]] = $roleArray;
  6076. // $verifyList[$k]['roleArray']=$roleArray;
  6077. }
  6078. $verifyList [$k] ['date'] = "";
  6079. $verifyList [$k] ['opinion'] = "";
  6080. $verifyList [$k] ['status'] = "";
  6081. if (empty ( $verifyStaff )) {
  6082. $verifyList [$k] ['date'] = "";
  6083. $verifyList [$k] ['opinion'] = "";
  6084. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6085. $verifyList [$k] ['status'] = 4;
  6086. $flag = false;
  6087. }
  6088. } else {
  6089. foreach ( $verifyStaff as $m => $u ) {
  6090. if ($v [0] == $m) {
  6091. $verifyList [$k] ['date'] = $u ['date'];
  6092. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6093. $verifyList [$k] ['status'] = $u ['status'];
  6094. $flag = false;
  6095. break;
  6096. }
  6097. }
  6098. $endStaffArray = end ( $verifyStaff );
  6099. if (isset ( $endStaffArray ['ROLE'] )) {
  6100. } else {
  6101. // $endKey=key($verifyStaff);
  6102. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6103. // $button=4;
  6104. // $verifyList[$k]['status']=4;
  6105. // }
  6106. }
  6107. }
  6108. }
  6109. $rolename ['name'] = '';
  6110. if (! empty ( $roleId )) {
  6111. Doo::loadModel ( 'role' );
  6112. $role = new role ();
  6113. $rolename = $role->getOne ( array (
  6114. 'where' => 'rid=' . $roleId,
  6115. 'asArray' => true
  6116. ) );
  6117. }
  6118. if (! empty ( $verifyStaff ))
  6119. $endStaffArray = end ( $verifyStaff );
  6120. $KOP = false;
  6121. foreach ( $roleArrayCopy as $P => $A ) {
  6122. foreach ( $A as $MKI => $AVL ) {
  6123. if (! empty ( $verifyStaff )) {
  6124. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6125. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6126. $button = 4;
  6127. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6128. }
  6129. foreach ( $verifyStaff as $m => $u ) {
  6130. $AVLFK = $AVL [0] . '_R';
  6131. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6132. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6133. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6134. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6135. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6136. break;
  6137. }
  6138. }
  6139. } else {
  6140. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6141. $button = 4;
  6142. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6143. }
  6144. }
  6145. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6146. $KOP = true;
  6147. }
  6148. }
  6149. foreach ( $roleArrayCopy as $k => $v ) {
  6150. foreach ( $verifyList as $m => $n ) {
  6151. if ($n [0] == $k) {
  6152. array_splice ( $verifyList, $m, 1, $v );
  6153. }
  6154. }
  6155. }
  6156. $receiptList [$key] ['verifyList'] = $verifyList;
  6157. $receiptList [$key] ['executeList'] = $executeList;
  6158. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6159. 'where' => 'sid=' . $value ['staff'],
  6160. 'asArray' => true
  6161. ) );
  6162. $receiptList [$key] ['button2'] = $button2;
  6163. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  6164. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  6165. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  6166. $receiptList [$key] ['relust'] = $relust;
  6167. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  6168. $receiptList [$key] ['amountABS'] = abs ( $value ['amount'] );
  6169. }
  6170. //执行人是否是最后一位
  6171. $executeCopy = json_decode ( $receiptList [0] ['executeCopy'], true );
  6172. $executeStaff = json_decode ( $receiptList [0] ['executeStaff'], true );
  6173. $executePrimary=count($executeCopy)-1;
  6174. $lastOne=true;
  6175. if($executePrimary!=count($executeStaff)){
  6176. $lastOne=false;
  6177. }
  6178. $data['lastOne']=$lastOne;
  6179. // 是否写入过流水
  6180. $accountType = 0;
  6181. if ($receiptList [0] ['Rtype'] == 0) {
  6182. $accountType = 3;
  6183. } elseif ($receiptList [0] ['Rtype'] == 1) {
  6184. if (!empty($receiptList [0]['accountItem']) )
  6185. $accountType = 2;
  6186. else
  6187. $accountType = 1;
  6188. } elseif ($receiptList [0] ['Rtype'] == 2) {
  6189. $accountType = 4;
  6190. } elseif ($receiptList [0] ['Rtype'] == 3) {
  6191. $accountType = 12;
  6192. }
  6193. Doo::loadModel ( 'wasteBook' );
  6194. $wasteBook = new wasteBook ();
  6195. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  6196. $data ['wbDetail'] = $wbDetail;
  6197. $wbDetailLoan=array();
  6198. if ($accountType==2){
  6199. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  6200. }
  6201. $data ['wbDetailLoan'] = $wbDetailLoan;
  6202. $data['inputDate']=date ( "Y-m-d H:i:s" );
  6203. //print_r($wbDetail);
  6204. $data ['receiptList'] = $receiptList;
  6205. $data ['memu'] = "receipt";
  6206. $data ['staff'] = $this->staff;
  6207. $data ['receiptMemu'] = 'implement';
  6208. $data ['verifyId'] = $this->verifyId;
  6209. $data ['executeId'] = $this->executeId;
  6210. if ($Rtype=="loan"){
  6211. $this->render ( "/receipt/receiptImplementLoan", $data );
  6212. }elseif($Rtype=="receipt"){
  6213. if($receiptList[0]['receiptClass']==2){
  6214. //TODO 费用执行行程单2.0
  6215. if(!empty($receiptList[0]['itinerary2'])){
  6216. $this->render ( "/receipt/receiptImplementTrave2", $data );
  6217. }else{
  6218. $this->render ( "/receipt/receiptImplementTrave", $data );
  6219. }
  6220. }else{
  6221. $this->render ( "/receipt/receiptImplement", $data );
  6222. }
  6223. }elseif($Rtype=="public"){
  6224. $this->render ( "/receipt/receiptImplementPublic", $data );
  6225. }else{
  6226. //$this->render ( "/admin/implement", $data );
  6227. }
  6228. }
  6229. function implementDo() {
  6230. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  6231. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  6232. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  6233. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  6234. // $ab = '';
  6235. // if ($accountBank == 'CGBDeposit')
  6236. // $ab = '纵横广发';
  6237. // elseif ($accountBank == 'ICBCDeposit')
  6238. // $ab = '纵横工行';
  6239. // elseif ($accountBank == 'HUADeposit')
  6240. // $ab = '华润银行';
  6241. // elseif ($accountBank == 'PersonalDeposit')
  6242. // $ab = '个人广发';
  6243. // if (empty ( $ab ))
  6244. // die ( 'illegal request--22' );
  6245. if (! empty ( $rid )) {
  6246. Doo::loadModel ( 'receipt' );
  6247. $receipt = new receipt ();
  6248. Doo::loadClass ( 'XDeode' );
  6249. $XDeode = new XDeode ( 5 );
  6250. $rid=$XDeode->decode($rid);
  6251. if (!is_numeric($rid)){
  6252. die;
  6253. }
  6254. // $rinfo = $receipt->getOne ( array (
  6255. // 'where' => 'rid=' . $rid,
  6256. // 'asArray' => true
  6257. // ) );
  6258. $rinfo = $receipt->getReceiptByRid ( $rid );
  6259. // $accountType = '';
  6260. // if ($rinfo ['Rtype'] == 1) {
  6261. // if ($rinfo ['loanRid'] != 0)//判断有问题
  6262. // $accountType = 2;
  6263. // else
  6264. // $accountType = 1;
  6265. // } elseif ($rinfo ['Rtype'] == 2) {
  6266. // $accountType = 4;
  6267. // } elseif ($rinfo ['Rtype'] == 0)
  6268. // $accountType = 3;
  6269. // if (empty ( $accountType ))
  6270. // die ( 'illegal request' );
  6271. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  6272. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  6273. if (empty ( $executeStaff )) {
  6274. $executeStaff = array (
  6275. $this->staff [0] ['sid'] => array (
  6276. 'date' => date ( 'Y-m-d' ),
  6277. 'opinion' => $implementOpinions,
  6278. 'status' => 1
  6279. )
  6280. );
  6281. } else {
  6282. $executeStaff [$this->staff [0] ['sid']] = array (
  6283. 'date' => date ( 'Y-m-d' ),
  6284. 'opinion' => $implementOpinions,
  6285. 'status' => 1
  6286. );
  6287. }
  6288. if (count ( $executeStaff ) == count ( $executeCopy )) {
  6289. $receipt->executeStaff = json_encode ( $executeStaff );
  6290. $receipt->status = 8;
  6291. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  6292. $receipt->status = 9;
  6293. if ($rinfo ['status'] == 6) {
  6294. $receipt->loanDate = date ( "Y-m-d" );
  6295. }
  6296. $receipt->executeDate = date ( "Y-m-d" );
  6297. } else {
  6298. $receipt->executeStaff = json_encode ( $executeStaff );
  6299. }
  6300. //$receipt->amount = $amount;
  6301. $receipt->update ( array (
  6302. 'where' => 'rid=' . $rid
  6303. ) );
  6304. // 公司流水记录
  6305. // Doo::loadModel ( 'wasteBook' );
  6306. // $wasteBook = new wasteBook ();
  6307. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  6308. // // 银行
  6309. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  6310. // $item = array (
  6311. // 'dataID' => $rid,
  6312. // 'expensesType' => 2,
  6313. // 'accountType' => $accountType,
  6314. // 'accountPriceShow' => $amount,
  6315. // 'accountPrice' => - $amount,
  6316. // 'accountBank' => $accountBank,
  6317. // 'category' => $rinfo ['category'] [0] ['title'],
  6318. // 'cid' => $rinfo ['category'] [0] ['cid'],
  6319. // 'name' => $rinfo ['staffDetail'] ['username'],
  6320. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  6321. // 'inputDate' => date ( "Y-m-d H:i:s" )
  6322. // );
  6323. // $wasteBook->setAccountBookStatistics ( $item );
  6324. // }
  6325. }
  6326. //$ridKey = $XDeode->encode ( $rid );
  6327. return "/hisImplement";
  6328. // return "/implement/" . $ridKey . ".html";
  6329. }
  6330. function receiptburEdi() {
  6331. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6332. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  6333. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  6334. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  6335. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  6336. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  6337. if (empty ( $status ))
  6338. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  6339. $vidList = array ();
  6340. $button = 0;
  6341. Doo::loadModel ( 'verify' );
  6342. Doo::loadModel ( 'receipt' );
  6343. Doo::loadModel ( 'staff' );
  6344. $staff = new staff ();
  6345. $receipt = new receipt ();
  6346. $verify = new verify ();
  6347. Doo::loadModel ( 'L_category' );
  6348. $Lcategory = new L_category ();
  6349. Doo::loadModel ( 'enclosur' );
  6350. $enclosur = new enclosur ();
  6351. Doo::loadModel ( 'loanReceipt' );
  6352. $loanReceipt = new loanReceipt ();
  6353. // user verify ID
  6354. $verifyDetail = $verify->find ( array (
  6355. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  6356. 'asArray' => true
  6357. ) );
  6358. foreach ( $verifyDetail as $key => $value ) {
  6359. array_push ( $vidList, $value ['vid'] );
  6360. }
  6361. $vid = implode ( ",", $vidList );
  6362. if (empty ( $verifyDetail ))
  6363. $vid = 0;
  6364. $categoryList = $Lcategory->find ( array (
  6365. 'asArray' => true
  6366. ) );
  6367. $staffList = $staff->find ( array (
  6368. 'where' => 'cid=' . $cid,
  6369. 'asArray' => true
  6370. ) );
  6371. $ap = "";
  6372. if ($status == 4) {
  6373. $ap = 4;
  6374. $status = 2;
  6375. }
  6376. // get Receipt By verifyID status 2
  6377. $receiptList = $receipt->find ( array (
  6378. 'where' => 'rid =' . $rid . ' and status=2',
  6379. 'desc' => 'rid',
  6380. 'asArray' => true
  6381. ) );
  6382. if (empty ( $receiptList )) {
  6383. die ( 'illegal request' );
  6384. }
  6385. $loanList = $loanReceipt->find ( array (
  6386. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  6387. 'desc' => 'rid',
  6388. 'asArray' => true
  6389. ) );
  6390. $data ['explanation'] = '';
  6391. if (! empty ( $loanList ))
  6392. $data ['explanation'] = $loanList [0] ['explanation'];
  6393. $Locate = 0;
  6394. $roleId = 0;
  6395. $button = 0;
  6396. foreach ( $loanList as $key => $value ) {
  6397. $loanList [$key] ['Locate'] = $Locate;
  6398. $Locate ++;
  6399. $loanList [$key] ['reviseDetail'] = array ();
  6400. if (! empty ( $value ['reviseDetail'] ))
  6401. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6402. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6403. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6404. $categoryDetil = $Lcategory->getOne ( array (
  6405. 'where' => 'cid=' . $value ['cid'],
  6406. 'asArray' => true
  6407. ) );
  6408. $loanList [$key] ['category'] = $categoryDetil ['title'];
  6409. // 检测编辑状态
  6410. $verifyList = $verify->getOne ( array (
  6411. 'where' => 'vid=' . $value ['verify'],
  6412. 'asArray' => true
  6413. ) );
  6414. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6415. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6416. Doo::loadModel ( 'role' );
  6417. $role = new role ();
  6418. $flag = true;
  6419. $roleKey = 0;
  6420. $endStaffArray = array ();
  6421. $roleArrayCopy = array ();
  6422. foreach ( $verifyList as $k => $v ) {
  6423. // init verifyStaff
  6424. if ($v [1] == 'ROLE') {
  6425. if (! empty ( $verifyStaff )) {
  6426. $endStaffArray = end ( $verifyStaff );
  6427. }
  6428. $roleVerify = json_decode ( $v [3], true );
  6429. $roleKey = $k;
  6430. $roleArray = array ();
  6431. $rolename = $role->getOne ( array (
  6432. 'where' => 'rid=' . $v [0],
  6433. 'asArray' => true
  6434. ) );
  6435. foreach ( $roleVerify as $o => $p ) {
  6436. $staffID = explode ( '_', $p );
  6437. $staffInfo = $staff->getOne ( array (
  6438. 'where' => 'sid=' . $staffID [0],
  6439. 'asArray' => true
  6440. ) );
  6441. // print_r($staffID);
  6442. $exp = array (
  6443. 0 => $staffInfo ['sid'],
  6444. 1 => $staffID [1],
  6445. 2 => $staffInfo ['avatar'],
  6446. 'date' => '',
  6447. 'date' => '',
  6448. 'opinion' => '',
  6449. 'status' => '',
  6450. 'rolename' => $rolename ['name']
  6451. );
  6452. array_push ( $roleArray, $exp );
  6453. }
  6454. $roleArrayCopy [$v [0]] = $roleArray;
  6455. // $verifyList[$k]['roleArray']=$roleArray;
  6456. }
  6457. $verifyList [$k] ['date'] = "";
  6458. $verifyList [$k] ['opinion'] = "";
  6459. $verifyList [$k] ['status'] = "";
  6460. if (empty ( $verifyStaff )) {
  6461. $verifyList [$k] ['date'] = "";
  6462. $verifyList [$k] ['opinion'] = "";
  6463. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6464. $verifyList [$k] ['status'] = 4;
  6465. $flag = false;
  6466. }
  6467. } else {
  6468. foreach ( $verifyStaff as $m => $u ) {
  6469. if ($v [0] == $m) {
  6470. $verifyList [$k] ['date'] = $u ['date'];
  6471. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6472. $verifyList [$k] ['status'] = $u ['status'];
  6473. $flag = false;
  6474. break;
  6475. }
  6476. }
  6477. $endStaffArray = end ( $verifyStaff );
  6478. if (isset ( $endStaffArray ['ROLE'] )) {
  6479. } else {
  6480. }
  6481. }
  6482. }
  6483. $rolename ['name'] = '';
  6484. if (! empty ( $roleId )) {
  6485. Doo::loadModel ( 'role' );
  6486. $role = new role ();
  6487. $rolename = $role->getOne ( array (
  6488. 'where' => 'rid=' . $roleId,
  6489. 'asArray' => true
  6490. ) );
  6491. }
  6492. if (! empty ( $verifyStaff ))
  6493. $endStaffArray = end ( $verifyStaff );
  6494. $KOP = false;
  6495. foreach ( $roleArrayCopy as $P => $A ) {
  6496. foreach ( $A as $MKI => $AVL ) {
  6497. if (! empty ( $verifyStaff )) {
  6498. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6499. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6500. $button = 4;
  6501. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6502. }
  6503. foreach ( $verifyStaff as $m => $u ) {
  6504. $AVLFK = $AVL [0] . '_R';
  6505. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6506. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6507. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6508. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6509. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6510. break;
  6511. }
  6512. }
  6513. } else {
  6514. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6515. $button = 4;
  6516. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6517. }
  6518. }
  6519. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6520. $KOP = true;
  6521. }
  6522. }
  6523. foreach ( $roleArrayCopy as $k => $v ) {
  6524. foreach ( $verifyList as $m => $n ) {
  6525. if ($n [0] == $k) {
  6526. array_splice ( $verifyList, $m, 1, $v );
  6527. }
  6528. }
  6529. }
  6530. $loanList [$key] ['verifyList'] = $verifyList;
  6531. }
  6532. $htmlLoan = '';
  6533. $data ['loanReceiptDate'] = '';
  6534. if (isset ( $loanList [0] )) {
  6535. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  6536. if ($value ['status'] == 1)
  6537. $htmlLoan .= '<li class="done" >';
  6538. elseif ($value ['status'] == 3)
  6539. $htmlLoan .= '<li class="undone" >';
  6540. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  6541. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  6542. if (isset ( $value ['rolename'] ))
  6543. $htmlLoan .= $value ['rolename'];
  6544. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  6545. }
  6546. $data ['loanDate'] = $loanList [0] ['date'];
  6547. } else {
  6548. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  6549. }
  6550. $data ['htmlLoan'] = $htmlLoan;
  6551. // $data ['LoanReceipt']=$loanList[0];
  6552. // print_r($loanList);
  6553. $Locate = 0;
  6554. $roleId = 0;
  6555. $button = 0;
  6556. if ($ap == 4)
  6557. $status = 4;
  6558. Doo::loadClass ( 'XDeode' );
  6559. $XDeode = new XDeode ( 5 );
  6560. foreach ( $receiptList as $key => $value ) {
  6561. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  6562. $receiptList [$key] ['Locate'] = $Locate;
  6563. $Locate ++;
  6564. $receiptList [$key] ['reviseDetail'] = array ();
  6565. // 调整金额 代码调整
  6566. if (! empty ( $value ['reviseDetail'] )) {
  6567. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  6568. foreach ( $reviseDetail as $ry => $re ) {
  6569. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  6570. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  6571. }
  6572. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  6573. // print_r($reviseDetail);
  6574. }
  6575. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6576. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6577. $categoryDetil = $Lcategory->getOne ( array (
  6578. 'where' => 'cid=' . $value ['cid'],
  6579. 'asArray' => true
  6580. ) );
  6581. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6582. // 检测编辑状态
  6583. $verifyList = $verify->getOne ( array (
  6584. 'where' => 'vid=' . $value ['verify'],
  6585. 'asArray' => true
  6586. ) );
  6587. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6588. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6589. Doo::loadModel ( 'role' );
  6590. $role = new role ();
  6591. // print_r($verifyList);
  6592. $flag = true;
  6593. $roleKey = 0;
  6594. $endStaffArray = array ();
  6595. $roleArrayCopy = array ();
  6596. foreach ( $verifyList as $k => $v ) {
  6597. // init verifyStaff
  6598. if ($v [1] == 'ROLE') {
  6599. if (! empty ( $verifyStaff )) {
  6600. $endStaffArray = end ( $verifyStaff );
  6601. if ($v [0] == $endStaffArray ['nextStaff']) {
  6602. $roleId = $v [0];
  6603. }
  6604. }
  6605. $roleVerify = json_decode ( $v [3], true );
  6606. $roleKey = $k;
  6607. $roleArray = array ();
  6608. $rolename = $role->getOne ( array (
  6609. 'where' => 'rid=' . $v [0],
  6610. 'asArray' => true
  6611. ) );
  6612. foreach ( $roleVerify as $o => $p ) {
  6613. $staffID = explode ( '_', $p );
  6614. $staffInfo = $staff->getOne ( array (
  6615. 'where' => 'sid=' . $staffID [0],
  6616. 'asArray' => true
  6617. ) );
  6618. // print_r($staffID);
  6619. $exp = array (
  6620. 0 => $staffInfo ['sid'],
  6621. 1 => $staffID [1],
  6622. 2 => $staffInfo ['avatar'],
  6623. 'date' => '',
  6624. 'date' => '',
  6625. 'opinion' => '',
  6626. 'status' => '',
  6627. 'rolename' => $rolename ['name']
  6628. );
  6629. array_push ( $roleArray, $exp );
  6630. }
  6631. $roleArrayCopy [$v [0]] = $roleArray;
  6632. // $verifyList[$k]['roleArray']=$roleArray;
  6633. }
  6634. // print_r($roleArray);
  6635. $verifyList [$k] ['date'] = "";
  6636. $verifyList [$k] ['opinion'] = "";
  6637. $verifyList [$k] ['status'] = "";
  6638. if (empty ( $verifyStaff )) {
  6639. $verifyList [$k] ['date'] = "";
  6640. $verifyList [$k] ['opinion'] = "";
  6641. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6642. $verifyList [$k] ['status'] = 4;
  6643. $button = 4;
  6644. $flag = false;
  6645. }
  6646. } else {
  6647. foreach ( $verifyStaff as $m => $u ) {
  6648. if ($v [0] == $m) {
  6649. $verifyList [$k] ['date'] = $u ['date'];
  6650. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6651. $verifyList [$k] ['status'] = $u ['status'];
  6652. $flag = false;
  6653. break;
  6654. }
  6655. }
  6656. $endStaffArray = end ( $verifyStaff );
  6657. if (isset ( $endStaffArray ['ROLE'] )) {
  6658. } else {
  6659. $endKey = key ( $verifyStaff );
  6660. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  6661. $button = 4;
  6662. $verifyList [$k] ['status'] = 4;
  6663. }
  6664. }
  6665. }
  6666. }
  6667. $rolename ['name'] = '';
  6668. if (! empty ( $roleId )) {
  6669. Doo::loadModel ( 'role' );
  6670. $role = new role ();
  6671. $rolename = $role->getOne ( array (
  6672. 'where' => 'rid=' . $roleId,
  6673. 'asArray' => true
  6674. ) );
  6675. }
  6676. if (! empty ( $verifyStaff ))
  6677. $endStaffArray = end ( $verifyStaff );
  6678. $KOP = false;
  6679. foreach ( $roleArrayCopy as $P => $A ) {
  6680. foreach ( $A as $MKI => $AVL ) {
  6681. if (! empty ( $verifyStaff )) {
  6682. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6683. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6684. $button = 4;
  6685. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6686. }
  6687. foreach ( $verifyStaff as $m => $u ) {
  6688. $AVLFK = $AVL [0] . '_R';
  6689. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6690. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6691. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6692. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6693. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6694. break;
  6695. }
  6696. }
  6697. } else {
  6698. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6699. $button = 4;
  6700. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6701. }
  6702. }
  6703. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6704. $KOP = true;
  6705. }
  6706. }
  6707. foreach ( $roleArrayCopy as $k => $v ) {
  6708. foreach ( $verifyList as $m => $n ) {
  6709. if ($n [0] == $k) {
  6710. array_splice ( $verifyList, $m, 1, $v );
  6711. }
  6712. }
  6713. }
  6714. // print_r($verifyList);
  6715. $receiptList [$key] ['verifyList'] = $verifyList;
  6716. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6717. 'where' => 'sid=' . $value ['staff'],
  6718. 'asArray' => true
  6719. ) );
  6720. $receiptList [$key] ['button'] = $button;
  6721. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  6722. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  6723. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  6724. $receiptList [$key] ['relust'] = $relust;
  6725. $receiptList [$key] ['relustABS'] = abs ( $relust );
  6726. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  6727. }
  6728. //print_r($receiptList);die;
  6729. // $data['verifyDetail']=$verifyDetail;
  6730. $mothHtml = "";
  6731. for($i = 1; $i <= 12; $i ++) {
  6732. if ($month == $i)
  6733. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6734. else
  6735. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6736. }
  6737. // 获取审批日志
  6738. Doo::loadModel ( 'receiptLog' );
  6739. $receiptLog = new receiptLog ();
  6740. $rlList = array ();
  6741. $rlInfo = $receiptLog->getOne ( array (
  6742. 'where' => 'rid=' . $rid . ' and status=4',
  6743. 'asArray' => true
  6744. ) );
  6745. $tijdate = $receiptLog->getOne ( array (
  6746. 'where' => 'rid=' . $rid . ' and status=2',
  6747. 'asc' => 'rlid',
  6748. 'asArray' => true
  6749. ) );
  6750. if (! empty ( $rlInfo )) {
  6751. $rlList = $receiptLog->find ( array (
  6752. 'where' => 'rid=' . $rid,
  6753. 'asc' => 'rlid',
  6754. 'asArray' => true
  6755. ) );
  6756. }
  6757. // echo $rid;
  6758. // print_r($receiptList);
  6759. $receiptList [0] ['rlList'] = $rlList;
  6760. // print_r($receiptList);
  6761. $enclosurList = $enclosur->find ( array (
  6762. 'where' => 'rid=' . $rid,
  6763. 'asArray' => true
  6764. ) );
  6765. $enclosurHtml = '';
  6766. foreach ( $enclosurList as $value ) {
  6767. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  6768. }
  6769. $data ['enclosurHtml'] = $enclosurHtml;
  6770. $data ['rolename'] = $rolename ['name'];
  6771. $data ['mothHtml'] = $mothHtml;
  6772. $receiptList[0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  6773. $data ['rid'] = $rid;
  6774. $data ['tijdate'] = $tijdate ['date'];
  6775. $data ['receiptList'] = $receiptList;
  6776. $data ['receiptApprovalCount'] = count ( $receiptList );
  6777. $data ['status'] = $status;
  6778. $data ['year'] = $year;
  6779. $data ['categoryList'] = $categoryList;
  6780. $data ['staffList'] = $staffList;
  6781. $data ['cid'] = $cid;
  6782. $data ['sid'] = $sid;
  6783. $data ['ap'] = $ap;
  6784. $data ['memu'] = "receipt";
  6785. $data ['staff'] = $this->staff;
  6786. $data ['receiptMemu'] = 'approvalExpenses';
  6787. $data ['verifyId'] = $this->verifyId;
  6788. $data ['executeId'] = $this->executeId;
  6789. if($receiptList[0]['receiptClass']==1){
  6790. $this->render ( "/receipt/feeAgencyApproval", $data );
  6791. }elseif($receiptList[0]['receiptClass']==2){
  6792. //TODO 行程单2.0
  6793. if(!empty($receiptList[0]['itinerary2'])){
  6794. $this->render ( "/receipt/feeTraveApproval2", $data );
  6795. }else{
  6796. $this->render ( "/receipt/feeTraveApproval", $data );
  6797. }
  6798. }elseif($receiptList[0]['receiptClass']==3){
  6799. $this->render ( "/receipt/feeInternalTrainApproval", $data );
  6800. }else{
  6801. $this->render ( "/admin/receiptburEdi", $data );
  6802. }
  6803. }
  6804. function hisImplement() {
  6805. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6806. if (empty ( $item ))
  6807. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  6808. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  6809. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6810. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  6811. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  6812. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  6813. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  6814. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  6815. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  6816. Doo::loadClass ( 'XDeode' );
  6817. $XDeode = new XDeode ( 5 );
  6818. Doo::loadModel ( 'receipt' );
  6819. $receipt = new receipt ();
  6820. Doo::loadModel ( 'L_category' );
  6821. $Lcategory = new L_category ();
  6822. Doo::loadModel ( 'verify' );
  6823. Doo::loadModel ( 'statistics' );
  6824. $statistics = new statistics ();
  6825. $verify = new verify ();
  6826. Doo::loadModel ( 'staff' );
  6827. $staff = new staff ();
  6828. Doo::loadClass ( 'XDeode' );
  6829. $XDeode = new XDeode ( 5 );
  6830. $XDeode7 = new XDeode ( 7 );
  6831. $cid = $XDeode->decode ( $cidKey );
  6832. $condition = "";
  6833. if ($item == "expenses")
  6834. $condition = " and Rtype=1 ";
  6835. elseif ($item == "receipts")
  6836. $condition = " and Rtype=0 ";
  6837. elseif ($item == "remits")
  6838. $condition = " and Rtype=2 ";
  6839. elseif($item == "train")
  6840. $condition = " and Rtype=3 ";
  6841. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  6842. $sopString = $cidString = "";
  6843. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  6844. if (empty ( $rdate ))
  6845. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  6846. else
  6847. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  6848. if ($status == 'pendImplement') {
  6849. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and (executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" or executeStaff is null ) ) ';
  6850. } elseif ($status == 'alerpts') {
  6851. $statusCon = '(status=8 or status=9 )';
  6852. if (empty ( $rdate )){
  6853. $dateCondition = " and Year(date) =" . $year;
  6854. }else{
  6855. $dateCondition = " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  6856. }
  6857. }
  6858. if ($sop != 'SOP')
  6859. $sopString = " and staff=" . $sop;
  6860. if ($cidKey != 'ALL')
  6861. $cidString = " and cid=" . $cid;
  6862. //汇款信息需要提取出来
  6863. if(!empty($receiptOrder)){
  6864. $receiptList = $receipt->find ( array (
  6865. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  6866. 'desc' => 'rid',
  6867. 'asArray' => true
  6868. ) );
  6869. // 员工筛选
  6870. $receiptList2 = $receipt->find ( array (
  6871. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  6872. 'desc' => 'rid',
  6873. 'asArray' => true
  6874. ) );
  6875. }else{
  6876. $receiptList = $receipt->find ( array (
  6877. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  6878. 'desc' => 'rid',
  6879. 'asArray' => true
  6880. ) );
  6881. // 员工筛选
  6882. $receiptList2 = $receipt->find ( array (
  6883. 'where' => $statusCon . $condition . $dateCondition,
  6884. 'desc' => 'rid',
  6885. 'asArray' => true
  6886. ) );
  6887. }
  6888. $sopStaff = array ();
  6889. foreach ( $receiptList2 as $key => $value ) {
  6890. $staffDetail = $staff->getOne ( array (
  6891. 'select' => 'username',
  6892. 'where' => 'sid=' . $value ['staff'],
  6893. 'asArray' => true
  6894. ) );
  6895. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  6896. }
  6897. // 办事处筛选
  6898. $categoryScreen = array ();
  6899. $categorList = $Lcategory->getCategory ();
  6900. foreach ( $receiptList2 as $key => $value ) {
  6901. foreach ( $categorList as $k => $v ) {
  6902. if ($value ['cid'] == $v ['cid']) {
  6903. $categoryScreen [$v ['cidKey']] = $v ['title'];
  6904. break;
  6905. }
  6906. }
  6907. }
  6908. $categoryScreenHtml = "";
  6909. foreach ( $categoryScreen as $key => $value ) {
  6910. if ($cidKey == $key)
  6911. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6912. else
  6913. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6914. }
  6915. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  6916. $data ['cidKey'] = $cidKey;
  6917. $Locate = 0;
  6918. $roleId = 0;
  6919. $button = 0;
  6920. $staffBatchNumber = 100001;
  6921. $remittanceList = array ();
  6922. foreach ( $receiptList as $key => $value ) {
  6923. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  6924. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  6925. $receiptList [$key] ['Texe'] = 'false';
  6926. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  6927. $receiptList [$key] ['Texe'] = 'true';
  6928. }
  6929. $receiptList [$key] ['TRexe'] = 'true';
  6930. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  6931. $receiptList [$key] ['TRexe'] = 'false';
  6932. }
  6933. $receiptList [$key] ['Locate'] = $Locate;
  6934. $Locate ++;
  6935. $receiptList [$key] ['reviseDetail'] = array ();
  6936. if (! empty ( $value ['reviseDetail'] ))
  6937. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6938. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6939. $categoryDetil = $Lcategory->getOne ( array (
  6940. 'where' => 'cid=' . $value ['cid'],
  6941. 'asArray' => true
  6942. ) );
  6943. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6944. // 检测编辑状态
  6945. $verifyList = $verify->getOne ( array (
  6946. 'where' => 'vid=' . $value ['verify'],
  6947. 'asArray' => true
  6948. ) );
  6949. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6950. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6951. Doo::loadModel ( 'role' );
  6952. $role = new role ();
  6953. $flag = true;
  6954. $roleKey = 0;
  6955. $endStaffArray = array ();
  6956. $roleArrayCopy = array ();
  6957. foreach ( $verifyList as $k => $v ) {
  6958. // init verifyStaff
  6959. if ($v [1] == 'ROLE') {
  6960. if (! empty ( $verifyStaff )) {
  6961. $endStaffArray = end ( $verifyStaff );
  6962. }
  6963. $roleVerify = json_decode ( $v [3], true );
  6964. $roleKey = $k;
  6965. $roleArray = array ();
  6966. $rolename = $role->getOne ( array (
  6967. 'where' => 'rid=' . $v [0],
  6968. 'asArray' => true
  6969. ) );
  6970. foreach ( $roleVerify as $o => $p ) {
  6971. $staffID = explode ( '_', $p );
  6972. $staffInfo = $staff->getOne ( array (
  6973. 'where' => 'sid=' . $staffID [0],
  6974. 'asArray' => true
  6975. ) );
  6976. $exp = array (
  6977. 0 => $staffInfo ['sid'],
  6978. 1 => $staffID [1],
  6979. 2 => $staffInfo ['avatar'],
  6980. 'date' => '',
  6981. 'date' => '',
  6982. 'opinion' => '',
  6983. 'status' => '',
  6984. 'rolename' => $rolename ['name']
  6985. );
  6986. array_push ( $roleArray, $exp );
  6987. }
  6988. $roleArrayCopy [$v [0]] = $roleArray;
  6989. }
  6990. $verifyList [$k] ['date'] = "";
  6991. $verifyList [$k] ['opinion'] = "";
  6992. $verifyList [$k] ['status'] = "";
  6993. if (empty ( $verifyStaff )) {
  6994. $verifyList [$k] ['date'] = "";
  6995. $verifyList [$k] ['opinion'] = "";
  6996. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6997. $verifyList [$k] ['status'] = 4;
  6998. $flag = false;
  6999. }
  7000. } else {
  7001. foreach ( $verifyStaff as $m => $u ) {
  7002. if ($v [0] == $m) {
  7003. $verifyList [$k] ['date'] = $u ['date'];
  7004. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7005. $verifyList [$k] ['status'] = $u ['status'];
  7006. $flag = false;
  7007. break;
  7008. }
  7009. }
  7010. $endStaffArray = end ( $verifyStaff );
  7011. }
  7012. }
  7013. $rolename ['name'] = '';
  7014. if (! empty ( $roleId )) {
  7015. Doo::loadModel ( 'role' );
  7016. $role = new role ();
  7017. $rolename = $role->getOne ( array (
  7018. 'where' => 'rid=' . $roleId,
  7019. 'asArray' => true
  7020. ) );
  7021. }
  7022. if (! empty ( $verifyStaff ))
  7023. $endStaffArray = end ( $verifyStaff );
  7024. $KOP = false;
  7025. foreach ( $roleArrayCopy as $P => $A ) {
  7026. foreach ( $A as $MKI => $AVL ) {
  7027. if (! empty ( $verifyStaff )) {
  7028. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7029. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7030. $button = 4;
  7031. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7032. }
  7033. foreach ( $verifyStaff as $m => $u ) {
  7034. $AVLFK = $AVL [0] . '_R';
  7035. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7036. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7037. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7038. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7039. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7040. break;
  7041. }
  7042. }
  7043. } else {
  7044. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7045. $button = 4;
  7046. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7047. }
  7048. }
  7049. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7050. $KOP = true;
  7051. }
  7052. }
  7053. foreach ( $roleArrayCopy as $k => $v ) {
  7054. foreach ( $verifyList as $m => $n ) {
  7055. if ($n [0] == $k) {
  7056. array_splice ( $verifyList, $m, 1, $v );
  7057. }
  7058. }
  7059. }
  7060. $receiptList [$key] ['verifyList'] = $verifyList;
  7061. $staffDetail = $staff->getOne ( array (
  7062. 'where' => 'sid=' . $value ['staff'],
  7063. 'asArray' => true
  7064. ) );
  7065. $receiptList [$key] ['staffDetail'] = $staffDetail;
  7066. $receiptList [$key] ['button'] = $button;
  7067. if ($value['Rtype']==1){
  7068. $receiptList [$key] ['relust'] = $value['sum']-$value['loanSum'];
  7069. $receiptList [$key] ['relustABS'] = sprintf("%.2f",abs($receiptList [$key] ['relust']));
  7070. }elseif($value['Rtype']==3){
  7071. // 收入合计
  7072. Doo::loadModel ( 'invoiceTraining' );
  7073. $invoiceTraining = new invoiceTraining ();
  7074. $invoiceTrainingDetail = array (
  7075. 'invoiceArriveAmount' => '0.00',
  7076. 'RIAmount' => '0.00',
  7077. 'invoiceTotalAmount' => '0.00',
  7078. 'invoiceCompanyAmount' => '0.00',
  7079. 'invoiceArriveAmountM'=>'0.00',
  7080. 'invoiceCompanyAmountM'=>'0.00'
  7081. );
  7082. if ($value ['invoiceTrainId'] != 0) {
  7083. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value['invoiceTrainId'] );
  7084. }
  7085. $invoiceArriveAmount = $RIAmount = 0;
  7086. if (! empty ( $invoiceTrainingDetail )) {
  7087. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  7088. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  7089. }
  7090. // 备用金
  7091. $sum = 0;
  7092. if (! empty ( $value ['trainLoanRid'] )) {
  7093. $receiptLoanList = $receipt->getReceiptInRid ( $value ['trainLoanRid'] );
  7094. foreach ($receiptLoanList as $kll=>$vll){
  7095. $sum+=$vll['sum'];
  7096. }
  7097. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $value ['trainLoanRid'] );
  7098. // $sum = $receiptLoanDetailBak ['sum'];
  7099. }
  7100. // 支出项金额详情
  7101. // 项目金额合计
  7102. Doo::loadModel ( 'RItem' );
  7103. $RItem = new RItem ();
  7104. Doo::loadModel ( 'accountItem' );
  7105. $accountItem = new accountItem ();
  7106. // 讲师获得
  7107. Doo::loadModel ( 'RILecturer' );
  7108. $RILecturer = new RILecturer ();
  7109. $RItemList = $RItem->getRItemByRid ( $value['rid'] );
  7110. $RILecturerList = $RILecturer->getRILecturerByRid ( $value['rid'] );
  7111. // 支出项金额详情
  7112. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  7113. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  7114. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  7115. $receiptList [$key] ['payment'] =$payment;
  7116. $receiptList [$key] ['paymentABS'] =sprintf("%.2f",abs($payment));
  7117. }
  7118. // 设置导出汇款execl
  7119. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  7120. $remittanceDetail = array (
  7121. $staffBatchNumber,
  7122. $value ['remittanceName'],
  7123. $value ['bankNumber'],
  7124. $value ['bankName'],
  7125. $value ['remittanceBankType'],
  7126. $value ['coupletNumber'],
  7127. $value ['sum']
  7128. );
  7129. array_push ( $remittanceList, $remittanceDetail );
  7130. $staffBatchNumber ++;
  7131. }
  7132. }
  7133. $data ['remittanceList'] = json_encode ( $remittanceList );
  7134. // print_r($receiptList);
  7135. $mothHtml = "";
  7136. for($i = 1; $i <= 12; $i ++) {
  7137. if ($moth == $i)
  7138. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7139. else
  7140. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7141. }
  7142. $dayHtml = "";
  7143. if ($day != "DAY" || $moth != "MONTH") {
  7144. for($i = 1; $i <= 31; $i ++) {
  7145. if ($day == $i)
  7146. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7147. else
  7148. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7149. }
  7150. }
  7151. $sopHtml = "";
  7152. foreach ( $sopStaff as $key => $value ) {
  7153. if ($sop == $key)
  7154. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  7155. else
  7156. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  7157. }
  7158. $data ['status'] = $status;
  7159. $data ['rdate'] = $rdate;
  7160. $data ['sopHtml'] = $sopHtml;
  7161. $data ['dayHtml'] = $dayHtml;
  7162. $data ['mothHtml'] = $mothHtml;
  7163. $data ['receiptList'] = $receiptList;
  7164. $data ['memu'] = "receipt";
  7165. $data ['staff'] = $this->staff;
  7166. $data ['receiptMemu'] = 'implement';
  7167. $data ['verifyId'] = $this->verifyId;
  7168. $data ['executeId'] = $this->executeId;
  7169. $data ['item'] = $item;
  7170. $data ['year'] = $year;
  7171. $data ['moth'] = $moth;
  7172. $data['receiptOrder']=$receiptOrder;
  7173. $data ['day'] = $day;
  7174. $data ['sop'] = $sop;
  7175. $this->render ( "/admin/hisImplement", $data );
  7176. }
  7177. /**
  7178. * 导出汇款信息的exelc
  7179. */
  7180. function exportRemittance() {
  7181. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  7182. if (empty ( $remittanceInfo ))
  7183. die ( 'illegal request' );
  7184. $title = array (
  7185. '员工编号',
  7186. '姓名',
  7187. '员工账号',
  7188. '员工账户开户行',
  7189. '转账类型',
  7190. '联行号',
  7191. '金额'
  7192. );
  7193. $data = json_decode ( $remittanceInfo, true );
  7194. if (empty ( $data ))
  7195. die ( 'illegal request' );
  7196. Doo::loadClass ( 'receipt.func' );
  7197. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  7198. header ( 'Content-Type:text/html;charset=utf-8' );
  7199. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  7200. }
  7201. function ajaxExamine() {
  7202. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  7203. Doo::loadModel ( 'receipt' );
  7204. $receipt = new receipt ();
  7205. if (! empty ( $rid )) {
  7206. $rLRes = $receipt->find ( array (
  7207. 'where' => 'status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) and rid!=' . $rid,
  7208. 'asArray' => true
  7209. ) );
  7210. if(!empty($rLRes)){
  7211. Doo::loadClass ( 'XDeode' );
  7212. $XDeode = new XDeode ( 7 );
  7213. $rLRes [0]['ridKey'] = $XDeode->encode( $rLRes [0]['rid'] );
  7214. echo json_encode ( array (
  7215. 'status' => 1,
  7216. 'receipt' => $rLRes [0]
  7217. ) );
  7218. die ();
  7219. }else{
  7220. echo json_encode ( array (
  7221. 'status' => 1,
  7222. 'receipt' => array ()
  7223. ) );
  7224. die ();
  7225. }
  7226. }
  7227. echo json_encode ( array (
  7228. 'status' => 0,
  7229. 'receipt' => array ()
  7230. ) );
  7231. die ();
  7232. }
  7233. /*
  7234. * 废弃
  7235. */
  7236. function myReceipt() {
  7237. // all approval past withdraw
  7238. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  7239. if (empty ( $item ))
  7240. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  7241. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7242. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  7243. Doo::loadModel ( 'receipt' );
  7244. $receipt = new receipt ();
  7245. // pre-loaded
  7246. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  7247. // have cache
  7248. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  7249. if (! empty ( $moth )) // yearPage
  7250. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  7251. $this->showCache ( $path );
  7252. }
  7253. Doo::loadModel ( 'L_category' );
  7254. $Lcategory = new L_category ();
  7255. Doo::loadModel ( 'verify' );
  7256. Doo::loadModel ( 'statistics' );
  7257. $statistics = new statistics ();
  7258. $verify = new verify ();
  7259. Doo::loadModel ( 'staff' );
  7260. $staff = new staff ();
  7261. $condition = " and status!=0 ";
  7262. if ($item == "approval")
  7263. $condition = " and status=2 ";
  7264. elseif ($item == "withdraw")
  7265. $condition = " and status=3 ";
  7266. elseif ($item == "past")
  7267. $condition = " and status=1 ";
  7268. elseif ($item == "whdw")
  7269. $condition = " and status=4 ";
  7270. $dateCondition = " and Year(date) =" . $year;
  7271. if (! empty ( $moth )) {
  7272. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  7273. $stList = $statistics->getOne ( array (
  7274. 'select' => 'rePrice ,agPrice',
  7275. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7276. 'asArray' => true
  7277. ) );
  7278. } else
  7279. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  7280. if (empty ( $stList ))
  7281. $stList = array (
  7282. 'rePrice' => 0,
  7283. 'agPrice' => 0
  7284. );
  7285. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  7286. $data ['stList'] = array (
  7287. 'rePrice' => $stList ['rePrice'],
  7288. 'agPrice' => $stList ['agPrice'],
  7289. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  7290. );
  7291. $receiptList = $receipt->find ( array (
  7292. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  7293. 'desc' => 'rid',
  7294. 'asArray' => true
  7295. ) );
  7296. $Locate = 0;
  7297. $roleId = 0;
  7298. $button = 0;
  7299. foreach ( $receiptList as $key => $value ) {
  7300. $receiptList [$key] ['Locate'] = $Locate;
  7301. $Locate ++;
  7302. $receiptList [$key] ['reviseDetail'] = array ();
  7303. if (! empty ( $value ['reviseDetail'] ))
  7304. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7305. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7306. $categoryDetil = $Lcategory->getOne ( array (
  7307. 'where' => 'cid=' . $value ['cid'],
  7308. 'asArray' => true
  7309. ) );
  7310. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7311. // 检测编辑状态
  7312. $verifyList = $verify->getOne ( array (
  7313. 'where' => 'vid=' . $value ['verify'],
  7314. 'asArray' => true
  7315. ) );
  7316. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7317. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7318. Doo::loadModel ( 'role' );
  7319. $role = new role ();
  7320. $flag = true;
  7321. $roleKey = 0;
  7322. $endStaffArray = array ();
  7323. $roleArrayCopy = array ();
  7324. foreach ( $verifyList as $k => $v ) {
  7325. // init verifyStaff
  7326. if ($v [1] == 'ROLE') {
  7327. if (! empty ( $verifyStaff )) {
  7328. $endStaffArray = end ( $verifyStaff );
  7329. // if ($v[0]==$endStaffArray['nextStaff']){
  7330. // $roleId=$v[0];
  7331. // }
  7332. }
  7333. $roleVerify = json_decode ( $v [3], true );
  7334. $roleKey = $k;
  7335. $roleArray = array ();
  7336. $rolename = $role->getOne ( array (
  7337. 'where' => 'rid=' . $v [0],
  7338. 'asArray' => true
  7339. ) );
  7340. foreach ( $roleVerify as $o => $p ) {
  7341. $staffID = explode ( '_', $p );
  7342. $staffInfo = $staff->getOne ( array (
  7343. 'where' => 'sid=' . $staffID [0],
  7344. 'asArray' => true
  7345. ) );
  7346. // print_r($staffID);
  7347. $exp = array (
  7348. 0 => $staffInfo ['sid'],
  7349. 1 => $staffID [1],
  7350. 2 => $staffInfo ['avatar'],
  7351. 'date' => '',
  7352. 'date' => '',
  7353. 'opinion' => '',
  7354. 'status' => '',
  7355. 'rolename' => $rolename ['name']
  7356. );
  7357. array_push ( $roleArray, $exp );
  7358. }
  7359. $roleArrayCopy [$v [0]] = $roleArray;
  7360. // $verifyList[$k]['roleArray']=$roleArray;
  7361. }
  7362. $verifyList [$k] ['date'] = "";
  7363. $verifyList [$k] ['opinion'] = "";
  7364. $verifyList [$k] ['status'] = "";
  7365. if (empty ( $verifyStaff )) {
  7366. $verifyList [$k] ['date'] = "";
  7367. $verifyList [$k] ['opinion'] = "";
  7368. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7369. $verifyList [$k] ['status'] = 4;
  7370. $flag = false;
  7371. }
  7372. } else {
  7373. foreach ( $verifyStaff as $m => $u ) {
  7374. if ($v [0] == $m) {
  7375. $verifyList [$k] ['date'] = $u ['date'];
  7376. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7377. $verifyList [$k] ['status'] = $u ['status'];
  7378. $flag = false;
  7379. break;
  7380. }
  7381. }
  7382. $endStaffArray = end ( $verifyStaff );
  7383. if (isset ( $endStaffArray ['ROLE'] )) {
  7384. } else {
  7385. // $endKey=key($verifyStaff);
  7386. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  7387. // $button=4;
  7388. // $verifyList[$k]['status']=4;
  7389. // }
  7390. }
  7391. }
  7392. }
  7393. $rolename ['name'] = '';
  7394. if (! empty ( $roleId )) {
  7395. Doo::loadModel ( 'role' );
  7396. $role = new role ();
  7397. $rolename = $role->getOne ( array (
  7398. 'where' => 'rid=' . $roleId,
  7399. 'asArray' => true
  7400. ) );
  7401. }
  7402. if (! empty ( $verifyStaff ))
  7403. $endStaffArray = end ( $verifyStaff );
  7404. $KOP = false;
  7405. foreach ( $roleArrayCopy as $P => $A ) {
  7406. foreach ( $A as $MKI => $AVL ) {
  7407. if (! empty ( $verifyStaff )) {
  7408. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7409. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7410. $button = 4;
  7411. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7412. }
  7413. foreach ( $verifyStaff as $m => $u ) {
  7414. $AVLFK = $AVL [0] . '_R';
  7415. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7416. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7417. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7418. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7419. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7420. break;
  7421. }
  7422. }
  7423. } else {
  7424. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7425. $button = 4;
  7426. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7427. }
  7428. }
  7429. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7430. $KOP = true;
  7431. }
  7432. }
  7433. foreach ( $roleArrayCopy as $k => $v ) {
  7434. foreach ( $verifyList as $m => $n ) {
  7435. if ($n [0] == $k) {
  7436. array_splice ( $verifyList, $m, 1, $v );
  7437. }
  7438. }
  7439. }
  7440. $receiptList [$key] ['verifyList'] = $verifyList;
  7441. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7442. 'where' => 'sid=' . $value ['staff'],
  7443. 'asArray' => true
  7444. ) );
  7445. $receiptList [$key] ['button'] = $button;
  7446. }
  7447. // print_r($receiptList);die;
  7448. $mothHtml = "";
  7449. for($i = 1; $i <= 12; $i ++) {
  7450. if ($moth == $i)
  7451. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7452. else
  7453. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7454. }
  7455. $data ['mothHtml'] = $mothHtml;
  7456. $data ['receiptList'] = $receiptList;
  7457. $data ['memu'] = "receipt";
  7458. $data ['staff'] = $this->staff;
  7459. $data ['receiptMemu'] = 'receipt';
  7460. $data ['verifyId'] = $this->verifyId;
  7461. $data ['executeId'] = $this->executeId;
  7462. $data ['item'] = $item;
  7463. $data ['year'] = $year;
  7464. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  7465. // sufficient condition to generate cache
  7466. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  7467. $receiptList = $receipt->find ( array (
  7468. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  7469. 'asArray' => true
  7470. ) );
  7471. if (empty ( $receiptList )) { // generated files
  7472. ob_start ();
  7473. $this->render ( "/admin/saea_myList", $data );
  7474. $this->cacheFile ( $path );
  7475. die ();
  7476. // $content = ob_get_contents();
  7477. // $fp = fopen($path, "w");
  7478. // fwrite($fp, $content);
  7479. // fclose($fp);
  7480. }
  7481. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  7482. $receiptList = $receipt->find ( array (
  7483. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  7484. 'asArray' => true
  7485. ) );
  7486. if (empty ( $receiptList )) { // generated files
  7487. ob_start ();
  7488. $this->render ( "/admin/saea_myList", $data );
  7489. $this->cacheFile ( $path );
  7490. die ();
  7491. }
  7492. }
  7493. }
  7494. $this->render ( "/admin/saea_myList", $data );
  7495. }
  7496. function approvedReceipt() {
  7497. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7498. Doo::loadModel ( 'receipt' );
  7499. Doo::loadModel ( 'receiptDetail' );
  7500. $receipt = new receipt ();
  7501. $receiptDetail = new receiptDetail ();
  7502. Doo::loadModel ( 'statistics' );
  7503. Doo::loadModel ( 'itemStatistics' );
  7504. $statistics = new statistics ();
  7505. $itemStatistics = new itemStatistics ();
  7506. Doo::loadModel ( "verify" );
  7507. $verify = new verify ();
  7508. // 审批状态的判定
  7509. $receiptDetailList = $receipt->getOne ( array (
  7510. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  7511. 'asArray' => true
  7512. ) );
  7513. if (empty ( $receiptDetailList ))
  7514. return "/saeaBorad";
  7515. $verifyDetail = $verify->getOne ( array (
  7516. 'where' => ' vid =' . $receiptDetailList ['verify'],
  7517. 'asArray' => true
  7518. ) );
  7519. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  7520. if (empty ( $receiptDetailList ['nowStaff'] )) {
  7521. $nowStaff = "";
  7522. $nowStaffList = array ();
  7523. if ($verifyDetail [0] [1] == 'ROLE') {
  7524. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7525. foreach ( $vStaffString as $key => $value ) {
  7526. $staffK = explode ( "_", $value );
  7527. array_push ( $nowStaffList, $staffK [0] );
  7528. }
  7529. $nowStaff = implode ( ',', $nowStaffList );
  7530. } else {
  7531. $nowStaff = $verifyDetail [0] [0];
  7532. }
  7533. $receipt->nowStaff = $nowStaff;
  7534. }
  7535. // echo $nowStaff;
  7536. // print_r($verifyDetail);die;
  7537. $receipt->rid = $receiptDetailList ['rid'];
  7538. $receipt->date = date ( "Y-m-d" );
  7539. $receipt->status = 2;
  7540. $receipt->update ();
  7541. $receiptDetail->status = 2;
  7542. $receiptDetail->update ( array (
  7543. 'where' => 'rid=' . $receiptDetailList ['rid']
  7544. ) );
  7545. Doo::loadModel ( "receiptLog" );
  7546. $receiptLog = new receiptLog ();
  7547. Doo::loadModel ( "verify" );
  7548. $verify = new verify ();
  7549. $receiptInfo = $receipt->getOne ( array (
  7550. 'where' => 'rid=' . $rid,
  7551. 'asArray' => true
  7552. ) );
  7553. $vr = $verify->getOne ( array (
  7554. 'where' => 'vid=' . $receiptInfo ['verify'],
  7555. 'asArray' => true
  7556. ) );
  7557. $jd = json_decode ( $vr ['staff'] );
  7558. $roleId = 0;
  7559. foreach ( $jd as $key => $value ) {
  7560. if ($value [1] == 'ROLE') {
  7561. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7562. if ($pos !== false) {
  7563. $roleId = $value [0];
  7564. }
  7565. }
  7566. }
  7567. // 审批日志
  7568. // echo $roleId;die;
  7569. if (! empty ( $roleId )) {
  7570. Doo::loadModel ( "role" );
  7571. $role = new role ();
  7572. $roleInfo = $role->getOne ( array (
  7573. 'where' => 'rid=' . $roleId,
  7574. 'asArray' => true
  7575. ) );
  7576. // $receiptLog->rolename = $roleInfo ['name'];
  7577. }
  7578. $receiptLog->username = $this->staff [0] ['username'];
  7579. $receiptLog->uid = $this->staff [0] ['sid'];
  7580. $receiptLog->date = date ( "Y-m-d" );
  7581. $receiptLog->opinion = '提交审批';
  7582. $receiptLog->img = $this->staff [0] ['avatar'];
  7583. $receiptLog->status = 2;
  7584. $receiptLog->rid = $rid;
  7585. $receiptLog->insert ();
  7586. // statistics item
  7587. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7588. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7589. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7590. $stat = $statistics->getOne ( array (
  7591. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7592. 'asArray' => true
  7593. ) );
  7594. if (empty ( $stat )) {
  7595. $statistics->date = date ( "Y-m-d" );
  7596. $statistics->cid = $this->staff [0] ['cid'];
  7597. $statistics->staff = $this->staff [0] ['sid'];
  7598. $statistics->agPrice = 0;
  7599. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7600. $statistics->insert ();
  7601. } else {
  7602. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7603. $statistics->update ( array (
  7604. 'where' => 'sid=' . $stat ['sid']
  7605. ) );
  7606. }
  7607. return "/expenses";
  7608. }
  7609. function approval() {
  7610. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7611. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7612. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7613. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7614. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7615. if (empty ( $status ))
  7616. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7617. $vidList = array ();
  7618. $button = 0;
  7619. Doo::loadModel ( 'verify' );
  7620. $verify = new verify ();
  7621. Doo::loadModel ( 'receipt' );
  7622. $receipt = new receipt ();
  7623. Doo::loadModel ( 'staff' );
  7624. $staff = new staff ();
  7625. Doo::loadModel ( 'L_category' );
  7626. $Lcategory = new L_category ();
  7627. // user verify ID
  7628. $verifyDetail = $verify->find ( array (
  7629. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7630. 'asArray' => true
  7631. ) );
  7632. foreach ( $verifyDetail as $key => $value ) {
  7633. array_push ( $vidList, $value ['vid'] );
  7634. }
  7635. $vid = implode ( ",", $vidList );
  7636. if (empty ( $verifyDetail ))
  7637. $vid = 0;
  7638. /*
  7639. */
  7640. $dateCondition = " and Year(date) =" . $year;
  7641. if (! empty ( $month ))
  7642. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7643. $categoryList = $Lcategory->find ( array (
  7644. 'asArray' => true
  7645. ) );
  7646. $staffList = $staff->find ( array (
  7647. 'where' => 'cid=' . $cid,
  7648. 'asArray' => true
  7649. ) );
  7650. $cateCondition = "";
  7651. $staffCondition = "";
  7652. $approvalCondition = "";
  7653. if (! empty ( $cid ))
  7654. $cateCondition = ' and cid=' . $cid;
  7655. if (! empty ( $sid )) {
  7656. $staffCondition = ' and staff=' . $sid;
  7657. $cateCondition = "";
  7658. }
  7659. // elseif($status==1){
  7660. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7661. // }
  7662. if ($status == 2) {
  7663. // 查找角色审批人
  7664. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7665. }
  7666. $ap = "";
  7667. if ($status == 4) {
  7668. $ap = 4;
  7669. $status = 2;
  7670. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7671. }
  7672. if ($status == 5) {
  7673. $status = 4;
  7674. $ap = 5;
  7675. }
  7676. // echo $vid;
  7677. // get Receipt By verifyID status 2 .$approvalCondition
  7678. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7679. $receiptList = $receipt->find ( array (
  7680. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7681. 'desc' => 'rid',
  7682. 'asArray' => true
  7683. ) );
  7684. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7685. $Locate = 0;
  7686. if ($ap == 4)
  7687. $status = 4;
  7688. elseif ($ap == 5)
  7689. $status = 5;
  7690. foreach ( $receiptList as $key => $value ) {
  7691. $receiptList [$key] ['Locate'] = $Locate;
  7692. $Locate ++;
  7693. $receiptList [$key] ['reviseDetail'] = array ();
  7694. if (! empty ( $value ['reviseDetail'] ))
  7695. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7696. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7697. $categoryDetil = $Lcategory->getOne ( array (
  7698. 'where' => 'cid=' . $value ['cid'],
  7699. 'asArray' => true
  7700. ) );
  7701. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7702. $verifyList = $verify->getOne ( array (
  7703. 'where' => 'vid=' . $value ['verify'],
  7704. 'asArray' => true
  7705. ) );
  7706. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7707. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7708. foreach ( $verifyList as $k => $v ) {
  7709. // init verifyStaff
  7710. $verifyList [$k] ['date'] = "";
  7711. $verifyList [$k] ['opinion'] = "";
  7712. $verifyList [$k] ['status'] = "";
  7713. if (empty ( $verifyStaff )) {
  7714. $verifyList [$k] ['date'] = "";
  7715. $verifyList [$k] ['opinion'] = "";
  7716. if ($v [0] == $this->staff [0] ['sid']) {
  7717. $verifyList [$k] ['status'] = 4;
  7718. $button = 4;
  7719. }
  7720. } else {
  7721. $flag = true;
  7722. foreach ( $verifyStaff as $m => $u ) {
  7723. if ($v [0] == $m) {
  7724. $verifyList [$k] ['date'] = $u ['date'];
  7725. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7726. $verifyList [$k] ['status'] = $u ['status'];
  7727. $flag = false;
  7728. break;
  7729. }
  7730. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7731. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7732. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7733. }
  7734. if ($flag) { // 检测可编辑
  7735. if ($v [0] == $this->staff [0] ['sid']) {
  7736. $verifyList [$k] ['status'] = 4;
  7737. $button = 4;
  7738. }
  7739. }
  7740. }
  7741. }
  7742. $receiptList [$key] ['verifyList'] = $verifyList;
  7743. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7744. 'where' => 'sid=' . $value ['staff'],
  7745. 'asArray' => true
  7746. ) );
  7747. $receiptList [$key] ['button'] = $button;
  7748. }
  7749. // print_r($receiptList);die;
  7750. // $data['verifyDetail']=$verifyDetail;
  7751. $mothHtml = "";
  7752. for($i = 1; $i <= 12; $i ++) {
  7753. if ($month == $i)
  7754. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7755. else
  7756. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7757. }
  7758. $data ['mothHtml'] = $mothHtml;
  7759. $data ['receiptList'] = $receiptList;
  7760. $data ['receiptApprovalCount'] = count ( $receiptList );
  7761. $data ['status'] = $status;
  7762. $data ['year'] = $year;
  7763. $data ['categoryList'] = $categoryList;
  7764. $data ['staffList'] = $staffList;
  7765. $data ['cid'] = $cid;
  7766. $data ['sid'] = $sid;
  7767. $data ['ap'] = $ap;
  7768. $data ['memu'] = "receipt";
  7769. $data ['staff'] = $this->staff;
  7770. $data ['receiptMemu'] = 'approval';
  7771. $data ['verifyId'] = $this->verifyId;
  7772. $data ['executeId'] = $this->executeId;
  7773. $this->render ( "/admin/saea_reportList", $data );
  7774. }
  7775. function approvalDetails() {
  7776. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7777. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7778. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7779. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7780. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7781. Doo::loadModel ( 'verify' );
  7782. $verify = new verify ();
  7783. Doo::loadModel ( 'receipt' );
  7784. $receipt = new receipt ();
  7785. Doo::loadModel ( 'staff' );
  7786. $staff = new staff ();
  7787. Doo::loadModel ( 'L_category' );
  7788. $Lcategory = new L_category ();
  7789. Doo::loadModel ( 'enclosur' );
  7790. $enclosur = new enclosur ();
  7791. $vidList = array ();
  7792. $verifyDetail = $verify->find ( array (
  7793. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7794. 'asArray' => true
  7795. ) );
  7796. foreach ( $verifyDetail as $key => $value ) {
  7797. array_push ( $vidList, $value ['vid'] );
  7798. }
  7799. $vid = implode ( ",", $vidList );
  7800. if (empty ( $verifyDetail ))
  7801. $vid = 0;
  7802. $categoryList = $Lcategory->find ( array (
  7803. 'asArray' => true
  7804. ) );
  7805. $staffList = $staff->find ( array (
  7806. 'where' => 'cid=' . $cid,
  7807. 'asArray' => true
  7808. ) );
  7809. $ap = 0;
  7810. $receiptList = $receipt->find ( array (
  7811. 'where' => 'rid =' . $rid,
  7812. 'desc' => 'rid',
  7813. 'asArray' => true
  7814. ) );
  7815. $Locate = 0;
  7816. $roleId = 0;
  7817. $button = 0;
  7818. foreach ( $receiptList as $key => $value ) {
  7819. $receiptList [$key] ['Locate'] = $Locate;
  7820. $Locate ++;
  7821. $receiptList [$key] ['reviseDetail'] = array ();
  7822. if (! empty ( $value ['reviseDetail'] ))
  7823. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7824. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7825. $categoryDetil = $Lcategory->getOne ( array (
  7826. 'where' => 'cid=' . $value ['cid'],
  7827. 'asArray' => true
  7828. ) );
  7829. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7830. // 检测编辑状态
  7831. $verifyList = $verify->getOne ( array (
  7832. 'where' => 'vid=' . $value ['verify'],
  7833. 'asArray' => true
  7834. ) );
  7835. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7836. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7837. Doo::loadModel ( 'role' );
  7838. $role = new role ();
  7839. // print_r($verifyList);
  7840. $flag = true;
  7841. $roleKey = 0;
  7842. $endStaffArray = array ();
  7843. $roleArrayCopy = array ();
  7844. foreach ( $verifyList as $k => $v ) {
  7845. // init verifyStaff
  7846. if ($v [1] == 'ROLE') {
  7847. if (! empty ( $verifyStaff )) {
  7848. $endStaffArray = end ( $verifyStaff );
  7849. if ($v [0] == $endStaffArray ['nextStaff']) {
  7850. $roleId = $v [0];
  7851. }
  7852. }
  7853. $roleVerify = json_decode ( $v [3], true );
  7854. $roleKey = $k;
  7855. $roleArray = array ();
  7856. $rolename = $role->getOne ( array (
  7857. 'where' => 'rid=' . $v [0],
  7858. 'asArray' => true
  7859. ) );
  7860. foreach ( $roleVerify as $o => $p ) {
  7861. $staffID = explode ( '_', $p );
  7862. $staffInfo = $staff->getOne ( array (
  7863. 'where' => 'sid=' . $staffID [0],
  7864. 'asArray' => true
  7865. ) );
  7866. // print_r($staffID);
  7867. $exp = array (
  7868. 0 => $staffInfo ['sid'],
  7869. 1 => $staffID [1],
  7870. 2 => $staffInfo ['avatar'],
  7871. 'date' => '',
  7872. 'date' => '',
  7873. 'opinion' => '',
  7874. 'status' => '',
  7875. 'rolename' => $rolename ['name']
  7876. );
  7877. array_push ( $roleArray, $exp );
  7878. }
  7879. $roleArrayCopy [$v [0]] = $roleArray;
  7880. // $verifyList[$k]['roleArray']=$roleArray;
  7881. }
  7882. // print_r($roleArray);
  7883. $verifyList [$k] ['date'] = "";
  7884. $verifyList [$k] ['opinion'] = "";
  7885. $verifyList [$k] ['status'] = "";
  7886. if (empty ( $verifyStaff )) {
  7887. $verifyList [$k] ['date'] = "";
  7888. $verifyList [$k] ['opinion'] = "";
  7889. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7890. $verifyList [$k] ['status'] = 4;
  7891. $button = 4;
  7892. $flag = false;
  7893. }
  7894. } else {
  7895. foreach ( $verifyStaff as $m => $u ) {
  7896. if ($v [0] == $m) {
  7897. $verifyList [$k] ['date'] = $u ['date'];
  7898. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7899. $verifyList [$k] ['status'] = $u ['status'];
  7900. $flag = false;
  7901. break;
  7902. }
  7903. }
  7904. $endStaffArray = end ( $verifyStaff );
  7905. if (isset ( $endStaffArray ['ROLE'] )) {
  7906. } else {
  7907. $endKey = key ( $verifyStaff );
  7908. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7909. $button = 4;
  7910. $verifyList [$k] ['status'] = 4;
  7911. }
  7912. }
  7913. }
  7914. }
  7915. $rolename ['name'] = '';
  7916. if (! empty ( $roleId )) {
  7917. Doo::loadModel ( 'role' );
  7918. $role = new role ();
  7919. $rolename = $role->getOne ( array (
  7920. 'where' => 'rid=' . $roleId,
  7921. 'asArray' => true
  7922. ) );
  7923. }
  7924. if (! empty ( $verifyStaff ))
  7925. $endStaffArray = end ( $verifyStaff );
  7926. $KOP = false;
  7927. foreach ( $roleArrayCopy as $P => $A ) {
  7928. foreach ( $A as $MKI => $AVL ) {
  7929. if (! empty ( $verifyStaff )) {
  7930. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7931. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7932. $button = 4;
  7933. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7934. }
  7935. foreach ( $verifyStaff as $m => $u ) {
  7936. $AVLFK = $AVL [0] . '_R';
  7937. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7938. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7939. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7940. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7941. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7942. break;
  7943. }
  7944. }
  7945. } else {
  7946. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7947. $button = 4;
  7948. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7949. }
  7950. }
  7951. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7952. $KOP = true;
  7953. }
  7954. }
  7955. foreach ( $roleArrayCopy as $k => $v ) {
  7956. foreach ( $verifyList as $m => $n ) {
  7957. if ($n [0] == $k) {
  7958. array_splice ( $verifyList, $m, 1, $v );
  7959. }
  7960. }
  7961. }
  7962. $receiptList [$key] ['verifyList'] = $verifyList;
  7963. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7964. 'where' => 'sid=' . $value ['staff'],
  7965. 'asArray' => true
  7966. ) );
  7967. $receiptList [$key] ['button'] = $button;
  7968. }
  7969. $mothHtml = "";
  7970. for($i = 1; $i <= 12; $i ++) {
  7971. if ($month == $i)
  7972. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7973. else
  7974. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7975. }
  7976. // 获取审批日志
  7977. Doo::loadModel ( 'receiptLog' );
  7978. $receiptLog = new receiptLog ();
  7979. $rlList = array ();
  7980. $rlInfo = $receiptLog->getOne ( array (
  7981. 'where' => 'rid=' . $rid . ' and status=4',
  7982. 'asArray' => true
  7983. ) );
  7984. $tijdate = $receiptLog->getOne ( array (
  7985. 'where' => 'rid=' . $rid . ' and status=2',
  7986. 'asc' => 'rlid',
  7987. 'asArray' => true
  7988. ) );
  7989. if (! empty ( $rlInfo )) {
  7990. $rlList = $receiptLog->find ( array (
  7991. 'where' => 'rid=' . $rid,
  7992. 'asc' => 'rlid',
  7993. 'asArray' => true
  7994. ) );
  7995. }
  7996. $receiptList [0] ['rlList'] = $rlList;
  7997. $enclosurList = $enclosur->find ( array (
  7998. 'where' => 'rid=' . $rid,
  7999. 'asArray' => true
  8000. ) );
  8001. $enclosurHtml = '';
  8002. foreach ( $enclosurList as $value ) {
  8003. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  8004. }
  8005. $data ['enclosurHtml'] = $enclosurHtml;
  8006. $data ['rolename'] = $rolename ['name'];
  8007. $data ['datetij'] = $tijdate ['date'];
  8008. $data ['mothHtml'] = $mothHtml;
  8009. $data ['receiptList'] = $receiptList;
  8010. $data ['receiptApprovalCount'] = count ( $receiptList );
  8011. $data ['year'] = $year;
  8012. $data ['categoryList'] = $categoryList;
  8013. $data ['staffList'] = $staffList;
  8014. $data ['cid'] = $cid;
  8015. $data ['sid'] = $sid;
  8016. $data ['status'] = 0;
  8017. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  8018. $ap = 4;
  8019. } else
  8020. $data ['status'] = $receiptList [0] ['status'];
  8021. if ($receiptList [0] ['status'] == 4) {
  8022. $data ['status'] = 5;
  8023. $ap = 0;
  8024. }
  8025. $data ['ap'] = $ap;
  8026. $data ['memu'] = "receipt";
  8027. $data ['staff'] = $this->staff;
  8028. $data ['receiptMemu'] = 'approval';
  8029. $data ['verifyId'] = $this->verifyId;
  8030. $data ['executeId'] = $this->executeId;
  8031. $this->render ( "/admin/saeaReportListReport", $data );
  8032. }
  8033. function approvalEdi() {
  8034. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8035. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  8036. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8037. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8038. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  8039. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  8040. if (empty ( $status ))
  8041. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  8042. $vidList = array ();
  8043. $button = 0;
  8044. Doo::loadModel ( 'verify' );
  8045. Doo::loadModel ( 'receipt' );
  8046. Doo::loadModel ( 'staff' );
  8047. $staff = new staff ();
  8048. $receipt = new receipt ();
  8049. $verify = new verify ();
  8050. Doo::loadModel ( 'L_category' );
  8051. $Lcategory = new L_category ();
  8052. Doo::loadModel ( 'enclosur' );
  8053. $enclosur = new enclosur ();
  8054. // user verify ID
  8055. $verifyDetail = $verify->find ( array (
  8056. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  8057. 'asArray' => true
  8058. ) );
  8059. foreach ( $verifyDetail as $key => $value ) {
  8060. array_push ( $vidList, $value ['vid'] );
  8061. }
  8062. $vid = implode ( ",", $vidList );
  8063. if (empty ( $verifyDetail ))
  8064. $vid = 0;
  8065. $categoryList = $Lcategory->find ( array (
  8066. 'asArray' => true
  8067. ) );
  8068. $staffList = $staff->find ( array (
  8069. 'where' => 'cid=' . $cid,
  8070. 'asArray' => true
  8071. ) );
  8072. $ap = "";
  8073. if ($status == 4) {
  8074. $ap = 4;
  8075. $status = 2;
  8076. }
  8077. // get Receipt By verifyID status 2
  8078. $receiptList = $receipt->find ( array (
  8079. 'where' => 'rid =' . $rid,
  8080. 'desc' => 'rid',
  8081. 'asArray' => true
  8082. ) );
  8083. $Locate = 0;
  8084. $roleId = 0;
  8085. if ($ap == 4)
  8086. $status = 4;
  8087. foreach ( $receiptList as $key => $value ) {
  8088. $receiptList [$key] ['Locate'] = $Locate;
  8089. $Locate ++;
  8090. $receiptList [$key] ['reviseDetail'] = array ();
  8091. if (! empty ( $value ['reviseDetail'] ))
  8092. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  8093. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  8094. $categoryDetil = $Lcategory->getOne ( array (
  8095. 'where' => 'cid=' . $value ['cid'],
  8096. 'asArray' => true
  8097. ) );
  8098. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  8099. // 检测编辑状态
  8100. $verifyList = $verify->getOne ( array (
  8101. 'where' => 'vid=' . $value ['verify'],
  8102. 'asArray' => true
  8103. ) );
  8104. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  8105. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  8106. // print_r($verifyList);
  8107. //
  8108. // if (empty($verifyStaff)){
  8109. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  8110. // $verifyList[0]['status']=4;$button=4;
  8111. // }
  8112. //
  8113. // }else{
  8114. //
  8115. // }
  8116. // die;
  8117. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  8118. // echo array_search("green",$a);
  8119. //
  8120. Doo::loadModel ( 'role' );
  8121. $role = new role ();
  8122. // print_r($verifyList);
  8123. $flag = true;
  8124. $roleKey = 0;
  8125. $endStaffArray = array ();
  8126. $roleArrayCopy = array ();
  8127. foreach ( $verifyList as $k => $v ) {
  8128. // init verifyStaff
  8129. if ($v [1] == 'ROLE') {
  8130. if (! empty ( $verifyStaff )) {
  8131. $endStaffArray = end ( $verifyStaff );
  8132. if ($v [0] == $endStaffArray ['nextStaff']) {
  8133. $roleId = $v [0];
  8134. }
  8135. }
  8136. $roleVerify = json_decode ( $v [3], true );
  8137. $roleKey = $k;
  8138. $roleArray = array ();
  8139. $rolename = $role->getOne ( array (
  8140. 'where' => 'rid=' . $v [0],
  8141. 'asArray' => true
  8142. ) );
  8143. foreach ( $roleVerify as $o => $p ) {
  8144. $staffID = explode ( '_', $p );
  8145. $staffInfo = $staff->getOne ( array (
  8146. 'where' => 'sid=' . $staffID [0],
  8147. 'asArray' => true
  8148. ) );
  8149. // print_r($staffID);
  8150. $exp = array (
  8151. 0 => $staffInfo ['sid'],
  8152. 1 => $staffID [1],
  8153. 2 => $staffInfo ['avatar'],
  8154. 'date' => '',
  8155. 'date' => '',
  8156. 'opinion' => '',
  8157. 'status' => '',
  8158. 'rolename' => $rolename ['name']
  8159. );
  8160. array_push ( $roleArray, $exp );
  8161. }
  8162. $roleArrayCopy [$v [0]] = $roleArray;
  8163. // $verifyList[$k]['roleArray']=$roleArray;
  8164. }
  8165. // print_r($roleArray);
  8166. $verifyList [$k] ['date'] = "";
  8167. $verifyList [$k] ['opinion'] = "";
  8168. $verifyList [$k] ['status'] = "";
  8169. if (empty ( $verifyStaff )) {
  8170. $verifyList [$k] ['date'] = "";
  8171. $verifyList [$k] ['opinion'] = "";
  8172. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  8173. $verifyList [$k] ['status'] = 4;
  8174. $button = 4;
  8175. $flag = false;
  8176. }
  8177. } else {
  8178. foreach ( $verifyStaff as $m => $u ) {
  8179. if ($v [0] == $m) {
  8180. $verifyList [$k] ['date'] = $u ['date'];
  8181. $verifyList [$k] ['opinion'] = $u ['opinion'];
  8182. $verifyList [$k] ['status'] = $u ['status'];
  8183. $flag = false;
  8184. break;
  8185. }
  8186. }
  8187. $endStaffArray = end ( $verifyStaff );
  8188. if (isset ( $endStaffArray ['ROLE'] )) {
  8189. } else {
  8190. $endKey = key ( $verifyStaff );
  8191. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  8192. $button = 4;
  8193. $verifyList [$k] ['status'] = 4;
  8194. }
  8195. }
  8196. // print_r($endStaffArray);die;
  8197. // if (empty($verifyStaff)){
  8198. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  8199. // $verifyList[$k]['status']=4;$button=4;
  8200. // }
  8201. //
  8202. // }else{
  8203. //
  8204. // }
  8205. // if($flag){//检测可编辑
  8206. // if($v[0]==$this->staff[0]['sid']){
  8207. // $verifyList[$k]['status']=4;$button=4;
  8208. // }
  8209. // }
  8210. }
  8211. }
  8212. $rolename ['name'] = '';
  8213. if (! empty ( $roleId )) {
  8214. Doo::loadModel ( 'role' );
  8215. $role = new role ();
  8216. $rolename = $role->getOne ( array (
  8217. 'where' => 'rid=' . $roleId,
  8218. 'asArray' => true
  8219. ) );
  8220. }
  8221. if (! empty ( $verifyStaff ))
  8222. $endStaffArray = end ( $verifyStaff );
  8223. $KOP = false;
  8224. foreach ( $roleArrayCopy as $P => $A ) {
  8225. foreach ( $A as $MKI => $AVL ) {
  8226. if (! empty ( $verifyStaff )) {
  8227. // &&$rolename['rid']==$endStaffArray['nextStaff']
  8228. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  8229. $button = 4;
  8230. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  8231. }
  8232. foreach ( $verifyStaff as $m => $u ) {
  8233. $AVLFK = $AVL [0] . '_R';
  8234. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  8235. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  8236. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  8237. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  8238. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  8239. break;
  8240. }
  8241. }
  8242. } else {
  8243. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  8244. $button = 4;
  8245. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  8246. }
  8247. }
  8248. // $roleArray[$MKI]['rolename']=$rolename['name'];
  8249. $KOP = true;
  8250. }
  8251. }
  8252. // print_r($roleArrayCopy);
  8253. // echo $roleKey;
  8254. foreach ( $roleArrayCopy as $k => $v ) {
  8255. foreach ( $verifyList as $m => $n ) {
  8256. if ($n [0] == $k) {
  8257. array_splice ( $verifyList, $m, 1, $v );
  8258. }
  8259. }
  8260. }
  8261. // if ($KOP)
  8262. // array_splice($verifyList,$roleKey,1,$roleArray);
  8263. // print_r($verifyList);
  8264. $receiptList [$key] ['verifyList'] = $verifyList;
  8265. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  8266. 'where' => 'sid=' . $value ['staff'],
  8267. 'asArray' => true
  8268. ) );
  8269. $receiptList [$key] ['button'] = $button;
  8270. }
  8271. // $data['verifyDetail']=$verifyDetail;
  8272. $mothHtml = "";
  8273. for($i = 1; $i <= 12; $i ++) {
  8274. if ($month == $i)
  8275. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8276. else
  8277. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8278. }
  8279. // 获取审批日志
  8280. Doo::loadModel ( 'receiptLog' );
  8281. $receiptLog = new receiptLog ();
  8282. $rlList = array ();
  8283. $rlInfo = $receiptLog->getOne ( array (
  8284. 'where' => 'rid=' . $rid . ' and status=4',
  8285. 'asArray' => true
  8286. ) );
  8287. $tijdate = $receiptLog->getOne ( array (
  8288. 'where' => 'rid=' . $rid . ' and status=2',
  8289. 'asc' => 'rlid',
  8290. 'asArray' => true
  8291. ) );
  8292. if (! empty ( $rlInfo )) {
  8293. $rlList = $receiptLog->find ( array (
  8294. 'where' => 'rid=' . $rid,
  8295. 'asc' => 'rlid',
  8296. 'asArray' => true
  8297. ) );
  8298. }
  8299. $receiptList [0] ['rlList'] = $rlList;
  8300. $enclosurList = $enclosur->find ( array (
  8301. 'where' => 'rid=' . $rid,
  8302. 'asArray' => true
  8303. ) );
  8304. $enclosurHtml = '';
  8305. foreach ( $enclosurList as $value ) {
  8306. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  8307. }
  8308. $data ['enclosurHtml'] = $enclosurHtml;
  8309. $data ['rolename'] = $rolename ['name'];
  8310. $data ['datetij'] = $tijdate ['date'];
  8311. $data ['mothHtml'] = $mothHtml;
  8312. $data ['receiptList'] = $receiptList;
  8313. $data ['receiptApprovalCount'] = count ( $receiptList );
  8314. $data ['status'] = $status;
  8315. $data ['year'] = $year;
  8316. $data ['categoryList'] = $categoryList;
  8317. $data ['staffList'] = $staffList;
  8318. $data ['cid'] = $cid;
  8319. $data ['sid'] = $sid;
  8320. $data ['ap'] = $ap;
  8321. $data ['memu'] = "receipt";
  8322. $data ['staff'] = $this->staff;
  8323. $data ['receiptMemu'] = 'approval';
  8324. $data ['verifyId'] = $this->verifyId;
  8325. $data ['executeId'] = $this->executeId;
  8326. $this->render ( "/admin/saeaReportListReport", $data );
  8327. }
  8328. function remittanceHky() {
  8329. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  8330. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  8331. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  8332. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  8333. $page_size = 15;
  8334. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  8335. Doo::loadModel ( 'receipt' );
  8336. $receipt = new receipt ();
  8337. Doo::loadModel ( 'staff' );
  8338. $staff = new staff ();
  8339. $dateCondition = " and Year(executeDate) =" . $year;
  8340. if ($moth != 'MONTH')
  8341. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  8342. if ($day != 'DAY' && $moth != 'MONTH')
  8343. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  8344. $sql = ' (status =8 or status=9 ) and amount>0 ' . $dateCondition;
  8345. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  8346. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  8347. $limit = $pageinfo ['lower'] . ',' . $page_size;
  8348. $dayList = $receipt->find ( array (
  8349. 'select' => 'executeDate,sum(amount) as amount',
  8350. 'where' => $sql,
  8351. 'desc' => 'executeDate',
  8352. 'groupby' => 'executeDate',
  8353. 'limit' => $limit,
  8354. 'asArray' => true
  8355. ) );
  8356. // print_r($dayList);
  8357. foreach ( $dayList as $key => $value ) {
  8358. $remitString = "";
  8359. $receiptList = $receipt->find ( array (
  8360. 'select' => 'rid,executeDate,amount,staff,cid',
  8361. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  8362. 'desc' => 'executeDate',
  8363. 'asArray' => true
  8364. ) );
  8365. foreach ( $receiptList as $k => $v ) {
  8366. $sinfo = $staff->getOne ( array (
  8367. 'select' => 'username,category',
  8368. 'where' => ' sid=' . $v ['staff'],
  8369. 'asArray' => true
  8370. ) );
  8371. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  8372. }
  8373. $dayList [$key] ['staff'] = $remitString;
  8374. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  8375. }
  8376. // print_r($dayList);
  8377. $mothHtml = "";
  8378. for($i = 1; $i <= 12; $i ++) {
  8379. if ($moth == $i)
  8380. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8381. else
  8382. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8383. }
  8384. $dayHtml = "";
  8385. if ($day != "DAY" || $moth != "MONTH") {
  8386. for($i = 1; $i <= 31; $i ++) {
  8387. if ($day == $i)
  8388. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  8389. else
  8390. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  8391. }
  8392. }
  8393. $dateHtml = "";
  8394. $now = date ( "Y" );
  8395. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  8396. if ($YEARD <= $now) {
  8397. $dateHtml .= '<option ';
  8398. if ($year == $YEARD) {
  8399. $dateHtml .= 'selected ';
  8400. }
  8401. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  8402. }
  8403. }
  8404. $data ['dateHtml'] = $dateHtml;
  8405. $data ['page'] = $pageinfo;
  8406. $data ['year'] = $year;
  8407. $data ['moth'] = $moth;
  8408. $data ['day'] = $day;
  8409. $data ['get'] = $get;
  8410. $data ['dayHtml'] = $dayHtml;
  8411. $data ['mothHtml'] = $mothHtml;
  8412. $data ['receiptList'] = $dayList;
  8413. $data ['memu'] = "receipt";
  8414. $data ['staff'] = $this->staff;
  8415. $data ['receiptMemu'] = 'remittanceHky';
  8416. $data ['verifyId'] = $this->verifyId;
  8417. $data ['executeId'] = $this->executeId;
  8418. $this->render ( "/admin/remittanceHky", $data );
  8419. }
  8420. function remittancep() {
  8421. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  8422. Doo::loadModel ( 'receipt' );
  8423. $receipt = new receipt ();
  8424. Doo::loadModel ( 'staff' );
  8425. $staff = new staff ();
  8426. Doo::loadClass ( 'XDeode' );
  8427. $XDeode = new XDeode ( 5 );
  8428. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  8429. $rplist = $receipt->find ( array (
  8430. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8431. 'asArray' => true
  8432. ) );
  8433. $dayList = $receipt->find ( array (
  8434. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8435. 'desc' => 'executeDate',
  8436. 'groupby' => 'staff',
  8437. 'asArray' => true
  8438. ) );
  8439. $html = '';
  8440. foreach ( $dayList as $key => $value ) {
  8441. $sinfo = $staff->getOne ( array (
  8442. 'select' => 'username,category',
  8443. 'where' => ' sid=' . $value ['staff'],
  8444. 'asArray' => true
  8445. ) );
  8446. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  8447. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  8448. $au = 0;
  8449. foreach ( $rplist as $k => $v ) {
  8450. if ($value ['staff'] == $v ['staff']) {
  8451. $html .= '<tr><td><a href="#saea-detail" node-invoice="INFO" data-iskey="' . $XDeode->encode ( $v ['rid'] ) . '" data-toggle="modal">' . $v ['receiptOrder'] . '</a></td><td class="taR">¥' . $v ['amount'] . '</td></tr>';
  8452. $au += $v ['amount'];
  8453. }
  8454. }
  8455. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  8456. }
  8457. $data ['html'] = $html;
  8458. $data ['memu'] = "receipt";
  8459. $data ['staff'] = $this->staff;
  8460. $data ['receiptMemu'] = 'remittanceHky';
  8461. $data ['verifyId'] = $this->verifyId;
  8462. $data ['executeId'] = $this->executeId;
  8463. $this->render ( "/admin/remittancep", $data );
  8464. }
  8465. function ajaxGetReceiptDetails() {
  8466. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  8467. Doo::loadClass ( 'XDeode' );
  8468. $XDeode = new XDeode ( 5 );
  8469. $rid = $XDeode->decode ( $rid );
  8470. if (empty ( $rid )) {
  8471. echo json_encode ( array (
  8472. 'status' => 2,
  8473. 'msg' => 'illegal request'
  8474. ) );
  8475. die ();
  8476. }
  8477. Doo::loadModel ( 'receipt' );
  8478. $receipt = new receipt ();
  8479. Doo::loadModel ( 'staff' );
  8480. $staff = new staff ();
  8481. $rinfo = $receipt->getOne ( array (
  8482. 'where' => 'rid= ' . $rid,
  8483. 'asArray' => true
  8484. ) );
  8485. $sinfo = $staff->getOne ( array (
  8486. 'select' => 'username,category',
  8487. 'where' => ' sid=' . $rinfo ['staff'],
  8488. 'asArray' => true
  8489. ) );
  8490. $rinfo ['reviseDetail'] = array ();
  8491. if (! empty ( $rinfo ['reviseDetail'] ))
  8492. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  8493. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  8494. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  8495. $rinfo ['category'] = $sinfo ['category'];
  8496. $verifyStaff = array ();
  8497. if (! empty ( $rinfo ['verifyStaff'] ))
  8498. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  8499. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  8500. $rinfo ['relust'] = $relust;
  8501. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  8502. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  8503. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  8504. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  8505. // 费用执行人相关数据
  8506. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  8507. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  8508. foreach ( $executeCopy as $k => $v ) {
  8509. $executeCopy [$k] ['date'] = '';
  8510. $executeCopy [$k] ['opinion'] = '';
  8511. $executeCopy [$k] ['status'] = '';
  8512. if (! empty ( $executeStaff ))
  8513. foreach ( $executeStaff as $m => $u ) {
  8514. if ($v [0] == $m) {
  8515. $executeCopy [$k] ['date'] = $u ['date'];
  8516. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  8517. $executeCopy [$k] ['status'] = $u ['status'];
  8518. break;
  8519. }
  8520. }
  8521. }
  8522. $rinfo ['executeCopy'] = $executeCopy;
  8523. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8524. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8525. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8526. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8527. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8528. $html .= '<tr><th>' . $value ['name'] . '</th>
  8529. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8530. }
  8531. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8532. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8533. <tr><th class="taC" colspan="2">费用说明</th>
  8534. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8535. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8536. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8537. </tbody></table>';
  8538. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8539. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8540. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8541. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8542. $html .= '<tr><th>' . $value ['name'] . '</th>
  8543. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8544. }
  8545. $html .= '<tr><th class="taR">合计</th>
  8546. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8547. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8548. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8549. $html .= '<tr><th>' . $value ['name'] . '</th>
  8550. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8551. }
  8552. $html .= '<tr><th class="taR">合计</th>
  8553. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8554. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8555. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8556. $html .= '<tr><th>' . $value ['name'] . '</th>
  8557. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8558. }
  8559. $html .= '<tr><th class="taR">合计</th>
  8560. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8561. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8562. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8563. $html .= '<tr><th>' . $value ['name'] . '</th>
  8564. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8565. }
  8566. $html .= '<tr><th class="taR">合计</th>
  8567. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8568. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8569. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8570. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8571. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8572. }
  8573. $html .= '<tr><th class="taR">合计</th>
  8574. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8575. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8576. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8577. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8578. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8579. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8580. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8581. <tr';
  8582. if ($rinfo ['relust'] >= 0) {
  8583. $html .= 'class="success"';
  8584. } else {
  8585. $html .= 'class="error"';
  8586. }
  8587. $html .= '><td class="taR"><b>借款结余</b></td>
  8588. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8589. </tbody></table>
  8590. ';
  8591. }
  8592. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8593. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8594. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8595. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8596. $html .= '<tr><th>' . $value ['name'] . '</th>
  8597. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8598. }
  8599. $html .= '<tr><th class="taR">合计</th>
  8600. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8601. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8602. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8603. <tr><th class="taC" colspan="2">费用说明</th>
  8604. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8605. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8606. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8607. </tbody></table>';
  8608. } else {
  8609. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8610. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8611. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8612. $html .= '<tr><th>' . $value ['name'] . '</th>
  8613. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8614. }
  8615. $html .= '<tr><th class="taR">合计</th>
  8616. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8617. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8618. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8619. $html .= '<tr><th>' . $value ['name'] . '</th>
  8620. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8621. }
  8622. $html .= '<tr><th class="taR">合计</th>
  8623. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8624. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8625. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8626. $html .= '<tr><th>' . $value ['name'] . '</th>
  8627. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8628. }
  8629. $html .= '<tr><th class="taR">合计</th>
  8630. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8631. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8632. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8633. $html .= '<tr><th>' . $value ['name'] . '</th>
  8634. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8635. }
  8636. $html .= '<tr><th class="taR">合计</th>
  8637. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8638. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8639. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8640. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8641. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8642. }
  8643. $html .= '<tr><th class="taR">合计</th>
  8644. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8645. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8646. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8647. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8648. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8649. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8650. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8651. $html .= '</tbody></table>';
  8652. /*
  8653. * <table class="table table-bordered table-condensed table-hover"> <tbody> <tr><th colspan="2" class="taC">日常相关费用</th></tr> <!-- loop receiptList' value.accountItem.日常相关费用 --> <tr><th>{{receiptList' value' value.name}}</th><td width="140" class="taR">¥{{receiptList' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptList' value.accountItem.cSum.agencySum}}</td></tr> <tr><th colspan="2" class="taC">差旅相关费用</th></tr> <!-- loop receiptDetail' value.accountItem.差旅相关费用 --> <tr><th>{{receiptDetail' value' value.name}}</th><td width="140" class="taR">¥{{receiptDetail' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptDetail' value.accountItem.cSum.travelSum}}</td></tr> <tr><th colspan="2" class="taC">培训班费用</th></tr> <!-- loop receiptDetail' value.accountItem.培训班费用 --> <tr><th>{{receiptDetail' value' value.name}}</th><td width="140" class="taR">¥{{receiptDetail' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptDetail' value.accountItem.cSum.trainSum}}</td></tr> <tr><th colspan="2" class="taC">其他</th></tr> <!-- loop receiptDetail' value.accountItem.其他 --> <tr><th>{{receiptDetail' value' value.name}}</th><td width="140" class="taR">¥{{receiptDetail' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptDetail' value.accountItem.cSum.otherSum}}</td></tr> <tr><th colspan="2" class="taC">报销金额调整</th></tr> <!-- loop receiptList' value.reviseDetail --> <tr><th><span class="interval">|</span>{{receiptList' value' value.name}}:{{receiptList' value' value.description}}</th><td class="taR">¥{{receiptList' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colOrange taR">¥{{receiptList' value.revisePrice}}</td></tr> <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr> <tr><th style="text-align:center" colspan="2">{{receiptDetail' value.category}}</th></tr> <tr><th class="taC" colspan="2">报销说明</th></tr> <tr><td colspan="2">{{receiptDetail' value.explanation}}</td></tr> <tr class="warning"><td class="taR"><b>({{receiptDetail' value.receiptOrder}})本次报销费用合计</b></td> <td class="colGreed taR"><b style="font-size:24px">¥{{receiptDetail' value.sum}}</b><br>{{receiptDetail' value.sumCN}}</td></tr> </tbody> </table>
  8654. */
  8655. }
  8656. // print_r($verifyStaff);die;
  8657. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8658. foreach ( $verifyStaff as $key => $value ) {
  8659. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8660. $sinfo = $staff->getOne ( array (
  8661. 'select' => 'username',
  8662. 'where' => ' sid=' . $key,
  8663. 'asArray' => true
  8664. ) );
  8665. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8666. }
  8667. $html .= '</tbody></table>';
  8668. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8669. foreach ( $rinfo ['executeCopy'] as $value ) {
  8670. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8671. }
  8672. $html .= '</tbody></table>';
  8673. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8674. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8675. </tr></table>';
  8676. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8677. echo json_encode ( array (
  8678. 'status' => 1,
  8679. 'html' => $html
  8680. ) );
  8681. die ();
  8682. }
  8683. /**
  8684. * 删除附件
  8685. */
  8686. function ajaxRemEnclousur() {
  8687. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8688. if (empty ( $key ))
  8689. echo json_encode ( array (
  8690. 'status' => 2
  8691. ) );
  8692. Doo::loadModel ( 'enclosur' );
  8693. $enclosur = new enclosur ();
  8694. $enclosur->delEnclosurByEid ( $key );
  8695. echo json_encode ( array (
  8696. 'status' => 1
  8697. ) );
  8698. }
  8699. function remittance() {
  8700. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8701. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8702. Doo::loadModel ( 'receipt' );
  8703. $receipt = new receipt ();
  8704. Doo::loadModel ( 'staff' );
  8705. $staff = new staff ();
  8706. $dateCondition = " and Year(pastDate) =" . $year;
  8707. if (! empty ( $month ))
  8708. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8709. // get Receipt By verifyID status 1
  8710. $receiptList = $receipt->find ( array (
  8711. 'select' => 'sum(sum) as sum,staff,pastDate',
  8712. 'where' => ' status=1' . $dateCondition,
  8713. 'desc' => 'pastDate',
  8714. 'groupby' => 'staff,pastDate',
  8715. 'asArray' => true
  8716. ) );
  8717. $dateList = $receipt->find ( array (
  8718. 'select' => 'pastDate,verifyStaff',
  8719. 'where' => ' status=1' . $dateCondition,
  8720. 'desc' => 'pastDate',
  8721. 'groupby' => 'pastDate',
  8722. 'asArray' => true
  8723. ) );
  8724. $dataList = array ();
  8725. foreach ( $dateList as $d => $a ) {
  8726. $dataList [$a ['pastDate']] = array ();
  8727. $daySum = 0;
  8728. foreach ( $receiptList as $key => $value ) {
  8729. if ($a ['pastDate'] == $value ['pastDate']) {
  8730. $oderList = $receipt->find ( array (
  8731. 'select' => 'receiptOrder',
  8732. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8733. 'asArray' => true
  8734. ) );
  8735. $list = array ();
  8736. $html = "";
  8737. foreach ( $oderList as $v ) {
  8738. array_push ( $list, $v ['receiptOrder'] );
  8739. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8740. }
  8741. $receiptList [$key] ['receiptOrder'] = $html;
  8742. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8743. $sinfo = $staff->getOne ( array (
  8744. 'select' => 'username ',
  8745. 'where' => ' sid=' . $value ['staff'],
  8746. 'asArray' => true
  8747. ) );
  8748. $receiptList [$key] ['username'] = $sinfo ['username'];
  8749. $daySum += $value ['sum'];
  8750. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8751. }
  8752. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8753. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8754. }
  8755. }
  8756. // print_r($dataList);
  8757. $data ['dataList'] = $dataList;
  8758. $mothHtml = "";
  8759. for($i = 1; $i <= 12; $i ++) {
  8760. if ($month == $i)
  8761. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8762. else
  8763. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8764. }
  8765. $data ['year'] = $year;
  8766. $data ['mothHtml'] = $mothHtml;
  8767. $data ['memu'] = "receipt";
  8768. $data ['staff'] = $this->staff;
  8769. $data ['receiptMemu'] = 'approval';
  8770. $data ['verifyId'] = $this->verifyId;
  8771. $data ['executeId'] = $this->executeId;
  8772. $this->render ( "/admin/saeaReportListPay", $data );
  8773. }
  8774. /**
  8775. * 金额调整,提高稳定性
  8776. * @return string
  8777. */
  8778. function revocationAdjustment() {
  8779. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8780. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8781. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8782. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8783. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8784. Doo::loadClass ( 'XDeode' );
  8785. $XDeode = new XDeode ( 5 );
  8786. Doo::loadModel ( 'receipt' );
  8787. $receipt = new receipt ();
  8788. $sid = $XDeode->decode ( $sidKey );
  8789. $rid = $XDeode->decode ( $ridKey );
  8790. $reviseKey = $XDeode->decode ( $reviseKey );
  8791. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8792. die ( 'illegal request' );
  8793. $receiptDetail = $receipt->getOne ( array (
  8794. 'where' => 'rid=' . $rid,
  8795. 'asArray' => true
  8796. ) );
  8797. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8798. die ( 'illegal request' );
  8799. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8800. if (! isset ( $reviseDetail [$reviseKey] ))
  8801. die ( 'illegal request' );
  8802. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8803. unset ( $reviseDetail [$reviseKey] );
  8804. $revisePrice = 0;
  8805. foreach ( $reviseDetail as $key => $value ) {
  8806. $revisePrice += $value ['price'];
  8807. }
  8808. $reviseDetailString = json_encode ( $reviseDetail );
  8809. $receipt->reviseDetail = $reviseDetailString;
  8810. $receipt->sum = $receiptDetail ['sum'] - $price;
  8811. $receipt->revisePrice = $revisePrice;
  8812. $receipt->update ( array (
  8813. 'where' => 'rid=' . $rid
  8814. ) );
  8815. return '/receiptburEdi/' . $rid;
  8816. } else
  8817. die ( 'illegal request2' );
  8818. }
  8819. function updateApprovalReceipt() {
  8820. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8821. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8822. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8823. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8824. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8825. if (! empty ( $rid )) {
  8826. Doo::loadModel ( "verify" );
  8827. $verify = new verify ();
  8828. Doo::loadModel ( "receiptDetail" );
  8829. $receiptDetailObj = new receiptDetail ();
  8830. Doo::loadModel ( "itemStatistics" );
  8831. Doo::loadModel ( "statistics" );
  8832. $statistics = new statistics ();
  8833. $itemStatistics = new itemStatistics ();
  8834. Doo::loadModel ( "receipt" );
  8835. $receipt = new receipt ();
  8836. $receiptDetail = $receipt->getOne ( array (
  8837. 'where' => 'rid=' . $rid . ' and status=2 ',
  8838. 'asArray' => true
  8839. ) );
  8840. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8841. $nsflag = true;
  8842. foreach ( $nslist as $value ) {
  8843. if ($value == $this->staff ['0'] ['sid']) {
  8844. $nsflag = false;
  8845. break;
  8846. }
  8847. }
  8848. if (empty ( $receiptDetail ) || $nsflag)
  8849. return "/approvalExpenses/pendApproval";
  8850. $verifyDetail = $verify->getOne ( array (
  8851. 'where' => ' vid =' . $receiptDetail ['verify'],
  8852. 'asArray' => true
  8853. ) );
  8854. $verifyString = $verifyDetail ['staff'];
  8855. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8856. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8857. if (empty ( $opinion )) {
  8858. if ($status == 3)
  8859. $opinion = "终止";
  8860. else
  8861. $opinion = "同意支付";
  8862. }
  8863. $nowStaff = 0;
  8864. $nowStaffList = array ();
  8865. if (empty ( $verifyStaff )) {
  8866. // 还需加入是否已经进入角色审批
  8867. if ($verifyDetail [0] [1] == 'ROLE') {
  8868. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8869. foreach ( $vStaffString as $key => $value ) {
  8870. $staffK = explode ( "_", $value );
  8871. if ($staffK [0] != $this->staff [0] ['sid'])
  8872. array_push ( $nowStaffList, $staffK [0] );
  8873. }
  8874. // print_r($verifyDetail);
  8875. // die;
  8876. if (! empty ( $nowStaffList )) {
  8877. $nowStaff = implode ( ',', $nowStaffList );
  8878. $verifyStaff = array (
  8879. $this->staff [0] ['sid'] . "_R" => array (
  8880. 'date' => date ( 'Y-m-d' ),
  8881. 'opinion' => $opinion,
  8882. 'status' => $status,
  8883. 'nextStaff' => $verifyDetail [0] [0],
  8884. 'ROLE' => 1
  8885. )
  8886. );
  8887. } else {
  8888. $nowStaff = $verifyDetail [1] [0];
  8889. $verifyStaff = array (
  8890. $this->staff [0] ['sid'] . "_R" => array (
  8891. 'date' => date ( 'Y-m-d' ),
  8892. 'opinion' => $opinion,
  8893. 'status' => $status,
  8894. 'nextStaff' => $verifyDetail [1] [0]
  8895. )
  8896. );
  8897. }
  8898. } else {
  8899. if ($verifyDetail [1] [1] == 'ROLE') {
  8900. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8901. // echo "dd";
  8902. foreach ( $vStaffString as $key => $value ) {
  8903. $staffK = explode ( "_", $value );
  8904. array_push ( $nowStaffList, $staffK [0] );
  8905. }
  8906. $nowStaff = implode ( ',', $nowStaffList );
  8907. $verifyStaff = array (
  8908. $this->staff [0] ['sid'] => array (
  8909. 'date' => date ( 'Y-m-d' ),
  8910. 'opinion' => $opinion,
  8911. 'status' => $status,
  8912. 'nextStaff' => $verifyDetail [1] [0],
  8913. 'ROLE' => 1
  8914. )
  8915. );
  8916. } else {
  8917. $nowStaff = $verifyDetail [1] [0];
  8918. $verifyStaff = array (
  8919. $this->staff [0] ['sid'] => array (
  8920. 'date' => date ( 'Y-m-d' ),
  8921. 'opinion' => $opinion,
  8922. 'status' => $status,
  8923. 'nextStaff' => $verifyDetail [1] [0]
  8924. )
  8925. );
  8926. }
  8927. }
  8928. if ($status == 3)
  8929. $verifyStaff = array (
  8930. 'final' => $status,
  8931. $this->staff [0] ['sid'] => array (
  8932. 'date' => date ( 'Y-m-d' ),
  8933. 'opinion' => $opinion,
  8934. 'status' => $status
  8935. )
  8936. );
  8937. $vStaffString = json_encode ( $verifyStaff );
  8938. $receipt->nowStaff = $nowStaff;
  8939. $receipt->verifyStaff = $vStaffString;
  8940. } else {
  8941. $VS = end ( $verifyStaff );
  8942. // 非角色审批
  8943. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8944. $nextStaff = 0;
  8945. $roleSTF = false;
  8946. foreach ( $verifyDetail as $key => $value ) {
  8947. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8948. if (isset ( $verifyDetail [$key + 1] )) {
  8949. $nextStaff = $verifyDetail [$key + 1] [0];
  8950. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8951. $roleSTF = true;
  8952. }
  8953. break;
  8954. }
  8955. }
  8956. if (! $roleSTF) {
  8957. $nowStaff = $nextStaff;
  8958. $verifyStaff [$this->staff [0] ['sid']] = array (
  8959. 'date' => date ( 'Y-m-d' ),
  8960. 'opinion' => $opinion,
  8961. 'status' => $status,
  8962. 'nextStaff' => $nextStaff
  8963. );
  8964. } else {
  8965. // 获取角色下的所有用户ID
  8966. $nowStaffList = array ();
  8967. foreach ( $verifyDetail as $vfk ) {
  8968. if ($vfk [1] == 'ROLE') {
  8969. $vStaffString = json_decode ( $vfk [3] );
  8970. foreach ( $vStaffString as $key => $value ) {
  8971. $staffK = explode ( "_", $value );
  8972. array_push ( $nowStaffList, $staffK [0] );
  8973. }
  8974. }
  8975. }
  8976. $nowStaff = implode ( ',', $nowStaffList );
  8977. $verifyStaff [$this->staff [0] ['sid']] = array (
  8978. 'date' => date ( 'Y-m-d' ),
  8979. 'opinion' => $opinion,
  8980. 'status' => $status,
  8981. 'nextStaff' => $nextStaff,
  8982. 'ROLE' => 0
  8983. );
  8984. }
  8985. if ($status == 3) {
  8986. $verifyStaff ['final'] = $status;
  8987. $verifyStaff [$this->staff [0] ['sid']] = array (
  8988. 'date' => date ( 'Y-m-d' ),
  8989. 'opinion' => $opinion,
  8990. 'status' => $status
  8991. );
  8992. }
  8993. $vStaffString = json_encode ( $verifyStaff );
  8994. $receipt->nowStaff = $nowStaff;
  8995. $receipt->verifyStaff = $vStaffString;
  8996. }
  8997. // 角色审批
  8998. if (isset ( $VS ['ROLE'] )) {
  8999. // 找出角色人 当前审批角色组
  9000. $verifyJSStaff = array ();
  9001. $nowStaffList2 = array ();
  9002. foreach ( $verifyDetail as $key => $value ) {
  9003. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  9004. $verifyJSStaff = json_decode ( $value [3] );
  9005. foreach ( $verifyJSStaff as $m ) {
  9006. $staffK = explode ( "_", $m );
  9007. array_push ( $nowStaffList2, $staffK [0] );
  9008. }
  9009. // print_r($nowStaffList2);
  9010. }
  9011. }
  9012. $RoleVerifyStaff = array ();
  9013. foreach ( $verifyStaff as $key => $value ) {
  9014. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  9015. foreach ( $nowStaffList2 as $m ) {
  9016. if ($key == $m . "_R")
  9017. $RoleVerifyStaff [$key] = $value;
  9018. }
  9019. }
  9020. }
  9021. // print_r($verifyStaff);
  9022. // print_r($nowStaffList2);
  9023. // print_r($RoleVerifyStaff);
  9024. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  9025. // print_r($verifyJSStaff);
  9026. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  9027. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  9028. // 下一个审批人ID
  9029. $nextStaff = 0;
  9030. $falg = false;
  9031. foreach ( $verifyDetail as $key => $value ) {
  9032. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  9033. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  9034. $falg = true;
  9035. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  9036. $nowStaffList = array ();
  9037. foreach ( $vStaffString as $v ) {
  9038. $staffK = explode ( "_", $v );
  9039. array_push ( $nowStaffList, $staffK [0] );
  9040. }
  9041. $nowStaff = implode ( ',', $nowStaffList );
  9042. $nextStaff = $verifyDetail [$key + 1] [0];
  9043. } elseif (isset ( $verifyDetail [$key + 1] )) {
  9044. $nextStaff = $verifyDetail [$key + 1] [0];
  9045. $nowStaff = $nextStaff;
  9046. } else
  9047. $nowStaff = '';
  9048. break;
  9049. }
  9050. }
  9051. if ($falg)
  9052. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9053. 'date' => date ( 'Y-m-d' ),
  9054. 'opinion' => $opinion,
  9055. 'status' => $status,
  9056. 'nextStaff' => $nextStaff,
  9057. 'ROLE' => 1
  9058. );
  9059. else
  9060. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9061. 'date' => date ( 'Y-m-d' ),
  9062. 'opinion' => $opinion,
  9063. 'status' => $status,
  9064. 'nextStaff' => $nextStaff
  9065. );
  9066. // print_r($verifyStaff);
  9067. // echo $nowStaff;die;
  9068. } else { // 进入下一个角色或者审批人
  9069. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  9070. //
  9071. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  9072. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9073. 'date' => date ( 'Y-m-d' ),
  9074. 'opinion' => $opinion,
  9075. 'status' => $status,
  9076. 'nextStaff' => $VS ['nextStaff'],
  9077. 'ROLE' => 1
  9078. );
  9079. // print_r($verifyStaff);
  9080. // die;
  9081. }
  9082. if ($status == 3) {
  9083. $verifyStaff ['final'] = $status;
  9084. $verifyStaff [$this->staff [0] ['sid']] = array (
  9085. 'date' => date ( 'Y-m-d' ),
  9086. 'opinion' => $opinion,
  9087. 'status' => $status
  9088. );
  9089. }
  9090. $vStaffString = json_encode ( $verifyStaff );
  9091. $receipt->verifyStaff = $vStaffString;
  9092. $receipt->nowStaff = $nowStaff;
  9093. // die;
  9094. // }
  9095. // print_r($verifyStaff);
  9096. // die;
  9097. }
  9098. // print_r($verifyStaff);die;
  9099. }
  9100. // print_r($verifyDetail);
  9101. $roleKey = 0;
  9102. $roleId = 0;
  9103. $verifyDetailCopy = array ();
  9104. foreach ( $verifyDetail as $k => $v ) {
  9105. if ($v [1] == 'ROLE') {
  9106. $roleId = $v [0];
  9107. $roleVerify = json_decode ( $v [3], true );
  9108. $roleKey = $k;
  9109. $roleArray = array ();
  9110. foreach ( $roleVerify as $o => $p ) {
  9111. $staffID = explode ( '_', $p );
  9112. $exp = array (
  9113. 0 => $staffID [0],
  9114. 1 => $staffID [1]
  9115. );
  9116. array_push ( $roleArray, $exp );
  9117. }
  9118. $verifyDetailCopy [$v [0]] = $roleArray;
  9119. }
  9120. }
  9121. // print_r($verifyDetail);
  9122. foreach ( $verifyDetailCopy as $k => $v ) {
  9123. foreach ( $verifyDetail as $m => $n ) {
  9124. if ($n [0] == $k) {
  9125. array_splice ( $verifyDetail, $m, 1, $v );
  9126. }
  9127. }
  9128. }
  9129. // die;
  9130. // if (!empty($roleArray))
  9131. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  9132. // echo $roleId;
  9133. // print_r($verifyStaff);
  9134. // print_r($verifyDetail);
  9135. // die;
  9136. Doo::loadModel ( "receiptLog" );
  9137. $receiptLog = new receiptLog ();
  9138. // 审批日志
  9139. if (! isset ( $verifyStaff ['final'] )) {
  9140. if (! empty ( $roleId )) {
  9141. Doo::loadModel ( "role" );
  9142. $role = new role ();
  9143. $roleInfo = $role->getOne ( array (
  9144. 'where' => 'rid=' . $roleId,
  9145. 'asArray' => true
  9146. ) );
  9147. $receiptLog->rolename = $roleInfo ['name'];
  9148. }
  9149. $receiptLog->username = $this->staff [0] ['username'];
  9150. $receiptLog->uid = $this->staff [0] ['sid'];
  9151. $receiptLog->date = date ( "Y-m-d" );
  9152. $receiptLog->opinion = $opinion;
  9153. $receiptLog->img = $this->staff [0] ['avatar'];
  9154. $receiptLog->status = 1;
  9155. $receiptLog->rid = $rid;
  9156. $receiptLog->insert ();
  9157. }
  9158. if (isset ( $verifyStaff ['final'] )) { // rDetail
  9159. $receipt->verifyBreakup = $verifyString;
  9160. $receipt->status = 3;
  9161. $receiptDetailObj->status = 3;
  9162. $receiptDetailObj->update ( array (
  9163. 'where' => 'rid=' . $rid
  9164. ) );
  9165. if (! empty ( $roleId )) {
  9166. Doo::loadModel ( "role" );
  9167. $role = new role ();
  9168. $roleInfo = $role->getOne ( array (
  9169. 'where' => 'rid=' . $roleId,
  9170. 'asArray' => true
  9171. ) );
  9172. $receiptLog->rolename = $roleInfo ['name'];
  9173. }
  9174. $receiptLog->username = $this->staff [0] ['username'];
  9175. $receiptLog->uid = $this->staff [0] ['sid'];
  9176. $receiptLog->date = date ( "Y-m-d" );
  9177. $receiptLog->opinion = $opinion;
  9178. $receiptLog->img = $this->staff [0] ['avatar'];
  9179. $receiptLog->status = 3;
  9180. $receiptLog->rid = $rid;
  9181. $receiptLog->insert ();
  9182. //删除行程单
  9183. Doo::loadModel ( 'itinerary' );
  9184. $itinerary = new itinerary ();
  9185. $itinerary->delete ( array (
  9186. 'where' => 'rid="' . $rid . '"'
  9187. ) );
  9188. // 微信企业号通知
  9189. $this->setWXMsg ( $rid, 3 );
  9190. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  9191. $receipt->status = 1;
  9192. $reviseSum = 0;
  9193. $receipt->verifyBreakup = $verifyString;
  9194. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  9195. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9196. foreach ( $reviseDetail as $key => $value ) {
  9197. $receiptDetailObj = new receiptDetail ();
  9198. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9199. $receiptDetailObj->item = $value ['description'];
  9200. $receiptDetailObj->itemCategory = "报销金额调整";
  9201. $receiptDetailObj->price = $value ['price'];
  9202. $receiptDetailObj->date = $receiptDetail ['date'];
  9203. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  9204. $receiptDetailObj->rid = $rid;
  9205. $receiptDetailObj->status = 1;
  9206. $receiptDetailObj->insert ();
  9207. $reviseSum += $value ['price'];
  9208. }
  9209. $itemStatistics = new itemStatistics ();
  9210. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  9211. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9212. $itemStatistics->price = $reviseSum;
  9213. $itemStatistics->itemCategory = "报销金额调整";
  9214. $itemStatistics->date = $receiptDetail ['date'];
  9215. $itemStatistics->insert ();
  9216. }
  9217. $receiptDetailObj = new receiptDetail ();
  9218. $receiptDetailObj->status = 1;
  9219. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  9220. $receiptDetailObj->update ( array (
  9221. 'where' => 'rid=' . $rid
  9222. ) );
  9223. $dateArray = explode ( "-", $receiptDetail ['date'] );
  9224. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  9225. $stat = $statistics->getOne ( array (
  9226. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  9227. 'asArray' => true
  9228. ) );
  9229. if (empty ( $stat )) {
  9230. $statistics->date = $receiptDetail ['date'];
  9231. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  9232. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9233. $statistics->agPrice = $receiptDetail ['sum'];
  9234. $statistics->rePrice = $reviseSum;
  9235. $statistics->insert ();
  9236. } else {
  9237. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  9238. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  9239. $statistics->update ( array (
  9240. 'where' => 'sid=' . $stat ['sid']
  9241. ) );
  9242. }
  9243. $dateArray = explode ( "-", $receiptDetail ['date'] );
  9244. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  9245. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  9246. foreach ( $accountItem ['cSum'] as $key => $value ) {
  9247. if ($key == "agencySum") {
  9248. $iStatistics = $itemStatistics->getOne ( array (
  9249. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  9250. 'asArray' => true
  9251. ) );
  9252. if (empty ( $iStatistics )) {
  9253. $itemStatistics->cid = $receiptDetail ['cid'];
  9254. ;
  9255. $itemStatistics->staff = $receiptDetail ['staff'];
  9256. $itemStatistics->price = $value;
  9257. $itemStatistics->itemCategory = $this->AGENCY;
  9258. $itemStatistics->date = $receiptDetail ['date'];
  9259. $itemStatistics->insert ();
  9260. } else {
  9261. if (! empty ( $value )) {
  9262. $itemStatistics->price = $value + $iStatistics ['price'];
  9263. $itemStatistics->update ( array (
  9264. 'where' => 'sid=' . $iStatistics ['sid']
  9265. ) );
  9266. }
  9267. }
  9268. } elseif ($key == "travelSum") {
  9269. $iStatistics = $itemStatistics->getOne ( array (
  9270. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  9271. 'asArray' => true
  9272. ) );
  9273. if (empty ( $iStatistics )) {
  9274. $itemStatistics->cid = $receiptDetail ['cid'];
  9275. $itemStatistics->staff = $receiptDetail ['staff'];
  9276. $itemStatistics->price = $value;
  9277. $itemStatistics->itemCategory = $this->TRAVEL;
  9278. $itemStatistics->date = $receiptDetail ['date'];
  9279. $itemStatistics->insert ();
  9280. } else {
  9281. if (! empty ( $value )) {
  9282. $itemStatistics->price = $value + $iStatistics ['price'];
  9283. $itemStatistics->update ( array (
  9284. 'where' => 'sid=' . $iStatistics ['sid']
  9285. ) );
  9286. }
  9287. }
  9288. } elseif ($key == "trainSum") {
  9289. $iStatistics = $itemStatistics->getOne ( array (
  9290. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  9291. 'asArray' => true
  9292. ) );
  9293. if (empty ( $iStatistics )) {
  9294. $itemStatistics->cid = $receiptDetail ['cid'];
  9295. $itemStatistics->staff = $receiptDetail ['staff'];
  9296. $itemStatistics->price = $value;
  9297. $itemStatistics->itemCategory = $this->TRAIN;
  9298. $itemStatistics->date = $receiptDetail ['date'];
  9299. $itemStatistics->insert ();
  9300. } else {
  9301. if (! empty ( $value )) {
  9302. $itemStatistics->price = $value + $iStatistics ['price'];
  9303. $itemStatistics->update ( array (
  9304. 'where' => 'sid=' . $iStatistics ['sid']
  9305. ) );
  9306. }
  9307. }
  9308. } elseif ($key == "otherSum") {
  9309. $iStatistics = $itemStatistics->getOne ( array (
  9310. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  9311. 'asArray' => true
  9312. ) );
  9313. if (empty ( $iStatistics )) {
  9314. $itemStatistics->cid = $receiptDetail ['cid'];
  9315. $itemStatistics->staff = $receiptDetail ['staff'];
  9316. $itemStatistics->price = $value;
  9317. $itemStatistics->itemCategory = $this->OTHER;
  9318. $itemStatistics->date = $receiptDetail ['date'];
  9319. $itemStatistics->insert ();
  9320. } else {
  9321. if (! empty ( $value )) {
  9322. $itemStatistics->price = $value + $iStatistics ['price'];
  9323. $itemStatistics->update ( array (
  9324. 'where' => 'sid=' . $iStatistics ['sid']
  9325. ) );
  9326. }
  9327. }
  9328. }
  9329. }
  9330. $receipt->pastDate = date ( "Y-m-d" );
  9331. // 微信企业号通知
  9332. $this->setWXMsg ( $rid, 1 );
  9333. }
  9334. //是否有流水
  9335. Doo::loadModel ( 'wasteBook' );
  9336. $wasteBook = new wasteBook ();
  9337. $accountType=3;
  9338. if ($receiptDetail['Rtype']==1){
  9339. $accountType=2;
  9340. }elseif($receiptDetail['Rtype']==2){
  9341. $accountType=4;
  9342. }
  9343. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  9344. if (empty($wbDetail)){
  9345. $rsum=$receiptDetail['sum']-$receiptDetail['loanSum'];
  9346. $receipt->amount = $rsum;//$amount;
  9347. }
  9348. $receipt->update ( array (
  9349. 'where' => ' rid = ' . $rid
  9350. ) );
  9351. // 进入下一条审批费用新加需求
  9352. $vidList = array ();
  9353. $verifyDetail = $verify->find ( array (
  9354. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  9355. 'asArray' => true
  9356. ) );
  9357. foreach ( $verifyDetail as $key => $value ) {
  9358. array_push ( $vidList, $value ['vid'] );
  9359. }
  9360. $vid = implode ( ",", $vidList );
  9361. if (empty ( $verifyDetail ))
  9362. $vid = 0;
  9363. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  9364. $receipt = new receipt ();
  9365. $rd = $receipt->getOne ( array (
  9366. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  9367. 'asc' => 'rid',
  9368. 'asArray' => true
  9369. ) );
  9370. if (empty ( $rd )) {
  9371. return '/approvalExpenses/pendApproval';
  9372. }
  9373. if ($rd ['Rtype'] == 1) {
  9374. if ($rd ['isBK'] == 1) {
  9375. return '/receiptburEdi/' . $rd ['rid'];
  9376. } else {
  9377. return '/expensesEdi/' . $rd ['rid'];
  9378. }
  9379. } elseif ($rd ['Rtype'] == 2) {
  9380. return '/remitApproval/' . $rd ['rid'];
  9381. } else {
  9382. return '/receiptburEdi/' . $rd ['rid'];
  9383. }
  9384. // return "/approvalExpenses/pendApproval";
  9385. }
  9386. }
  9387. function expensesRetreats() {
  9388. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  9389. if (! empty ( $rid )) {
  9390. // 操作记录
  9391. Doo::loadModel ( "receipt" );
  9392. $receipt = new receipt ();
  9393. Doo::loadModel ( "receiptLog" );
  9394. $receiptLog = new receiptLog ();
  9395. Doo::loadModel ( "verify" );
  9396. $verify = new verify ();
  9397. $receiptInfo = $receipt->getOne ( array (
  9398. 'where' => 'rid=' . $rid,
  9399. 'asArray' => true
  9400. ) );
  9401. $vr = $verify->getOne ( array (
  9402. 'where' => 'vid=' . $receiptInfo ['verify'],
  9403. 'asArray' => true
  9404. ) );
  9405. $jd = json_decode ( $vr ['staff'] );
  9406. $roleId = 0;
  9407. foreach ( $jd as $key => $value ) {
  9408. if ($value [1] == 'ROLE') {
  9409. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9410. if ($pos !== false) {
  9411. $roleId = $value [0];
  9412. }
  9413. }
  9414. }
  9415. // 审批日志
  9416. // echo $roleId;die;
  9417. if (! empty ( $roleId )) {
  9418. Doo::loadModel ( "role" );
  9419. $role = new role ();
  9420. $roleInfo = $role->getOne ( array (
  9421. 'where' => 'rid=' . $roleId,
  9422. 'asArray' => true
  9423. ) );
  9424. $receiptLog->rolename = $roleInfo ['name'];
  9425. }
  9426. $receiptLog->username = $this->staff [0] ['username'];
  9427. $receiptLog->uid = $this->staff [0] ['sid'];
  9428. $receiptLog->date = date ( "Y-m-d" );
  9429. $receiptLog->opinion = '撤回';
  9430. $receiptLog->img = $this->staff [0] ['avatar'];
  9431. $receiptLog->status = 4;
  9432. $receiptLog->rid = $rid;
  9433. $receiptLog->insert ();
  9434. $receipt->status = 4;
  9435. $receipt->update ( array (
  9436. 'where' => 'rid=' . $rid
  9437. ) );
  9438. // 微信企业号通知
  9439. $this->setWXMsg ( $rid, 2 );
  9440. }
  9441. // echo "ddd";
  9442. return '/approvalExpenses/pendApproval';
  9443. }
  9444. function updateCheReceipt() {
  9445. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9446. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  9447. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  9448. if (! empty ( $rid )) {
  9449. // 操作记录
  9450. Doo::loadModel ( "receipt" );
  9451. $receipt = new receipt ();
  9452. Doo::loadModel ( "receiptLog" );
  9453. $receiptLog = new receiptLog ();
  9454. Doo::loadModel ( "verify" );
  9455. $verify = new verify ();
  9456. $receiptInfo = $receipt->getOne ( array (
  9457. 'where' => 'rid=' . $rid . ' and status=2',
  9458. 'asArray' => true
  9459. ) );
  9460. if (empty ( $receiptInfo )) {
  9461. echo json_encode ( array (
  9462. 'status' => 2
  9463. ) );
  9464. die ();
  9465. }
  9466. $vr = $verify->getOne ( array (
  9467. 'where' => 'vid=' . $receiptInfo ['verify'],
  9468. 'asArray' => true
  9469. ) );
  9470. $jd = json_decode ( $vr ['staff'] );
  9471. $roleId = 0;
  9472. foreach ( $jd as $key => $value ) {
  9473. if ($value [1] == 'ROLE') {
  9474. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9475. if ($pos !== false) {
  9476. $roleId = $value [0];
  9477. }
  9478. }
  9479. }
  9480. // 审批日志
  9481. // echo $roleId;die;
  9482. if (! empty ( $roleId )) {
  9483. Doo::loadModel ( "role" );
  9484. $role = new role ();
  9485. $roleInfo = $role->getOne ( array (
  9486. 'where' => 'rid=' . $roleId,
  9487. 'asArray' => true
  9488. ) );
  9489. $receiptLog->rolename = $roleInfo ['name'];
  9490. }
  9491. $receiptLog->username = $this->staff [0] ['username'];
  9492. $receiptLog->uid = $this->staff [0] ['sid'];
  9493. $receiptLog->date = date ( "Y-m-d" );
  9494. $receiptLog->opinion = $opinion;
  9495. $receiptLog->img = $this->staff [0] ['avatar'];
  9496. $receiptLog->status = 4;
  9497. $receiptLog->rid = $rid;
  9498. $receiptLog->insert ();
  9499. $receipt->status = 4;
  9500. $receipt->update ( array (
  9501. 'where' => 'rid=' . $rid
  9502. ) );
  9503. // 微信企业号通知
  9504. $this->setWXMsg ( $rid, 2 );
  9505. echo json_encode ( array (
  9506. 'status' => 1
  9507. ) );
  9508. // Header("HTTP/1.1 303 See Other");
  9509. // Header("Location: /approvalExpenses/pendApproval");
  9510. die ();
  9511. }
  9512. echo json_encode ( array (
  9513. 'status' => 2
  9514. ) );
  9515. die ();
  9516. // echo "ddd";
  9517. // return '/saeaBorad';
  9518. }
  9519. function revisePrice() {
  9520. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  9521. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  9522. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9523. // echo $price;die;
  9524. if (! empty ( $rid )) {
  9525. Doo::loadModel ( "receipt" );
  9526. $receipt = new receipt ();
  9527. $receiptDetail = $receipt->getOne ( array (
  9528. 'where' => 'rid=' . $rid . ' and status=2 ',
  9529. 'asArray' => true
  9530. ) );
  9531. if (empty ( $receiptDetail ))
  9532. die ( 'illegal request' );
  9533. $reviseDetail = array ();
  9534. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9535. array_push ( $reviseDetail, array (
  9536. 'sid' => $this->staff [0] ['sid'],
  9537. 'name' => $this->staff [0] ['username'],
  9538. 'description' => $description,
  9539. 'price' => $price
  9540. ) );
  9541. $reviseDetailString = json_encode ( $reviseDetail );
  9542. $receipt->reviseDetail = $reviseDetailString;
  9543. $receipt->revisePrice = $price;
  9544. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9545. } else {
  9546. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9547. array_push ( $reviseDetail, array (
  9548. 'sid' => $this->staff [0] ['sid'],
  9549. 'name' => $this->staff [0] ['username'],
  9550. 'description' => $description,
  9551. 'price' => $price
  9552. ) );
  9553. $reviseDetailString = json_encode ( $reviseDetail );
  9554. $receipt->reviseDetail = $reviseDetailString;
  9555. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9556. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9557. }
  9558. $receipt->update ( array (
  9559. 'where' => 'rid=' . $rid
  9560. ) );
  9561. if ($receiptDetail ['Rtype'] == 1) {
  9562. if ($receiptDetail ['isBK'] == 1) {
  9563. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9564. }
  9565. } elseif ($receiptDetail ['Rtype'] == 2) {
  9566. } else {
  9567. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9568. }
  9569. }
  9570. die ( 'illegal request' );
  9571. }
  9572. function personalCollect() {
  9573. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9574. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9575. $this->showCache ( $path );
  9576. Doo::loadModel ( "receiptDetail" );
  9577. Doo::loadModel ( "itemStatistics" );
  9578. Doo::loadModel ( 'statistics' );
  9579. $statistics = new statistics ();
  9580. $itemStatistics = new itemStatistics ();
  9581. $receiptDetail = new receiptDetail ();
  9582. $receiptCollectList = $receiptDetail->find ( array (
  9583. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9584. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9585. 'groupby' => 'itemCategory,Month(date)',
  9586. 'asArray' => true
  9587. ) );
  9588. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9589. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9590. 'asArray' => true
  9591. ) );
  9592. // create collect html
  9593. $collectArray = array (
  9594. '日常相关费用' => array (),
  9595. '差旅相关费用' => array (),
  9596. '培训班费用' => array (),
  9597. '其他' => array ()
  9598. );
  9599. $adjustment = array ();
  9600. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9601. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9602. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9603. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9604. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9605. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9606. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9607. array_push ( $collectArray ['其他'], $collectHtml );
  9608. $data ['collectArray'] = $collectArray;
  9609. // statistics html
  9610. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9611. if (empty ( $stList ))
  9612. $stList = array (
  9613. 'rePrice' => 0,
  9614. 'agPrice' => 0
  9615. );
  9616. $data ['stList'] = array (
  9617. 'rePrice' => $stList ['rePrice'],
  9618. 'agPrice' => $stList ['agPrice'],
  9619. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9620. );
  9621. // Adjustment price html
  9622. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9623. array_push ( $adjustment, $collectHtml );
  9624. $data ['adjustment'] = $adjustment;
  9625. // total price html
  9626. $collectHtml = "";
  9627. $total = 0;
  9628. for($i = 1; $i <= 12; $i ++) {
  9629. $sumPrice = 0;
  9630. foreach ( $receiptCollectList as $key => $value ) {
  9631. if ($value ['month'] == $i) {
  9632. $sumPrice += $value ['price'];
  9633. }
  9634. }
  9635. if ($sumPrice == 0)
  9636. $collectHtml .= '<td class="taR">-</td>';
  9637. else
  9638. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9639. $total += $sumPrice;
  9640. }
  9641. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9642. $data ['totalPrice'] = $collectHtml;
  9643. $dateHtml = "";
  9644. $now = date ( "Y" );
  9645. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9646. if ($YEARD <= $now) {
  9647. $dateHtml .= '<option ';
  9648. if ($year == $YEARD) {
  9649. $dateHtml .= 'selected ';
  9650. }
  9651. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9652. }
  9653. }
  9654. $data ['dateHtml'] = $dateHtml;
  9655. $data ['year'] = $year;
  9656. $data ['totalYear'] = $total;
  9657. $data ['memu'] = "receipt";
  9658. $data ['staff'] = $this->staff;
  9659. $data ['receiptMemu'] = 'personalCollect';
  9660. $data ['verifyId'] = $this->verifyId;
  9661. $data ['executeId'] = $this->executeId;
  9662. // year staff status 2,4
  9663. if ($year < date ( "Y" )) {
  9664. Doo::loadModel ( 'receipt' );
  9665. $receipt = new receipt ();
  9666. $receiptList = $receipt->find ( array (
  9667. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9668. 'asArray' => true
  9669. ) );
  9670. if (empty ( $receiptList )) {
  9671. ob_start ();
  9672. $this->render ( "/admin/saea_slist_collect", $data );
  9673. $this->cacheFile ( $path );
  9674. die ();
  9675. }
  9676. }
  9677. $this->render ( "/admin/saea_slist_collect", $data );
  9678. }
  9679. function personalCollectDetail() {
  9680. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9681. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9682. $this->showCache ( $path );
  9683. Doo::loadModel ( "receiptDetail" );
  9684. Doo::loadModel ( "itemStatistics" );
  9685. Doo::loadModel ( 'statistics' );
  9686. Doo::loadModel ( 'accountItem' );
  9687. $accountItem = new accountItem ();
  9688. $statistics = new statistics ();
  9689. $itemStatistics = new itemStatistics ();
  9690. $receiptDetail = new receiptDetail ();
  9691. $receiptCollectList = $receiptDetail->find ( array (
  9692. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9693. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9694. 'groupby' => 'item,Month(date)',
  9695. 'asArray' => true
  9696. ) );
  9697. $accountList = $accountItem->find ( array (
  9698. 'asArray' => true
  9699. ) );
  9700. // create CollectDetail HTML
  9701. $collectHtml = array ();
  9702. foreach ( $accountList as $key => $value ) {
  9703. $html = "";
  9704. $asum = 0;
  9705. for($i = 1; $i <= 12; $i ++) {
  9706. $falg = true;
  9707. foreach ( $receiptCollectList as $v ) {
  9708. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9709. $asum += $v ['price'];
  9710. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9711. $falg = false;
  9712. break;
  9713. }
  9714. }
  9715. if ($falg)
  9716. $html .= '<td class="taR">-</td>';
  9717. }
  9718. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9719. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9720. }
  9721. $data ['collectHtml'] = $collectHtml;
  9722. // create Adjustment price html
  9723. $receiptCollectList = $receiptDetail->find ( array (
  9724. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9725. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9726. 'groupby' => 'itemCategory,Month(date)',
  9727. 'asArray' => true
  9728. ) );
  9729. $adjustment = array ();
  9730. $collectArray = array (
  9731. '日常相关费用' => array (),
  9732. '差旅相关费用' => array (),
  9733. '培训班费用' => array (),
  9734. '其他' => array ()
  9735. );
  9736. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9737. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9738. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9739. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9740. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9741. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9742. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9743. array_push ( $collectArray ['其他'], $collectHtml );
  9744. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9745. array_push ( $adjustment, $collectHtml );
  9746. // total price html
  9747. $collectHtml = "";
  9748. $total = 0;
  9749. for($i = 1; $i <= 12; $i ++) {
  9750. $sumPrice = 0;
  9751. foreach ( $receiptCollectList as $key => $value ) {
  9752. if ($value ['month'] == $i) {
  9753. $sumPrice += $value ['price'];
  9754. }
  9755. }
  9756. if ($sumPrice == 0)
  9757. $collectHtml .= '<td class="taR">-</td>';
  9758. else
  9759. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9760. $total += $sumPrice;
  9761. }
  9762. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9763. // statistics html
  9764. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9765. if (empty ( $stList ))
  9766. $stList = array (
  9767. 'rePrice' => 0,
  9768. 'agPrice' => 0
  9769. );
  9770. $data ['stList'] = array (
  9771. 'rePrice' => $stList ['rePrice'],
  9772. 'agPrice' => $stList ['agPrice'],
  9773. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9774. );
  9775. $data ['collectArray'] = $collectArray;
  9776. $data ['adjustment'] = $adjustment;
  9777. $data ['totalPrice'] = $collectHtml;
  9778. $data ['totalYear'] = $total;
  9779. $data ['year'] = $year;
  9780. $dateHtml = "";
  9781. $now = date ( "Y" );
  9782. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9783. if ($YEARD <= $now) {
  9784. $dateHtml .= '<option ';
  9785. if ($year == $YEARD) {
  9786. $dateHtml .= 'selected ';
  9787. }
  9788. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9789. }
  9790. }
  9791. $data ['dateHtml'] = $dateHtml;
  9792. $data ['memu'] = "receipt";
  9793. $data ['staff'] = $this->staff;
  9794. $data ['receiptMemu'] = 'personalCollect';
  9795. $data ['verifyId'] = $this->verifyId;
  9796. $data ['executeId'] = $this->executeId;
  9797. // year staff status 2,4
  9798. if ($year < date ( "Y" )) {
  9799. Doo::loadModel ( 'receipt' );
  9800. $receipt = new receipt ();
  9801. $receiptList = $receipt->find ( array (
  9802. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9803. 'asArray' => true
  9804. ) );
  9805. if (empty ( $receiptList )) {
  9806. ob_start ();
  9807. $this->render ( "/admin/saeaCollectArticles", $data );
  9808. $this->cacheFile ( $path );
  9809. die ();
  9810. }
  9811. }
  9812. $this->render ( "/admin/saeaCollectArticles", $data );
  9813. }
  9814. function companyCategoryCollect() {
  9815. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9816. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9817. $this->showCache ( $path );
  9818. Doo::loadModel ( 'L_category' );
  9819. Doo::loadModel ( 'itemStatistics' );
  9820. Doo::loadModel ( 'statistics' );
  9821. $statistics = new statistics ();
  9822. $Lcategory = new L_category ();
  9823. $itemStatistics = new itemStatistics ();
  9824. Doo::loadModel ( "receiptAuthorityManage" );
  9825. $receiptAuthorityManage = new receiptAuthorityManage ();
  9826. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9827. $cidList = array ();
  9828. foreach ( $imcStaff as $key => $value ) {
  9829. array_push ( $cidList, $value ['cid'] );
  9830. }
  9831. $cidString = implode ( ',', $cidList );
  9832. $LcategoryList = $Lcategory->find ( array (
  9833. 'where' => ' cid in (' . $cidString . ')',
  9834. 'asArray' => true
  9835. ) ); // 'staff='.$this->staff[0]['sid']." and
  9836. $itemStatisticsList = $itemStatistics->find ( array (
  9837. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9838. 'where' => " Year(date)=" . $year,
  9839. 'groupby' => 'cid,Month(date)',
  9840. 'asArray' => true
  9841. ) );
  9842. // ceatre companyCollectHtml
  9843. foreach ( $LcategoryList as $value ) {
  9844. $html = "";
  9845. $asum = 0;
  9846. for($i = 1; $i <= 12; $i ++) {
  9847. $falg = true;
  9848. foreach ( $itemStatisticsList as $v ) {
  9849. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9850. $asum += $v ['price'];
  9851. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9852. $falg = false;
  9853. break;
  9854. }
  9855. }
  9856. if ($falg)
  9857. $html .= '<td class="taR">-</td>';
  9858. }
  9859. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9860. $collectHtml [$value ['title']] = array (
  9861. 'html' => $html,
  9862. 'cid' => $value ['cid']
  9863. );
  9864. }
  9865. $data ['companyHtml'] = $collectHtml;
  9866. // total price html
  9867. $collectHtml = "";
  9868. $total = 0;
  9869. for($i = 1; $i <= 12; $i ++) {
  9870. $sumPrice = 0;
  9871. foreach ( $itemStatisticsList as $key => $value ) {
  9872. if ($value ['month'] == $i) {
  9873. $sumPrice += $value ['price'];
  9874. }
  9875. }
  9876. if ($sumPrice == 0)
  9877. $collectHtml .= '<td class="taR">-</td>';
  9878. else
  9879. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9880. $total += $sumPrice;
  9881. }
  9882. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9883. $data ['companyTotalHtml'] = $collectHtml;
  9884. $data ['total'] = $total;
  9885. // statistics html
  9886. // echo $cidString;
  9887. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9888. if (empty ( $stList ))
  9889. $stList = array (
  9890. 'rePrice' => 0,
  9891. 'agPrice' => 0
  9892. );
  9893. $data ['stList'] = array (
  9894. 'rePrice' => $stList ['rePrice'],
  9895. 'agPrice' => $stList ['agPrice'],
  9896. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9897. );
  9898. $data ['year'] = $year;
  9899. $data ['memu'] = "receipt";
  9900. $data ['staff'] = $this->staff;
  9901. $data ['receiptMemu'] = 'companyCategoryCollect';
  9902. $data ['verifyId'] = $this->verifyId;
  9903. $data ['executeId'] = $this->executeId;
  9904. $dateHtml = "";
  9905. $now = date ( "Y" );
  9906. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9907. if ($YEARD <= $now) {
  9908. $dateHtml .= '<option ';
  9909. if ($year == $YEARD) {
  9910. $dateHtml .= 'selected ';
  9911. }
  9912. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9913. }
  9914. }
  9915. $data ['dateHtml'] = $dateHtml;
  9916. // year staff status 2,4
  9917. if ($year < date ( "Y" )) {
  9918. Doo::loadModel ( 'receipt' );
  9919. $receipt = new receipt ();
  9920. $receiptList = $receipt->find ( array (
  9921. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9922. 'asArray' => true
  9923. ) );
  9924. if (empty ( $receiptList )) {
  9925. ob_start ();
  9926. $this->render ( "/admin/saeaCompanyCollect", $data );
  9927. $this->cacheFile ( $path );
  9928. die ();
  9929. }
  9930. }
  9931. $this->render ( "/admin/saeaCompanyCollect", $data );
  9932. }
  9933. function categoryCollectDetail() {
  9934. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9935. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9936. /* $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9937. $this->showCache ( $path ); */
  9938. Doo::loadModel ( 'statistics' );
  9939. $statistics = new statistics ();
  9940. Doo::loadModel ( "receiptDetail" );
  9941. $receiptDetail = new receiptDetail ();
  9942. Doo::loadModel ( 'L_category' );
  9943. $Lcategory = new L_category ();
  9944. Doo::loadModel ( 'accountItem' );
  9945. $accountItem = new accountItem ();
  9946. Doo::loadModel ( "receiptAuthorityManage" );
  9947. $receiptAuthorityManage = new receiptAuthorityManage ();
  9948. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9949. $cidList = array ();
  9950. foreach ( $imcStaff as $key => $value ) {
  9951. array_push ( $cidList, $value ['cid'] );
  9952. }
  9953. $cidString = implode ( ',', $cidList );
  9954. $LcategoryList = $Lcategory->find ( array (
  9955. 'where' => 'cid in (' . $cidString . ')',
  9956. 'asArray' => true
  9957. ) );
  9958. if ($cid == 0) {
  9959. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9960. if ($cid == 0)
  9961. $cid = $LcategoryList [0] ['cid'];
  9962. }
  9963. $data ['LcategoryList'] = $LcategoryList;
  9964. $receiptCollectList = $receiptDetail->find ( array (
  9965. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9966. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9967. 'groupby' => 'item,Month(pastDate)',
  9968. 'asArray' => true
  9969. ) );
  9970. $accountList = $accountItem->find ( array (
  9971. 'asArray' => true
  9972. ) );
  9973. // create CollectDetail HTML
  9974. $collectHtml = array ();
  9975. foreach ( $accountList as $key => $value ) {
  9976. $html = "";
  9977. $asum = 0;
  9978. for($i = 1; $i <= 12; $i ++) {
  9979. $falg = true;
  9980. foreach ( $receiptCollectList as $v ) {
  9981. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9982. $asum += $v ['price'];
  9983. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9984. $falg = false;
  9985. break;
  9986. }
  9987. }
  9988. if ($falg)
  9989. $html .= '<td class="taR">-</td>';
  9990. }
  9991. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9992. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9993. }
  9994. $data ['collectHtml'] = $collectHtml;
  9995. // create Adjustment price html
  9996. $receiptCollectList = $receiptDetail->find ( array (
  9997. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9998. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9999. 'groupby' => 'itemCategory,Month(pastDate)',
  10000. 'asArray' => true
  10001. ) );
  10002. $adjustment = array ();
  10003. $collectArray = array (
  10004. '日常相关费用' => array (),
  10005. '差旅相关费用' => array (),
  10006. '培训班费用' => array (),
  10007. '内部培训费用'=>array(),
  10008. '其他' => array ()
  10009. );
  10010. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  10011. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  10012. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  10013. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  10014. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  10015. array_push ( $collectArray ['培训班费用'], $collectHtml );
  10016. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  10017. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  10018. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  10019. array_push ( $collectArray ['其他'], $collectHtml );
  10020. $data ['collectArray'] = $collectArray;
  10021. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  10022. array_push ( $adjustment, $collectHtml );
  10023. $data ['adjustment'] = $adjustment;
  10024. // total price html
  10025. $collectHtml = "";
  10026. $total = 0;
  10027. for($i = 1; $i <= 12; $i ++) {
  10028. $sumPrice = 0;
  10029. foreach ( $receiptCollectList as $key => $value ) {
  10030. if ($value ['month'] == $i) {
  10031. $sumPrice += $value ['price'];
  10032. }
  10033. }
  10034. if ($sumPrice == 0)
  10035. $collectHtml .= '<td class="taR">-</td>';
  10036. else
  10037. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  10038. $total += $sumPrice;
  10039. }
  10040. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  10041. // statistics html
  10042. $stList = $statistics->statisticsByCid ( $year, $cid );
  10043. if (empty ( $stList ))
  10044. $stList = array (
  10045. 'rePrice' => 0,
  10046. 'agPrice' => 0
  10047. );
  10048. $data ['stList'] = array (
  10049. 'rePrice' => $stList ['rePrice'],
  10050. 'agPrice' => $stList ['agPrice'],
  10051. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10052. );
  10053. $data ['totalYear'] = $total;
  10054. $data ['year'] = $year;
  10055. $data ['cid'] = $cid;
  10056. $data ['memu'] = "receipt";
  10057. $data ['staff'] = $this->staff;
  10058. $data ['receiptMemu'] = 'companyCategoryCollect';
  10059. $data ['verifyId'] = $this->verifyId;
  10060. $data ['executeId'] = $this->executeId;
  10061. // year staff status 2,4
  10062. /* if ($year < date ( "Y" )) {
  10063. Doo::loadModel ( 'receipt' );
  10064. $receipt = new receipt ();
  10065. $receiptList = $receipt->find ( array (
  10066. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  10067. 'asArray' => true
  10068. ) );
  10069. if (empty ( $receiptList )) {
  10070. ob_start ();
  10071. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  10072. $this->cacheFile ( $path );
  10073. die ();
  10074. }
  10075. } */
  10076. $dateHtml = "";
  10077. $now = date ( "Y" );
  10078. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  10079. if ($YEARD <= $now) {
  10080. $dateHtml .= '<option ';
  10081. if ($year == $YEARD) {
  10082. $dateHtml .= 'selected ';
  10083. }
  10084. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  10085. }
  10086. }
  10087. $data ['dateHtml'] = $dateHtml;
  10088. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  10089. }
  10090. function staffCollect() {
  10091. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  10092. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  10093. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  10094. // $this->showCache($path);
  10095. Doo::loadModel ( 'statistics' );
  10096. $statistics = new statistics ();
  10097. Doo::loadModel ( "receiptDetail" );
  10098. $receiptDetail = new receiptDetail ();
  10099. Doo::loadModel ( 'L_category' );
  10100. $Lcategory = new L_category ();
  10101. Doo::loadModel ( 'accountItem' );
  10102. $accountItem = new accountItem ();
  10103. Doo::loadModel ( 'staff' );
  10104. $staff = new staff ();
  10105. Doo::loadModel ( 'itemStatistics' );
  10106. $itemStatistics = new itemStatistics ();
  10107. Doo::loadModel ( "receiptAuthorityManage" );
  10108. $receiptAuthorityManage = new receiptAuthorityManage ();
  10109. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  10110. $cidList = array ();
  10111. foreach ( $imcStaff as $key => $value ) {
  10112. array_push ( $cidList, $value ['cid'] );
  10113. }
  10114. $cidString = implode ( ',', $cidList );
  10115. $naturecon='';
  10116. if ($nature=='ONJOB'){
  10117. $naturecon=' and (nature!=4 )';
  10118. }elseif($nature=='LEAVEJOB'){
  10119. $naturecon=' and (nature=4 )';
  10120. }else{
  10121. die ( 'illegal request--nature' );
  10122. }
  10123. // statistics html
  10124. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  10125. if (empty ( $stList ))
  10126. $stList = array (
  10127. 'rePrice' => 0,
  10128. 'agPrice' => 0
  10129. );
  10130. $data ['stList'] = array (
  10131. 'rePrice' => $stList ['rePrice'],
  10132. 'agPrice' => $stList ['agPrice'],
  10133. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10134. );
  10135. // ---
  10136. $staffList = $staff->find ( array (
  10137. 'where' => 'username !="admin" '.$naturecon,
  10138. 'asArray' => true
  10139. ) );
  10140. $LcategoryList = $Lcategory->find ( array (
  10141. 'asArray' => true
  10142. ) ); // 'staff='.$this->staff[0]['sid']." and
  10143. $itemStatisticsList = $itemStatistics->find ( array (
  10144. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10145. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  10146. 'groupby' => 'staff,Month(date)',
  10147. 'asArray' => true
  10148. ) );
  10149. $categoryList = $staff->find ( array (
  10150. 'select' => 'COUNT(*) as count,cid,category',
  10151. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  10152. 'groupby' => 'cid',
  10153. 'asArray' => true
  10154. ) );
  10155. // print_r($itemStatisticsList);die;
  10156. // ceatre companyCollectHtml
  10157. foreach ( $categoryList as $vlu ) {
  10158. $count = $vlu ['count'] + 1;
  10159. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  10160. $m1 = 0;
  10161. $m2 = 0;
  10162. $m3 = 0;
  10163. $m4 = 0;
  10164. $m5 = 0;
  10165. $m6 = 0;
  10166. $m7 = 0;
  10167. $m8 = 0;
  10168. $m9 = 0;
  10169. $m10 = 0;
  10170. $m11 = 0;
  10171. $m12 = 0;
  10172. $m13 = 0;
  10173. foreach ( $staffList as $value ) {
  10174. if ($vlu ['cid'] == $value ['cid']) {
  10175. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  10176. $asum = 0;
  10177. for($i = 1; $i <= 12; $i ++) {
  10178. $falg = true;
  10179. foreach ( $itemStatisticsList as $v ) {
  10180. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  10181. if ($v ['month'] == 1)
  10182. $m1 += $v ['price'];
  10183. if ($v ['month'] == 2)
  10184. $m2 += $v ['price'];
  10185. if ($v ['month'] == 3)
  10186. $m3 += $v ['price'];
  10187. if ($v ['month'] == 4)
  10188. $m4 += $v ['price'];
  10189. if ($v ['month'] == 5)
  10190. $m5 += $v ['price'];
  10191. if ($v ['month'] == 6)
  10192. $m6 += $v ['price'];
  10193. if ($v ['month'] == 7)
  10194. $m7 += $v ['price'];
  10195. if ($v ['month'] == 8)
  10196. $m8 += $v ['price'];
  10197. if ($v ['month'] == 9)
  10198. $m9 += $v ['price'];
  10199. if ($v ['month'] == 10)
  10200. $m10 += $v ['price'];
  10201. if ($v ['month'] == 11)
  10202. $m11 += $v ['price'];
  10203. if ($v ['month'] == 12)
  10204. $m12 += $v ['price'];
  10205. $asum += $v ['price'];
  10206. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  10207. $falg = false;
  10208. break;
  10209. }
  10210. }
  10211. if ($falg)
  10212. $html .= '<td class="taR">-</td>';
  10213. }
  10214. $m13 += $asum;
  10215. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  10216. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  10217. 'html' => $html,
  10218. 'sid' => $value ['sid']
  10219. );
  10220. $html = "";
  10221. }
  10222. }
  10223. $hl = '<th class="taR">小计</th><td class="taR">¥' . $m1 . '</td><td class="taR">¥' . $m2 . '</td><td class="taR">¥' . $m3 . '</td><td class="taR">¥' . $m4 . '</td><td class="taR">¥' . $m5 . '</td>
  10224. <td class="taR">¥' . $m6 . '</td><td class="taR">¥' . $m7 . '</td><td class="taR">¥' . $m8 . '</td><td class="taR">¥' . $m9 . '</td><td class="taR">¥' . $m10 . '</td><td class="taR">¥' . $m11 . '</td>
  10225. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  10226. $collectHtml [$vlu ['cid']] = array (
  10227. 'html' => $hl,
  10228. 'sid' => ''
  10229. );
  10230. }
  10231. $data ['companyHtml'] = $collectHtml;
  10232. // total price html
  10233. $collectHtml = "";
  10234. $total = 0;
  10235. for($i = 1; $i <= 12; $i ++) {
  10236. $sumPrice = 0;
  10237. foreach ( $itemStatisticsList as $key => $value ) {
  10238. if ($value ['month'] == $i) {
  10239. $sumPrice += $value ['price'];
  10240. }
  10241. }
  10242. if ($sumPrice == 0)
  10243. $collectHtml .= '<td class="taR">-</td>';
  10244. else
  10245. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  10246. $total += $sumPrice;
  10247. }
  10248. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  10249. $data ['companyTotalHtml'] = $collectHtml;
  10250. $data ['total'] = $total;
  10251. $data ['nature'] =$nature;
  10252. $data ['year'] = $year;
  10253. $data ['memu'] = "receipt";
  10254. $data ['staff'] = $this->staff;
  10255. $data ['receiptMemu'] = 'companyCategoryCollect';
  10256. $data ['verifyId'] = $this->verifyId;
  10257. $data ['executeId'] = $this->executeId;
  10258. if ($year <= date ( "Y" )) {
  10259. Doo::loadModel ( 'receipt' );
  10260. $receipt = new receipt ();
  10261. $receiptList = $receipt->find ( array (
  10262. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  10263. 'asArray' => true
  10264. ) );
  10265. if (empty ( $receiptList )) { // generated files
  10266. ob_start ();
  10267. $this->render ( "/admin/saeaStaffCollectB", $data );
  10268. $this->cacheFile ( $path );
  10269. die ();
  10270. }
  10271. }
  10272. $this->render ( "/admin/saeaStaffCollectB", $data );
  10273. }
  10274. function staffCollectBak() {
  10275. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  10276. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  10277. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  10278. $this->showCache ( $path );
  10279. Doo::loadModel ( 'statistics' );
  10280. $statistics = new statistics ();
  10281. Doo::loadModel ( "receiptDetail" );
  10282. $receiptDetail = new receiptDetail ();
  10283. Doo::loadModel ( 'L_category' );
  10284. $Lcategory = new L_category ();
  10285. Doo::loadModel ( 'accountItem' );
  10286. $accountItem = new accountItem ();
  10287. Doo::loadModel ( 'staff' );
  10288. $staff = new staff ();
  10289. Doo::loadModel ( 'itemStatistics' );
  10290. $itemStatistics = new itemStatistics ();
  10291. $itemStatisticsList = $itemStatistics->find ( array (
  10292. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10293. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10294. 'groupby' => 'staff,itemCategory,Month(date)',
  10295. 'asArray' => true
  10296. ) );
  10297. $itemCategoryList = $itemStatistics->find ( array (
  10298. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10299. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10300. 'groupby' => 'cid,itemCategory,Month(date)',
  10301. 'asArray' => true
  10302. ) );
  10303. $LcategoryList = $Lcategory->find ( array (
  10304. 'asArray' => true
  10305. ) );
  10306. $staffList = $staff->find ( array (
  10307. 'asArray' => true
  10308. ) );
  10309. $htmlArray = array ();
  10310. foreach ( $LcategoryList as $value ) {
  10311. $htmlArray [$value ['title']] = array ();
  10312. foreach ( $staffList as $v ) {
  10313. if ($value ['cid'] == $v ['cid']) {
  10314. $html = "";
  10315. $falg = true;
  10316. $staffSumPrice = 0;
  10317. foreach ( $itemStatisticsList as $a ) {
  10318. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  10319. if (empty ( $a ['price'] )) {
  10320. $html .= '<td class="taR">-</td>';
  10321. $falg = false;
  10322. break;
  10323. } else {
  10324. $staffSumPrice += $a ['price'];
  10325. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10326. $falg = false;
  10327. break;
  10328. }
  10329. }
  10330. }
  10331. if ($falg) {
  10332. $html .= '<td class="taR">-</td>';
  10333. $falg = true;
  10334. }
  10335. $falg = true;
  10336. foreach ( $itemStatisticsList as $a ) {
  10337. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  10338. if (empty ( $a ['price'] )) {
  10339. $html .= '<td class="taR">-</td>';
  10340. $falg = false;
  10341. break;
  10342. } else {
  10343. $staffSumPrice += $a ['price'];
  10344. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10345. $falg = false;
  10346. break;
  10347. }
  10348. }
  10349. }
  10350. if ($falg) {
  10351. $html .= '<td class="taR">-</td>';
  10352. $falg = true;
  10353. }
  10354. $falg = true;
  10355. foreach ( $itemStatisticsList as $a ) {
  10356. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  10357. if (empty ( $a ['price'] )) {
  10358. $html .= '<td class="taR">-</td>';
  10359. $falg = false;
  10360. break;
  10361. } else {
  10362. $staffSumPrice += $a ['price'];
  10363. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10364. $falg = false;
  10365. break;
  10366. }
  10367. }
  10368. }
  10369. if ($falg) {
  10370. $html .= '<td class="taR">-</td>';
  10371. $falg = true;
  10372. }
  10373. $falg = true;
  10374. foreach ( $itemStatisticsList as $a ) {
  10375. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  10376. if (! empty ( $a ['price'] )) {
  10377. $staffSumPrice += $a ['price'];
  10378. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10379. $falg = false;
  10380. break;
  10381. } else {
  10382. $html .= '<td class="taR">-</td>';
  10383. $falg = false;
  10384. break;
  10385. }
  10386. }
  10387. }
  10388. if ($falg) {
  10389. $html .= '<td class="taR">-</td>';
  10390. $falg = true;
  10391. }
  10392. $falg = true;
  10393. foreach ( $itemStatisticsList as $a ) {
  10394. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  10395. if (! empty ( $a ['price'] )) {
  10396. $staffSumPrice += $a ['price'];
  10397. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10398. $falg = false;
  10399. break;
  10400. } else {
  10401. $html .= '<td class="taR">-</td>';
  10402. $falg = false;
  10403. break;
  10404. }
  10405. }
  10406. }
  10407. if ($falg) {
  10408. $html .= '<td class="taR">-</td>';
  10409. $falg = true;
  10410. }
  10411. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  10412. $htmlArray [$value ['title']] [$v ['username']] = $html;
  10413. }
  10414. }
  10415. /* -- --- */
  10416. // 合计费用
  10417. $cateHtml = "";
  10418. $catePrice = 0;
  10419. $cateFalg = true;
  10420. foreach ( $itemCategoryList as $l ) {
  10421. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  10422. if (empty ( $l ['price'] )) {
  10423. $cateHtml .= '<td class="colGreen taR">-</td>';
  10424. $cateFalg = false;
  10425. break;
  10426. } else {
  10427. $catePrice += $l ['price'];
  10428. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10429. $cateFalg = false;
  10430. break;
  10431. }
  10432. }
  10433. }
  10434. if ($cateFalg) {
  10435. $cateHtml .= '<td class="colGreen taR">-</td>';
  10436. $cateFalg = true;
  10437. }
  10438. $cateFalg = true;
  10439. foreach ( $itemCategoryList as $l ) {
  10440. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  10441. if (empty ( $l ['price'] )) {
  10442. $cateHtml .= '<td class="colGreen taR">-</td>';
  10443. $cateFalg = false;
  10444. break;
  10445. } else {
  10446. $catePrice += $l ['price'];
  10447. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10448. $cateFalg = false;
  10449. break;
  10450. }
  10451. }
  10452. }
  10453. if ($cateFalg) {
  10454. $cateHtml .= '<td class="colGreen taR">-</td>';
  10455. $cateFalg = true;
  10456. }
  10457. $cateFalg = true;
  10458. foreach ( $itemCategoryList as $l ) {
  10459. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  10460. if (empty ( $l ['price'] )) {
  10461. $cateHtml .= '<td class="colGreen taR">-</td>';
  10462. $cateFalg = false;
  10463. break;
  10464. } else {
  10465. $catePrice += $l ['price'];
  10466. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10467. $cateFalg = false;
  10468. break;
  10469. }
  10470. }
  10471. }
  10472. if ($cateFalg) {
  10473. $cateHtml .= '<td class="colGreen taR">-</td>';
  10474. $cateFalg = true;
  10475. }
  10476. $cateFalg = true;
  10477. foreach ( $itemCategoryList as $l ) {
  10478. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  10479. if (empty ( $l ['price'] )) {
  10480. $cateHtml .= '<td class="colGreen taR">-</td>';
  10481. $cateFalg = false;
  10482. break;
  10483. } else {
  10484. $catePrice += $l ['price'];
  10485. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10486. $cateFalg = false;
  10487. break;
  10488. }
  10489. }
  10490. }
  10491. if ($cateFalg) {
  10492. $cateHtml .= '<td class="colGreen taR">-</td>';
  10493. $cateFalg = true;
  10494. }
  10495. $cateFalg = true;
  10496. foreach ( $itemCategoryList as $l ) {
  10497. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  10498. if (empty ( $l ['price'] )) {
  10499. $cateHtml .= '<td class="colGreen taR">-</td>';
  10500. $cateFalg = false;
  10501. break;
  10502. } else {
  10503. $catePrice += $l ['price'];
  10504. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10505. $cateFalg = false;
  10506. break;
  10507. }
  10508. }
  10509. }
  10510. if ($cateFalg) {
  10511. $cateHtml .= '<td class="colGreen taR">-</td>';
  10512. $cateFalg = true;
  10513. }
  10514. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  10515. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  10516. /* -- --- */
  10517. }
  10518. // print_r($htmlArray);die;
  10519. $data ['htmlArray'] = $htmlArray;
  10520. // statistics html
  10521. $stList = $statistics->getOne ( array (
  10522. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  10523. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10524. 'groupby' => 'Month(date)',
  10525. 'asArray' => true
  10526. ) );
  10527. if (empty ( $stList ))
  10528. $stList = array (
  10529. 'rePrice' => 0,
  10530. 'agPrice' => 0
  10531. );
  10532. $data ['stList'] = array (
  10533. 'rePrice' => $stList ['rePrice'],
  10534. 'agPrice' => $stList ['agPrice'],
  10535. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10536. );
  10537. $monthHtml = "";
  10538. for($i = 1; $i <= 12; $i ++) {
  10539. if ($i == $month)
  10540. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  10541. else
  10542. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10543. }
  10544. $data ['monthHtml'] = $monthHtml;
  10545. $data ['year'] = $year;
  10546. $data ['month'] = $month;
  10547. $data ['memu'] = "receipt";
  10548. $data ['staff'] = $this->staff;
  10549. $data ['receiptMemu'] = 'companyCategoryCollect';
  10550. $data ['verifyId'] = $this->verifyId;
  10551. $data ['executeId'] = $this->executeId;
  10552. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10553. Doo::loadModel ( 'receipt' );
  10554. $receipt = new receipt ();
  10555. $receiptList = $receipt->find ( array (
  10556. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10557. 'asArray' => true
  10558. ) );
  10559. if (empty ( $receiptList )) { // generated files
  10560. ob_start ();
  10561. $this->render ( "/admin/saeaStaffCollect", $data );
  10562. $this->cacheFile ( $path );
  10563. die ();
  10564. }
  10565. }
  10566. $this->render ( "/admin/saeaStaffCollect", $data );
  10567. }
  10568. /**
  10569. * 日常收支
  10570. */
  10571. function payments() {
  10572. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10573. Doo::loadModel ( "execute" );
  10574. $execute = new execute ();
  10575. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10576. die ( 'illegal request' );
  10577. }
  10578. Doo::loadModel ( "accountBook" );
  10579. $accountBook = new accountBook ();
  10580. Doo::loadModel ( "accountBookStatistics" );
  10581. $accountBookStatistics = new accountBookStatistics ();
  10582. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10583. $list = $accountBook->getAccountBookByLimit ( 10 );
  10584. $data ['date'] = date ( "Y-m-d" );
  10585. $data ['statisticsList'] = $statisticsList;
  10586. $data ['list'] = $list;
  10587. $data ['memu'] = "receipt";
  10588. $data ['staff'] = $this->staff;
  10589. $data ['receiptMemu'] = 'payments';
  10590. $data ['verifyId'] = $this->verifyId;
  10591. $data ['executeId'] = $this->executeId;
  10592. $this->render ( "/expenses/payments", $data );
  10593. }
  10594. function paymentsIncomeDo() {
  10595. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10596. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10597. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10598. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10599. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10600. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10601. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10602. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10603. Doo::loadClass ( 'XDeode' );
  10604. $XDeode = new XDeode ( 5 );
  10605. Doo::loadModel ( "accountBook" );
  10606. Doo::loadModel ( "accountBookStatistics" );
  10607. Doo::loadModel ( 'wasteBook' );
  10608. // 记录流水时银行的转换
  10609. $accountBank = '';
  10610. if ($receivedBank == '纵横广发') {
  10611. $accountBank = 'CGBDeposit';
  10612. } elseif ($receivedBank == '纵横工行') {
  10613. $accountBank = 'ICBCDeposit';
  10614. } elseif ($receivedBank == '华润银行') {
  10615. $accountBank = 'HUADeposit';
  10616. } elseif ($receivedBank == '个人广发') {
  10617. $accountBank = 'PersonalDeposit';
  10618. }
  10619. if (empty ( $accountBank ))
  10620. die ( 'illegal request-bank' );
  10621. //TODO -存款功能 提取
  10622. if($accountType == 11 || $accountType == 12){
  10623. if($accountType == 11){
  10624. $receivedBank = '纵横广发';
  10625. }elseif($accountType == 12){
  10626. $receivedBank = '纵横工行';
  10627. }
  10628. // 添加一条收入
  10629. $accountBook = new accountBook ();
  10630. $accountBook->accountType = $accountType;
  10631. $accountBook->accountMsg = $accountMsg;
  10632. $accountBook->receivedPrice = $receivedPrice;
  10633. $accountBook->receivedMsg = $receivedMsg;
  10634. $accountBook->receivedBank = $receivedBank;
  10635. $accountBook->receivedDate = $receivedDate;
  10636. $accountBook->remarks = $remarks;
  10637. $accountBook->expensesType = 1;
  10638. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10639. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10640. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10641. $inComeId = $accountBook->insert ();
  10642. // 收支汇总-添加一条收入日常汇总
  10643. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10644. $accountBookStatistics = new accountBookStatistics ();
  10645. $item = array (
  10646. 'date' => date ( "Y-m-d" ),
  10647. 'accountType' => $abDetail ['accountType'],
  10648. 'accountMsg' => $abDetail ['accountMsg'],
  10649. 'aid' => $abDetail ['aid'],
  10650. 'inComePrice' => $abDetail ['receivedPrice'],
  10651. 'expensesType' => $abDetail ['expensesType']
  10652. );
  10653. $accountBookStatistics->setAccountBookStatistics ( $item );
  10654. // 添加收入流水
  10655. if($accountType == 11){
  10656. $accountBank = 'CGBDeposit';
  10657. }elseif($accountType == 12){
  10658. $accountBank = 'ICBCDeposit';
  10659. }
  10660. $wasteBook = new wasteBook ();
  10661. $itemWaste = array (
  10662. 'accountPriceShow' => $receivedPrice,
  10663. 'accountPrice' => $receivedPrice,
  10664. 'expensesType' => 1,
  10665. 'accountType' => 6, // 流水类型
  10666. 'dataID' => $inComeId,
  10667. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10668. 'accountBank' => $accountBank,
  10669. 'category' => $this->staff [0] ['category'],
  10670. 'cid' => $this->staff [0] ['cid'],
  10671. 'name' => $this->staff [0] ['username'],
  10672. 'sid' => $this->staff [0] ['sid'],
  10673. 'inputDate' => $receivedDate,
  10674. 'createAt'=>date ( "Y-m-d H:i:s" ),
  10675. 'synPaymentDate'=>1,
  10676. );
  10677. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10678. }
  10679. //TODO --移除理财相关
  10680. // elseif($accountType == 7 || $accountType == 9) { // 收入为理财时特殊处理
  10681. // // if ($receivedBank == '个人广发') {
  10682. // // die ( '个人广发 illegal request' );
  10683. // // }
  10684. // // echo $receivedBank;
  10685. // die;
  10686. // // 添加一条收入
  10687. // $accountBook = new accountBook ();
  10688. // $accountBook->accountType = 10;
  10689. // $accountBook->accountMsg = $accountMsg;
  10690. // $accountBook->receivedPrice = $receivedPrice;
  10691. // $accountBook->receivedMsg = $receivedMsg;
  10692. // $accountBook->receivedBank = $receivedBank;
  10693. // $accountBook->receivedDate = $receivedDate;
  10694. // $accountBook->remarks = $remarks;
  10695. // $accountBook->expensesType = 1;
  10696. // $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10697. // $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10698. // $accountBook->inputStaff = $this->staff [0] ['sid'];
  10699. // $inComeId = $accountBook->insert ();
  10700. // // 收支汇总-添加一条收入日常汇总
  10701. // $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10702. // $accountBookStatistics = new accountBookStatistics ();
  10703. // $item = array (
  10704. // 'date' => date ( "Y-m-d" ),
  10705. // 'accountType' => $abDetail ['accountType'],
  10706. // 'accountMsg' => $abDetail ['accountMsg'],
  10707. // 'aid' => $abDetail ['aid'],
  10708. // 'inComePrice' => $abDetail ['receivedPrice'],
  10709. // 'expensesType' => $abDetail ['expensesType']
  10710. // );
  10711. // $accountBookStatistics->setAccountBookStatistics ( $item );
  10712. // // 添加收入流水
  10713. // $wasteBook = new wasteBook ();
  10714. // $itemWaste = array (
  10715. // 'accountPriceShow' => $receivedPrice,
  10716. // 'accountPrice' => $receivedPrice,
  10717. // 'expensesType' => 1,
  10718. // 'accountType' => 6, // 流水类型
  10719. // 'dataID' => $inComeId,
  10720. // 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10721. // 'accountBank' => $accountBank,
  10722. // 'category' => $this->staff [0] ['category'],
  10723. // 'cid' => $this->staff [0] ['cid'],
  10724. // 'name' => $this->staff [0] ['username'],
  10725. // 'sid' => $this->staff [0] ['sid'],
  10726. // 'inputDate' => date ( "Y-m-d H:i:s" )
  10727. // );
  10728. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  10729. // // 添加一条理财支出
  10730. // $accountBank = 'CGBDeposit';
  10731. // $expenditureBank = '纵横广发';
  10732. // if($accountMsg=='个人(GR)'){
  10733. // $expenditureBank = '个人广发';
  10734. // }
  10735. // $dailyExpenditureType = 4;
  10736. // if ($accountType == 9) {
  10737. // $accountBank = 'ICBCDeposit';
  10738. // $expenditureBank = '纵横工行';
  10739. // $dailyExpenditureType = 6;
  10740. // }
  10741. // $accountBook = new accountBook ();
  10742. // $accountBook->expensesType = 2;
  10743. // $accountBook->expenditureType = $dailyExpenditureType;
  10744. // $accountBook->expenditureMsg = $accountMsg;
  10745. // $accountBook->expenditurePrice = $receivedPrice;
  10746. // $accountBook->expenditureBank = $expenditureBank;
  10747. // $accountBook->expenditureDate = $receivedDate;
  10748. // $accountBook->remarks = $remarks;
  10749. // $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10750. // $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10751. // $accountBook->inputStaff = $this->staff [0] ['sid'];
  10752. // $id = $accountBook->insert ();
  10753. // // 收支汇总-添加一条理财支出汇总
  10754. // $abDetail = $accountBook->getAccountBookByAid ( $id );
  10755. // $accountBookStatistics = new accountBookStatistics ();
  10756. // $item = array (
  10757. // 'date' => date ( "Y-m-d" ),
  10758. // 'accountType' => $abDetail ['accountType'],
  10759. // 'accountMsg' => $abDetail ['accountMsg'],
  10760. // 'aid' => $abDetail ['aid'],
  10761. // 'financingPrice' => - $receivedPrice,
  10762. // 'expensesType' => 3
  10763. // );
  10764. // $accountBookStatistics->setAccountBookStatistics ( $item );
  10765. // //TODO -新增理财为个人时的情况 添加一条支出理财流水
  10766. // $accountTypeWaste = 5;
  10767. // if ($accountMsg == '公司固定') {
  10768. // $accountTypeWaste = 9;
  10769. // } elseif ($accountMsg == '公司活期') {
  10770. // $accountTypeWaste = 10;
  10771. // } elseif ($receivedBank == '个人广发') {
  10772. // $accountTypeWaste = 9;
  10773. // $accountBank = 'ICBCDeposit';
  10774. // }
  10775. // $itemWaste = array (
  10776. // 'expensesType' => 2,
  10777. // 'accountType' => $accountTypeWaste,
  10778. // 'accountPriceShow' => $receivedPrice,
  10779. // 'accountPrice' => - $receivedPrice,
  10780. // 'dataID' => $id,
  10781. // 'dailyExpenditureType' => $dailyExpenditureType,
  10782. // 'accountBank' => $accountBank,
  10783. // 'category' => $this->staff [0] ['category'],
  10784. // 'cid' => $this->staff [0] ['cid'],
  10785. // 'name' => $this->staff [0] ['username'],
  10786. // 'sid' => $this->staff [0] ['sid'],
  10787. // 'inputDate' => date ( "Y-m-d H:i:s" )
  10788. // );
  10789. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  10790. // }
  10791. elseif ($accountType == 1) {
  10792. // if ($receivedBank == '个人广发')
  10793. // die ( 'illegal request--no man' );
  10794. // 添加一条收入
  10795. $accountBook = new accountBook ();
  10796. $accountBook->accountType = $accountType;
  10797. $accountBook->accountMsg = $accountMsg;
  10798. $accountBook->receivedPrice = $receivedPrice;
  10799. $accountBook->receivedMsg = $receivedMsg;
  10800. $accountBook->receivedBank = $receivedBank;
  10801. $accountBook->receivedDate = $receivedDate;
  10802. $accountBook->remarks = $remarks;
  10803. $accountBook->expensesType = 1;
  10804. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10805. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10806. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10807. $id = $accountBook->insert ();
  10808. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10809. // 收支汇总-添加一条收入日常汇总
  10810. $accountBookStatistics = new accountBookStatistics ();
  10811. $item = array (
  10812. 'date' => date ( "Y-m-d" ),
  10813. 'accountType' => $abDetail ['accountType'],
  10814. 'accountMsg' => $abDetail ['accountMsg'],
  10815. 'aid' => $abDetail ['aid'],
  10816. 'expensesType' => $abDetail ['expensesType']
  10817. );
  10818. if ($abDetail ['accountType'] == 8) {
  10819. $item += array (
  10820. 'inComePrice' => $abDetail ['receivedPrice']
  10821. );
  10822. } else {
  10823. $item += array (
  10824. 'inComePrice' => $abDetail ['receivedPrice']
  10825. );
  10826. }
  10827. $accountBookStatistics->setAccountBookStatistics ( $item );
  10828. // 流水存储方向
  10829. $itemWaste = array (
  10830. 'accountType' => 6
  10831. ); // 流水类型
  10832. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10833. // }else
  10834. if ($accountMsg == '活期理财收益') {
  10835. $itemWaste = array (
  10836. 'accountType' => 10
  10837. ); // 流水类型
  10838. }
  10839. // 添加收入流水
  10840. $wasteBook = new wasteBook ();
  10841. $itemWaste += array (
  10842. 'accountPrice' => $receivedPrice,
  10843. 'accountPriceShow' => $receivedPrice,
  10844. 'expensesType' => 1,
  10845. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10846. 'dataID' => $id,
  10847. 'accountBank' => $accountBank,
  10848. 'category' => $this->staff [0] ['category'],
  10849. 'cid' => $this->staff [0] ['cid'],
  10850. 'name' => $this->staff [0] ['username'],
  10851. 'sid' => $this->staff [0] ['sid'],
  10852. 'inputDate' => $receivedDate,
  10853. 'createAt'=>date ( "Y-m-d H:i:s" ),
  10854. 'synPaymentDate'=>1,
  10855. );
  10856. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10857. } else { // 普通日常收入处理
  10858. // 添加一条收入
  10859. $accountBook = new accountBook ();
  10860. $accountBook->accountType = $accountType;
  10861. $accountBook->accountMsg = $accountMsg;
  10862. $accountBook->receivedPrice = $receivedPrice;
  10863. $accountBook->receivedMsg = $receivedMsg;
  10864. $accountBook->receivedBank = $receivedBank;
  10865. $accountBook->receivedDate = $receivedDate;
  10866. $accountBook->remarks = $remarks;
  10867. $accountBook->expensesType = 1;
  10868. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10869. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10870. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10871. $id = $accountBook->insert ();
  10872. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10873. // 收支汇总-添加一条收入日常汇总
  10874. $accountBookStatistics = new accountBookStatistics ();
  10875. $item = array (
  10876. 'date' => date ( "Y-m-d" ),
  10877. 'accountType' => $abDetail ['accountType'],
  10878. 'accountMsg' => $abDetail ['accountMsg'],
  10879. 'aid' => $abDetail ['aid'],
  10880. 'expensesType' => $abDetail ['expensesType']
  10881. );
  10882. if ($abDetail ['accountType'] == 8) {
  10883. $item += array (
  10884. 'inComePrice' => $abDetail ['receivedPrice']
  10885. );
  10886. } else {
  10887. $item += array (
  10888. 'inComePrice' => $abDetail ['receivedPrice']
  10889. );
  10890. }
  10891. $accountBookStatistics->setAccountBookStatistics ( $item );
  10892. // 添加收入流水
  10893. // $itemWaste = array (
  10894. // 'accountPrice' => $receivedPrice
  10895. // );
  10896. // if ($receivedBank == '个人广发') {
  10897. // $itemWaste = array (
  10898. // 'accountPrice' => - $receivedPrice
  10899. // );
  10900. // }
  10901. $wasteBook = new wasteBook ();
  10902. $itemWaste = array (
  10903. 'accountPriceShow' => $receivedPrice,
  10904. 'accountPrice' => $receivedPrice,
  10905. 'expensesType' => 1,
  10906. 'accountType' => 6, // 流水类型
  10907. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10908. 'dataID' => $id,
  10909. 'accountBank' => $accountBank,
  10910. 'category' => $this->staff [0] ['category'],
  10911. 'cid' => $this->staff [0] ['cid'],
  10912. 'name' => $this->staff [0] ['username'],
  10913. 'sid' => $this->staff [0] ['sid'],
  10914. 'inputDate' => $receivedDate,
  10915. 'createAt'=>date ( "Y-m-d H:i:s" ),
  10916. 'synPaymentDate'=>1,
  10917. );
  10918. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10919. }
  10920. }
  10921. return '/payments';
  10922. }
  10923. function paymentsExpenditureDo() {
  10924. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10925. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10926. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10927. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10928. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10929. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10930. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10931. // 理财支出特殊处理
  10932. Doo::loadModel ( "accountBook" );
  10933. Doo::loadModel ( "accountBookStatistics" );
  10934. Doo::loadModel ( 'wasteBook' );
  10935. $accountBank = '';
  10936. if ($expenditureBank == '纵横广发') {
  10937. $accountBank = 'CGBDeposit';
  10938. } elseif ($expenditureBank == '纵横工行') {
  10939. $accountBank = 'ICBCDeposit';
  10940. } elseif ($expenditureBank == '华润银行') {
  10941. $accountBank = 'HUADeposit';
  10942. } elseif ($expenditureBank == '个人广发') {
  10943. $accountBank = 'PersonalDeposit';
  10944. }
  10945. if (empty ( $accountBank ))
  10946. die ( 'illegal request' );
  10947. if($expenditureType == 8 || $expenditureType == 9){
  10948. // if($expenditureType == 8 ){
  10949. // $expenditureBank='纵横广发';
  10950. // }elseif($expenditureType == 9){
  10951. // $expenditureBank='纵横工行';
  10952. // }
  10953. // // 添加一笔日常支出
  10954. // $accountBook = new accountBook ();
  10955. // $accountBook->expensesType = 2;
  10956. // $accountBook->expenditureType = $expenditureType;
  10957. // $accountBook->expenditureMsg = $expenditureMsg;
  10958. // $accountBook->expenditurePrice = $expenditurePrice;
  10959. // $accountBook->expenditureBank = $expenditureBank;
  10960. // $accountBook->expenditureDate = $expenditureDate;
  10961. // $accountBook->remarks = $remarks;
  10962. // $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10963. // $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10964. // $accountBook->inputStaff = $this->staff [0] ['sid'];
  10965. // $expenditureId = $accountBook->insert ();
  10966. // // 添加日常支出汇总
  10967. // $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10968. // $accountBookStatistics = new accountBookStatistics ();
  10969. // $item = array (
  10970. // 'date' => date ( "Y-m-d" ),
  10971. // 'expenditureType' => $abDetail ['expenditureType'],
  10972. // 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10973. // 'aid' => $abDetail ['aid'],
  10974. // 'payPrice' => $abDetail ['expenditurePrice'],
  10975. // 'expensesType' => $abDetail ['expensesType']
  10976. // );
  10977. // $accountBookStatistics->setAccountBookStatistics ( $item );
  10978. // // 公司日常支出流水
  10979. // if($expenditureType == 8 ){
  10980. // $accountBank = 'CGBDeposit';
  10981. // }elseif($expenditureType == 9){
  10982. // $accountBank = 'ICBCDeposit';
  10983. // }
  10984. // if($accountBank=='CGBDeposit'){
  10985. // $dailyExpenditureType='8';
  10986. // }elseif($accountBank=='ICBCDeposit'){
  10987. // $dailyExpenditureType='9';
  10988. // }elseif($accountBank=='PersonalDeposit'){
  10989. // $dailyExpenditureType='10';
  10990. // }elseif($accountBank=='HUADeposit'){
  10991. // $dailyExpenditureType='11';
  10992. // }
  10993. // $wasteBook = new wasteBook ();
  10994. // $itemWaste = array (
  10995. // 'expensesType' => 2,
  10996. // 'accountType' => 5,
  10997. // 'dailyExpenditureType' => $dailyExpenditureType,
  10998. // 'accountPriceShow' => $expenditurePrice,
  10999. // 'accountPrice' => - $expenditurePrice,
  11000. // 'dataID' => $expenditureId,
  11001. // 'accountBank' => $accountBank,
  11002. // 'category' => $this->staff [0] ['category'],
  11003. // 'cid' => $this->staff [0] ['cid'],
  11004. // 'name' => $this->staff [0] ['username'],
  11005. // 'sid' => $this->staff [0] ['sid'],
  11006. // 'inputDate' => date ( "Y-m-d H:i:s" )
  11007. // );
  11008. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  11009. //TODO 日常支出 个人理财情况的相关修改
  11010. }elseif ($expenditureType == 4 || $expenditureType == 6) {
  11011. // if ($expenditureBank == '个人广发') {
  11012. // die ( '个人广发 illegal request' );
  11013. // }
  11014. // echo $expenditureMsg;
  11015. die;
  11016. // // 添加一笔日常支出
  11017. // $accountBook = new accountBook ();
  11018. // $accountBook->expensesType = 2;
  11019. // $accountBook->expenditureType = 7;
  11020. // $accountBook->expenditureMsg = $expenditureMsg;
  11021. // $accountBook->expenditurePrice = $expenditurePrice;
  11022. // $accountBook->expenditureBank = $expenditureBank;
  11023. // $accountBook->expenditureDate = $expenditureDate;
  11024. // $accountBook->remarks = $remarks;
  11025. // $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11026. // $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11027. // $accountBook->inputStaff = $this->staff [0] ['sid'];
  11028. // $expenditureId = $accountBook->insert ();
  11029. // // 添加日常支出汇总
  11030. // $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  11031. // $accountBookStatistics = new accountBookStatistics ();
  11032. // $item = array (
  11033. // 'date' => date ( "Y-m-d" ),
  11034. // 'expenditureType' => $abDetail ['expenditureType'],
  11035. // 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11036. // 'aid' => $abDetail ['aid'],
  11037. // 'payPrice' => $abDetail ['expenditurePrice'],
  11038. // 'expensesType' => $abDetail ['expensesType']
  11039. // );
  11040. // $accountBookStatistics->setAccountBookStatistics ( $item );
  11041. // // 公司日常支出流水
  11042. // $wasteBook = new wasteBook ();
  11043. // $itemWaste = array (
  11044. // 'accountPrice' => - $expenditurePrice
  11045. // );
  11046. // if($expenditureMsg!='个人(GR)'){
  11047. // if ($expenditureBank == '个人广发') {
  11048. // $itemWaste = array (
  11049. // 'accountPrice' => $expenditurePrice
  11050. // );
  11051. // }
  11052. // }
  11053. // $itemWaste += array (
  11054. // 'expensesType' => 2,
  11055. // 'accountType' => 5,
  11056. // 'dailyExpenditureType' => $expenditureType,
  11057. // 'accountPriceShow' => $expenditurePrice,
  11058. // 'accountPrice' => - $expenditurePrice,
  11059. // 'dataID' => $expenditureId,
  11060. // 'accountBank' => $accountBank,
  11061. // 'category' => $this->staff [0] ['category'],
  11062. // 'cid' => $this->staff [0] ['cid'],
  11063. // 'name' => $this->staff [0] ['username'],
  11064. // 'sid' => $this->staff [0] ['sid'],
  11065. // 'inputDate' => date ( "Y-m-d H:i:s" )
  11066. // );
  11067. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  11068. // // 添加一笔理财收入
  11069. // $accountBank = 'CGBDeposit';
  11070. // $dailyIncomeType = 7;
  11071. // $receivedBank = '纵横广发';
  11072. // if ($expenditureType == 6) {
  11073. // $accountBank = 'ICBCDeposit';
  11074. // $receivedBank = '纵横工行';
  11075. // $dailyIncomeType = 9;
  11076. // }elseif($expenditureMsg=='个人(GR)'){
  11077. // $receivedBank = '个人广发';
  11078. // }
  11079. // $accountBook = new accountBook ();
  11080. // $accountBook->expensesType = 1;
  11081. // $accountBook->accountType = $dailyIncomeType;
  11082. // $accountBook->accountMsg = $expenditureMsg;
  11083. // $accountBook->receivedPrice = $expenditurePrice;
  11084. // $accountBook->receivedBank = $receivedBank;
  11085. // $accountBook->receivedDate = $expenditureDate;
  11086. // $accountBook->remarks = $remarks;
  11087. // $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11088. // $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11089. // $accountBook->inputStaff = $this->staff [0] ['sid'];
  11090. // $id = $accountBook->insert ();
  11091. // // 添加日常理财收入汇总
  11092. // $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  11093. // $accountBookStatistics = new accountBookStatistics ();
  11094. // $item = array (
  11095. // 'date' => date ( "Y-m-d" ),
  11096. // 'expenditureType' => $abDetail ['expenditureType'],
  11097. // 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11098. // 'aid' => $abDetail ['aid'],
  11099. // 'financingPrice' => $expenditurePrice,
  11100. // 'expensesType' => 3
  11101. // );
  11102. // $accountBookStatistics->setAccountBookStatistics ( $item );
  11103. // //TODO 修改理财收入 添加一笔收入流水
  11104. // if ($expenditureMsg == '公司固定') {
  11105. // $accountTypeWaste = 9;
  11106. // } elseif ($expenditureMsg == '公司活期') {
  11107. // $accountTypeWaste = 10;
  11108. // } elseif ($expenditureMsg == '个人(GR)') {
  11109. // $accountTypeWaste = 9;
  11110. // $accountBank = 'ICBCDeposit';
  11111. // }
  11112. // $itemWaste = array (
  11113. // 'expensesType' => 1,
  11114. // 'accountType' => $accountTypeWaste,
  11115. // 'accountPriceShow' => $expenditurePrice,
  11116. // 'accountPrice' => $expenditurePrice,
  11117. // 'dataID' => $id,
  11118. // 'dailyIncomeType' => $dailyIncomeType,
  11119. // 'accountBank' => $accountBank,
  11120. // 'category' => $this->staff [0] ['category'],
  11121. // 'cid' => $this->staff [0] ['cid'],
  11122. // 'name' => $this->staff [0] ['username'],
  11123. // 'sid' => $this->staff [0] ['sid'],
  11124. // 'inputDate' => date ( "Y-m-d H:i:s" )
  11125. // );
  11126. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  11127. } else {
  11128. // 添加一笔日常支出
  11129. $accountBook = new accountBook ();
  11130. $accountBook->expensesType = 2;
  11131. $accountBook->expenditureType = $expenditureType;
  11132. $accountBook->expenditureMsg = $expenditureMsg;
  11133. $accountBook->expenditurePrice = $expenditurePrice;
  11134. $accountBook->expenditureBank = $expenditureBank;
  11135. $accountBook->expenditureDate = $expenditureDate;
  11136. $accountBook->remarks = $remarks;
  11137. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11138. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11139. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11140. $id = $accountBook->insert ();
  11141. // 添加日常支出汇总
  11142. $abDetail = $accountBook->getAccountBookByAid ( $id );
  11143. $accountBookStatistics = new accountBookStatistics ();
  11144. $item = array (
  11145. 'date' => date ( "Y-m-d" ),
  11146. 'expenditureType' => $abDetail ['expenditureType'],
  11147. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11148. 'aid' => $abDetail ['aid'],
  11149. 'expensesType' => $abDetail ['expensesType']
  11150. );
  11151. if ($expenditureType == 5) {
  11152. $item += array (
  11153. 'payPrice' => - $abDetail ['expenditurePrice']
  11154. );
  11155. } else {
  11156. $item += array (
  11157. 'payPrice' => $abDetail ['expenditurePrice']
  11158. );
  11159. }
  11160. $accountBookStatistics->setAccountBookStatistics ( $item );
  11161. // 公司日常支出流水
  11162. $wasteBook = new wasteBook ();
  11163. $itemWaste = array (
  11164. 'accountPrice' => - $expenditurePrice
  11165. );
  11166. if ($expenditureBank == '个人广发') {
  11167. $itemWaste = array (
  11168. 'accountPrice' => $expenditurePrice
  11169. );
  11170. }
  11171. $itemWaste += array (
  11172. 'expensesType' => 2,
  11173. 'accountType' => 5,
  11174. 'accountPriceShow' => $expenditurePrice,
  11175. 'dataID' => $id,
  11176. 'dailyExpenditureType' => $expenditureType,
  11177. 'accountBank' => $accountBank,
  11178. 'category' => $this->staff [0] ['category'],
  11179. 'cid' => $this->staff [0] ['cid'],
  11180. 'name' => $this->staff [0] ['username'],
  11181. 'sid' => $this->staff [0] ['sid'],
  11182. 'inputDate' => date ( "Y-m-d H:i:s" )
  11183. );
  11184. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11185. }
  11186. }
  11187. return '/payments';
  11188. }
  11189. /**
  11190. * 添加支出
  11191. */
  11192. function paymentsExpenditureDo_() {
  11193. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11194. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11195. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11196. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11197. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11198. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11199. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11200. $dailyExpenditureType = '';
  11201. $accountTypeWaste = 5;
  11202. $accountBank = '';
  11203. if ($expenditureBank == '纵横广发') {
  11204. $accountBank = 'CGBDeposit';
  11205. } elseif ($expenditureBank == '纵横工行') {
  11206. $accountBank = 'ICBCDeposit';
  11207. } elseif ($expenditureBank == '华润银行') {
  11208. $accountBank = 'HUADeposit';
  11209. } elseif ($expenditureBank == '个人广发') {
  11210. $accountBank = 'PersonalDeposit';
  11211. }
  11212. if (empty ( $accountBank ))
  11213. die ( 'illegal request' );
  11214. $itemWaste = array (
  11215. 'accountPrice' => - $expenditurePrice
  11216. );
  11217. if ($expenditureBank == '个人广发') {
  11218. $itemWaste = array (
  11219. 'accountPrice' => $expenditurePrice
  11220. );
  11221. }
  11222. if ($expenditureType == 4 || $expenditureType == 6) {
  11223. $dailyExpenditureType = 4;
  11224. if ($expenditureMsg == '公司固定') {
  11225. $accountTypeWaste = 9;
  11226. } elseif ($expenditureMsg == '公司活期') {
  11227. $accountTypeWaste = 10;
  11228. } elseif ($expenditureMsg == '个人(GR)') {
  11229. $accountBank = 'PersonalDeposit';
  11230. }
  11231. $itemWaste = array (
  11232. 'accountPrice' => $expenditurePrice
  11233. );
  11234. } elseif ($expenditureType == 1) {
  11235. $dailyExpenditureType = 1;
  11236. } elseif ($expenditureType == 2) {
  11237. $dailyExpenditureType = 2;
  11238. } elseif ($expenditureType == 3) {
  11239. $dailyExpenditureType = 3;
  11240. } elseif ($expenditureType == 5) {
  11241. $dailyExpenditureType = 5;
  11242. }
  11243. if (empty ( $dailyExpenditureType ))
  11244. die ( 'illegal request' );
  11245. Doo::loadModel ( "accountBook" );
  11246. $accountBook = new accountBook ();
  11247. $accountBook->expenditureType = $expenditureType;
  11248. $accountBook->expenditureMsg = $expenditureMsg;
  11249. $accountBook->expenditurePrice = $expenditurePrice;
  11250. $accountBook->expenditureBank = $expenditureBank;
  11251. $accountBook->expenditureDate = $expenditureDate;
  11252. $accountBook->remarks = $remarks;
  11253. $accountBook->expensesType = 2;
  11254. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11255. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11256. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11257. $id = $accountBook->insert ();
  11258. //
  11259. $abDetail = $accountBook->getAccountBookByAid ( $id );
  11260. Doo::loadModel ( "accountBookStatistics" );
  11261. $accountBookStatistics = new accountBookStatistics ();
  11262. $item = array (
  11263. 'date' => date ( "Y-m-d" ),
  11264. 'expenditureType' => $abDetail ['expenditureType'],
  11265. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11266. 'aid' => $abDetail ['aid']
  11267. );
  11268. if ($abDetail ['expensesType'] == 2) {
  11269. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  11270. $item += array (
  11271. 'financingPrice' => $expenditurePrice,
  11272. 'expensesType' => 3
  11273. );
  11274. } elseif ($abDetail ['expenditureType'] == 5) {
  11275. $item += array (
  11276. 'payPrice' => $abDetail ['expenditurePrice'],
  11277. 'expensesType' => $abDetail ['expensesType']
  11278. );
  11279. } else {
  11280. $item += array (
  11281. 'payPrice' => $abDetail ['expenditurePrice'],
  11282. 'expensesType' => $abDetail ['expensesType']
  11283. );
  11284. }
  11285. }
  11286. $accountBookStatistics->setAccountBookStatistics ( $item );
  11287. // 公司流水记录
  11288. Doo::loadModel ( 'wasteBook' );
  11289. $wasteBook = new wasteBook ();
  11290. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  11291. // 银行
  11292. if (empty ( $abDetail )) {
  11293. $itemWaste += array (
  11294. 'accountPriceShow' => $expenditurePrice,
  11295. 'dataID' => $id,
  11296. 'expensesType' => 2,
  11297. 'accountType' => $accountTypeWaste,
  11298. 'dailyExpenditureType' => $expenditureType,
  11299. 'accountBank' => $accountBank,
  11300. 'category' => $this->staff [0] ['category'],
  11301. 'cid' => $this->staff [0] ['cid'],
  11302. 'name' => $this->staff [0] ['username'],
  11303. 'sid' => $this->staff [0] ['sid'],
  11304. 'inputDate' => date ( "Y-m-d H:i:s" )
  11305. );
  11306. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11307. }
  11308. // 支出类型为4或者6 需要添加一笔收入和收入流水
  11309. if ($expenditureType == 4 || $expenditureType == 6) {
  11310. $accountBank = 'CGBDeposit';
  11311. $dailyIncomeType = 7;
  11312. $receivedBank = '纵横广发';
  11313. if ($expenditureType == 6) {
  11314. $accountBank = 'ICBCDeposit';
  11315. $receivedBank = '纵横工行';
  11316. $dailyIncomeType = 9;
  11317. }
  11318. // 添加一笔收入
  11319. $accountBook = new accountBook ();
  11320. $accountBook->accountType = $dailyIncomeType;
  11321. $accountBook->accountMsg = $expenditureMsg;
  11322. $accountBook->receivedPrice = $expenditurePrice;
  11323. $accountBook->receivedBank = $receivedBank;
  11324. $accountBook->receivedDate = $expenditureDate;
  11325. $accountBook->remarks = $remarks;
  11326. $accountBook->expensesType = 1;
  11327. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11328. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11329. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11330. $id = $accountBook->insert ();
  11331. // 添加一笔收入流水
  11332. $itemWaste = array (
  11333. 'accountPriceShow' => $expenditurePrice,
  11334. 'accountPrice' => - $expenditurePrice,
  11335. 'dataID' => $id,
  11336. 'expensesType' => 1,
  11337. 'accountType' => $accountTypeWaste,
  11338. 'dailyIncomeType' => $dailyIncomeType,
  11339. 'accountBank' => $accountBank,
  11340. 'category' => $this->staff [0] ['category'],
  11341. 'cid' => $this->staff [0] ['cid'],
  11342. 'name' => $this->staff [0] ['username'],
  11343. 'sid' => $this->staff [0] ['sid'],
  11344. 'inputDate' => date ( "Y-m-d H:i:s" )
  11345. );
  11346. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11347. }
  11348. }
  11349. return '/payments';
  11350. }
  11351. /**
  11352. * 所有收支
  11353. */
  11354. function paymentsAchieve() {
  11355. $page_size = 12;
  11356. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  11357. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  11358. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11359. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  11360. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11361. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11362. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11363. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  11364. Doo::loadModel ( "accountBookStatistics" );
  11365. $accountBookStatistics = new accountBookStatistics ();
  11366. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  11367. $data ['statisticsList'] = $statisticsList;
  11368. Doo::loadModel ( "accountBook" );
  11369. $accountBook = new accountBook ();
  11370. $con = '';
  11371. if ($expensesType == 'INCOME')
  11372. $con = ' and expensesType=1 ';
  11373. elseif ($expensesType == 'PAY')
  11374. $con = ' and expensesType=2 ';
  11375. $dateArr = explode ( ':', $date );
  11376. $D1 = $dateString = '';
  11377. $D2 = '';
  11378. if (! empty ( $date )) {
  11379. $D1 = $dateArr [0];
  11380. if (isset ( $dateArr [1] ))
  11381. $D2 = $dateArr [1];
  11382. else
  11383. $D2 = '';
  11384. $dateString = $D1 . " : " . $D2;
  11385. }
  11386. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11387. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11388. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11389. $con .= ' and inputDate like "%' . $D1 . '%" ';
  11390. if (! empty ( $price ))
  11391. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  11392. if ($submitType == 1) {
  11393. if ($accountType != '') {
  11394. $expenditureType = '';
  11395. $con .= ' and accountType=' . $accountType;
  11396. if (! empty ( $accountMsg ))
  11397. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  11398. }
  11399. } elseif ($submitType == 2) {
  11400. if ($expenditureType != '') {
  11401. $accountType = $accountMsg = '';
  11402. $con .= ' and expenditureType=' . $expenditureType;
  11403. }
  11404. } else {
  11405. $accountType = $accountMsg = $expenditureType = '';
  11406. }
  11407. $sql = "" . $con;
  11408. $action = "paymentsAchieve";
  11409. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  11410. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  11411. $limit = $pageinfo ['lower'] . ',' . $page_size;
  11412. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  11413. $data ['expenditureType'] = $expenditureType;
  11414. $data ['accountMsg'] = $accountMsg;
  11415. $data ['accountType'] = $accountType;
  11416. $data ['inputDate'] = $date;
  11417. $data ['price'] = $price;
  11418. $data ['expensesType'] = $expensesType;
  11419. $data ['page'] = $pageinfo;
  11420. $data ['list'] = $list;
  11421. $data ['memu'] = "receipt";
  11422. $data ['staff'] = $this->staff;
  11423. $data ['receiptMemu'] = 'payments';
  11424. $data ['verifyId'] = $this->verifyId;
  11425. $data ['executeId'] = $this->executeId;
  11426. $this->render ( "/expenses/paymentsAchieve", $data );
  11427. }
  11428. function paymentsIncomeUpdateDo() {
  11429. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11430. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11431. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11432. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  11433. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  11434. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  11435. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  11436. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11437. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  11438. Doo::loadClass ( 'XDeode' );
  11439. $XDeode = new XDeode ( 5 );
  11440. $aid = $XDeode->decode ( $aidKey );
  11441. Doo::loadModel ( "accountBook" );
  11442. $accountBook = new accountBook ();
  11443. //
  11444. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11445. $price = $receivedPrice - $abDetail [inComePrice];
  11446. Doo::loadModel ( "accountBookStatistics" );
  11447. $accountBookStatistics = new accountBookStatistics ();
  11448. if ($abDetail ['accountType'] == 7) {
  11449. $item += array (
  11450. 'date' => date ( "Y-m-d" ),
  11451. 'financingPrice' => - $price,
  11452. 'expensesType' => 3,
  11453. 'aid' => $abDetail ['aid']
  11454. );
  11455. } elseif ($abDetail ['accountType'] == 8) {
  11456. $item += array (
  11457. 'date' => date ( "Y-m-d" ),
  11458. 'expensesType' => $abDetail ['expensesType'],
  11459. 'inComePrice' => - $price,
  11460. 'aid' => $abDetail ['aid']
  11461. );
  11462. } else {
  11463. $item = array (
  11464. 'date' => date ( "Y-m-d" ),
  11465. 'expensesType' => $abDetail ['expensesType'],
  11466. 'inComePrice' => $price,
  11467. 'aid' => $abDetail ['aid']
  11468. );
  11469. }
  11470. $accountBookStatistics->setAccountBookStatistics ( $item );
  11471. $accountBook->accountType = $accountType;
  11472. $accountBook->accountMsg = $accountMsg;
  11473. $accountBook->receivedPrice = $receivedPrice;
  11474. $accountBook->receivedMsg = $receivedMsg;
  11475. $accountBook->receivedBank = $receivedBank;
  11476. $accountBook->receivedDate = $receivedDate;
  11477. $accountBook->remarks = $remarks;
  11478. $accountBook->aid = $aid;
  11479. $accountBook->update ();
  11480. }
  11481. return '/paymentsAchieve';
  11482. }
  11483. function paymentsExpenditureEdiDo() {
  11484. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11485. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11486. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11487. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11488. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11489. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11490. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11491. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11492. Doo::loadClass ( 'XDeode' );
  11493. $XDeode = new XDeode ( 5 );
  11494. $aid = $XDeode->decode ( $aidKey );
  11495. Doo::loadModel ( "accountBook" );
  11496. $accountBook = new accountBook ();
  11497. // 汇总信息
  11498. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11499. $price = $expenditurePrice - $abDetail [expenditurePrice];
  11500. Doo::loadModel ( "accountBookStatistics" );
  11501. $accountBookStatistics = new accountBookStatistics ();
  11502. if ($abDetail ['expenditureType'] == 4) {
  11503. $item += array (
  11504. 'date' => date ( "Y-m-d" ),
  11505. 'financingPrice' => $price,
  11506. 'expensesType' => 3,
  11507. 'aid' => $abDetail ['aid']
  11508. );
  11509. } elseif ($abDetail ['expenditureType'] == 5) {
  11510. $item += array (
  11511. 'date' => date ( "Y-m-d" ),
  11512. 'expensesType' => $abDetail ['expensesType'],
  11513. 'payPrice' => $price,
  11514. 'aid' => $abDetail ['aid']
  11515. );
  11516. } else {
  11517. $item = array (
  11518. 'date' => date ( "Y-m-d" ),
  11519. 'expensesType' => $abDetail ['expensesType'],
  11520. 'payPrice' => $price,
  11521. 'aid' => $abDetail ['aid']
  11522. );
  11523. }
  11524. $accountBookStatistics->setAccountBookStatistics ( $item );
  11525. //
  11526. $accountBook->expenditureType = $expenditureType;
  11527. $accountBook->expenditureMsg = $expenditureMsg;
  11528. $accountBook->expenditurePrice = $expenditurePrice;
  11529. $accountBook->expenditureBank = $expenditureBank;
  11530. $accountBook->remarks = $remarks;
  11531. $accountBook->expenditureDate = $expenditureDate;
  11532. $accountBook->aid = $aid;
  11533. $id = $accountBook->update ();
  11534. }
  11535. return '/paymentsAchieve';
  11536. }
  11537. function paymentsDelDo() {
  11538. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11539. if (! empty ( $aidKey )) {
  11540. Doo::loadClass ( 'XDeode' );
  11541. $XDeode = new XDeode ( 5 );
  11542. $aid = $XDeode->decode ( $aidKey );
  11543. Doo::loadModel ( "accountBook" );
  11544. $accountBook = new accountBook ();
  11545. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11546. if (empty ( $abDetail ))
  11547. die ( 'illegal request' );
  11548. // 删除收支
  11549. Doo::loadModel ( "accountBookStatistics" );
  11550. $accountBookStatistics = new accountBookStatistics ();
  11551. $item = array (
  11552. 'date' => date ( "Y-m-d" ),
  11553. 'aid' => $abDetail ['aid']
  11554. );
  11555. $accountType = '';
  11556. if ($abDetail ['expensesType'] == 1) {
  11557. $accountType = 6;
  11558. if ($abDetail ['accountType'] != 7) {
  11559. $item += array (
  11560. 'expensesType' => $abDetail ['expensesType'],
  11561. 'inComePrice' => - $abDetail ['receivedPrice']
  11562. );
  11563. } else {
  11564. $item += array (
  11565. 'financingPrice' => $abDetail ['receivedPrice'],
  11566. 'expensesType' => 3
  11567. );
  11568. }
  11569. } elseif ($abDetail ['expensesType'] == 2) {
  11570. $accountType = 5;
  11571. if ($abDetail ['accountType'] != 7) {
  11572. $item += array (
  11573. 'expensesType' => $abDetail ['expensesType'],
  11574. 'payPrice' => - $abDetail ['expenditurePrice']
  11575. );
  11576. } else {
  11577. $item += array (
  11578. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11579. 'expensesType' => 3
  11580. );
  11581. }
  11582. }
  11583. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11584. if ($abDetail ['expenditureMsg'] == '公司固定')
  11585. $accountType = 9;
  11586. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11587. $accountType = 10;
  11588. }
  11589. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11590. if ($abDetail ['accountMsg'] == '公司固定')
  11591. $accountType = 9;
  11592. elseif ($abDetail ['accountMsg'] == '公司活期')
  11593. $accountType = 10;
  11594. }
  11595. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11596. $accountType = 10;
  11597. }
  11598. $accountBookStatistics->setAccountBookStatistics ( $item );
  11599. $accountBook->delete ( array (
  11600. 'where' => 'aid=' . $aid,
  11601. 'limit' => 1
  11602. ) );
  11603. // 删除收入流水
  11604. //TODO 2020-07-23 删除新增理财和银行存款流水
  11605. if (! empty ( $accountType )) {
  11606. Doo::loadModel ( 'wasteBook' );
  11607. $wasteBook = new wasteBook ();
  11608. $wasteBook->delete ( array (
  11609. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11610. 'limit' => 1
  11611. ) );
  11612. }
  11613. }
  11614. return '/paymentsAchieve';
  11615. }
  11616. function paymentsCollect() {
  11617. Doo::loadModel ( "execute" );
  11618. $execute = new execute ();
  11619. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11620. die ( 'illegal request' );
  11621. }
  11622. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11623. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11624. Doo::loadModel ( "accountBookStatistics" );
  11625. $accountBookStatistics = new accountBookStatistics ();
  11626. Doo::loadClass ( 'receipt.func' );
  11627. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11628. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11629. $data ['html'] = $html ['html'];
  11630. $data ['inSum'] = $html ['sum'];
  11631. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11632. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11633. $data ['payHtml'] = $html ['html'];
  11634. $data ['paySum'] = $html ['sum'];
  11635. // 余额统计
  11636. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11637. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11638. include './protected/config/wasteBook.conf.php';
  11639. Doo::loadModel ( 'wasteBook' );
  11640. $wasteBook = new wasteBook ();
  11641. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11642. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11643. // 获得年份之前所有金额
  11644. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11645. // print_r($detail);
  11646. // $waste['total'];
  11647. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11648. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11649. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11650. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11651. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11652. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11653. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11654. if (date ( 'Y' ) > $year) {
  11655. $limitMonth = 12;
  11656. }
  11657. for($i = 1; $i <= 12; $i ++) {
  11658. $inComeA = $payB = 0;
  11659. $falg = true;
  11660. foreach ( $inComePay as $key => $value ) {
  11661. if ($value ['month'] == $i) {
  11662. $falg = false;
  11663. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11664. $inSum += $value ['accountPrice'];
  11665. $showInSum += $value ['accountPriceShow'];
  11666. $inComeA = $value ['accountPrice'];
  11667. break;
  11668. }
  11669. }
  11670. if ($falg)
  11671. $inComeHtml .= '<td class="taR">-</td>';
  11672. $payFalg = true;
  11673. foreach ( $pay as $key => $value ) {
  11674. if ($value ['month'] == $i) {
  11675. $payFalg = false;
  11676. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11677. $paySum += $value ['accountPrice'];
  11678. $showPaySum += $value ['accountPriceShow'];
  11679. $payB = $value ['accountPrice'];
  11680. break;
  11681. }
  11682. }
  11683. if ($payFalg)
  11684. $payHtml .= '<td class="taR">-</td>';
  11685. if (empty ( $balanceC ) || $limitMonth < $i)
  11686. $lastBalanceHtml .= '<td class="taR">-</td>';
  11687. else
  11688. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11689. $balanceC = $balanceC + $inComeA + $payB;
  11690. $balanceSum += $balanceC;
  11691. if (empty ( $balanceC ) || $limitMonth < $i)
  11692. $BalanceHtml .= '<td class="taR">-</td>';
  11693. else
  11694. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11695. // 余额统计
  11696. }
  11697. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11698. $data ['inComeHtml'] = $inComeHtml;
  11699. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11700. $data ['payBalanceHtml'] = $payHtml;
  11701. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11702. $data ['BalanceHtml'] = $BalanceHtml;
  11703. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11704. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11705. $mothHtml = "";
  11706. for($i = 1; $i <= 12; $i ++) {
  11707. if ($moth == $i)
  11708. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11709. else
  11710. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11711. }
  11712. $data ['mothHtml'] = $mothHtml;
  11713. $dateHtml = "";
  11714. $now = date ( "Y" );
  11715. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11716. if ($YEARD <= $now) {
  11717. $dateHtml .= '<option ';
  11718. if ($year == $YEARD) {
  11719. $dateHtml .= 'selected ';
  11720. }
  11721. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11722. }
  11723. }
  11724. $data ['dateHtml'] = $dateHtml;
  11725. $data ['year'] = $year;
  11726. $data ['memu'] = "receipt";
  11727. $data ['staff'] = $this->staff;
  11728. $data ['receiptMemu'] = 'paymentsCollect';
  11729. $data ['verifyId'] = $this->verifyId;
  11730. $data ['executeId'] = $this->executeId;
  11731. $this->render ( "/expenses/paymentsCollect", $data );
  11732. }
  11733. function paymentsCollectDay() {
  11734. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11735. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11736. if (empty ( $moth ))
  11737. return 'paymentsCollect';
  11738. Doo::loadModel ( "accountBookStatistics" );
  11739. $accountBookStatistics = new accountBookStatistics ();
  11740. $i = 2;
  11741. $y = 2013;
  11742. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11743. Doo::loadClass ( 'receipt.func' );
  11744. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11745. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11746. $data ['html'] = $html ['html'];
  11747. $data ['inSum'] = $html ['sum'];
  11748. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11749. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11750. $data ['payHtml'] = $html ['html'];
  11751. $data ['paySum'] = $html ['sum'];
  11752. $mothHtml = "";
  11753. for($i = 1; $i <= 12; $i ++) {
  11754. if ($moth == $i)
  11755. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11756. else
  11757. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11758. }
  11759. $data ['mothHtml'] = $mothHtml;
  11760. $data ['year'] = $year;
  11761. // 余额
  11762. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11763. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11764. include './protected/config/wasteBook.conf.php';
  11765. Doo::loadModel ( 'wasteBook' );
  11766. $wasteBook = new wasteBook ();
  11767. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11768. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11769. // 获得年份之前所有金额
  11770. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11771. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11772. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11773. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11774. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11775. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11776. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11777. // $balanceC = 0;
  11778. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11779. $limitDay = date ( 'd' );
  11780. $monthLK = ( int ) date ( 'm' );
  11781. if (date ( 'Y' ) > $year) {
  11782. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11783. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11784. $limitDay = 0;
  11785. }
  11786. for($i = 1; $i <= $day; $i ++) {
  11787. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11788. $inComeA = $payB = 0;
  11789. $falg = true;
  11790. foreach ( $inComePay as $key => $value ) {
  11791. if ($value ['day'] == $i) {
  11792. $falg = false;
  11793. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11794. $inSum += $value ['accountPrice'];
  11795. $showInSum += $value ['accountPriceShow'];
  11796. $inComeA = $value ['accountPrice'];
  11797. break;
  11798. }
  11799. }
  11800. if ($falg)
  11801. $inComeHtml .= '<td class="taR">-</td>';
  11802. $payFalg = true;
  11803. foreach ( $pay as $key => $value ) {
  11804. if ($value ['day'] == $i) {
  11805. $payFalg = false;
  11806. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11807. $paySum += $value ['accountPrice'];
  11808. $showPaySum += $value ['accountPriceShow'];
  11809. $payB = $value ['accountPrice'];
  11810. break;
  11811. }
  11812. }
  11813. if ($payFalg)
  11814. $payHtml .= '<td class="taR">-</td>';
  11815. if (empty ( $balanceC ) || $limitDay < $i)
  11816. $lastBalanceHtml .= '<td class="taR">-</td>';
  11817. else
  11818. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11819. $balanceC = $balanceC + $inComeA + $payB;
  11820. $balanceSum += $balanceC;
  11821. if (empty ( $balanceC ) || $limitDay < $i)
  11822. $BalanceHtml .= '<td class="taR">-</td>';
  11823. else
  11824. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11825. }
  11826. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11827. $data ['inComeHtml'] = $inComeHtml;
  11828. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11829. $data ['payBalanceHtml'] = $payHtml;
  11830. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11831. $data ['BalanceHtml'] = $BalanceHtml;
  11832. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11833. $data ['dayHtml'] = $dayHtml;
  11834. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11835. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11836. $dateHtml = "";
  11837. $now = date ( "Y" );
  11838. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11839. if ($YEARD <= $now) {
  11840. $dateHtml .= '<option ';
  11841. if ($year == $YEARD) {
  11842. $dateHtml .= 'selected ';
  11843. }
  11844. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11845. }
  11846. }
  11847. $data ['dateHtml'] = $dateHtml;
  11848. $data ['memu'] = "receipt";
  11849. $data ['staff'] = $this->staff;
  11850. $data ['receiptMemu'] = 'paymentsCollect';
  11851. $data ['verifyId'] = $this->verifyId;
  11852. $data ['executeId'] = $this->executeId;
  11853. $this->render ( "/expenses/paymentsCollectDay", $data );
  11854. }
  11855. // 公司流水
  11856. function wasteBook() {
  11857. Doo::loadModel ( "execute" );
  11858. $execute = new execute ();
  11859. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11860. die ( 'illegal request' );
  11861. }
  11862. include './protected/config/wasteBook.conf.php';
  11863. Doo::loadModel ( 'wasteBook' );
  11864. $wasteBook = new wasteBook ();
  11865. $data ['store']=$waste;
  11866. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11867. //print_r($waste);
  11868. //1-收入支出流水金额合计
  11869. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11870. //echo $waste['bank']['CGBDeposit'].'</br>';
  11871. //2020-07-20 -理财相关-面板数据
  11872. Doo::loadClass ( 'wasteBook.finances.func' );
  11873. $financesStatistics=$wasteBook->getFinancesStatistics();
  11874. //print_r($waste);
  11875. // 展示使用
  11876. //收入
  11877. //print_r($inComeStatistics);
  11878. $wasteStatistics['CGBDeposit']=0;
  11879. $wasteStatistics['ICBCDeposit']=0;
  11880. $wasteStatistics['HUADeposit']=0;
  11881. $wasteStatistics['PersonalDeposit']=0;
  11882. foreach ($inComeStatistics['incomeStatistics'] as $value ){
  11883. if($value['accountBank']=='CGBDeposit'){
  11884. $wasteStatistics['CGBDeposit']+=$value['accountPrice'];
  11885. }
  11886. if($value['accountBank']=='ICBCDeposit'){
  11887. $wasteStatistics['ICBCDeposit']+=$value['accountPrice'];
  11888. }
  11889. if($value['accountBank']=='HUADeposit'){
  11890. $wasteStatistics['HUADeposit']+=$value['accountPrice'];
  11891. }
  11892. if($value['accountBank']=='PersonalDeposit'){
  11893. $wasteStatistics['PersonalDeposit']+=$value['accountPrice'];
  11894. }
  11895. }
  11896. $data ['wasteStatistics']=$wasteStatistics;
  11897. //支出
  11898. $wasteStatistics['CGBDeposit']=0;
  11899. $wasteStatistics['ICBCDeposit']=0;
  11900. $wasteStatistics['HUADeposit']=0;
  11901. $wasteStatistics['PersonalDeposit']=0;
  11902. foreach ($inComeStatistics['expenditureStatistics'] as $value ){
  11903. if($value['accountBank']=='CGBDeposit'){
  11904. $wasteStatistics['CGBDeposit']+=$value['accountPrice'];
  11905. }
  11906. if($value['accountBank']=='ICBCDeposit'){
  11907. $wasteStatistics['ICBCDeposit']+=$value['accountPrice'];
  11908. }
  11909. if($value['accountBank']=='HUADeposit'){
  11910. $wasteStatistics['HUADeposit']+=$value['accountPrice'];
  11911. }
  11912. if($value['accountBank']=='PersonalDeposit'){
  11913. $wasteStatistics['PersonalDeposit']+=$value['accountPrice'];
  11914. }
  11915. }
  11916. $data ['wastePay']=$wasteStatistics;
  11917. //理财公司账号部分
  11918. $wasteStatistics['CGBDeposit']=0;
  11919. $wasteStatistics['ICBCDeposit']=0;
  11920. $wasteStatistics['HUADeposit']=0;
  11921. $wasteStatistics['PersonalDeposit']=0;
  11922. foreach ($financesStatistics['companyAccount'] as $value ){
  11923. //(纵横广发)广发存款
  11924. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'CGBDeposit') {
  11925. $wasteStatistics['CGBDeposit']+=$value['accountPrice'];
  11926. }
  11927. //工行存款
  11928. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'ICBCDeposit') {
  11929. $wasteStatistics['ICBCDeposit']+=$value['accountPrice'];
  11930. }
  11931. //个人存款
  11932. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'PersonalDeposit') {
  11933. $wasteStatistics['PersonalDeposit']+=$value['accountPrice'];
  11934. }
  11935. }
  11936. $data ['wasteCompanyAccount']=$wasteStatistics;
  11937. //理财部分的金额计算
  11938. $waste =_getFinancesWBS ( $waste, $financesStatistics );
  11939. //echo $waste['bank']['CGBDeposit'].'</br>';;
  11940. //存款面板数据--日常收支改变后的金额汇总
  11941. $bankSavingsStatistics=$wasteBook->getBankSavingsStatistics();
  11942. $waste =_getBankSavingsWBS ( $waste, $bankSavingsStatistics );
  11943. //展示调试BUG-使用
  11944. //print_r($bankSavingsStatistics);
  11945. $wasteStatistics['CGBDeposit']=0;
  11946. $wasteStatistics['ICBCDeposit']=0;
  11947. $wasteStatistics['PersonalDeposit']=0;
  11948. foreach ($bankSavingsStatistics as $value ){
  11949. //(纵横广发)广发存款
  11950. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'CGBDeposit') {
  11951. $wasteStatistics['CGBDeposit']+=$value['accountPrice'];
  11952. }
  11953. //工行存款
  11954. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'ICBCDeposit') {
  11955. $wasteStatistics['ICBCDeposit']+=$value['accountPrice'];
  11956. }
  11957. //个人存款
  11958. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'PersonalDeposit') {
  11959. $wasteStatistics['PersonalDeposit']+=$value['accountPrice'];
  11960. }
  11961. }
  11962. $data ['wasteNewPay']=$wasteStatistics;
  11963. //echo $waste['bank']['CGBDeposit'].'</br>';;
  11964. //
  11965. $total = $waste ['bank'] ['CGBDeposit'] + $waste ['bank'] ['ICBCDeposit']+ $waste ['bank'] ['HUADeposit'] + $waste ['bank'] ['PersonalDeposit'] + $waste ['financial'] ['current'] ['CGBDeposit'] + $waste ['financial'] ['current'] ['ICBCDeposit'] + $waste ['financial'] ['fixed'] ['CGBDeposit'] + $waste ['financial'] ['fixed'] ['ICBCDeposit'];
  11966. $CGBDeposit_total =$waste ['bank'] ['CGBDeposit']+$waste ['bank'] ['HUADeposit'];
  11967. //$waste ['bank'] ['ICBCDeposit']=sprintf("%.2f", round($waste ['bank'] ['ICBCDeposit'], 2));
  11968. // print_r($waste);
  11969. $data ['total'] = number_format($total,2);
  11970. $data ['CGBDeposit_total'] = number_format($CGBDeposit_total,2);
  11971. $cashBalance=$CGBDeposit_total+$waste ['bank'] ['ICBCDeposit']+$waste ['bank'] ['PersonalDeposit']+$waste ['financial'] ['current'] ['CGBDeposit']+$waste ['financial'] ['current'] ['ICBCDeposit'];
  11972. $data['cashBalance']= number_format($cashBalance,2);
  11973. $waste ['bank'] ['CGBDeposit']=sprintf("%.2f", round($waste ['bank'] ['CGBDeposit'], 2));
  11974. $data ['waste'] = $waste;
  11975. // 月流水数据结构
  11976. $monthStatistics = array ();
  11977. $incomeMothStatistics = array ();
  11978. $expenditureMothStatistics = array ();
  11979. for($i = 1; $i <= 12; $i ++) {
  11980. $month = date ( 'Y' ) . '-' . $i;
  11981. if ($i < 10)
  11982. $month = date ( 'Y' ) . '-0' . $i;
  11983. array_push ( $monthStatistics, $month );
  11984. }
  11985. foreach ( $monthStatistics as $value ) {
  11986. $falg = true;
  11987. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11988. if ($value == $v ['inputDate']) {
  11989. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11990. $falg = false;
  11991. }
  11992. }
  11993. if ($falg) {
  11994. array_push ( $incomeMothStatistics, '' );
  11995. }
  11996. $falgEx = true;
  11997. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11998. if ($value == $v ['inputDate']) {
  11999. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  12000. $falg = false;
  12001. }
  12002. }
  12003. if ($falgEx) {
  12004. array_push ( $expenditureMothStatistics, '' );
  12005. }
  12006. }
  12007. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  12008. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  12009. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  12010. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  12011. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  12012. // print_r($incomeList);
  12013. $data ['expenditureList'] = $expenditureList;
  12014. $data ['incomeList'] = $incomeList;
  12015. $data ['memu'] = "receipt";
  12016. $data ['staff'] = $this->staff;
  12017. $data ['receiptMemu'] = 'wasteBook';
  12018. $data ['verifyId'] = $this->verifyId;
  12019. $data ['executeId'] = $this->executeId;
  12020. $this->render ( "/expenses/wasteBook", $data );
  12021. }
  12022. function wasteBookIncome() {
  12023. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  12024. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  12025. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  12026. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  12027. $data ['dailyIncomeType'] = $dailyIncomeType;
  12028. Doo::loadModel ( 'wasteBook' );
  12029. $wasteBook = new wasteBook ();
  12030. Doo::loadModel ( 'L_category' );
  12031. $L_category = new L_category ();
  12032. Doo::loadClass ( 'XDeode' );
  12033. $XDeode = new XDeode ( 5 );
  12034. $year=date("Y");
  12035. $theDay=date("Y-m-d");
  12036. $dateArr = explode ( ':', $date );
  12037. $D1 = '';
  12038. $D2 = '';
  12039. $con = '';
  12040. if (! empty ( $date )) {
  12041. $D1 = $dateArr [0];
  12042. $D2 = $dateArr [1];
  12043. }
  12044. if (! empty ( $D1 ) && ! empty ( $D2 ))
  12045. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  12046. elseif (! empty ( $D1 ) && empty ( $D2 ))
  12047. $con = ' and inputDate = "' . $D1 . '"';
  12048. else{
  12049. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  12050. }
  12051. if ($cid != 'ALL') {
  12052. $cid = $XDeode->decode ( $cid );
  12053. $con .= ' and cid = "' . $cid . '"';
  12054. }
  12055. if ($accountType != 'ALL') {
  12056. if ($accountType == 'INVOICE') {
  12057. $con .= ' and (accountType = 7 or accountType = 8)';
  12058. } elseif ($accountType == 'PAYMENTS') {
  12059. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  12060. if ($dailyIncomeType != 'ALL') {
  12061. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  12062. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  12063. }
  12064. }
  12065. }
  12066. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  12067. foreach ($incomeList as $key=>$value){
  12068. if(($value['accountType']==6||$value['accountType']==9||$value['accountType']==10)&&$value['synPaymentDate']==0){
  12069. $wasteBook = new wasteBook ();
  12070. $wasteBook->wid = $value['wid'];
  12071. $wasteBook->synPaymentDate = 1;
  12072. $wasteBook->inputDate = $value['data']['receivedDate'];
  12073. $wasteBook->update();
  12074. }
  12075. }
  12076. $sum = 0;$thsDaySum=0;
  12077. foreach ( $incomeList as $key => $value ) {
  12078. $sum += $value ['accountPrice'];
  12079. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  12080. $thsDaySum+=$value ['accountPrice'];
  12081. }
  12082. }
  12083. // print_r($incomeList);
  12084. // 获得办事和部门
  12085. $categoryList = $L_category->getCategory ();
  12086. $data ['accountType'] = $accountType;
  12087. $data ['cid'] = $cid;
  12088. $data ['categoryList'] = $categoryList;
  12089. $data ['sum'] = $sum;
  12090. $data ['incomeList'] = $incomeList;
  12091. $data ['inputDate'] = $date;
  12092. $data['year']=$year;
  12093. $data ['thsDay'] =$theDay;
  12094. $data ['thsDaySum'] =$thsDaySum;
  12095. $data ['memu'] = "receipt";
  12096. $data ['staff'] = $this->staff;
  12097. $data ['receiptMemu'] = 'wasteBook';
  12098. $data ['verifyId'] = $this->verifyId;
  12099. $data ['executeId'] = $this->executeId;
  12100. $this->render ( "/expenses/wasteBookIncome", $data );
  12101. }
  12102. /**
  12103. * 所有支出
  12104. */
  12105. function wasteBookExpenditure() {
  12106. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  12107. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  12108. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  12109. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  12110. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  12111. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  12112. $data ['receiptType'] = $receiptType;
  12113. Doo::loadModel ( 'wasteBook' );
  12114. $wasteBook = new wasteBook ();
  12115. Doo::loadModel ( 'L_category' );
  12116. $L_category = new L_category ();
  12117. Doo::loadClass ( 'XDeode' );
  12118. $XDeode = new XDeode ( 5 );
  12119. $year=date("Y");
  12120. $theDay=date("Y-m-d");
  12121. $dateArr = explode ( ':', $date );
  12122. $D1 = '';
  12123. $D2 = '';
  12124. $con = '';
  12125. if (! empty ( $date )) {
  12126. $D1 = $dateArr [0];
  12127. $D2 = $dateArr [1];
  12128. }
  12129. if (! empty ( $D1 ) && ! empty ( $D2 ))
  12130. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  12131. elseif (! empty ( $D1 ) && empty ( $D2 ))
  12132. $con = ' and inputDate = "' . $D1 . '"';
  12133. else{
  12134. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  12135. }
  12136. if ($cid != 'ALL') {
  12137. $cid = $XDeode->decode ( $cid );
  12138. $con .= ' and cid = "' . $cid . '"';
  12139. }
  12140. if ($accountType != 'ALL') {
  12141. if ($accountType == 'INVOICE') {
  12142. $con .= ' and accountType = 11';
  12143. } elseif ($accountType == 'PAYMENTS') {
  12144. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  12145. if ($dailyExpenditureType != 'ALL') {
  12146. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  12147. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  12148. }
  12149. } elseif ($accountType == 'RECEIPT') {
  12150. if ($receiptType == 'ALL') {
  12151. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  12152. } else {
  12153. $receiptType = $XDeode->decode ( $receiptType );
  12154. echo $receiptType;
  12155. if ($receiptType == 1) {
  12156. $con .= ' and (accountType = 1 or accountType=2)';
  12157. } else {
  12158. $con .= ' and accountType = ' . $receiptType;
  12159. }
  12160. }
  12161. }
  12162. }
  12163. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  12164. foreach ($incomeList as $key=>$value){
  12165. if(($value['accountType']==5||$value['accountType']==9||$value['accountType']==10)&&$value['synPaymentDate']==0){
  12166. $wasteBook = new wasteBook ();
  12167. $wasteBook->wid = $value['wid'];
  12168. $wasteBook->synPaymentDate = 1;
  12169. $wasteBook->inputDate = $value['data']['expenditureDate'];
  12170. $wasteBook->update();
  12171. }
  12172. }
  12173. $sum = 0;$thsDaySum=0;
  12174. foreach ( $incomeList as $key => $value ) {
  12175. $sum += $value ['accountPriceShow'];
  12176. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  12177. $thsDaySum+=$value ['accountPriceShow'];
  12178. }
  12179. }
  12180. // print_r($incomeList);
  12181. // 获得办事和部门
  12182. $categoryList = $L_category->getCategory ();
  12183. $data ['accountType'] = $accountType;
  12184. $data ['cid'] = $cid;
  12185. $data ['categoryList'] = $categoryList;
  12186. $data ['sum'] = $sum;
  12187. $data ['incomeList'] = $incomeList;
  12188. $data ['inputDate'] = $date;
  12189. $data['year']=$year;
  12190. $data ['thsDay'] =$theDay;
  12191. $data ['thsDaySum'] =$thsDaySum;
  12192. $data ['memu'] = "receipt";
  12193. $data ['staff'] = $this->staff;
  12194. $data ['receiptMemu'] = 'wasteBook';
  12195. $data ['verifyId'] = $this->verifyId;
  12196. $data ['executeId'] = $this->executeId;
  12197. $this->render ( "/expenses/wasteBookExpenditure", $data );
  12198. }
  12199. function ajaxGetWasteinvoiceReceivables() {
  12200. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12201. Doo::loadClass ( 'XDeode' );
  12202. $XDeode = new XDeode ( 5 );
  12203. $irid = $XDeode->decode ( $serial );
  12204. Doo::loadModel ( 'invoiceReceivables' );
  12205. $invoiceReceivables = new invoiceReceivables ();
  12206. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  12207. echo json_encode ( array (
  12208. 'status' => 1,
  12209. 'detail' => $detail
  12210. ) );
  12211. }
  12212. function ajaxGetPaymentsByAid() {
  12213. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12214. Doo::loadModel ( "accountBook" );
  12215. $accountBook = new accountBook ();
  12216. $detail = $accountBook->getAccountBookByAid ( $serial );
  12217. echo json_encode ( array (
  12218. 'status' => 1,
  12219. 'detail' => $detail
  12220. ) );
  12221. }
  12222. function ajaxGetWasteInvoice() {
  12223. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12224. Doo::loadModel ( 'invoice' );
  12225. $invoice = new invoice ();
  12226. Doo::loadModel ( 'invoiceReceivables' );
  12227. $invoiceReceivables = new invoiceReceivables ();
  12228. $detail = $invoice->getInvoiceByIid ( $serial );
  12229. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  12230. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  12231. echo json_encode ( array (
  12232. 'status' => 1,
  12233. 'detail' => $detail
  12234. ) );
  12235. }
  12236. /**
  12237. */
  12238. function ajaxGetWasteReceipt() {
  12239. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12240. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  12241. Doo::loadModel ( 'receipt' );
  12242. $receipt = new receipt ();
  12243. Doo::loadClass ( 'XDeode' );
  12244. $XDeode = new XDeode ( 5 );
  12245. $rid = $XDeode->decode ( $serial );
  12246. $accountType= $XDeode->decode ( $accountTypeKey );
  12247. // 获得个数据
  12248. $detail = $receipt->getReceiptByRid ( $rid );
  12249. // 初始化
  12250. $detail ['reviseDetail'] = array ();
  12251. if (! empty ( $value ['reviseDetail'] ))
  12252. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  12253. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  12254. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  12255. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  12256. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  12257. // 获得费用html
  12258. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  12259. // 获得费用审批人数据
  12260. $detail = $this->getReceiptApproverHtml ( $detail );
  12261. // 审批执行
  12262. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  12263. <th class="taC" width="90">审批人</th>
  12264. <th class="taC">审批意见</th></tr>';
  12265. foreach ( $detail ['verifyList'] as $key => $value ) {
  12266. $html .= '<tr>
  12267. <td>' . $value [1] . '</td>
  12268. <td>' . $value ['opinion'] . '</td>
  12269. </tr>
  12270. ';
  12271. }
  12272. $html .= ' </tbody></table>';
  12273. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  12274. <th class="taC" width="90">执行人</th>
  12275. <th class="taC">执行意见</th></tr>';
  12276. foreach ( $detail ['executeCopy'] as $key => $value ) {
  12277. $html .= '<tr>
  12278. <td>' . $value [1] . '</td>
  12279. <td>' . $value ['opinion'] . '</td>
  12280. </tr>
  12281. ';
  12282. }
  12283. $html .= ' </tbody></table>';
  12284. if($accountType==1){
  12285. Doo::loadModel ( 'loanReceipt' );
  12286. $loanReceipt = new loanReceipt ();
  12287. $loanList = $loanReceipt->getOne ( array (
  12288. 'where' => 'rid=' . $detail ['loanRid'],
  12289. 'desc' => 'rid',
  12290. 'asArray' => true
  12291. ) );
  12292. $html .= '<table class="table table-bordered table-condensed">
  12293. <tr class="warning">
  12294. <td class="taR"><b>汇款金额</b></td>
  12295. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  12296. </tr>
  12297. </table>';
  12298. }else{
  12299. $html .= '<table class="table table-bordered table-condensed">
  12300. <tr class="warning">
  12301. <td class="taR"><b>汇款金额</b></td>
  12302. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  12303. </tr>
  12304. </table>';
  12305. }
  12306. // print_r($detail['verifyList']);
  12307. // header ( 'Content-Type:text/html;charset=utf-8' );
  12308. // echo $html;
  12309. echo json_encode ( array (
  12310. 'status' => 1,
  12311. 'html' => $html,
  12312. 'detail' => $detail
  12313. ) );
  12314. }
  12315. function getReceiptApproverHtml($detail = array()) {
  12316. Doo::loadModel ( 'loanReceipt' );
  12317. $loanReceipt = new loanReceipt ();
  12318. Doo::loadModel ( 'verify' );
  12319. $verify = new verify ();
  12320. Doo::loadModel ( 'staff' );
  12321. $staff = new staff ();
  12322. if (empty ( $detail ))
  12323. return array ();
  12324. $loanList = $loanReceipt->getOne ( array (
  12325. 'where' => 'rid=' . $detail ['loanRid'],
  12326. 'desc' => 'rid',
  12327. 'asArray' => true
  12328. ) );
  12329. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  12330. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  12331. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  12332. else
  12333. $verifyList ['staff'] = $detail ['verifyBreakup'];
  12334. } else
  12335. $verifyList = $verify->getOne ( array (
  12336. 'where' => 'vid=' . $detail ['verify'],
  12337. 'asArray' => true
  12338. ) );
  12339. $verifyList = json_decode ( $verifyList ['staff'], true );
  12340. Doo::loadModel ( 'role' );
  12341. $role = new role ();
  12342. $roleId = 0;
  12343. $flag = true;
  12344. $roleKey = 0;
  12345. $endStaffArray = array ();
  12346. $roleArrayCopy = array ();
  12347. foreach ( $verifyList as $k => $v ) {
  12348. // init verifyStaff
  12349. if ($v [1] == 'ROLE') {
  12350. if (! empty ( $verifyStaff )) {
  12351. $endStaffArray = end ( $verifyStaff );
  12352. }
  12353. $roleVerify = json_decode ( $v [3], true );
  12354. $roleKey = $k;
  12355. $roleArray = array ();
  12356. $rolename = $role->getOne ( array (
  12357. 'where' => 'rid=' . $v [0],
  12358. 'asArray' => true
  12359. ) );
  12360. foreach ( $roleVerify as $o => $p ) {
  12361. $staffID = explode ( '_', $p );
  12362. $staffInfo = $staff->getOne ( array (
  12363. 'where' => 'sid=' . $staffID [0],
  12364. 'asArray' => true
  12365. ) );
  12366. // print_r($staffID);
  12367. $exp = array (
  12368. 0 => $staffInfo ['sid'],
  12369. 1 => $staffID [1],
  12370. 2 => $staffInfo ['avatar'],
  12371. 'date' => '',
  12372. 'date' => '',
  12373. 'opinion' => '',
  12374. 'status' => '',
  12375. 'rolename' => $rolename ['name']
  12376. );
  12377. array_push ( $roleArray, $exp );
  12378. }
  12379. $roleArrayCopy [$v [0]] = $roleArray;
  12380. // $verifyList[$k]['roleArray']=$roleArray;
  12381. }
  12382. $verifyList [$k] ['date'] = "";
  12383. $verifyList [$k] ['opinion'] = "";
  12384. $verifyList [$k] ['status'] = "";
  12385. if (empty ( $verifyStaff )) {
  12386. $verifyList [$k] ['date'] = "";
  12387. $verifyList [$k] ['opinion'] = "";
  12388. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  12389. $verifyList [$k] ['status'] = 4;
  12390. $flag = false;
  12391. }
  12392. } else {
  12393. foreach ( $verifyStaff as $m => $u ) {
  12394. if ($v [0] == $m) {
  12395. $verifyList [$k] ['date'] = $u ['date'];
  12396. $verifyList [$k] ['opinion'] = $u ['opinion'];
  12397. $verifyList [$k] ['status'] = $u ['status'];
  12398. $flag = false;
  12399. break;
  12400. }
  12401. }
  12402. $endStaffArray = end ( $verifyStaff );
  12403. }
  12404. }
  12405. $rolename ['name'] = '';
  12406. if (! empty ( $roleId )) {
  12407. Doo::loadModel ( 'role' );
  12408. $role = new role ();
  12409. $rolename = $role->getOne ( array (
  12410. 'where' => 'rid=' . $roleId,
  12411. 'asArray' => true
  12412. ) );
  12413. }
  12414. if (! empty ( $verifyStaff ))
  12415. $endStaffArray = end ( $verifyStaff );
  12416. $KOP = false;
  12417. foreach ( $roleArrayCopy as $P => $A ) {
  12418. foreach ( $A as $MKI => $AVL ) {
  12419. if (! empty ( $verifyStaff )) {
  12420. // &&$rolename['rid']==$endStaffArray['nextStaff']
  12421. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  12422. $button = 4;
  12423. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  12424. }
  12425. foreach ( $verifyStaff as $m => $u ) {
  12426. $AVLFK = $AVL [0] . '_R';
  12427. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  12428. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  12429. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  12430. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  12431. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  12432. break;
  12433. }
  12434. }
  12435. } else {
  12436. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  12437. $button = 4;
  12438. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  12439. }
  12440. }
  12441. // $roleArray[$MKI]['rolename']=$rolename['name'];
  12442. $KOP = true;
  12443. }
  12444. }
  12445. foreach ( $roleArrayCopy as $k => $v ) {
  12446. foreach ( $verifyList as $m => $n ) {
  12447. if ($n [0] == $k) {
  12448. array_splice ( $verifyList, $m, 1, $v );
  12449. }
  12450. }
  12451. }
  12452. // 费用执行人相关数据
  12453. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  12454. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  12455. foreach ( $executeCopy as $k => $v ) {
  12456. $executeCopy [$k] ['date'] = '';
  12457. $executeCopy [$k] ['opinion'] = '';
  12458. $executeCopy [$k] ['status'] = '';
  12459. if (! empty ( $executeStaff ))
  12460. foreach ( $executeStaff as $m => $u ) {
  12461. if ($v [0] == $m) {
  12462. $executeCopy [$k] ['date'] = $u ['date'];
  12463. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  12464. $executeCopy [$k] ['status'] = $u ['status'];
  12465. break;
  12466. }
  12467. }
  12468. }
  12469. $detail ['executeCopy'] = $executeCopy;
  12470. $detail ['verifyList'] = $verifyList;
  12471. return $detail;
  12472. }
  12473. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  12474. if (empty ( $detail ))
  12475. return '';
  12476. $html = '';
  12477. if ($detail ['Rtype'] == 0) { // 报销单
  12478. $html .= '<table class="table table-bordered table-condensed">
  12479. <tbody>
  12480. <tr>
  12481. <th colspan="2" class="taC">日常相关费用</th>
  12482. </tr>';
  12483. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12484. $html .= '
  12485. <tr>
  12486. <th>' . $value ['name'] . '</th>
  12487. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12488. </tr>';
  12489. }
  12490. $html .= '
  12491. <tr>
  12492. <th class="taR">合计</th>
  12493. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12494. </tr>';
  12495. $html .= '<tr>
  12496. <th colspan="2" class="taC">差旅相关费用</th>
  12497. </tr>';
  12498. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12499. $html .= '
  12500. <tr>
  12501. <th>' . $value ['name'] . '</th>
  12502. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12503. </tr>';
  12504. }
  12505. $html .= '
  12506. <tr>
  12507. <th class="taR">合计</th>
  12508. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12509. </tr>';
  12510. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12511. $html .= '<tr>
  12512. <th colspan="2" class="taC">内部培训费用</th>
  12513. </tr>';
  12514. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12515. $html .= '
  12516. <tr>
  12517. <th>' . $value ['name'] . '</th>
  12518. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12519. </tr>';
  12520. }
  12521. $html .= '
  12522. <tr>
  12523. <th class="taR">合计</th>
  12524. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12525. </tr>';
  12526. }
  12527. $html .= '<tr>
  12528. <th colspan="2" class="taC">其他</th>
  12529. </tr>';
  12530. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12531. $html .= '
  12532. <tr>
  12533. <th>' . $value ['name'] . '</th>
  12534. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12535. </tr>';
  12536. }
  12537. $html .= '
  12538. <tr>
  12539. <th class="taR">合计</th>
  12540. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12541. </tr>';
  12542. $html .= '<tr>
  12543. <th colspan="2" class="taC">报销金额调整</th>
  12544. </tr>';
  12545. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12546. $html .= '
  12547. <tr>
  12548. <th>' . $value ['name'] . '</th>
  12549. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12550. </tr>';
  12551. }
  12552. $html .= '
  12553. <tr>
  12554. <th class="taR">合计</th>
  12555. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12556. </tr>';
  12557. $html .= '
  12558. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12559. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12560. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12561. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12562. <tr class="warning">
  12563. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12564. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12565. </tr>
  12566. </tbody>
  12567. </table>';
  12568. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  12569. $html .= '
  12570. <table class="table table-bordered table-condensed">
  12571. <tbody>
  12572. <tr>
  12573. <th colspan="2" class="taC">办事处相关费用</th>
  12574. </tr>';
  12575. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12576. $html .= '
  12577. <tr>
  12578. <th>' . $value ['name'] . '</th>
  12579. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12580. </tr>';
  12581. }
  12582. $html .= '
  12583. <tr>
  12584. <th class="taR">合计</th>
  12585. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12586. </tr>';
  12587. $html .= '
  12588. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12589. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12590. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12591. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12592. <tr class="warning">
  12593. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12594. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12595. </tr>
  12596. </tbody>
  12597. </table>';
  12598. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  12599. Doo::loadModel ( 'loanReceipt' );
  12600. $loanReceipt = new loanReceipt ();
  12601. $loanList = $loanReceipt->getOne ( array (
  12602. 'where' => 'rid=' . $detail ['loanRid'],
  12603. 'desc' => 'rid',
  12604. 'asArray' => true
  12605. ) );
  12606. // print_r($loanList);
  12607. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  12608. $html .= '<table class="table table-bordered table-condensed">
  12609. <tbody>
  12610. <tr>
  12611. <th colspan="2" class="taC">借款费用</th>
  12612. </tr>';
  12613. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  12614. $html .= '<tr>
  12615. <th>' . $value ['name'] . '</th>
  12616. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12617. </tr>';
  12618. }
  12619. $html .= '<tr>
  12620. <th class="taC" colspan="2">产生费用所在办事处</th>
  12621. </tr>
  12622. <tr>
  12623. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  12624. </tr>
  12625. <tr>
  12626. <th class="taC" colspan="2">费用说明</th>
  12627. </tr>
  12628. <tr>
  12629. <td colspan="2">' . $loanList ['explanation'] . '</td>
  12630. </tr>
  12631. <tr class="warning">
  12632. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  12633. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  12634. </tr>
  12635. </tbody>
  12636. </table>
  12637. ';
  12638. if ( $accountType==2) {
  12639. $balance=$detail ['sum']-$loanList ['sum'];
  12640. $balanceCN=$this->num_to_rmb($balance);
  12641. $html .= '<table class="table table-bordered table-condensed">
  12642. <tbody>
  12643. <tr>
  12644. <th colspan="2" class="taC">日常相关费用</th>
  12645. </tr>';
  12646. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12647. $html .= '
  12648. <tr>
  12649. <th>' . $value ['name'] . '</th>
  12650. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12651. </tr>';
  12652. }
  12653. $html .= '
  12654. <tr>
  12655. <th class="taR">合计</th>
  12656. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12657. </tr>';
  12658. $html .= '<tr>
  12659. <th colspan="2" class="taC">差旅相关费用</th>
  12660. </tr>';
  12661. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12662. $html .= '
  12663. <tr>
  12664. <th>' . $value ['name'] . '</th>
  12665. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12666. </tr>';
  12667. }
  12668. $html .= '
  12669. <tr>
  12670. <th class="taR">合计</th>
  12671. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12672. </tr>';
  12673. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12674. $html .= '<tr>
  12675. <th colspan="2" class="taC">内部培训费用</th>
  12676. </tr>';
  12677. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12678. $html .= '
  12679. <tr>
  12680. <th>' . $value ['name'] . '</th>
  12681. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12682. </tr>';
  12683. }
  12684. $html .= '
  12685. <tr>
  12686. <th class="taR">合计</th>
  12687. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12688. </tr>';
  12689. }
  12690. $html .= '<tr>
  12691. <th colspan="2" class="taC">其他</th>
  12692. </tr>';
  12693. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12694. $html .= '
  12695. <tr>
  12696. <th>' . $value ['name'] . '</th>
  12697. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12698. </tr>';
  12699. }
  12700. $html .= '
  12701. <tr>
  12702. <th class="taR">合计</th>
  12703. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12704. </tr>';
  12705. $html .= '<tr>
  12706. <th colspan="2" class="taC">报销金额调整</th>
  12707. </tr>';
  12708. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12709. $html .= '
  12710. <tr>
  12711. <th>' . $value ['name'] . '</th>
  12712. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12713. </tr>';
  12714. }
  12715. $html .= '
  12716. <tr>
  12717. <th class="taR">合计</th>
  12718. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12719. </tr>';
  12720. $html .= '
  12721. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12722. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12723. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12724. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12725. <tr class="warning">
  12726. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12727. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12728. </tr>
  12729. <tr class="success">
  12730. <td class="taR"><b>借款结余</b></td>
  12731. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12732. </tr>
  12733. </tbody>
  12734. </table>';
  12735. }
  12736. }
  12737. return $html;
  12738. }
  12739. /**
  12740. * 计算流水
  12741. */
  12742. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12743. $bakWaste ['bank'] = array (
  12744. 'CGBDeposit' => 0,
  12745. 'ICBCDeposit' => 0,
  12746. 'HUADeposit' => 0,
  12747. 'PersonalDeposit' => 0
  12748. );
  12749. $bakWaste ['financial'] = array (
  12750. 'current' => array (
  12751. 'CGBDeposit' => 0,
  12752. 'ICBCDeposit' => 0
  12753. ),
  12754. 'fixed' => array (
  12755. 'CGBDeposit' => 0,
  12756. 'ICBCDeposit' => 0
  12757. )
  12758. );
  12759. // 存款
  12760. foreach ( $waste ['bank'] as $key => $value ) {
  12761. // 收入
  12762. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12763. // 广发
  12764. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12765. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12766. }
  12767. // 工商
  12768. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12769. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12770. }
  12771. // 华润
  12772. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12773. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12774. }
  12775. // 个人
  12776. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12777. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12778. }
  12779. }
  12780. }
  12781. foreach ( $waste ['bank'] as $key => $value ) {
  12782. // 支出
  12783. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12784. // 广发
  12785. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12786. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12787. }
  12788. // 工商
  12789. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12790. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12791. }
  12792. // 华润
  12793. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12794. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12795. }
  12796. // 个人
  12797. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12798. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12799. }
  12800. }
  12801. }
  12802. // 活期
  12803. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12804. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12805. // 广发
  12806. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12807. $waste ['financial'] ['current'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12808. }
  12809. // 工商
  12810. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12811. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12812. }
  12813. // 个人
  12814. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12815. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12816. }
  12817. }
  12818. }
  12819. // print_r($inComeStatistics ['fixedStatistics']);
  12820. // 固期
  12821. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12822. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12823. // 广发
  12824. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12825. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12826. }
  12827. // 工商---已经转变成个人理财固定代表含义
  12828. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12829. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12830. }
  12831. // 个人
  12832. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12833. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12834. }
  12835. }
  12836. }
  12837. $waste ['bank'] ['ICBCDeposit'] = sprintf("%.2f", $waste ['bank'] ['ICBCDeposit']);
  12838. return $waste;
  12839. }
  12840. function lyt() {
  12841. Doo::loadModel ( "receiptDetail" );
  12842. $receiptDetail = new receiptDetail ();
  12843. $receiptCollectList = $receiptDetail->find ( array (
  12844. 'where' => 'status=1 ',
  12845. 'asArray' => true
  12846. ) );
  12847. foreach ( $receiptCollectList as $key => $value ) {
  12848. $receiptDetail = new receiptDetail ();
  12849. $receiptDetail->pastDate = $value ['date'];
  12850. $receiptDetail->update ( array (
  12851. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12852. ) );
  12853. }
  12854. }
  12855. function staffCollectMonthDetail() {
  12856. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12857. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12858. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12859. if (! $year)
  12860. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12861. if (! $month)
  12862. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12863. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12864. if (! $nature){
  12865. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12866. }
  12867. Doo::loadModel ( 'staff' );
  12868. $staff = new staff ();
  12869. Doo::loadModel ( "receiptDetail" );
  12870. $receiptDetail = new receiptDetail ();
  12871. Doo::loadModel ( 'accountItem' );
  12872. $accountItem = new accountItem ();
  12873. Doo::loadModel ( 'statistics' );
  12874. $statistics = new statistics ();
  12875. Doo::loadModel ( "receiptAuthorityManage" );
  12876. $receiptAuthorityManage = new receiptAuthorityManage ();
  12877. $aiList=$accountItem->getAccountItem();
  12878. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12879. $cidList = array ();
  12880. foreach ( $imcStaff as $key => $value ) {
  12881. array_push ( $cidList, $value ['cid'] );
  12882. }
  12883. $cidString = implode ( ',', $cidList );
  12884. $naturecon='';
  12885. if ($nature=='ONJOB'){
  12886. $naturecon=' and (nature!=4 )';
  12887. }elseif($nature=='LEAVEJOB'){
  12888. $naturecon=' and (nature=4 )';
  12889. }else{
  12890. die ( 'illegal request--nature' );
  12891. }
  12892. $staffList = $staff->find ( array (
  12893. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12894. 'asArray' => true
  12895. ) );
  12896. $categoryList = $staff->find ( array (
  12897. 'select' => 'COUNT(*) as count,cid,category',
  12898. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12899. 'groupby' => 'cid',
  12900. 'asArray' => true
  12901. ) );
  12902. $list = array ();
  12903. foreach($aiList as $key=>$value){
  12904. foreach ($value as $v){
  12905. $subtotal[$key][$v['name']]=0;
  12906. }
  12907. }
  12908. foreach ( $categoryList as $vlu ) {
  12909. $s1 = 0;
  12910. $m1 = 0;
  12911. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12912. foreach ( $staffList as $value ) {
  12913. if ($vlu ['cid'] == $value ['cid']) {
  12914. // pastDate
  12915. $receiptCollectList = $receiptDetail->find ( array (
  12916. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12917. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12918. 'groupby' => 'item,Month(pastDate),itemCategory',
  12919. 'asArray' => true
  12920. ) );
  12921. if (! empty ( $receiptCollectList )) {
  12922. $receiptL = array (
  12923. '日常相关费用' => array (),
  12924. '差旅相关费用' => array (),
  12925. '内部培训费用' => array (),
  12926. '培训班费用' => array (),
  12927. '其他' => array ()
  12928. );
  12929. $html = "";
  12930. $psum = 0;
  12931. foreach ( $aiList[$this->AGENCY] as $va ) {
  12932. $falg = true;
  12933. foreach ( $receiptCollectList as $v ) {
  12934. if ($v ['itemCategory'] == '日常相关费用') {
  12935. if ($v ['item'] == $va['name']) {
  12936. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12937. $psum += $v ['price'];
  12938. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12939. $falg = false;
  12940. break;
  12941. }
  12942. }
  12943. }
  12944. if ($falg)
  12945. $html .= '<td class="taR">-</td>';
  12946. }
  12947. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12948. if (! empty ( $psum ))
  12949. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12950. else
  12951. $psum = '<td class="colGreen taR">-</td>';
  12952. $receiptL ['日常相关费用'] = $psum . $html;
  12953. /* ----------------------------------- */
  12954. $html = "";
  12955. $psum = 0;
  12956. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12957. $falg = true;
  12958. foreach ( $receiptCollectList as $v ) {
  12959. if ($v ['itemCategory'] == '差旅相关费用') {
  12960. if ($v ['item'] == $va['name']) {
  12961. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12962. $psum += $v ['price'];
  12963. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12964. $falg = false;
  12965. break;
  12966. }
  12967. }
  12968. }
  12969. if ($falg)
  12970. $html .= '<td class="taR">-</td>';
  12971. }
  12972. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12973. if (! empty ( $psum ))
  12974. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12975. else
  12976. $psum = '<td class="colGreen taR">-</td>';
  12977. $receiptL ['差旅相关费用'] = $psum . $html;
  12978. /* ------------------------------------- */
  12979. $html = "";
  12980. $psum = 0;
  12981. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12982. $falg = true;
  12983. foreach ( $receiptCollectList as $v ) {
  12984. if ($v ['itemCategory'] == '内部培训费用') {
  12985. if ($v ['item'] == $va['name']) {
  12986. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12987. $psum += $v ['price'];
  12988. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12989. $falg = false;
  12990. break;
  12991. }
  12992. }
  12993. }
  12994. if ($falg)
  12995. $html .= '<td class="taR">-</td>';
  12996. }
  12997. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12998. if (! empty ( $psum ))
  12999. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13000. else
  13001. $psum = '<td class="colGreen taR">-</td>';
  13002. $receiptL ['内部培训费用'] = $psum . $html;
  13003. /* ----------------------------------- */
  13004. $html = "";
  13005. $psum = 0;
  13006. foreach ( $aiList[$this->TRAIN] as $va ) {
  13007. $falg = true;
  13008. foreach ( $receiptCollectList as $v ) {
  13009. if ($v ['itemCategory'] == '培训班费用') {
  13010. if ($v ['item'] == $va['name']) {
  13011. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  13012. $psum += $v ['price'];
  13013. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13014. $falg = false;
  13015. break;
  13016. }
  13017. }
  13018. }
  13019. if ($falg)
  13020. $html .= '<td class="taR">-</td>';
  13021. }
  13022. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  13023. if (! empty ( $psum ))
  13024. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13025. else
  13026. $psum = '<td class="colGreen taR">-</td>';
  13027. $receiptL ['培训班费用'] = $psum . $html;
  13028. /* ------------------------------------- */
  13029. $html = "";
  13030. $psum = 0;
  13031. foreach ( $aiList[$this->OTHER] as $va ) {
  13032. $falg = true;
  13033. foreach ( $receiptCollectList as $v ) {
  13034. if ($v ['itemCategory'] == '其他') {
  13035. if (trim ( $v ['item'] ) == $va['name']) {
  13036. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  13037. $psum += $v ['price'];
  13038. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13039. $falg = false;
  13040. break;
  13041. }
  13042. }
  13043. }
  13044. if ($falg)
  13045. $html .= '<td class="taR">-</td>';
  13046. }
  13047. $subtotal[$this->OTHER]['OTHER'] += $psum;
  13048. if (! empty ( $psum ))
  13049. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13050. else
  13051. $psum = '<td class="colGreen taR">-</td>';
  13052. $receiptL ['其他'] = $psum . $html;
  13053. /* ------------------------------------- */
  13054. $html = "";
  13055. $psum = 0;
  13056. foreach ( $receiptCollectList as $v ) {
  13057. if ($v ['itemCategory'] == '报销金额调整') {
  13058. if (! empty ( $v ['price'] )) {
  13059. $psum += $v ['price'];
  13060. }
  13061. }
  13062. }
  13063. $s1 += $psum;
  13064. if (! empty ( $psum ))
  13065. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  13066. else
  13067. $psum = '<td class="taR colOrange">-</td>';
  13068. $receiptL ['报销金额调整'] = $psum . $html;
  13069. } else {
  13070. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13071. foreach ( $aiList[$this->AGENCY] as $va ) {
  13072. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13073. }
  13074. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13075. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13076. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13077. }
  13078. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13079. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13080. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13081. }
  13082. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13083. foreach ( $aiList[$this->TRAIN] as $va ) {
  13084. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13085. }
  13086. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13087. foreach ( $aiList[$this->OTHER] as $va ) {
  13088. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13089. }
  13090. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13091. }
  13092. $monthStaffPrice = $receiptDetail->find ( array (
  13093. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13094. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13095. 'groupby' => 'Month(pastDate)',
  13096. 'asArray' => true
  13097. ) );
  13098. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  13099. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  13100. $m1 += $monthStaffPrice [0] ['price'];
  13101. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13102. } else
  13103. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13104. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  13105. $list [$value ['username']] = $receiptL;
  13106. }
  13107. }
  13108. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  13109. foreach ( $aiList[$this->AGENCY] as $va ) {
  13110. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  13111. $subtotal[$this->AGENCY][$va['name']]=0;
  13112. }
  13113. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  13114. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13115. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  13116. $subtotal[$this->TRAVEL][$va['name']]=0;
  13117. }
  13118. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  13119. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13120. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  13121. $subtotal[$this->INTTRAIN][$va['name']]=0;
  13122. }
  13123. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  13124. foreach ( $aiList[$this->TRAIN] as $va ) {
  13125. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  13126. $subtotal[$this->TRAIN][$va['name']]=0;
  13127. }
  13128. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  13129. foreach ( $aiList[$this->OTHER] as $va ) {
  13130. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  13131. $subtotal[$this->OTHER][$va['name']]=0;
  13132. }
  13133. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13134. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13135. $receiptL ['usernameEn'] =false;
  13136. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13137. }
  13138. $data ['list'] = $list;
  13139. // print_r($list);
  13140. $receiptCollectList = $receiptDetail->find ( array (
  13141. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13142. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13143. 'groupby' => 'item,Month(pastDate),itemCategory',
  13144. 'asArray' => true
  13145. ) );
  13146. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13147. // statistics html
  13148. $stList = $statistics->getOne ( array (
  13149. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13150. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13151. 'groupby' => 'Month(date)',
  13152. 'asArray' => true
  13153. ) );
  13154. if (empty ( $stList ))
  13155. $stList = array (
  13156. 'rePrice' => 0,
  13157. 'agPrice' => 0
  13158. );
  13159. $data ['stList'] = array (
  13160. 'rePrice' => $stList ['rePrice'],
  13161. 'agPrice' => $stList ['agPrice'],
  13162. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13163. );
  13164. $monthHtml = "";
  13165. for($i = 1; $i <= 12; $i ++) {
  13166. if ($i == $month)
  13167. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13168. else
  13169. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13170. }
  13171. $data ['monthHtml'] = $monthHtml;
  13172. $data ['year'] = $year;
  13173. $data ['month'] = $month;
  13174. $data ['nature'] = $nature;
  13175. $data ['aiList'] = $aiList;
  13176. $data ['memu'] = "receipt";
  13177. $data ['staff'] = $this->staff;
  13178. $data ['receiptMemu'] = 'companyCategoryCollect';
  13179. $data ['verifyId'] = $this->verifyId;
  13180. $data ['executeId'] = $this->executeId;
  13181. $this->render ( "/admin/staffCollectMonthDetail", $data );
  13182. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13183. }
  13184. function staffCollectMonthDetail2() {
  13185. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13186. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13187. if (! $year)
  13188. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13189. if (! $month)
  13190. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13191. Doo::loadModel ( 'staff' );
  13192. $staff = new staff ();
  13193. Doo::loadModel ( "receiptDetail" );
  13194. $receiptDetail = new receiptDetail ();
  13195. Doo::loadModel ( 'accountItem' );
  13196. $accountItem = new accountItem ();
  13197. Doo::loadModel ( 'statistics' );
  13198. $statistics = new statistics ();
  13199. Doo::loadModel ( 'L_category' );
  13200. $lCategory = new L_category ();
  13201. $staffList = $staff->find ( array (
  13202. 'where' => 'username!="admin"',
  13203. 'asArray' => true
  13204. ) );
  13205. $categoryList = $staff->find ( array (
  13206. 'select' => 'COUNT(*) as count,cid,category',
  13207. 'where' => 'username !="admin"',
  13208. 'groupby' => 'cid',
  13209. 'asArray' => true
  13210. ) );
  13211. $list = array ();
  13212. foreach ( $categoryList as $vlu ) {
  13213. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  13214. $r1 = 0;
  13215. $r2 = 0;
  13216. $r3 = 0;
  13217. $r4 = 0;
  13218. $r5 = 0;
  13219. $r6 = 0;
  13220. $r7 = 0;
  13221. $r8 = 0;
  13222. $r9 = 0;
  13223. $r10 = 0;
  13224. $r11 = 0;
  13225. $r12 = 0;
  13226. $r13 = 0;
  13227. $r14 = 0;
  13228. $r15 = 0;
  13229. $c1 = 0;
  13230. $c2 = 0;
  13231. $c3 = 0;
  13232. $c4 = 0;
  13233. $c5 = 0;
  13234. $c6 = 0;
  13235. $p1 = 0;
  13236. $p2 = 0;
  13237. $p3 = 0;
  13238. $p4 = 0;
  13239. $p5 = 0;
  13240. $p6 = 0;
  13241. $p7 = 0;
  13242. $p8 = 0;
  13243. $p9 = 0;
  13244. $t1 = 0;
  13245. $t2 = 0;
  13246. $t3 = 0;
  13247. $t4 = 0;
  13248. $t5 = 0;
  13249. $s1 = 0;
  13250. $m1 = 0;
  13251. foreach ( $staffList as $value ) {
  13252. if ($vlu ['cid'] == $value ['cid']) {
  13253. $receiptCollectList = $receiptDetail->find ( array (
  13254. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13255. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13256. 'groupby' => 'item,Month(date),itemCategory',
  13257. 'asArray' => true
  13258. ) );
  13259. if (! empty ( $receiptCollectList )) {
  13260. $receiptL = array (
  13261. '日常相关费用' => array (),
  13262. '差旅相关费用' => array (),
  13263. '培训班费用' => array (),
  13264. '其他' => array ()
  13265. );
  13266. $html = "";
  13267. $psum = 0;
  13268. $item = array (
  13269. '市内交通费',
  13270. '市内出租费',
  13271. '办事处房租',
  13272. '电话费',
  13273. '水费',
  13274. '电费',
  13275. '办公费用',
  13276. '邮寄费',
  13277. '其他费用',
  13278. '车辆费用',
  13279. '广告费',
  13280. '团队建设费',
  13281. '物业管理费',
  13282. '宽带费'
  13283. );
  13284. foreach ( $item as $va ) {
  13285. $falg = true;
  13286. foreach ( $receiptCollectList as $v ) {
  13287. if ($v ['itemCategory'] == '日常相关费用') {
  13288. if ($v ['item'] == $va) {
  13289. if ($va == '市内交通费')
  13290. $r1 += $v ['price'];
  13291. if ($va == '市内出租费')
  13292. $r2 += $v ['price'];
  13293. if ($va == '办事处房租')
  13294. $r3 += $v ['price'];
  13295. if ($va == '电话费')
  13296. $r4 += $v ['price'];
  13297. if ($va == '水费')
  13298. $r5 += $v ['price'];
  13299. if ($va == '电费')
  13300. $r6 += $v ['price'];
  13301. if ($va == '办公费用')
  13302. $r7 += $v ['price'];
  13303. if ($va == '邮寄费')
  13304. $r8 += $v ['price'];
  13305. if ($va == '其他费用')
  13306. $r9 += $v ['price'];
  13307. if ($va == '车辆费用')
  13308. $r10 += $v ['price'];
  13309. if ($va == '广告费')
  13310. $r11 += $v ['price'];
  13311. if ($va == '团队建设费')
  13312. $r13 += $v ['price'];
  13313. if ($va == '物业管理费')
  13314. $r14 += $v ['price'];
  13315. if ($va == '宽带费')
  13316. $r15 += $v ['price'];
  13317. $psum += $v ['price'];
  13318. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13319. $falg = false;
  13320. break;
  13321. }
  13322. }
  13323. }
  13324. if ($falg)
  13325. $html .= '<td class="taR">-</td>';
  13326. }
  13327. $r12 += $psum;
  13328. if (! empty ( $psum ))
  13329. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13330. else
  13331. $psum = '<td class="colGreen taR">-</td>';
  13332. $receiptL ['日常相关费用'] = $psum . $html;
  13333. /* ----------------------------------- */
  13334. $html = "";
  13335. $psum = 0;
  13336. $item = array (
  13337. '往来交通费',
  13338. '市内交通费',
  13339. '出差住宿费',
  13340. '出差补助',
  13341. '其他费用'
  13342. );
  13343. foreach ( $item as $va ) {
  13344. $falg = true;
  13345. foreach ( $receiptCollectList as $v ) {
  13346. if ($v ['itemCategory'] == '差旅相关费用') {
  13347. if ($v ['item'] == $va) {
  13348. if ($va == '往来交通费')
  13349. $c1 += $v ['price'];
  13350. if ($va == '市内交通费')
  13351. $c2 += $v ['price'];
  13352. if ($va == '出差住宿费')
  13353. $c3 += $v ['price'];
  13354. if ($va == '出差补助')
  13355. $c4 += $v ['price'];
  13356. if ($va == '其他费用')
  13357. $c5 += $v ['price'];
  13358. $psum += $v ['price'];
  13359. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13360. $falg = false;
  13361. break;
  13362. }
  13363. }
  13364. }
  13365. if ($falg)
  13366. $html .= '<td class="taR">-</td>';
  13367. }
  13368. $c6 += $psum;
  13369. if (! empty ( $psum ))
  13370. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13371. else
  13372. $psum = '<td class="colGreen taR">-</td>';
  13373. $receiptL ['差旅相关费用'] = $psum . $html;
  13374. /* ------------------------------------- */
  13375. $html = "";
  13376. $psum = 0;
  13377. $item = array (
  13378. '场租费',
  13379. '薪酬',
  13380. '住宿费',
  13381. '交通费',
  13382. '餐饮费',
  13383. '办公费',
  13384. '公关费',
  13385. '其他'
  13386. );
  13387. foreach ( $item as $va ) {
  13388. $falg = true;
  13389. foreach ( $receiptCollectList as $v ) {
  13390. if ($v ['itemCategory'] == '培训班费用') {
  13391. if ($v ['item'] == $va) {
  13392. if ($va == '场租费')
  13393. $p1 += $v ['price'];
  13394. if ($va == '薪酬')
  13395. $p2 += $v ['price'];
  13396. if ($va == '住宿费')
  13397. $p3 += $v ['price'];
  13398. if ($va == '交通费')
  13399. $p4 += $v ['price'];
  13400. if ($va == '餐饮费')
  13401. $p5 += $v ['price'];
  13402. if ($va == '办公费')
  13403. $p6 += $v ['price'];
  13404. if ($va == '公关费')
  13405. $p7 += $v ['price'];
  13406. if ($va == '其他')
  13407. $p8 += $v ['price'];
  13408. $psum += $v ['price'];
  13409. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13410. $falg = false;
  13411. break;
  13412. }
  13413. }
  13414. }
  13415. if ($falg)
  13416. $html .= '<td class="taR">-</td>';
  13417. }
  13418. $p9 += $psum;
  13419. if (! empty ( $psum ))
  13420. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13421. else
  13422. $psum = '<td class="colGreen taR">-</td>';
  13423. $receiptL ['培训班费用'] = $psum . $html;
  13424. /* ------------------------------------- */
  13425. $html = "";
  13426. $psum = 0;
  13427. $item = array (
  13428. '公关费',
  13429. '广告费',
  13430. '借款',
  13431. '可自加费用'
  13432. );
  13433. foreach ( $item as $va ) {
  13434. $falg = true;
  13435. foreach ( $receiptCollectList as $v ) {
  13436. if ($v ['itemCategory'] == '其他') {
  13437. if ($v ['item'] == $va) {
  13438. if ($va == '公关费')
  13439. $t1 += $v ['price'];
  13440. if ($va == '广告费')
  13441. $t2 += $v ['price'];
  13442. if ($va == '借款')
  13443. $t3 += $v ['price'];
  13444. if ($va == '可自加费用')
  13445. $t4 += $v ['price'];
  13446. $psum += $v ['price'];
  13447. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13448. $falg = false;
  13449. break;
  13450. }
  13451. }
  13452. }
  13453. if ($falg)
  13454. $html .= '<td class="taR">-</td>';
  13455. }
  13456. $t5 += $psum;
  13457. if (! empty ( $psum ))
  13458. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13459. else
  13460. $psum = '<td class="colGreen taR">-</td>';
  13461. $receiptL ['其他'] = $psum . $html;
  13462. /* ------------------------------------- */
  13463. $html = "";
  13464. $psum = 0;
  13465. foreach ( $receiptCollectList as $v ) {
  13466. if ($v ['itemCategory'] == '报销金额调整') {
  13467. if (! empty ( $v ['price'] )) {
  13468. $psum += $v ['price'];
  13469. }
  13470. }
  13471. }
  13472. $s1 += $psum;
  13473. if (! empty ( $psum ))
  13474. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  13475. else
  13476. $psum = '<td class="taR colOrange">-</td>';
  13477. $receiptL ['报销金额调整'] = $psum . $html;
  13478. } else {
  13479. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13480. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13481. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  13482. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13483. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13484. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13485. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13486. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13487. }
  13488. $monthStaffPrice = $receiptDetail->find ( array (
  13489. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13490. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13491. 'asArray' => true
  13492. ) );
  13493. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  13494. $m1 += $monthStaffPrice [0] ['price'];
  13495. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13496. } else
  13497. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13498. $list [$value ['username']] = $receiptL;
  13499. }
  13500. }
  13501. $receiptL ['日常相关费用'] = '<td class="colGreen taR">' . $r12 . '</td><td class="taR">' . $r1 . '</td><td class="taR">' . $r2 . '</td><td class="taR">' . $r3 . '</td><td class="taR">' . $r4 . '</td><td class="taR">' . $r5 . '</td>
  13502. <td class="taR">' . $r6 . '</td><td class="taR">' . $r7 . '</td><td class="taR">' . $r8 . '</td><td class="taR">' . $r9 . '</td><td class="taR">' . $r10 . '</td><td class="taR">' . $r11 . '</td><td class="taR">' . $r13 . '</td>
  13503. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  13504. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  13505. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  13506. $receiptL ['培训班费用'] = '<td class="colGreen taR">' . $p9 . '</td><td class="taR">' . $p1 . '</td><td class="taR">' . $p2 . '</td><td class="taR">' . $p3 . '</td><td class="taR">' . $p4 . '</td>
  13507. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  13508. $receiptL ['其他'] = '<td class="colGreen taR">' . $t5 . '</td><td class="taR">' . $t1 . '</td><td class="taR">' . $t2 . '</td><td class="taR">' . $t3 . '</td><td class="taR">' . $t4 . '</td>';
  13509. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13510. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13511. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13512. }
  13513. $data ['list'] = $list;
  13514. $receiptCollectList = $receiptDetail->find ( array (
  13515. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13516. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13517. 'groupby' => 'item,Month(date),itemCategory',
  13518. 'asArray' => true
  13519. ) );
  13520. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  13521. // statistics html
  13522. $stList = $statistics->getOne ( array (
  13523. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13524. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13525. 'groupby' => 'Month(date)',
  13526. 'asArray' => true
  13527. ) );
  13528. if (empty ( $stList ))
  13529. $stList = array (
  13530. 'rePrice' => 0,
  13531. 'agPrice' => 0
  13532. );
  13533. $data ['stList'] = array (
  13534. 'rePrice' => $stList ['rePrice'],
  13535. 'agPrice' => $stList ['agPrice'],
  13536. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13537. );
  13538. $monthHtml = "";
  13539. for($i = 1; $i <= 12; $i ++) {
  13540. if ($i == $month)
  13541. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13542. else
  13543. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13544. }
  13545. $data ['monthHtml'] = $monthHtml;
  13546. $data ['year'] = $year;
  13547. $data ['month'] = $month;
  13548. $data ['memu'] = "receipt";
  13549. $data ['staff'] = $this->staff;
  13550. $data ['receiptMemu'] = 'companyCategoryCollect';
  13551. $data ['verifyId'] = $this->verifyId;
  13552. $data ['executeId'] = $this->executeId;
  13553. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  13554. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13555. }
  13556. /**
  13557. * 用户报销单列表
  13558. */
  13559. function receiptStatisticsStaffDetail() {
  13560. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13561. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13562. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13563. Doo::loadModel ( "receipt" );
  13564. $receipt = new receipt ();
  13565. Doo::loadModel ( "receiptDetail" );
  13566. $receiptDetail = new receiptDetail ();
  13567. Doo::loadModel ( 'staff' );
  13568. $staff = new staff ();
  13569. Doo::loadModel ( 'accountItem' );
  13570. $accountItem = new accountItem ();
  13571. Doo::loadModel ( 'statistics' );
  13572. $statistics = new statistics ();
  13573. if (! empty ( $username )) {
  13574. $username = addslashes ( urldecode ( $username ) );
  13575. $staffDetail = $staff->getStaffByName ( $username );
  13576. if (empty ( $staffDetail ))
  13577. die ( 'illegal request' );
  13578. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  13579. $itemList = $accountItem->getAccountItem ();
  13580. $itemHtml = '';
  13581. $categoryHtml = '';
  13582. $itemKeyList = array_keys ( $itemList );
  13583. $revisePrice = 0;
  13584. // 报销单内容详情
  13585. foreach ( $list as $key => $value ) {
  13586. $accountItemList = json_decode ( $value ['accountItem'], true );
  13587. $list [$key] ['accountItemList'] = $accountItemList;
  13588. $receiptItemHtml = '';
  13589. foreach ( $itemKeyList as $v ) {
  13590. if ($v == '日常相关费用')
  13591. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  13592. elseif ($v == '差旅相关费用')
  13593. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  13594. elseif ($v == '培训班费用')
  13595. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  13596. elseif ($v == '内部培训费用'){
  13597. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  13598. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  13599. }else{
  13600. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  13601. }
  13602. }elseif ($v == '其他')
  13603. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  13604. foreach ( $itemList [$v] as $ke => $va ) {
  13605. $falg = true;
  13606. if (! empty ( $accountItemList [$v] )) {
  13607. foreach ( $accountItemList [$v] as $ve ) {
  13608. if ($va ['name'] == $ve ['name']) {
  13609. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  13610. $falg = false;
  13611. break;
  13612. }
  13613. }
  13614. }
  13615. if ($falg)
  13616. $receiptItemHtml .= '<td class="taR"></td>';
  13617. }
  13618. }
  13619. // 金额调整和费用查看
  13620. $revisePrice += $value ['revisePrice'];
  13621. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  13622. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  13623. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  13624. }
  13625. // 报销单合计
  13626. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  13627. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  13628. $receiptTotalHtml = '';
  13629. // 报销单项目抬头
  13630. foreach ( $itemKeyList as $value ) {
  13631. $count = count ( $itemList [$value] ) + 1;
  13632. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  13633. $categoryHtml .= '<th class="taC">合计</th>';
  13634. $sumfalg=true;
  13635. foreach ( $rtl as $rtlValue ) {
  13636. if ($rtlValue ['itemCategory'] == $value) {
  13637. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  13638. $sumfalg=false;
  13639. break;
  13640. }
  13641. }
  13642. if ($sumfalg)
  13643. $receiptTotalHtml .= '<th></th>';
  13644. foreach ( $itemList [$value] as $k => $v ) {
  13645. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13646. // 合计
  13647. $falg = true;
  13648. foreach ( $receiptTotalList as $ve ) {
  13649. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13650. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13651. $falg = false;
  13652. break;
  13653. }
  13654. }
  13655. if ($falg)
  13656. $receiptTotalHtml .= '<th></th>';
  13657. }
  13658. }
  13659. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13660. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13661. if (empty ( $stList ))
  13662. $stList = array (
  13663. 'rePrice' => 0,
  13664. 'agPrice' => 0
  13665. );
  13666. $data ['stList'] = array (
  13667. 'rePrice' => $stList ['rePrice'],
  13668. 'agPrice' => $stList ['agPrice'],
  13669. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13670. );
  13671. $monthHtml = "";
  13672. for($i = 1; $i <= 12; $i ++) {
  13673. if ($i == $month)
  13674. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13675. else
  13676. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13677. }
  13678. $data ['username'] = urlencode ( $username );
  13679. $data ['usernameEN'] = $username;
  13680. $data ['monthHtml'] = $monthHtml;
  13681. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13682. $data ['list'] = $list;
  13683. $data ['categoryHtml'] = $categoryHtml;
  13684. $data ['itemHtml'] = $itemHtml;
  13685. $data ['itemList'] = $itemList;
  13686. $data ['year'] = $year;
  13687. $data ['month'] = $month;
  13688. $data ['memu'] = "receipt";
  13689. $data ['staff'] = $this->staff;
  13690. $data ['receiptMemu'] = 'companyCategoryCollect';
  13691. $data ['verifyId'] = $this->verifyId;
  13692. $data ['executeId'] = $this->executeId;
  13693. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13694. }
  13695. die ( 'illegal request' );
  13696. }
  13697. function companyMonthCollectDetail() {
  13698. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13699. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13700. if (! $year)
  13701. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13702. if (! $month)
  13703. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13704. Doo::loadModel ( 'staff' );
  13705. $staff = new staff ();
  13706. Doo::loadModel ( "receiptDetail" );
  13707. $receiptDetail = new receiptDetail ();
  13708. Doo::loadModel ( 'accountItem' );
  13709. $accountItem = new accountItem ();
  13710. Doo::loadModel ( 'statistics' );
  13711. $statistics = new statistics ();
  13712. Doo::loadModel ( 'L_category' );
  13713. $lCategory = new L_category ();
  13714. $staffList = $staff->find ( array (
  13715. 'where' => 'username!="admin"',
  13716. 'asArray' => true
  13717. ) );
  13718. $categoryList = $lCategory->find ( array (
  13719. 'asArray' => true
  13720. ) );
  13721. $aiList=$accountItem->getAccountItem();
  13722. $list = array ();
  13723. foreach ( $categoryList as $value ) {
  13724. $receiptCollectList = $receiptDetail->find ( array (
  13725. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13726. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13727. 'groupby' => 'item,Month(pastDate),itemCategory',
  13728. 'asArray' => true
  13729. ) );
  13730. if (! empty ( $receiptCollectList )) {
  13731. $receiptL = array (
  13732. '日常相关费用' => array (),
  13733. '差旅相关费用' => array (),
  13734. '内部培训费用' => array (),
  13735. '培训班费用' => array (),
  13736. '其他' => array ()
  13737. );
  13738. $html = "";
  13739. $psum = 0;
  13740. foreach ( $aiList[$this->AGENCY] as $va ) {
  13741. $falg = true;
  13742. foreach ( $receiptCollectList as $v ) {
  13743. if ($v ['itemCategory'] == $this->AGENCY) {
  13744. if ($v ['item'] == $va['name']) {
  13745. $psum += $v ['price'];
  13746. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13747. $falg = false;
  13748. break;
  13749. }
  13750. }
  13751. }
  13752. if ($falg)
  13753. $html .= '<td class="taR">-</td>';
  13754. }
  13755. if (! empty ( $psum ))
  13756. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13757. else
  13758. $psum = '<td class="colGreen taR">-</td>';
  13759. $receiptL [$this->AGENCY] = $psum . $html;
  13760. /* ----------------------------------- */
  13761. $html = "";
  13762. $psum = 0;
  13763. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13764. $falg = true;
  13765. foreach ( $receiptCollectList as $v ) {
  13766. if ($v ['itemCategory'] == $this->TRAVEL) {
  13767. if ($v ['item'] == $va['name']) {
  13768. $psum += $v ['price'];
  13769. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13770. $falg = false;
  13771. break;
  13772. }
  13773. }
  13774. }
  13775. if ($falg)
  13776. $html .= '<td class="taR">-</td>';
  13777. }
  13778. if (! empty ( $psum ))
  13779. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13780. else
  13781. $psum = '<td class="colGreen taR">-</td>';
  13782. $receiptL [$this->TRAVEL] = $psum . $html;
  13783. /* ------------------------------------- */
  13784. $html = "";
  13785. $psum = 0;
  13786. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13787. $falg = true;
  13788. foreach ( $receiptCollectList as $v ) {
  13789. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13790. if ($v ['item'] == $va['name']) {
  13791. $psum += $v ['price'];
  13792. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13793. $falg = false;
  13794. break;
  13795. }
  13796. }
  13797. }
  13798. if ($falg)
  13799. $html .= '<td class="taR">-</td>';
  13800. }
  13801. if (! empty ( $psum ))
  13802. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13803. else
  13804. $psum = '<td class="colGreen taR">-</td>';
  13805. $receiptL [$this->INTTRAIN] = $psum . $html;
  13806. /* ------------------------------------- */
  13807. $html = "";
  13808. $psum = 0;
  13809. foreach ( $aiList[$this->TRAIN] as $va ) {
  13810. $falg = true;
  13811. foreach ( $receiptCollectList as $v ) {
  13812. if ($v ['itemCategory'] == $this->TRAIN) {
  13813. if ($v ['item'] == $va['name']) {
  13814. $psum += $v ['price'];
  13815. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13816. $falg = false;
  13817. break;
  13818. }
  13819. }
  13820. }
  13821. if ($falg)
  13822. $html .= '<td class="taR">-</td>';
  13823. }
  13824. if (! empty ( $psum ))
  13825. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13826. else
  13827. $psum = '<td class="colGreen taR">-</td>';
  13828. $receiptL [$this->TRAIN] = $psum . $html;
  13829. /* ------------------------------------- */
  13830. $html = "";
  13831. $psum = 0;
  13832. foreach ( $aiList[$this->OTHER] as $va ) {
  13833. $falg = true;
  13834. foreach ( $receiptCollectList as $v ) {
  13835. if ($v ['itemCategory'] == $this->OTHER) {
  13836. if ($v ['item'] == $va['name']) {
  13837. $psum += $v ['price'];
  13838. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13839. $falg = false;
  13840. break;
  13841. }
  13842. }
  13843. }
  13844. if ($falg)
  13845. $html .= '<td class="taR">-</td>';
  13846. }
  13847. if (! empty ( $psum ))
  13848. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13849. else
  13850. $psum = '<td class="colGreen taR">-</td>';
  13851. $receiptL [$this->OTHER] = $psum . $html;
  13852. /* ------------------------------------- */
  13853. $html = "";
  13854. $psum = 0;
  13855. foreach ( $receiptCollectList as $v ) {
  13856. if ($v ['itemCategory'] == '报销金额调整') {
  13857. if (! empty ( $v ['price'] ))
  13858. $psum += $v ['price'];
  13859. }
  13860. }
  13861. if (! empty ( $psum ))
  13862. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13863. else
  13864. $psum = '<td class="taR colOrange">-</td>';
  13865. $receiptL ['报销金额调整'] = $psum . $html;
  13866. } else {
  13867. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13868. foreach ( $aiList[$this->AGENCY] as $va ) {
  13869. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13870. }
  13871. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13872. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13873. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13874. }
  13875. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13876. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13877. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13878. }
  13879. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13880. foreach ( $aiList[$this->TRAIN] as $va ) {
  13881. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13882. }
  13883. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13884. foreach ( $aiList[$this->OTHER] as $va ) {
  13885. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13886. }
  13887. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13888. }
  13889. $monthStaffPrice = $receiptDetail->find ( array (
  13890. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13891. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13892. 'asArray' => true
  13893. ) );
  13894. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13895. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13896. else
  13897. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13898. $list [$value ['title']] = $receiptL;
  13899. }
  13900. $data ['list'] = $list;
  13901. $receiptCollectList = $receiptDetail->find ( array (
  13902. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13903. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13904. 'groupby' => 'item,Month(pastDate),itemCategory',
  13905. 'asArray' => true
  13906. ) );
  13907. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13908. //print_r($data['monthPriceHtml']);
  13909. // foreach ($data['monthPriceHtml'] as $value){
  13910. // echo $value;
  13911. // }
  13912. // die;
  13913. // statistics html
  13914. $stList = $statistics->getOne ( array (
  13915. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13916. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13917. 'groupby' => 'Month(date)',
  13918. 'asArray' => true
  13919. ) );
  13920. if (empty ( $stList ))
  13921. $stList = array (
  13922. 'rePrice' => 0,
  13923. 'agPrice' => 0
  13924. );
  13925. $data ['stList'] = array (
  13926. 'rePrice' => $stList ['rePrice'],
  13927. 'agPrice' => $stList ['agPrice'],
  13928. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13929. );
  13930. $monthHtml = "";
  13931. for($i = 1; $i <= 12; $i ++) {
  13932. if ($i == $month)
  13933. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13934. else
  13935. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13936. }
  13937. $data ['aiList'] = $aiList;
  13938. $dateHtml = "";
  13939. $now = date ( "Y" );
  13940. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  13941. if ($YEARD <= $now) {
  13942. $dateHtml .= '<option ';
  13943. if ($year == $YEARD) {
  13944. $dateHtml .= 'selected ';
  13945. }
  13946. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  13947. }
  13948. }
  13949. $data ['dateHtml'] = $dateHtml;
  13950. $data ['monthHtml'] = $monthHtml;
  13951. $data ['year'] = $year;
  13952. $data ['month'] = $month;
  13953. $data ['memu'] = "receipt";
  13954. $data ['staff'] = $this->staff;
  13955. $data ['receiptMemu'] = 'companyCategoryCollect';
  13956. $data ['verifyId'] = $this->verifyId;
  13957. $data ['executeId'] = $this->executeId;
  13958. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13959. }
  13960. function staffCollectDetail() {
  13961. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13962. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13963. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13964. if (! $staffname) {
  13965. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13966. $staffname = urldecode ( $staffname );
  13967. }
  13968. Doo::loadModel ( 'staff' );
  13969. $staff = new staff ();
  13970. Doo::loadModel ( "receiptDetail" );
  13971. $receiptDetail = new receiptDetail ();
  13972. Doo::loadModel ( 'accountItem' );
  13973. $accountItem = new accountItem ();
  13974. Doo::loadModel ( 'statistics' );
  13975. $statistics = new statistics ();
  13976. Doo::loadModel ( 'L_category' );
  13977. $lCategory = new L_category ();
  13978. Doo::loadModel ( "receiptAuthorityManage" );
  13979. $receiptAuthorityManage = new receiptAuthorityManage ();
  13980. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13981. $cidList = array ();
  13982. foreach ( $imcStaff as $key => $value ) {
  13983. array_push ( $cidList, $value ['cid'] );
  13984. }
  13985. $cidString = implode ( ',', $cidList );
  13986. $staffList = $staff->find ( array (
  13987. 'where' => ' cid in (' . $cidString . ')',
  13988. 'asArray' => true
  13989. ) );
  13990. $stHtml = '';
  13991. $stTitle = "";
  13992. $staffId = 0;
  13993. $cid = 0;
  13994. $ocid = 0;
  13995. foreach ( $staffList as $value ) {
  13996. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13997. $stTitle = $value ['category'] . '-' . $value ['username'];
  13998. $staffId = $value ['sid'];
  13999. $cid = $value ['cid'];
  14000. $ocid = $value ['cid'];
  14001. if (! empty ( $value ['othercid'] ))
  14002. $cid = $value ['cid'] . ',' . $value ['othercid'];
  14003. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  14004. } elseif ($value ['username'] != 'admin')
  14005. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  14006. }
  14007. $data ['lCategoryHtml'] = $lCategory->find ( array (
  14008. 'where' => 'cid in(' . $cid . ')',
  14009. 'asArray' => true
  14010. ) );
  14011. if (empty ( $pcid ))
  14012. $pcid = $ocid;
  14013. $data ['ocid'] = $pcid;
  14014. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  14015. $this->showCache ( $path );
  14016. //
  14017. $receiptCollectList = $receiptDetail->find ( array (
  14018. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  14019. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  14020. 'groupby' => 'item,Month(pastDate),itemCategory',
  14021. 'asArray' => true
  14022. ) );
  14023. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  14024. // print_r($receiptCollectList);
  14025. $accountList = $accountItem->find ( array (
  14026. 'asArray' => true
  14027. ) );
  14028. // create CollectDetail HTML
  14029. $collectHtml = array ();
  14030. foreach ( $accountList as $key => $value ) {
  14031. $html = "";
  14032. $asum = 0;
  14033. for($i = 1; $i <= 12; $i ++) {
  14034. $falg = true;
  14035. foreach ( $receiptCollectList as $v ) {
  14036. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  14037. if ($v ['item'] == '可自加费用') {
  14038. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  14039. }
  14040. $asum += $v ['price'];
  14041. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14042. $falg = false;
  14043. break;
  14044. }
  14045. }
  14046. if ($falg)
  14047. $html .= '<td class="taR">-</td>';
  14048. }
  14049. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  14050. $collectHtml [$value ['category']] [$value ['name']] = $html;
  14051. }
  14052. $data ['collectHtml'] = $collectHtml;
  14053. // print_r($collectHtml);
  14054. // create Adjustment price html
  14055. $receiptCollectList = $receiptDetail->find ( array (
  14056. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  14057. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  14058. 'groupby' => 'itemCategory,Month(pastDate)',
  14059. 'asArray' => true
  14060. ) );
  14061. $adjustment = array ();
  14062. $collectArray = array (
  14063. '日常相关费用' => array (),
  14064. '差旅相关费用' => array (),
  14065. '培训班费用' => array (),
  14066. '内部培训费用'=>array(),
  14067. '其他' => array ()
  14068. );
  14069. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  14070. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  14071. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  14072. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  14073. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  14074. array_push ( $collectArray ['培训班费用'], $collectHtml );
  14075. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  14076. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  14077. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  14078. array_push ( $collectArray ['其他'], $collectHtml );
  14079. $data ['collectArray'] = $collectArray;
  14080. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  14081. array_push ( $adjustment, $collectHtml );
  14082. $data ['adjustment'] = $adjustment;
  14083. // total price html
  14084. $collectHtml = "";
  14085. $total = 0;
  14086. for($i = 1; $i <= 12; $i ++) {
  14087. $sumPrice = 0;
  14088. foreach ( $receiptCollectList as $key => $value ) {
  14089. if ($value ['month'] == $i) {
  14090. $sumPrice += $value ['price'];
  14091. }
  14092. }
  14093. if ($sumPrice == 0)
  14094. $collectHtml .= '<td class="taR">-</td>';
  14095. else
  14096. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  14097. $total += $sumPrice;
  14098. }
  14099. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  14100. // statistics html
  14101. $stList = $statistics->statisticsByYear ( $year, $staffId );
  14102. if (empty ( $stList ))
  14103. $stList = array (
  14104. 'rePrice' => 0,
  14105. 'agPrice' => 0
  14106. );
  14107. $data ['stList'] = array (
  14108. 'rePrice' => $stList ['rePrice'],
  14109. 'agPrice' => $stList ['agPrice'],
  14110. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  14111. );
  14112. $data ['totalPrice'] = $collectHtml;
  14113. $data ['totalYear'] = $total;
  14114. $data ['stHtml'] = $stHtml;
  14115. $data ['year'] = $year;
  14116. $data ['stTitle'] = $stTitle;
  14117. $data ['staffname'] = urlencode ( $staffname );
  14118. $data ['memu'] = "receipt";
  14119. $data ['staff'] = $this->staff;
  14120. $data ['receiptMemu'] = 'companyCategoryCollect';
  14121. $data ['verifyId'] = $this->verifyId;
  14122. $data ['executeId'] = $this->executeId;
  14123. if ($year < date ( "Y" )) {
  14124. Doo::loadModel ( 'receipt' );
  14125. $receipt = new receipt ();
  14126. $receiptList = $receipt->find ( array (
  14127. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  14128. 'asArray' => true
  14129. ) );
  14130. if (empty ( $receiptList )) { // generated files
  14131. ob_start ();
  14132. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  14133. $this->cacheFile ( $path );
  14134. die ();
  14135. }
  14136. }
  14137. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  14138. }
  14139. function BUGFLAG() {
  14140. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  14141. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  14142. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  14143. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  14144. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  14145. if (empty ( $status ))
  14146. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  14147. $page_size = 12;
  14148. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  14149. $vidList = array ();
  14150. $button = 0;
  14151. Doo::loadModel ( 'verify' );
  14152. $verify = new verify ();
  14153. Doo::loadModel ( 'receipt' );
  14154. $receipt = new receipt ();
  14155. Doo::loadModel ( 'staff' );
  14156. $staff = new staff ();
  14157. Doo::loadModel ( 'L_category' );
  14158. $Lcategory = new L_category ();
  14159. $dateCondition = " and Year(date) =" . $year;
  14160. if (! empty ( $month ))
  14161. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  14162. $categoryList = $Lcategory->find ( array (
  14163. 'asArray' => true
  14164. ) );
  14165. $staffList = $staff->find ( array (
  14166. 'where' => 'cid=' . $cid,
  14167. 'asArray' => true
  14168. ) );
  14169. $cateCondition = "";
  14170. $staffCondition = "";
  14171. $approvalCondition = "";
  14172. if (! empty ( $cid ))
  14173. $cateCondition = ' and cid=' . $cid;
  14174. if (! empty ( $sid )) {
  14175. $staffCondition = ' and staff=' . $sid;
  14176. $cateCondition = "";
  14177. }
  14178. $approvalCondition = " and status=" . $status;
  14179. if ($status == 2) {
  14180. // 查找角色审批人
  14181. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  14182. }
  14183. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  14184. $approvalCondition = ' and status=2 ';
  14185. }
  14186. if ($status == 1) {
  14187. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  14188. }
  14189. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  14190. $pageinfo ['page'] = array (
  14191. 'previous' => ''
  14192. );
  14193. if ($status == 0) {
  14194. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  14195. $receiptList = $receipt->find ( array (
  14196. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  14197. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  14198. 'desc' => 'rid',
  14199. 'asArray' => true
  14200. ) );
  14201. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  14202. } else
  14203. $receiptList = $receipt->find ( array (
  14204. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  14205. 'desc' => 'rid',
  14206. 'asArray' => true
  14207. ) );
  14208. $rLRes = $receipt->find ( array (
  14209. 'where' => 'status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )' . $cateCondition . $staffCondition,
  14210. 'desc' => 'rid',
  14211. 'asArray' => true
  14212. ) );
  14213. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  14214. // print_r($pageinfo);
  14215. $Locate = 0;
  14216. foreach ( $receiptList as $key => $value ) {
  14217. $receiptList [$key] ['Locate'] = $Locate;
  14218. $Locate ++;
  14219. $receiptList [$key] ['reviseDetail'] = array ();
  14220. if (! empty ( $value ['reviseDetail'] ))
  14221. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  14222. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  14223. $categoryDetil = $Lcategory->getOne ( array (
  14224. 'where' => 'cid=' . $value ['cid'],
  14225. 'asArray' => true
  14226. ) );
  14227. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  14228. $verifyList = $verify->getOne ( array (
  14229. 'where' => 'vid=' . $value ['verify'],
  14230. 'asArray' => true
  14231. ) );
  14232. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  14233. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  14234. foreach ( $verifyList as $k => $v ) {
  14235. // init verifyStaff
  14236. $verifyList [$k] ['date'] = "";
  14237. $verifyList [$k] ['opinion'] = "";
  14238. $verifyList [$k] ['status'] = "";
  14239. if (empty ( $verifyStaff )) {
  14240. $verifyList [$k] ['date'] = "";
  14241. $verifyList [$k] ['opinion'] = "";
  14242. if ($v [0] == $this->staff [0] ['sid']) {
  14243. $verifyList [$k] ['status'] = 4;
  14244. $button = 4;
  14245. }
  14246. } else {
  14247. $flag = true;
  14248. foreach ( $verifyStaff as $m => $u ) {
  14249. if ($v [0] == $m) {
  14250. $verifyList [$k] ['date'] = $u ['date'];
  14251. $verifyList [$k] ['opinion'] = $u ['opinion'];
  14252. $verifyList [$k] ['status'] = $u ['status'];
  14253. $flag = false;
  14254. break;
  14255. }
  14256. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  14257. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  14258. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  14259. }
  14260. if ($flag) { // 检测可编辑
  14261. if ($v [0] == $this->staff [0] ['sid']) {
  14262. $verifyList [$k] ['status'] = 4;
  14263. $button = 4;
  14264. }
  14265. }
  14266. }
  14267. }
  14268. $receiptList [$key] ['verifyList'] = $verifyList;
  14269. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  14270. 'where' => 'sid=' . $value ['staff'],
  14271. 'asArray' => true
  14272. ) );
  14273. $receiptList [$key] ['button'] = $button;
  14274. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  14275. }
  14276. // print_r($receiptList);die;
  14277. // $data['verifyDetail']=$verifyDetail;
  14278. $mothHtml = "";
  14279. for($i = 1; $i <= 12; $i ++) {
  14280. if ($month == $i)
  14281. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  14282. else
  14283. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  14284. }
  14285. $data ['mothHtml'] = $mothHtml;
  14286. $data ['page'] = $pageinfo;
  14287. $data ['receiptList'] = $receiptList;
  14288. $data ['receiptApprovalCount'] = count ( $rLRes );
  14289. $data ['status'] = $status;
  14290. $data ['year'] = $year;
  14291. $data ['categoryList'] = $categoryList;
  14292. $data ['staffList'] = $staffList;
  14293. $data ['cid'] = $cid;
  14294. $data ['sid'] = $sid;
  14295. // print_r($receiptList);
  14296. $data ['memu'] = "receipt";
  14297. $data ['staff'] = $this->staff;
  14298. $data ['receiptMemu'] = 'approvalExpenses';
  14299. $data ['verifyId'] = $this->verifyId;
  14300. $data ['executeId'] = $this->executeId;
  14301. $this->render ( "/admin/FALG", $data );
  14302. }
  14303. function ajaxGetReceiptOrder() {
  14304. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  14305. if (! empty ( $receiptOrder )) {
  14306. Doo::loadModel ( 'receipt' );
  14307. $receipt = new receipt ();
  14308. Doo::loadModel ( 'staff' );
  14309. $staff = new staff ();
  14310. $receiptInfo = $receipt->getOne ( array (
  14311. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  14312. 'asArray' => true
  14313. ) );
  14314. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  14315. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  14316. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  14317. </tbody></table><table class="table table table-bordered"><tbody>';
  14318. foreach ( $verifyStaff as $key => $value ) {
  14319. $staffInfo = $staff->getOne ( array (
  14320. 'select' => 'username',
  14321. 'where' => ' sid="' . $key . '"',
  14322. 'asArray' => true
  14323. ) );
  14324. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  14325. }
  14326. $html .= '</tbody></table></div></div>';
  14327. echo json_encode ( array (
  14328. 'status' => 1,
  14329. 'receiptHtml' => $html
  14330. ) );
  14331. die ();
  14332. }
  14333. echo json_encode ( array (
  14334. 'status' => 2,
  14335. 'receiptHtml' => ''
  14336. ) );
  14337. die ();
  14338. }
  14339. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  14340. if (! empty ( $receiptCollectList )) {
  14341. $receiptL = array (
  14342. '日常相关费用' => array (),
  14343. '差旅相关费用' => array (),
  14344. '内部培训费用'=>array(),
  14345. '培训班费用' => array (),
  14346. '其他' => array ()
  14347. );
  14348. $html = "";
  14349. $psum = 0;
  14350. foreach ( $aiList[$this->AGENCY] as $value ) {
  14351. $falg = true;
  14352. foreach ( $receiptCollectList as $v ) {
  14353. if ($v ['itemCategory'] == '日常相关费用') {
  14354. if ($v ['item'] == $value['name']) {
  14355. $psum += $v ['price'];
  14356. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14357. $falg = false;
  14358. break;
  14359. }
  14360. }
  14361. }
  14362. if ($falg)
  14363. $html .= '<td class="taR">-</td>';
  14364. }
  14365. if (! empty ( $psum ))
  14366. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14367. else
  14368. $psum = '<td class="colGreen taR">-</td>';
  14369. $receiptL ['日常相关费用'] = $psum . $html;
  14370. /* ----------------------------------- */
  14371. $html = "";
  14372. $psum = 0;
  14373. foreach ( $aiList[$this->TRAVEL] as $value ) {
  14374. $falg = true;
  14375. foreach ( $receiptCollectList as $v ) {
  14376. if ($v ['itemCategory'] == '差旅相关费用') {
  14377. if ($v ['item'] == $value['name']) {
  14378. $psum += $v ['price'];
  14379. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14380. $falg = false;
  14381. break;
  14382. }
  14383. }
  14384. }
  14385. if ($falg)
  14386. $html .= '<td class="taR">-</td>';
  14387. }
  14388. if (! empty ( $psum ))
  14389. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14390. else
  14391. $psum = '<td class="colGreen taR">-</td>';
  14392. $receiptL ['差旅相关费用'] = $psum . $html;
  14393. /* ----------------------------------- */
  14394. $html = "";
  14395. $psum = 0;
  14396. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  14397. $falg = true;
  14398. foreach ( $receiptCollectList as $v ) {
  14399. if ($v ['itemCategory'] == '内部培训费用') {
  14400. if ($v ['item'] == $value['name']) {
  14401. $psum += $v ['price'];
  14402. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14403. $falg = false;
  14404. break;
  14405. }
  14406. }
  14407. }
  14408. if ($falg)
  14409. $html .= '<td class="taR">-</td>';
  14410. }
  14411. if (! empty ( $psum ))
  14412. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14413. else
  14414. $psum = '<td class="colGreen taR">-</td>';
  14415. $receiptL ['内部培训费用'] = $psum . $html;
  14416. /* ------------------------------------- */
  14417. $html = "";
  14418. $psum = 0;
  14419. foreach ( $aiList[$this->TRAIN] as $value ) {
  14420. $falg = true;
  14421. foreach ( $receiptCollectList as $v ) {
  14422. if ($v ['itemCategory'] == '培训班费用') {
  14423. if ($v ['item'] == $value['name']) {
  14424. $psum += $v ['price'];
  14425. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14426. $falg = false;
  14427. break;
  14428. }
  14429. }
  14430. }
  14431. if ($falg)
  14432. $html .= '<td class="taR">-</td>';
  14433. }
  14434. if (! empty ( $psum ))
  14435. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14436. else
  14437. $psum = '<td class="colGreen taR">-</td>';
  14438. $receiptL ['培训班费用'] = $psum . $html;
  14439. /* ------------------------------------- */
  14440. $html = "";
  14441. $psum = 0;
  14442. foreach ( $aiList[$this->OTHER] as $value ) {
  14443. $falg = true;
  14444. foreach ( $receiptCollectList as $v ) {
  14445. if ($v ['itemCategory'] == '其他') {
  14446. if ($v ['item'] == $value['name']) {
  14447. $psum += $v ['price'];
  14448. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14449. $falg = false;
  14450. break;
  14451. }
  14452. }
  14453. }
  14454. if ($falg)
  14455. $html .= '<td class="taR">-</td>';
  14456. }
  14457. if (! empty ( $psum ))
  14458. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14459. else
  14460. $psum = '<td class="colGreen taR">-</td>';
  14461. $receiptL ['其他'] = $psum . $html;
  14462. /* ------------------------------------- */
  14463. $html = "";
  14464. $psum = 0;
  14465. foreach ( $receiptCollectList as $v ) {
  14466. if ($v ['itemCategory'] == '报销金额调整') {
  14467. if (! empty ( $v ['price'] ))
  14468. $psum += $v ['price'];
  14469. }
  14470. }
  14471. if (! empty ( $psum ))
  14472. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  14473. else
  14474. $psum = '<td class="taR colOrange">-</td>';
  14475. $receiptL ['报销金额调整'] = $psum . $html;
  14476. } else {
  14477. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  14478. foreach ( $aiList[$this->AGENCY] as $va ) {
  14479. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  14480. }
  14481. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  14482. foreach ( $aiList[$this->TRAVEL] as $va ) {
  14483. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  14484. }
  14485. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  14486. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  14487. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  14488. }
  14489. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  14490. foreach ( $aiList[$this->TRAIN] as $va ) {
  14491. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  14492. }
  14493. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  14494. foreach ( $aiList[$this->OTHER] as $va ) {
  14495. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  14496. }
  14497. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  14498. }
  14499. return $receiptL;
  14500. }
  14501. function eMail() {
  14502. Doo::loadModel ( 'staff' );
  14503. $staff = new staff ();
  14504. Doo::loadModel ( 'receipt' );
  14505. $receipt = new receipt ();
  14506. Doo::loadModel ( 'L_category' );
  14507. $Lcategory = new L_category ();
  14508. Doo::loadModel ( "verify" );
  14509. $verify = new verify ();
  14510. $staffList = $staff->find ( array (
  14511. 'asArray' => true
  14512. ) );
  14513. foreach ( $staffList as $key => $value ) {
  14514. if ($value ['username'] != 'admin') {
  14515. // 提交人
  14516. $receiptList = $receipt->find ( array (
  14517. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  14518. 'asArray' => true
  14519. ) );
  14520. if (! empty ( $receiptList )) {
  14521. $html = '<br><div><style></style>
  14522. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  14523. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  14524. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14525. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  14526. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14527. <tbody><tr>
  14528. <td style="padding: 0 40px;" align="left">
  14529. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14530. </td></tr><tr>
  14531. <td style="padding: 0 40px;" align="left"><p style="margin-top:0px;margin-bottom:40px;color:#383838;font-size:20px;line-height:32px;">美好的一天从今天开始,您需要关注以下事项:</p></td>
  14532. </tr>
  14533. </tbody> </table></td> </tr> <tr><td>
  14534. <table style="background-color:#f5f6f7;width:100%;padding:0 0 20px;border-left:1px solid #ddd;border-right:1px solid #ddd;" cellpadding="0" cellspacing="0" align="left">
  14535. <tbody> <tr><td>
  14536. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  14537. 以下报销单完成了审批,等着收款吧:</p>
  14538. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  14539. foreach ( $receiptList as $k => $v ) {
  14540. $category = $Lcategory->getOne ( array (
  14541. 'where' => 'cid=' . $v ['cid'],
  14542. 'asArray' => true
  14543. ) );
  14544. $html .= '
  14545. <tr>
  14546. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14547. <td align="left">
  14548. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  14549. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  14550. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  14551. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  14552. </tr>';
  14553. }
  14554. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  14555. <tr><td style="height:150px;border:1px solid #ddd;border-top:none;background-color:#fff;" align="center"><a href="http://cld.smartcost.com.cn/approval" style="display:block;height:50px;width:260px;background-color:#0390ff;font-weight:normal;font-size:18px;color:white;line-height:50px;text-align:center;text-decoration:none;border-radius:3px;">立即登录</a></td>
  14556. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  14557. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  14558. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  14559. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14560. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14561. $receipt = new receipt ();
  14562. $receipt->notice = 1;
  14563. $receipt->update ( array (
  14564. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  14565. ) );
  14566. }
  14567. }
  14568. // 审批人
  14569. $verifyList = $verify->find ( array (
  14570. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  14571. 'asArray' => true
  14572. ) );
  14573. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  14574. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  14575. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14576. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  14577. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14578. <tbody><tr><td style="padding: 0 40px;" align="left">
  14579. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14580. </td></tr><tr><td style="padding: 0 40px;" align="left"><p style="margin-top:0px;margin-bottom:40px;color:#383838;font-size:20px;line-height:32px;">美好的一天从今天开始,您需要关注以下事项:</p></td>
  14581. </tr></tbody></table></td> </tr> <tr><td><table style="background-color:#f5f6f7;width:100%;padding:0 0 20px;border-left:1px solid #ddd;border-right:1px solid #ddd;" cellpadding="0" cellspacing="0" align="left">
  14582. <tbody><tr><td><p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">以下报销单需要您的审批:</p></td>
  14583. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  14584. foreach ( $verifyList as $k => $v ) {
  14585. $receiptList = $receipt->find ( array (
  14586. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  14587. 'asArray' => true
  14588. ) );
  14589. foreach ( $receiptList as $r => $l ) {
  14590. $category = $Lcategory->getOne ( array (
  14591. 'where' => 'cid=' . $l ['cid'],
  14592. 'asArray' => true
  14593. ) );
  14594. $staffDetile = $staff->getOne ( array (
  14595. 'where' => 'sid=' . $l ['staff'],
  14596. 'asArray' => true
  14597. ) );
  14598. $html .= '
  14599. <tr>
  14600. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14601. <td align="left">
  14602. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  14603. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  14604. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  14605. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  14606. </tr>';
  14607. }
  14608. }
  14609. $html .= '
  14610. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  14611. <td style="height:150px;border:1px solid #ddd;border-top:none;background-color:#fff;" align="center"><a href="http://cld.smartcost.com.cn/approval" style="display:block;height:50px;width:260px;background-color:#0390ff;font-weight:normal;font-size:18px;color:white;line-height:50px;text-align:center;text-decoration:none;border-radius:3px;">立即登录</a></td>
  14612. </tr></tbody></table></td></tr></tbody></table></div><br>';
  14613. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  14614. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  14615. // $receipt=new receipt();
  14616. // $receipt->notice=1;
  14617. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  14618. }
  14619. }
  14620. }
  14621. }
  14622. function setWXMsg($rid, $type) {
  14623. Doo::loadModel ( "receipt" );
  14624. $receipt = new receipt ();
  14625. $receiptDetail = $receipt->getOne ( array (
  14626. 'where' => 'rid=' . $rid,
  14627. 'asArray' => true
  14628. ) );
  14629. if (! empty ( $receiptDetail )) {
  14630. Doo::loadModel ( 'staff' );
  14631. $staff = new staff ();
  14632. $staffmsg = $staff->getOne ( array (
  14633. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  14634. 'asArray' => TRUE
  14635. ) );
  14636. if (! empty ( $staffmsg ['wxid'] )) {
  14637. require_once (SITE_PATH . '/protected/class/client.php');
  14638. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  14639. $user = $staffmsg ['wxid'];
  14640. $receiptName = '';
  14641. $msg = '';
  14642. switch ($receiptDetail ['Rtype']) {
  14643. case 0 :
  14644. $receiptName = '报销';
  14645. break;
  14646. case 1 :
  14647. $receiptName = '借款';
  14648. break;
  14649. case 2 :
  14650. $receiptName = '对公汇款';
  14651. break;
  14652. }
  14653. switch ($type) {
  14654. case 1 :
  14655. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14656. break;
  14657. case 2 :
  14658. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14659. break;
  14660. case 3 :
  14661. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14662. break;
  14663. }
  14664. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14665. }
  14666. }
  14667. }
  14668. // Email发送函数
  14669. function SMail($toemail, $subject, $contents) {
  14670. Doo::loadClass ( 'class.phpmailer' );
  14671. $mail = new PHPMailer ();
  14672. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14673. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14674. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14675. $mail->Password = "cDO1GjtY1seH"; // 密码
  14676. $mail->CharSet = "UTF8";
  14677. $mail->SMTPAuth = true;
  14678. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14679. $mail->Mailer = "smtp";
  14680. $mail->Port = 25;
  14681. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14682. $mail->MsgHTML ( $contents );
  14683. $mail->AddAddress ( $toemail );
  14684. $mail->CharSet = "UTF-8";
  14685. return $mail->Send ();
  14686. }
  14687. function h5Upload() {
  14688. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14689. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14690. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14691. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14692. header ( "HTTP/1.1 500 Internal Server Error" );
  14693. echo "POST exceeded maximum allowed size.";
  14694. exit ( 0 );
  14695. }
  14696. // Settings
  14697. $save_path = DOO::conf ()->SITE_PATH . "upload/swfupload/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  14698. $upload_name = "Filedata";
  14699. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14700. $extension_whitelist = array (
  14701. "doc",
  14702. "txt",
  14703. "jpg",
  14704. "gif",
  14705. "png"
  14706. ); // Allowed file extensions
  14707. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14708. // Other variables
  14709. $MAX_FILENAME_LENGTH = 260;
  14710. $file_name = "";
  14711. $file_extension = "";
  14712. $uploadErrors = array (
  14713. 0 => "文件上传成功",
  14714. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14715. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14716. 3 => "上传的文件仅为部分文件",
  14717. 4 => "没有文件上传",
  14718. 6 => "缺少临时文件夹"
  14719. );
  14720. $nk = time ();
  14721. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14722. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14723. echo "文件无法保存.";
  14724. exit ( 0 );
  14725. }
  14726. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14727. echo json_encode ( array (
  14728. 'filename' => $file_name,
  14729. 'id' => $nk
  14730. ) );
  14731. exit ( 0 );
  14732. }
  14733. function swfupload() {
  14734. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14735. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14736. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14737. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14738. header ( "HTTP/1.1 500 Internal Server Error" );
  14739. echo "POST exceeded maximum allowed size.";
  14740. exit ( 0 );
  14741. }
  14742. // Settings
  14743. $save_path = DOO::conf ()->SITE_PATH . "upload/swfupload/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  14744. $upload_name = "Filedata";
  14745. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14746. $extension_whitelist = array (
  14747. "doc",
  14748. "txt",
  14749. "jpg",
  14750. "gif",
  14751. "png"
  14752. ); // Allowed file extensions
  14753. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14754. // Other variables
  14755. $MAX_FILENAME_LENGTH = 260;
  14756. $file_name = "";
  14757. $file_extension = "";
  14758. $uploadErrors = array (
  14759. 0 => "文件上传成功",
  14760. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14761. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14762. 3 => "上传的文件仅为部分文件",
  14763. 4 => "没有文件上传",
  14764. 6 => "缺少临时文件夹"
  14765. );
  14766. $nk = time ();
  14767. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14768. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14769. echo "文件无法保存.";
  14770. exit ( 0 );
  14771. }
  14772. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14773. echo json_encode ( array (
  14774. 'filename' => $file_name,
  14775. 'id' => $nk
  14776. ) );
  14777. exit ( 0 );
  14778. }
  14779. function _GetFileEXT($filename) {
  14780. $pics = explode ( '.', $filename );
  14781. $num = count ( $pics );
  14782. return $pics [$num - 1];
  14783. }
  14784. /**
  14785. * 获取get或者POST值
  14786. * @param string $name 属性名称
  14787. * @return fixed 值
  14788. */
  14789. function get_args($name) {
  14790. if (isset ( $_GET [$name] )) {
  14791. if (is_array ( $_GET [$name] ))
  14792. return $_GET [$name];
  14793. else
  14794. return addslashes ( $_GET [$name] );
  14795. } elseif (isset ( $_POST [$name] )) {
  14796. if (is_array ( $_POST [$name] ))
  14797. return $_POST [$name];
  14798. else
  14799. return addslashes ( $_POST [$name] );
  14800. } else
  14801. return false;
  14802. }
  14803. function num_to_rmb($num) {
  14804. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14805. $c2 = "分角元拾佰仟万拾佰仟亿";
  14806. // 精确到分后面就不要了,所以只留两个小数位
  14807. $num = round ( $num, 2 );
  14808. // 将数字转化为整数
  14809. $num = $num * 100;
  14810. if (strlen ( $num ) > 10) {
  14811. return "金额太大,请检查";
  14812. }
  14813. $i = 0;
  14814. $c = "";
  14815. while ( 1 ) {
  14816. if ($i == 0) {
  14817. // 获取最后一位数字
  14818. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14819. } else {
  14820. $n = $num % 10;
  14821. }
  14822. // 每次将最后一位数字转化为中文
  14823. $p1 = substr ( $c1, 3 * $n, 3 );
  14824. $p2 = substr ( $c2, 3 * $i, 3 );
  14825. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14826. $c = $p1 . $p2 . $c;
  14827. } else {
  14828. $c = $p1 . $c;
  14829. }
  14830. $i = $i + 1;
  14831. // 去掉数字最后一位了
  14832. $num = $num / 10;
  14833. // echo $num.'</br>';
  14834. $num = ( int ) $num;
  14835. // $num =floor($num);
  14836. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14837. // echo $num.'</br>';
  14838. // 结束循环
  14839. if ($num == 0) {
  14840. break;
  14841. }
  14842. }
  14843. // echo $c.'</br>';
  14844. $j = 0;
  14845. $slen = strlen ( $c );
  14846. while ( $j < $slen ) {
  14847. // utf8一个汉字相当3个字符
  14848. $m = substr ( $c, $j, 6 );
  14849. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14850. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14851. $left = substr ( $c, 0, $j );
  14852. $right = substr ( $c, $j + 3 );
  14853. $c = $left . $right;
  14854. $j = $j - 3;
  14855. $slen = $slen - 3;
  14856. }
  14857. $j = $j + 3;
  14858. }
  14859. // 这个是为了去掉类似23.0中最后一个“零”字
  14860. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14861. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14862. }
  14863. // 将处理的汉字加上“整”
  14864. if (empty ( $c )) {
  14865. return "零元整";
  14866. } else {
  14867. return $c . "整";
  14868. }
  14869. }
  14870. /**
  14871. * 获得分页数据
  14872. * @param unknown_type $table
  14873. * @param unknown_type $condition
  14874. * @param unknown_type $on_page
  14875. * @param unknown_type $page_size
  14876. */
  14877. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14878. $page_c = "";
  14879. $page ['previous'] = $this->get_previous ( $on_page );
  14880. $page ['on_page'] = $on_page;
  14881. $total_count = $this->get_table_count ( $table, $condition );
  14882. $total = intval ( $total_count / $page_size );
  14883. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14884. $page ['total_data'] = $total_count;
  14885. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14886. $i = 1;
  14887. $page_max = 1;
  14888. $page_width = 3;
  14889. if ($on_page >= $page_width) {
  14890. $page_max = intval ( $on_page / $page_width ) + 1;
  14891. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14892. }
  14893. for(; $i <= $page ['total_page']; $i ++) {
  14894. if ($i == $on_page)
  14895. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14896. else
  14897. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14898. if ($i == ($page_width * $page_max))
  14899. break;
  14900. }
  14901. $page ['page'] = $page_c;
  14902. $page ['lower'] = (-- $on_page) * $page_size;
  14903. return $page;
  14904. }
  14905. /**
  14906. * 获取总页数
  14907. * @param unknown_type $table
  14908. * @param unknown_type $condition
  14909. */
  14910. public function get_table_count($table = "", $condition = "") {
  14911. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14912. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14913. // echo $sql;die;
  14914. $query = Doo::db ()->query ( $sql );
  14915. $result = $query->fetch ();
  14916. return $result ['count'];
  14917. }
  14918. /**
  14919. * 获取上一页
  14920. * @param unknown_type $on_page
  14921. */
  14922. function get_previous($on_page = 1) {
  14923. return $on_page != 0 ? $on_page - 1 : $on_page;
  14924. }
  14925. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  14926. // 收入合计
  14927. Doo::loadModel ( 'invoiceTraining' );
  14928. $invoiceTraining = new invoiceTraining ();
  14929. Doo::loadModel ( 'receipt' );
  14930. $receipt = new receipt ();
  14931. $invoiceTrainingDetail = array (
  14932. 'invoiceArriveAmount' => '0.00',
  14933. 'RIAmount' => '0.00',
  14934. 'invoiceTotalAmount' => '0.00',
  14935. 'invoiceCompanyAmount' => '0.00',
  14936. 'invoiceArriveAmountM'=>'0.00',
  14937. 'invoiceCompanyAmountM'=>'0.00'
  14938. );
  14939. if ($invoiceTrainId != 0) {
  14940. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  14941. }
  14942. $invoiceArriveAmount = $RIAmount = 0;
  14943. if (! empty ( $invoiceTrainingDetail )) {
  14944. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  14945. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  14946. }
  14947. // 备用金
  14948. $sum = 0;
  14949. if (! empty ( $trainLoanRid )) {
  14950. $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
  14951. foreach ($receiptLoanList as $key=>$value){
  14952. $sum+=$value['sum'];
  14953. }
  14954. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  14955. // $sum = $receiptLoanDetailBak ['sum'];
  14956. }
  14957. // 支出项金额详情
  14958. // 项目金额合计
  14959. Doo::loadModel ( 'RItem' );
  14960. $RItem = new RItem ();
  14961. Doo::loadModel ( 'accountItem' );
  14962. $accountItem = new accountItem ();
  14963. // 讲师获得
  14964. Doo::loadModel ( 'RILecturer' );
  14965. $RILecturer = new RILecturer ();
  14966. $RItemList = $RItem->getRItemByRid ($rid );
  14967. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  14968. // 支出项金额详情
  14969. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  14970. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  14971. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  14972. return $payment;
  14973. }
  14974. }
  14975. ?>