ReceiptController.php 291 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. public static $NEW = 0;
  10. public static $NEW2 = 0;
  11. public $AGENCY="日常相关费用";
  12. public $TRAVEL="差旅相关费用";
  13. public $TRAIN="培训班费用";
  14. public $OTHER="其他";
  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;die;
  23. }
  24. }
  25. private function cacheFile($path){
  26. $content = ob_get_contents();
  27. $fp = fopen($path, "w");
  28. fwrite($fp, $content);
  29. fclose($fp);
  30. }
  31. private function getExeCount(){
  32. Doo::loadModel('receipt');
  33. $receipt=new receipt();
  34. $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  35. return count($receiptList);
  36. }
  37. private function getReceiptCount(){
  38. $status=2;
  39. $year=date('Y');
  40. Doo::loadModel('receipt');
  41. $receipt=new receipt();
  42. Doo::loadModel('verify');
  43. // $verify=new verify();
  44. //
  45. // //user verify ID
  46. // $vidList=array();
  47. // $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'\"%"','asArray'=>true));
  48. // foreach ($verifyDetail as $key=>$value){
  49. // array_push($vidList, $value['vid']);
  50. // }
  51. // $vid=implode(",", $vidList);
  52. // if(empty($verifyDetail))
  53. // $vid=0;
  54. $dateCondition=" and Year(date) =".$year;
  55. //$approvalCondition=' and verifyStaff not like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  56. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  57. $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  58. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  59. return count($receiptList);
  60. }
  61. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  62. $collectHtml="";$sumPrice=0.00;
  63. for ($i=1;$i<=12;$i++){
  64. $falg=true;
  65. foreach ($receiptCollectList as $key=>$value){
  66. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  67. $sumPrice+=$value['price'];
  68. if ($classType=="b"){
  69. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  70. }else{
  71. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  72. }
  73. }
  74. }
  75. if ($falg)
  76. $collectHtml.='<td class="taR">-</td>';
  77. }
  78. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  79. return $collectHtml;
  80. }
  81. function __construct() {
  82. if(isset($_COOKIE["staff"])){
  83. if(!empty($_COOKIE["staff"])){
  84. Doo::loadModel ( 'staff' );
  85. Doo::loadModel('verify');
  86. $verify=new verify();
  87. $staff = new staff ();
  88. Doo::loadModel("execute");
  89. $execute=new execute();
  90. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  91. $list=array();
  92. //判断角色的审批权限
  93. foreach ($verifyList as $key=>$value){
  94. $ver=json_decode($value['staff']);
  95. foreach ($ver as $k=>$v){
  96. if ($v[1]=='ROLE'){
  97. $roleList=json_decode($v[3]);
  98. foreach ($roleList as $t=>$g){
  99. $gList=explode("_", $g);
  100. array_push($list, $gList[0]);
  101. //print_r($list);
  102. }
  103. }else
  104. array_push($list, $v[0]);
  105. }
  106. }
  107. //判断执行人的审批权限
  108. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  109. $list2=array();
  110. foreach ($executeList as $key=>$value){
  111. $ver=json_decode($value['staff']);
  112. foreach ($ver as $k=>$v){
  113. array_push($list2, $v[0]);
  114. }
  115. }
  116. $eidList=file_get_contents("protected/config/execute/execute.ini");
  117. $eidList=array_filter(explode(",", $eidList));
  118. $this->executeId= array_merge($list2,$eidList);
  119. $this->verifyId=$list;
  120. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  121. self::$NEW= $this->getReceiptCount();
  122. self::$NEW2= $this->getExeCount();
  123. return "/";
  124. }
  125. }
  126. Doo::loadCore ( 'uri/DooUriRouter' );
  127. $router = new DooUriRouter ();
  128. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  129. if($routeRs['1']!="login"){
  130. header ( 'Content-Type:text/html;charset=utf-8' );
  131. @header ( "Location: /login" );
  132. }
  133. }
  134. function saeaBorad(){
  135. Doo::loadModel('receipt');
  136. Doo::loadModel('verify');
  137. $verify=new verify();
  138. $receipt=new receipt();
  139. Doo::loadModel('L_category');
  140. $lCategory=new L_category();
  141. Doo::loadModel("role");
  142. $role=new role();
  143. Doo::loadModel("receiptLog");
  144. $receiptLog=new receiptLog();
  145. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  146. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)','desc'=>'rid','asArray'=>true));
  147. foreach ($receiptDetail as $key=>$value){
  148. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  149. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  150. $v=json_decode($veList['staff']);
  151. array_push($v[0], $veList['description']);
  152. foreach ($v as $n=>$m){
  153. if ($m['1']=='ROLE'){
  154. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  155. $v[$n][1]=$roleInfo['name'];
  156. }
  157. }
  158. $receiptDetail[$key]['staff']=$v;
  159. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  160. $receiptDetail[$key]['category']=$category['title'];
  161. }
  162. //print_r($receiptLogList);
  163. $data['receiptLogList']=$receiptLogList;
  164. $data['receiptDetail']=$receiptDetail;
  165. $data['memu']="receipt";
  166. $data['staff']=$this->staff;
  167. $data['receiptMemu']='saeaBorad';
  168. $data['verifyId']=$this->verifyId;
  169. $data['executeId']=$this->executeId;
  170. $this->render ( "/admin/saeaBorad", $data );
  171. }
  172. function remitAdd(){
  173. Doo::loadModel('accountItem');
  174. Doo::loadModel('verify');
  175. Doo::loadModel('receipt');
  176. Doo::loadModel('L_category');
  177. $lCategory=new L_category();
  178. $receipt=new receipt();
  179. $verify=new verify();
  180. $accountItem=new accountItem();
  181. Doo::loadModel("role");
  182. $role=new role();
  183. $acItem=$accountItem->find(array('asArray'=>true));
  184. $veList=$verify->find(array('asArray'=>true));
  185. foreach ($veList as $key=>$value){
  186. $v=json_decode($value['staff']);
  187. $list=array();
  188. foreach ($v as $n=>$m){
  189. if ($m['1']=='ROLE'){
  190. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  191. $v[$n][1]=$roleInfo['name'];
  192. array_push($list, $roleInfo['name']);
  193. }else{
  194. array_push($list, $v[$n][1]);
  195. }
  196. }
  197. $veList[$key]['staff']=implode('>', $list);
  198. }
  199. $data['category']=$lCategory->find(array('asArray'=>true));
  200. $data['veList']=$veList;
  201. $data['acItem']=$acItem;
  202. $data['memu']="receipt";
  203. $data['staff']=$this->staff;
  204. $data['receiptMemu']='saeaBorad';
  205. $data['verifyId']=$this->verifyId;
  206. $data['executeId']=$this->executeId;
  207. $this->render ( "/admin/remitAdd", $data );
  208. }
  209. function remitAddDo(){
  210. $agency=$this->get_args('agency');
  211. $travel=$this->get_args('travel');
  212. $train=$this->get_args('train');
  213. $other=$this->get_args('other');
  214. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  215. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  216. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  217. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  218. //print_r($agency);die;
  219. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  220. Doo::loadModel('receipt');
  221. Doo::loadModel('receiptDetail');
  222. Doo::loadModel('accountItem');
  223. $accountItem=new accountItem();
  224. $receipt=new receipt();
  225. Doo::loadModel('enclosur');
  226. Doo::loadModel('execute');
  227. $execute=new execute();
  228. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  229. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  230. // if(!empty($receiptDetail))
  231. // return "/referReceipt/".$receiptDetail['rid'];
  232. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  233. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  234. $ag=$tr=$ta=$ot=0;
  235. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  236. foreach ($aItem as $key=>$value){
  237. if ($value['category']==$this->AGENCY){
  238. if (isset($agency[$ag])){
  239. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  240. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  241. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  242. }
  243. }
  244. $ag++;
  245. }
  246. }
  247. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  248. //报销单
  249. $receipt->accountItem=json_encode($accountJson);
  250. $receipt->staff=$this->staff[0]['sid'];
  251. $receipt->sum=number_format($sum, 2, '.', '');
  252. $receipt->date=date("Y-m-d");
  253. $receipt->cid=$cid;
  254. $receipt->status=5;
  255. $receipt->Rtype=2;
  256. //修改审批流程加入角色
  257. $receipt->verify=$verify;
  258. $receipt->executeCopy=$executeDetail['staff'];
  259. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  260. $receipt->explanation=$explanation;
  261. $rid=$receipt->insert();
  262. //附件
  263. if (!empty($enclosurName)){
  264. $enclosurArray=explode('-', $enclosurName);
  265. foreach ($enclosurArray as $value){
  266. $enclosur=new enclosur();
  267. $enclosur->name=$value;
  268. $enclosur->rid=$rid;
  269. $enclosur->insert();
  270. }
  271. //print_r($enclosurArray);die;
  272. }
  273. //报销详情
  274. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  275. $receiptDetail=new receiptDetail();
  276. $receiptDetail->staff=$this->staff[0]['sid'];
  277. $receiptDetail->item=$value['name'];
  278. $receiptDetail->itemCategory=$this->AGENCY;
  279. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  280. $receiptDetail->date=date("Y-m-d");
  281. $receiptDetail->cid=$cid;
  282. $receiptDetail->rid=$rid;
  283. $receiptDetail->status=4;
  284. $receiptDetail->insert();
  285. }
  286. }
  287. return "/saeaBorad";
  288. }
  289. function remitEdit(){
  290. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  291. //echo $rid;
  292. Doo::loadModel('accountItem');
  293. Doo::loadModel('verify');
  294. Doo::loadModel('receipt');
  295. $receipt=new receipt();
  296. $verify=new verify();
  297. $accountItem=new accountItem();
  298. Doo::loadModel('L_category');
  299. $lCategory=new L_category();
  300. Doo::loadModel("role");
  301. $role=new role();
  302. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  303. if(empty($receiptDetail))
  304. return "/saeaCreate";
  305. $acItem=$accountItem->find(array('asArray'=>true));
  306. $veList=$verify->find(array('asArray'=>true));
  307. foreach ($veList as $key=>$value){
  308. $v=json_decode($value['staff']);
  309. $list=array();
  310. foreach ($v as $n=>$m){
  311. if ($m['1']=='ROLE'){
  312. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  313. $v[$n][1]=$roleInfo['name'];
  314. array_push($list, $roleInfo['name']);
  315. }else{
  316. array_push($list, $v[$n][1]);
  317. }
  318. }
  319. $veList[$key]['staff']=implode('>', $list);
  320. }
  321. //配置编辑信息
  322. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  323. foreach ($acItem as $key=>$value){
  324. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  325. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  326. $acItem[$key]['price']=$v['price'];
  327. }
  328. }
  329. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  330. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  331. $acItem[$key]['price']=$v['price'];
  332. }
  333. }
  334. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  335. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  336. $acItem[$key]['price']=$v['price'];
  337. }
  338. }
  339. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  340. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  341. $acItem[$key]['price']=$v['price'];
  342. }
  343. }
  344. }
  345. $data['category']=$lCategory->find(array('asArray'=>true));
  346. $data['cSum']=$accountItemList['cSum'];
  347. $data['sum']=$receiptDetail['sum'];
  348. $data['receiptDetail']=$receiptDetail;
  349. $data['veList']=$veList;
  350. $data['acItem']=$acItem;
  351. $data['memu']="receipt";
  352. $data['staff']=$this->staff;
  353. $data['receiptMemu']='saeaBorad';
  354. $data['verify']=$receiptDetail['verify'];
  355. $data['verifyId']=$this->verifyId;
  356. $data['executeId']=$this->executeId;
  357. $data['rid']=$rid;
  358. $this->render ( "/admin/remitEdit", $data );
  359. }
  360. function remitEdiDo(){
  361. $agency=$this->get_args('agency');
  362. $travel=$this->get_args('travel');
  363. $train=$this->get_args('train');
  364. $other=$this->get_args('other');
  365. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  366. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  367. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  368. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  369. if(!empty($verify)&&!empty($explanation)){
  370. Doo::loadModel('receipt');
  371. Doo::loadModel('receiptDetail');
  372. Doo::loadModel('accountItem');
  373. $accountItem=new accountItem();
  374. $receipt=new receipt();
  375. Doo::loadModel('execute');
  376. $execute=new execute();
  377. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  378. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  379. if(empty($receiptDetail))
  380. return "/saeaBorad";
  381. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  382. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  383. $ag=$tr=$ta=$ot=0;
  384. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  385. foreach ($aItem as $key=>$value){
  386. if ($value['category']==$this->AGENCY){
  387. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  388. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  389. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  390. }
  391. $ag++;
  392. }
  393. }
  394. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  395. //报销单
  396. $rid=$receipt->rid=$receiptDetail['rid'];
  397. $receipt->accountItem=json_encode($accountJson);
  398. $receipt->staff=$this->staff[0]['sid'];
  399. $receipt->sum=number_format($sum, 2, '.', '');
  400. $receipt->date=date("Y-m-d");
  401. $receipt->cid=$cid;
  402. if ($receiptDetail['Rtype']==1)
  403. $receipt->status=7;
  404. else
  405. $receipt->status=5;
  406. $receipt->verify=$verify;
  407. $receipt->executeCopy=$executeDetail['staff'];
  408. $receipt->explanation=$explanation;
  409. $receipt->update();
  410. $receiptDetail=new receiptDetail();
  411. $receiptDetail->delete(array('where'=>'rid='.$rid));
  412. //报销详情
  413. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  414. $receiptDetail=new receiptDetail();
  415. $receiptDetail->staff=$this->staff[0]['sid'];
  416. $receiptDetail->item=$value['name'];
  417. $receiptDetail->itemCategory=$this->AGENCY;
  418. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  419. $receiptDetail->date=date("Y-m-d");
  420. $receiptDetail->cid=$cid;
  421. $receiptDetail->rid=$rid;
  422. $receiptDetail->status=4;
  423. $receiptDetail->insert();
  424. }
  425. //return "/referReceipt/".$rid;
  426. }
  427. return "/saeaBorad";
  428. }
  429. function remitApproval(){
  430. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  431. $status=isset($this->params['status'])?$this->params['status']:'';
  432. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  433. $month=$this->get_args('month')?$this->get_args('month'):"";
  434. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  435. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  436. if (empty($status))
  437. $status=$this->get_args('status')?$this->get_args('status'):2;
  438. $vidList=array();
  439. $button=0;
  440. Doo::loadModel('verify');
  441. Doo::loadModel('receipt');
  442. Doo::loadModel('staff');
  443. $staff=new staff();
  444. $receipt=new receipt();
  445. $verify=new verify();
  446. Doo::loadModel('L_category');
  447. $Lcategory=new L_category();
  448. Doo::loadModel('enclosur');
  449. $enclosur=new enclosur();
  450. //user verify ID
  451. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  452. foreach ($verifyDetail as $key=>$value){
  453. array_push($vidList, $value['vid']);
  454. }
  455. $vid=implode(",", $vidList);
  456. if(empty($verifyDetail))
  457. $vid=0;
  458. $categoryList=$Lcategory->find(array('asArray'=>true));
  459. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  460. $ap="";
  461. if($status==4){
  462. $ap=4;$status=2;
  463. }
  464. //get Receipt By verifyID status 2
  465. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  466. $Locate=0;$roleId=0;
  467. if($ap==4)
  468. $status=4;
  469. foreach ($receiptList as $key=>$value){
  470. $receiptList[$key]['Locate']=$Locate;$Locate++;
  471. $receiptList[$key]['reviseDetail']=array();
  472. if (!empty($value['reviseDetail']))
  473. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  474. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  475. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  476. $receiptList[$key]['category']=$categoryDetil['title'];
  477. //检测编辑状态
  478. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  479. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  480. $verifyStaff=json_decode($value['verifyStaff'],true);
  481. Doo::loadModel('role');
  482. $role=new role();
  483. //print_r($verifyList);
  484. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  485. foreach ($verifyList as $k=>$v){
  486. //init verifyStaff
  487. if ($v[1]=='ROLE'){
  488. if (!empty($verifyStaff)){
  489. $endStaffArray=end($verifyStaff);
  490. if ($v[0]==$endStaffArray['nextStaff']){
  491. $roleId=$v[0];
  492. }
  493. }
  494. $roleVerify=json_decode($v[3],true);
  495. $roleKey=$k;$roleArray=array();
  496. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  497. foreach ($roleVerify as $o=>$p){
  498. $staffID=explode ('_',$p);
  499. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  500. //print_r($staffID);
  501. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  502. array_push($roleArray, $exp);
  503. }
  504. $roleArrayCopy[$v[0]]=$roleArray;
  505. //$verifyList[$k]['roleArray']=$roleArray;
  506. }
  507. //print_r($roleArray);
  508. $verifyList[$k]['date']="";
  509. $verifyList[$k]['opinion']="";
  510. $verifyList[$k]['status']="";
  511. if (empty($verifyStaff)){
  512. $verifyList[$k]['date']="";
  513. $verifyList[$k]['opinion']="";
  514. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  515. $verifyList[$k]['status']=4;
  516. $button=4;$flag=false;
  517. }
  518. }else{
  519. foreach ($verifyStaff as $m=>$u){
  520. if ($v[0]==$m){
  521. $verifyList[$k]['date']=$u['date'];
  522. $verifyList[$k]['opinion']=$u['opinion'];
  523. $verifyList[$k]['status']=$u['status'];
  524. $flag=false;
  525. break;
  526. }
  527. }
  528. $endStaffArray=end($verifyStaff);
  529. if (isset($endStaffArray['ROLE'])){
  530. }else{
  531. $endKey=key($verifyStaff);
  532. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  533. $button=4;
  534. $verifyList[$k]['status']=4;
  535. }
  536. }
  537. }
  538. }
  539. $rolename['name']='';
  540. if (!empty($roleId)){
  541. Doo::loadModel('role');
  542. $role=new role();
  543. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  544. }
  545. if (!empty($verifyStaff))
  546. $endStaffArray=end($verifyStaff);
  547. $KOP=false;
  548. foreach ($roleArrayCopy as $P=>$A){
  549. foreach ( $A as $MKI=>$AVL){
  550. if (!empty($verifyStaff)){
  551. //&&$rolename['rid']==$endStaffArray['nextStaff']
  552. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  553. $button=4;
  554. $roleArrayCopy[$P][$MKI]['status']=4;
  555. }
  556. foreach ($verifyStaff as $m=>$u){
  557. $AVLFK=$AVL[0].'_R';
  558. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  559. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  560. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  561. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  562. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  563. break;
  564. }
  565. }
  566. }else{
  567. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  568. $button=4;
  569. $roleArrayCopy[$P][$MKI]['status']=4;
  570. }
  571. }
  572. //$roleArray[$MKI]['rolename']=$rolename['name'];
  573. $KOP=true;
  574. }
  575. }
  576. // print_r($roleArrayCopy);
  577. // echo $roleKey;
  578. foreach ($roleArrayCopy as $k=>$v){
  579. foreach ($verifyList as $m=>$n){
  580. if ($n[0]==$k){
  581. array_splice($verifyList,$m,1,$v);
  582. }
  583. }
  584. }
  585. //print_r($verifyList);
  586. $receiptList[$key]['verifyList']=$verifyList;
  587. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  588. $receiptList[$key]['button']=$button;
  589. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  590. }
  591. $mothHtml="";
  592. for($i=1;$i<=12;$i++){
  593. if($month==$i)
  594. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  595. else
  596. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  597. }
  598. //获取审批日志
  599. Doo::loadModel('receiptLog');
  600. $receiptLog=new receiptLog();
  601. $rlList=array();
  602. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  603. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  604. if (!empty($rlInfo)){
  605. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  606. }
  607. $receiptList[0]['rlList']=$rlList;
  608. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  609. $enclosurHtml='';
  610. foreach ($enclosurList as $value){
  611. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  612. }
  613. $data['enclosurHtml']=$enclosurHtml;
  614. $data['rolename']=$rolename['name'];
  615. $data['datetij']=$tijdate['date'];
  616. $data['mothHtml']=$mothHtml;
  617. $data['rid']=$rid;
  618. $data['receiptList']=$receiptList;
  619. $data['receiptApprovalCount']=count($receiptList);
  620. $data['status']=$status;
  621. $data['year']=$year;
  622. $data['categoryList']=$categoryList;
  623. $data['staffList']=$staffList;
  624. $data['cid']=$cid;
  625. $data['sid']=$sid;
  626. $data['ap']=$ap;
  627. $data['memu']="receipt";
  628. $data['staff']=$this->staff;
  629. $data['receiptMemu']='approvalExpenses';
  630. $data['verifyId']=$this->verifyId;
  631. $data['executeId']=$this->executeId;
  632. $this->render ( "/admin/remitApproval", $data );
  633. }
  634. function saeaLoanAdd(){
  635. Doo::loadModel('verify');
  636. $verify=new verify();
  637. Doo::loadModel("role");
  638. $role=new role();
  639. Doo::loadModel('L_category');
  640. $lCategory=new L_category();
  641. $veList=$verify->find(array('asArray'=>true));
  642. foreach ($veList as $key=>$value){
  643. $v=json_decode($value['staff']);
  644. $list=array();
  645. foreach ($v as $n=>$m){
  646. if ($m['1']=='ROLE'){
  647. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  648. $v[$n][1]=$roleInfo['name'];
  649. array_push($list, $roleInfo['name']);
  650. }else{
  651. array_push($list, $v[$n][1]);
  652. }
  653. }
  654. $veList[$key]['staff']=implode('>', $list);
  655. }
  656. $data['category']=$lCategory->find(array('asArray'=>true));
  657. $data['veList']=$veList;
  658. $data['memu']="receipt";
  659. $data['staff']=$this->staff;
  660. $data['receiptMemu']='saeaBorad';
  661. $data['verifyId']=$this->verifyId;
  662. $data['executeId']=$this->executeId;
  663. $this->render ( "/admin/saeaLoanAdd", $data );
  664. }
  665. function saeaLoanAddDo(){
  666. $agency=$this->get_args('agency');
  667. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  668. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  669. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  670. //die;
  671. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  672. Doo::loadModel('receipt');
  673. Doo::loadModel('receiptDetail');
  674. Doo::loadModel('accountItem');
  675. $accountItem=new accountItem();
  676. $receipt=new receipt();
  677. Doo::loadModel('loanReceipt');
  678. $loanReceipt=new loanReceipt();
  679. Doo::loadModel('execute');
  680. $execute=new execute();
  681. Doo::loadModel('enclosur');
  682. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  683. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  684. // if(!empty($receiptDetail))
  685. // return "/referReceipt/".$receiptDetail['rid'];
  686. $aItem=$accountItem->find(array('asArray'=>true));
  687. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  688. $ag=$tr=$ta=$ot=0;
  689. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  690. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  691. $sum+=$agency;$agencySum+=$agency;
  692. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  693. //借款数据备份
  694. $loanReceipt->loanItem=json_encode($accountJson);
  695. $loanReceipt->staff=$this->staff[0]['sid'];
  696. $loanReceipt->sum=number_format($sum, 2, '.', '');
  697. $loanReceipt->date=date("Y-m-d");
  698. $loanReceipt->cid=$cid;
  699. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  700. $loanReceipt->status=5;
  701. $loanReceipt->Rtype=1;
  702. $loanReceipt->verify=$verify;
  703. $receipt->receiptOrder=$receipt->receiptOrder;
  704. $loanReceipt->explanation=$explanation;
  705. $loanRid=$loanReceipt->insert();
  706. //报销单
  707. $receipt->loanItem=json_encode($accountJson);
  708. $receipt->staff=$this->staff[0]['sid'];
  709. $receipt->sum=number_format($sum, 2, '.', '');
  710. $receipt->date=date("Y-m-d");
  711. $receipt->cid=$cid;
  712. //特殊状态
  713. $receipt->status=5;
  714. $receipt->Rtype=1;
  715. $receipt->loanRid=$loanRid;
  716. //修改审批流程加入角色
  717. $receipt->verify=$verify;
  718. $receipt->executeCopy=$executeDetail['staff'];
  719. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  720. $receipt->explanation=$explanation;
  721. $rid=$receipt->insert();
  722. //执行数据备份
  723. // $executeCopy->rid=$rid;
  724. // $executeCopy->staff=$executeDetail['staff'];
  725. // $executeCopy->eid=$executeDetail['eid'];
  726. // $ecid=$executeCopy->insert();
  727. }
  728. return "/saeaBorad";
  729. }
  730. function saeaLoanEdi(){
  731. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  732. Doo::loadModel('verify');
  733. $verify=new verify();
  734. Doo::loadModel("role");
  735. $role=new role();
  736. Doo::loadModel('L_category');
  737. $lCategory=new L_category();
  738. Doo::loadModel('receipt');
  739. $receipt=new receipt();
  740. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  741. $veList=$verify->find(array('asArray'=>true));
  742. foreach ($veList as $key=>$value){
  743. $v=json_decode($value['staff']);
  744. $list=array();
  745. foreach ($v as $n=>$m){
  746. if ($m['1']=='ROLE'){
  747. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  748. $v[$n][1]=$roleInfo['name'];
  749. array_push($list, $roleInfo['name']);
  750. }else{
  751. array_push($list, $v[$n][1]);
  752. }
  753. }
  754. $veList[$key]['staff']=implode('>', $list);
  755. }
  756. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  757. $data['receiptInfo']=$receiptInfo;
  758. $data['category']=$lCategory->find(array('asArray'=>true));
  759. $data['veList']=$veList;
  760. $data['memu']="receipt";
  761. $data['staff']=$this->staff;
  762. $data['receiptMemu']='saeaBorad';
  763. $data['verifyId']=$this->verifyId;
  764. $data['executeId']=$this->executeId;
  765. $this->render ( "/admin/saeaLoanEdi", $data );
  766. }
  767. function saeaLoanEdiDo(){
  768. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  769. $agency=$this->get_args('agency');
  770. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  771. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  772. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  773. //die;
  774. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  775. Doo::loadModel('receipt');
  776. Doo::loadModel('receiptDetail');
  777. Doo::loadModel('accountItem');
  778. $accountItem=new accountItem();
  779. $receipt=new receipt();
  780. Doo::loadModel('loanReceipt');
  781. $loanReceipt=new loanReceipt();
  782. Doo::loadModel('enclosur');
  783. Doo::loadModel('execute');
  784. $execute=new execute();
  785. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  786. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 and rid='.$rid,'asArray'=>true));
  787. if(empty($receiptDetail))
  788. die('参数错误');
  789. $aItem=$accountItem->find(array('asArray'=>true));
  790. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  791. $ag=$tr=$ta=$ot=0;
  792. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  793. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  794. $sum+=$agency;$agencySum+=$agency;
  795. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  796. //报销单
  797. $receipt->loanItem=json_encode($accountJson);
  798. $receipt->sum=number_format($sum, 2, '.', '');
  799. $receipt->cid=$cid;
  800. //特殊状态
  801. //修改审批流程加入角色
  802. $receipt->verify=$verify;
  803. $receipt->explanation=$explanation;
  804. $receipt->update(array('where'=>'rid='.$rid));
  805. //借款数据更新
  806. $loanReceipt->loanItem=json_encode($accountJson);
  807. $loanReceipt->sum=number_format($sum, 2, '.', '');
  808. $loanReceipt->cid=$cid;
  809. $loanReceipt->verify=$verify;
  810. $loanReceipt->explanation=$explanation;
  811. $receipt->executeCopy=$executeDetail['staff'];
  812. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  813. }
  814. return "/saeaBorad";
  815. }
  816. function saeaLoanReceiptAdd(){
  817. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  818. Doo::loadModel('receipt');
  819. $receipt=new receipt();
  820. Doo::loadModel('loanReceipt');
  821. $loanReceipt=new loanReceipt();
  822. Doo::loadModel('L_category');
  823. $Lcategory=new L_category();
  824. Doo::loadModel('verify');
  825. Doo::loadModel('statistics');
  826. $statistics=new statistics();
  827. $verify=new verify();
  828. Doo::loadModel('staff');
  829. $staff=new staff();
  830. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  831. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  832. $Locate=0;$roleId=0;$button=0;
  833. foreach ($receiptList as $key=>$value){
  834. $receiptList[$key]['Locate']=$Locate;$Locate++;
  835. $receiptList[$key]['reviseDetail']=array();
  836. if (!empty($value['reviseDetail']))
  837. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  838. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  839. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  840. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  841. $receiptList[$key]['category']=$categoryDetil['title'];
  842. //检测编辑状态
  843. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  844. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  845. $verifyStaff=json_decode($value['verifyStaff'],true);
  846. Doo::loadModel('role');
  847. $role=new role();
  848. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  849. foreach ($verifyList as $k=>$v){
  850. //init verifyStaff
  851. if ($v[1]=='ROLE'){
  852. if (!empty($verifyStaff)){
  853. $endStaffArray=end($verifyStaff);
  854. // if ($v[0]==$endStaffArray['nextStaff']){
  855. // $roleId=$v[0];
  856. // }
  857. }
  858. $roleVerify=json_decode($v[3],true);
  859. $roleKey=$k;$roleArray=array();
  860. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  861. foreach ($roleVerify as $o=>$p){
  862. $staffID=explode ('_',$p);
  863. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  864. //print_r($staffID);
  865. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  866. array_push($roleArray, $exp);
  867. }
  868. $roleArrayCopy[$v[0]]=$roleArray;
  869. //$verifyList[$k]['roleArray']=$roleArray;
  870. }
  871. $verifyList[$k]['date']="";
  872. $verifyList[$k]['opinion']="";
  873. $verifyList[$k]['status']="";
  874. if (empty($verifyStaff)){
  875. $verifyList[$k]['date']="";
  876. $verifyList[$k]['opinion']="";
  877. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  878. $verifyList[$k]['status']=4;
  879. $flag=false;
  880. }
  881. }else{
  882. foreach ($verifyStaff as $m=>$u){
  883. if ($v[0]==$m){
  884. $verifyList[$k]['date']=$u['date'];
  885. $verifyList[$k]['opinion']=$u['opinion'];
  886. $verifyList[$k]['status']=$u['status'];
  887. $flag=false;
  888. break;
  889. }
  890. }
  891. $endStaffArray=end($verifyStaff);
  892. if (isset($endStaffArray['ROLE'])){
  893. }else{
  894. // $endKey=key($verifyStaff);
  895. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  896. // $button=4;
  897. // $verifyList[$k]['status']=4;
  898. // }
  899. }
  900. }
  901. }
  902. $rolename['name']='';
  903. if (!empty($roleId)){
  904. Doo::loadModel('role');
  905. $role=new role();
  906. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  907. }
  908. if (!empty($verifyStaff))
  909. $endStaffArray=end($verifyStaff);
  910. $KOP=false;
  911. foreach ($roleArrayCopy as $P=>$A){
  912. foreach ( $A as $MKI=>$AVL){
  913. if (!empty($verifyStaff)){
  914. //&&$rolename['rid']==$endStaffArray['nextStaff']
  915. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  916. $button=4;
  917. $roleArrayCopy[$P][$MKI]['status']=4;
  918. }
  919. foreach ($verifyStaff as $m=>$u){
  920. $AVLFK=$AVL[0].'_R';
  921. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  922. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  923. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  924. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  925. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  926. break;
  927. }
  928. }
  929. }else{
  930. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  931. $button=4;
  932. $roleArrayCopy[$P][$MKI]['status']=4;
  933. }
  934. }
  935. //$roleArray[$MKI]['rolename']=$rolename['name'];
  936. $KOP=true;
  937. }
  938. }
  939. foreach ($roleArrayCopy as $k=>$v){
  940. foreach ($verifyList as $m=>$n){
  941. if ($n[0]==$k){
  942. array_splice($verifyList,$m,1,$v);
  943. }
  944. }
  945. }
  946. $receiptList[$key]['verifyList']=$verifyList;
  947. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  948. $receiptList[$key]['button']=$button;
  949. //
  950. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  951. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  952. }
  953. $data['receiptList']=$receiptList;
  954. Doo::loadModel('L_category');
  955. $lCategory=new L_category();
  956. Doo::loadModel('accountItem');
  957. $accountItem=new accountItem();
  958. $acItem=$accountItem->find(array('asArray'=>true));
  959. $veList=$verify->find(array('asArray'=>true));
  960. foreach ($veList as $key=>$value){
  961. $v=json_decode($value['staff']);
  962. $list=array();
  963. foreach ($v as $n=>$m){
  964. if ($m['1']=='ROLE'){
  965. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  966. $v[$n][1]=$roleInfo['name'];
  967. array_push($list, $roleInfo['name']);
  968. }else{
  969. array_push($list, $v[$n][1]);
  970. }
  971. }
  972. $veList[$key]['staff']=implode('>', $list);
  973. }
  974. $data['rid']=$rid;
  975. $data['category']=$lCategory->find(array('asArray'=>true));
  976. $data['veList']=$veList;
  977. $data['acItem']=$acItem;
  978. $data['memu']="receipt";
  979. $data['staff']=$this->staff;
  980. $data['receiptMemu']='saeaBorad';
  981. $data['verifyId']=$this->verifyId;
  982. $data['executeId']=$this->executeId;
  983. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  984. }
  985. function saeaLoanReceiptAddDo(){
  986. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  987. $agency=$this->get_args('agency');
  988. $travel=$this->get_args('travel');
  989. $train=$this->get_args('train');
  990. $other=$this->get_args('other');
  991. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  992. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  993. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  994. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  995. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  996. Doo::loadModel('receipt');
  997. Doo::loadModel('receiptDetail');
  998. Doo::loadModel('accountItem');
  999. $accountItem=new accountItem();
  1000. $receipt=new receipt();
  1001. Doo::loadModel('enclosur');
  1002. Doo::loadModel('execute');
  1003. $execute=new execute();
  1004. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  1005. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1006. // if(!empty($receiptDetail))
  1007. // return "/referReceipt/".$receiptDetail['rid'];
  1008. $aItem=$accountItem->find(array('asArray'=>true));
  1009. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  1010. $ag=$tr=$ta=$ot=0;
  1011. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  1012. foreach ($aItem as $key=>$value){
  1013. if ($value['category']==$this->AGENCY){
  1014. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  1015. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  1016. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  1017. }
  1018. $ag++;
  1019. }
  1020. if($value['category']==$this->TRAVEL){
  1021. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1022. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1023. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1024. }
  1025. $tr++;
  1026. }
  1027. if($value['category']==$this->TRAIN){
  1028. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1029. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1030. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1031. }
  1032. $ta++;
  1033. }
  1034. if($value['category']==$this->OTHER){
  1035. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1036. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1037. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1038. }
  1039. $ot++;
  1040. }
  1041. }
  1042. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1043. //报销单
  1044. $receipt->accountItem=json_encode($accountJson);
  1045. $receipt->staff=$this->staff[0]['sid'];
  1046. $receipt->loanSum=$receiptDet['sum'];
  1047. $receipt->sum=number_format($sum, 2, '.', '');
  1048. $receipt->date=date("Y-m-d");
  1049. $receipt->pastDate='';
  1050. $receipt->cid=$cid;
  1051. $receipt->status=7;
  1052. //修改审批流程加入角色
  1053. $receipt->verify=$verify;
  1054. $receipt->verifyStaff='';
  1055. $receipt->executeStaff='';
  1056. $receipt->executeCopy=$executeDetail['staff'];
  1057. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1058. $receipt->explanation=$explanation;
  1059. $receipt->update(array('where'=>'rid='.$rid));
  1060. //附件
  1061. if (!empty($enclosurName)){
  1062. $enclosurArray=explode('-', $enclosurName);
  1063. foreach ($enclosurArray as $value){
  1064. $enclosur=new enclosur();
  1065. $enclosur->name=$value;
  1066. $enclosur->rid=$rid;
  1067. $enclosur->insert();
  1068. }
  1069. //print_r($enclosurArray);die;
  1070. }
  1071. //报销详情
  1072. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1073. $receiptDetail=new receiptDetail();
  1074. $receiptDetail->staff=$this->staff[0]['sid'];
  1075. $receiptDetail->item=$value['name'];
  1076. $receiptDetail->itemCategory=$this->AGENCY;
  1077. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1078. $receiptDetail->date=date("Y-m-d");
  1079. $receiptDetail->cid=$cid;
  1080. $receiptDetail->rid=$rid;
  1081. $receiptDetail->status=4;
  1082. $receiptDetail->insert();
  1083. }
  1084. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1085. $receiptDetail=new receiptDetail();
  1086. $receiptDetail->staff=$this->staff[0]['sid'];
  1087. $receiptDetail->item=$value['name'];
  1088. $receiptDetail->itemCategory=$this->TRAVEL;
  1089. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1090. $receiptDetail->date=date("Y-m-d");
  1091. $receiptDetail->cid=$cid;
  1092. $receiptDetail->rid=$rid;
  1093. $receiptDetail->status=4;
  1094. $receiptDetail->insert();
  1095. }
  1096. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1097. $receiptDetail=new receiptDetail();
  1098. $receiptDetail->staff=$this->staff[0]['sid'];
  1099. $receiptDetail->item=$value['name'];
  1100. $receiptDetail->itemCategory=$this->TRAIN;
  1101. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1102. $receiptDetail->date=date("Y-m-d");
  1103. $receiptDetail->cid=$cid;
  1104. $receiptDetail->rid=$rid;
  1105. $receiptDetail->status=4;
  1106. $receiptDetail->insert();
  1107. }
  1108. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1109. $receiptDetail=new receiptDetail();
  1110. $receiptDetail->staff=$this->staff[0]['sid'];
  1111. $receiptDetail->item=$value['name'];
  1112. $receiptDetail->itemCategory=$this->OTHER;
  1113. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1114. $receiptDetail->date=date("Y-m-d");
  1115. $receiptDetail->cid=$cid;
  1116. $receiptDetail->rid=$rid;
  1117. $receiptDetail->status=4;
  1118. $receiptDetail->insert();
  1119. }
  1120. return "/saeaBorad";
  1121. }
  1122. return "/saeaLoanReceiptAdd/".$rid;
  1123. }
  1124. function saeaLoanReceiptEdi(){
  1125. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1126. //echo $rid;
  1127. Doo::loadModel('accountItem');
  1128. Doo::loadModel('verify');
  1129. Doo::loadModel('receipt');
  1130. $receipt=new receipt();
  1131. $verify=new verify();
  1132. $accountItem=new accountItem();
  1133. Doo::loadModel('L_category');
  1134. $Lcategory=new L_category();
  1135. Doo::loadModel("role");
  1136. $role=new role();
  1137. Doo::loadModel('loanReceipt');
  1138. $loanReceipt=new loanReceipt();
  1139. Doo::loadModel('staff');
  1140. $staff=new staff();
  1141. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1142. if(empty($receiptDetail))
  1143. return "/saeaBorad";
  1144. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1145. $Locate=0;$roleId=0;$button=0;
  1146. foreach ($receiptList as $key=>$value){
  1147. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1148. $receiptList[$key]['reviseDetail']=array();
  1149. if (!empty($value['reviseDetail']))
  1150. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1151. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1152. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1153. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1154. $receiptList[$key]['category']=$categoryDetil['title'];
  1155. //检测编辑状态
  1156. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1157. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1158. $verifyStaff=json_decode($value['verifyStaff'],true);
  1159. Doo::loadModel('role');
  1160. $role=new role();
  1161. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1162. foreach ($verifyList as $k=>$v){
  1163. //init verifyStaff
  1164. if ($v[1]=='ROLE'){
  1165. if (!empty($verifyStaff)){
  1166. $endStaffArray=end($verifyStaff);
  1167. // if ($v[0]==$endStaffArray['nextStaff']){
  1168. // $roleId=$v[0];
  1169. // }
  1170. }
  1171. $roleVerify=json_decode($v[3],true);
  1172. $roleKey=$k;$roleArray=array();
  1173. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1174. foreach ($roleVerify as $o=>$p){
  1175. $staffID=explode ('_',$p);
  1176. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1177. //print_r($staffID);
  1178. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1179. array_push($roleArray, $exp);
  1180. }
  1181. $roleArrayCopy[$v[0]]=$roleArray;
  1182. //$verifyList[$k]['roleArray']=$roleArray;
  1183. }
  1184. $verifyList[$k]['date']="";
  1185. $verifyList[$k]['opinion']="";
  1186. $verifyList[$k]['status']="";
  1187. if (empty($verifyStaff)){
  1188. $verifyList[$k]['date']="";
  1189. $verifyList[$k]['opinion']="";
  1190. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1191. $verifyList[$k]['status']=4;
  1192. $flag=false;
  1193. }
  1194. }else{
  1195. foreach ($verifyStaff as $m=>$u){
  1196. if ($v[0]==$m){
  1197. $verifyList[$k]['date']=$u['date'];
  1198. $verifyList[$k]['opinion']=$u['opinion'];
  1199. $verifyList[$k]['status']=$u['status'];
  1200. $flag=false;
  1201. break;
  1202. }
  1203. }
  1204. $endStaffArray=end($verifyStaff);
  1205. if (isset($endStaffArray['ROLE'])){
  1206. }else{
  1207. // $endKey=key($verifyStaff);
  1208. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1209. // $button=4;
  1210. // $verifyList[$k]['status']=4;
  1211. // }
  1212. }
  1213. }
  1214. }
  1215. $rolename['name']='';
  1216. if (!empty($roleId)){
  1217. Doo::loadModel('role');
  1218. $role=new role();
  1219. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1220. }
  1221. if (!empty($verifyStaff))
  1222. $endStaffArray=end($verifyStaff);
  1223. $KOP=false;
  1224. foreach ($roleArrayCopy as $P=>$A){
  1225. foreach ( $A as $MKI=>$AVL){
  1226. if (!empty($verifyStaff)){
  1227. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1228. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1229. $button=4;
  1230. $roleArrayCopy[$P][$MKI]['status']=4;
  1231. }
  1232. foreach ($verifyStaff as $m=>$u){
  1233. $AVLFK=$AVL[0].'_R';
  1234. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1235. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1236. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1237. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1238. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1239. break;
  1240. }
  1241. }
  1242. }else{
  1243. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1244. $button=4;
  1245. $roleArrayCopy[$P][$MKI]['status']=4;
  1246. }
  1247. }
  1248. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1249. $KOP=true;
  1250. }
  1251. }
  1252. foreach ($roleArrayCopy as $k=>$v){
  1253. foreach ($verifyList as $m=>$n){
  1254. if ($n[0]==$k){
  1255. array_splice($verifyList,$m,1,$v);
  1256. }
  1257. }
  1258. }
  1259. $receiptList[$key]['verifyList']=$verifyList;
  1260. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1261. $receiptList[$key]['button']=$button;
  1262. //
  1263. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1264. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1265. }
  1266. $data['receiptList']=$receiptList;
  1267. $acItem=$accountItem->find(array('asArray'=>true));
  1268. $veList=$verify->find(array('asArray'=>true));
  1269. foreach ($veList as $key=>$value){
  1270. $v=json_decode($value['staff']);
  1271. $list=array();
  1272. foreach ($v as $n=>$m){
  1273. if ($m['1']=='ROLE'){
  1274. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1275. $v[$n][1]=$roleInfo['name'];
  1276. array_push($list, $roleInfo['name']);
  1277. }else{
  1278. array_push($list, $v[$n][1]);
  1279. }
  1280. }
  1281. $veList[$key]['staff']=implode('>', $list);
  1282. }
  1283. //配置编辑信息
  1284. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1285. foreach ($acItem as $key=>$value){
  1286. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1287. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1288. $acItem[$key]['price']=$v['price'];
  1289. }
  1290. }
  1291. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1292. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1293. $acItem[$key]['price']=$v['price'];
  1294. }
  1295. }
  1296. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1297. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1298. $acItem[$key]['price']=$v['price'];
  1299. }
  1300. }
  1301. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1302. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1303. $acItem[$key]['price']=$v['price'];
  1304. }
  1305. }
  1306. }
  1307. $data['category']=$Lcategory->find(array('asArray'=>true));
  1308. $data['cSum']=$accountItemList['cSum'];
  1309. $data['sum']=$receiptDetail['sum'];
  1310. $data['receiptDetail']=$receiptDetail;
  1311. $data['veList']=$veList;
  1312. $data['acItem']=$acItem;
  1313. $data['memu']="receipt";
  1314. $data['staff']=$this->staff;
  1315. $data['receiptMemu']='saeaBorad';
  1316. $data['verify']=$receiptDetail['verify'];
  1317. $data['verifyId']=$this->verifyId;
  1318. $data['executeId']=$this->executeId;
  1319. $data['rid']=$rid;
  1320. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1321. }
  1322. function confirmation(){
  1323. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1324. Doo::loadModel('receipt');
  1325. Doo::loadModel('receiptDetail');
  1326. $receipt=new receipt();
  1327. $receiptDetail=new receiptDetail();
  1328. Doo::loadModel('statistics');
  1329. Doo::loadModel('itemStatistics');
  1330. $statistics=new statistics();
  1331. $itemStatistics=new itemStatistics();
  1332. Doo::loadModel("verify");
  1333. $verify=new verify();
  1334. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1335. if(empty($receiptDetailList))
  1336. return "/saeaBorad";
  1337. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1338. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1339. if (empty($receiptDetailList['nowStaff'])){
  1340. $nowStaff="";$nowStaffList=array();
  1341. if ($verifyDetail[0][1]=='ROLE'){
  1342. $vStaffString=json_decode($verifyDetail[0][3]);
  1343. foreach ($vStaffString as $key=>$value){
  1344. $staffK=explode("_", $value);
  1345. array_push($nowStaffList, $staffK[0]);
  1346. }
  1347. $nowStaff=implode(',', $nowStaffList);
  1348. }else{
  1349. $nowStaff=$verifyDetail[0][0];
  1350. }
  1351. $receipt->nowStaff=$nowStaff;
  1352. }
  1353. // echo $nowStaff;
  1354. // print_r($verifyDetail);die;
  1355. $receipt->rid=$receiptDetailList['rid'];
  1356. $receipt->status=2;
  1357. $receipt->update();
  1358. //操作日志
  1359. Doo::loadModel("receiptLog");
  1360. $receiptLog=new receiptLog();
  1361. $verify=new verify();
  1362. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1363. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1364. $jd=json_decode($vr['staff']);$roleId=0;
  1365. foreach ($jd as $key=>$value){
  1366. if ($value[1]=='ROLE'){
  1367. $pos = strpos($value[3], $this->staff[0]['sid']);
  1368. if ($pos !== false) {
  1369. $roleId=$value[0];
  1370. }
  1371. }
  1372. }
  1373. //审批日志
  1374. //echo $roleId;die;
  1375. if (!empty($roleId)){
  1376. Doo::loadModel("role");
  1377. $role=new role();
  1378. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1379. $receiptLog->rolename=$roleInfo['name'];
  1380. }
  1381. $receiptLog->username=$this->staff[0]['username'];
  1382. $receiptLog->uid=$this->staff[0]['sid'];
  1383. $receiptLog->date=date("Y-m-d");
  1384. $receiptLog->opinion='提交审批';
  1385. $receiptLog->img=$this->staff[0]['avatar'];
  1386. $receiptLog->status=2;
  1387. $receiptLog->rid=$rid;
  1388. $receiptLog->insert();
  1389. return "/expenses";
  1390. }
  1391. function expenses(){
  1392. $item=isset($this->params['item'])?$this->params['item']:"";
  1393. if(empty($item))
  1394. $item=$this->get_args('item')?$this->get_args('item'):"";
  1395. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1396. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1397. Doo::loadModel('receipt');
  1398. $receipt=new receipt();
  1399. Doo::loadModel('L_category');
  1400. $Lcategory=new L_category();
  1401. Doo::loadModel('verify');
  1402. Doo::loadModel('statistics');
  1403. $statistics=new statistics();
  1404. $verify=new verify();
  1405. Doo::loadModel('staff');
  1406. $staff=new staff();
  1407. $condition="";
  1408. if($item=="expenses")
  1409. $condition=" and Rtype=1 ";
  1410. elseif ($item=="receipts")
  1411. $condition=" and Rtype=0 ";
  1412. elseif ($item=="remits")
  1413. $condition=" and Rtype=2 ";
  1414. $dateCondition=" and Year(date) =".$year;
  1415. if(!empty($moth)){
  1416. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1417. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1418. }else
  1419. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1420. if(empty($stList))
  1421. $stList=array('rePrice'=>0,'agPrice'=>0);
  1422. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  1423. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  1424. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1425. $Locate=0;$roleId=0;$button=0;
  1426. foreach ($receiptList as $key=>$value){
  1427. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1428. $receiptList[$key]['reviseDetail']=array();
  1429. if (!empty($value['reviseDetail']))
  1430. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1431. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1432. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1433. $receiptList[$key]['category']=$categoryDetil['title'];
  1434. //检测编辑状态
  1435. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1436. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1437. $verifyStaff=json_decode($value['verifyStaff'],true);
  1438. Doo::loadModel('role');
  1439. $role=new role();
  1440. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1441. foreach ($verifyList as $k=>$v){
  1442. //init verifyStaff
  1443. if ($v[1]=='ROLE'){
  1444. if (!empty($verifyStaff)){
  1445. $endStaffArray=end($verifyStaff);
  1446. // if ($v[0]==$endStaffArray['nextStaff']){
  1447. // $roleId=$v[0];
  1448. // }
  1449. }
  1450. $roleVerify=json_decode($v[3],true);
  1451. $roleKey=$k;$roleArray=array();
  1452. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1453. foreach ($roleVerify as $o=>$p){
  1454. $staffID=explode ('_',$p);
  1455. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1456. //print_r($staffID);
  1457. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1458. array_push($roleArray, $exp);
  1459. }
  1460. $roleArrayCopy[$v[0]]=$roleArray;
  1461. //$verifyList[$k]['roleArray']=$roleArray;
  1462. }
  1463. $verifyList[$k]['date']="";
  1464. $verifyList[$k]['opinion']="";
  1465. $verifyList[$k]['status']="";
  1466. if (empty($verifyStaff)){
  1467. $verifyList[$k]['date']="";
  1468. $verifyList[$k]['opinion']="";
  1469. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1470. $verifyList[$k]['status']=4;
  1471. $flag=false;
  1472. }
  1473. }else{
  1474. foreach ($verifyStaff as $m=>$u){
  1475. if ($v[0]==$m){
  1476. $verifyList[$k]['date']=$u['date'];
  1477. $verifyList[$k]['opinion']=$u['opinion'];
  1478. $verifyList[$k]['status']=$u['status'];
  1479. $flag=false;
  1480. break;
  1481. }
  1482. }
  1483. $endStaffArray=end($verifyStaff);
  1484. if (isset($endStaffArray['ROLE'])){
  1485. }else{
  1486. // $endKey=key($verifyStaff);
  1487. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1488. // $button=4;
  1489. // $verifyList[$k]['status']=4;
  1490. // }
  1491. }
  1492. }
  1493. }
  1494. $rolename['name']='';
  1495. if (!empty($roleId)){
  1496. Doo::loadModel('role');
  1497. $role=new role();
  1498. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1499. }
  1500. if (!empty($verifyStaff))
  1501. $endStaffArray=end($verifyStaff);
  1502. $KOP=false;
  1503. foreach ($roleArrayCopy as $P=>$A){
  1504. foreach ( $A as $MKI=>$AVL){
  1505. if (!empty($verifyStaff)){
  1506. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1507. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1508. $button=4;
  1509. $roleArrayCopy[$P][$MKI]['status']=4;
  1510. }
  1511. foreach ($verifyStaff as $m=>$u){
  1512. $AVLFK=$AVL[0].'_R';
  1513. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1514. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1515. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1516. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1517. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1518. break;
  1519. }
  1520. }
  1521. }else{
  1522. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1523. $button=4;
  1524. $roleArrayCopy[$P][$MKI]['status']=4;
  1525. }
  1526. }
  1527. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1528. $KOP=true;
  1529. }
  1530. }
  1531. foreach ($roleArrayCopy as $k=>$v){
  1532. foreach ($verifyList as $m=>$n){
  1533. if ($n[0]==$k){
  1534. array_splice($verifyList,$m,1,$v);
  1535. }
  1536. }
  1537. }
  1538. $receiptList[$key]['verifyList']=$verifyList;
  1539. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1540. $receiptList[$key]['button']=$button;
  1541. }
  1542. //print_r($receiptList);die;
  1543. $mothHtml="";
  1544. for($i=1;$i<=12;$i++){
  1545. if($moth==$i)
  1546. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1547. else
  1548. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1549. }
  1550. $data['mothHtml']=$mothHtml;
  1551. $data['receiptList']=$receiptList;
  1552. $data['memu']="receipt";
  1553. $data['staff']=$this->staff;
  1554. $data['receiptMemu']='expenses';
  1555. $data['verifyId']=$this->verifyId;
  1556. $data['executeId']=$this->executeId;
  1557. $data['item']=$item;
  1558. $data['year']=$year;
  1559. $this->render ( "/admin/expenses", $data );
  1560. }
  1561. function expensesCollect(){
  1562. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1563. Doo::loadModel('receipt');
  1564. $receipt=new receipt();
  1565. Doo::loadModel('L_category');
  1566. $Lcategory=new L_category();
  1567. Doo::loadModel('verify');
  1568. Doo::loadModel('statistics');
  1569. $statistics=new statistics();
  1570. $verify=new verify();
  1571. Doo::loadModel('staff');
  1572. $staff=new staff();
  1573. Doo::loadModel('loanReceipt');
  1574. $loanReceipt=new loanReceipt();
  1575. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1576. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1577. $Locate=0;$roleId=0;$button=0;
  1578. foreach ($loanList as $key=>$value){
  1579. $loanList[$key]['Locate']=$Locate;$Locate++;
  1580. $loanList[$key]['reviseDetail']=array();
  1581. if (!empty($value['reviseDetail']))
  1582. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1583. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1584. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1585. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1586. $loanList[$key]['category']=$categoryDetil['title'];
  1587. //检测编辑状态
  1588. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1589. $verifyList['staff']=$value['verifyBreakup'];
  1590. else
  1591. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1592. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1593. $verifyStaff=json_decode($value['verifyStaff'],true);
  1594. Doo::loadModel('role');
  1595. $role=new role();
  1596. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1597. foreach ($verifyList as $k=>$v){
  1598. //init verifyStaff
  1599. if ($v[1]=='ROLE'){
  1600. if (!empty($verifyStaff)){
  1601. $endStaffArray=end($verifyStaff);
  1602. // if ($v[0]==$endStaffArray['nextStaff']){
  1603. // $roleId=$v[0];
  1604. // }
  1605. }
  1606. $roleVerify=json_decode($v[3],true);
  1607. $roleKey=$k;$roleArray=array();
  1608. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1609. foreach ($roleVerify as $o=>$p){
  1610. $staffID=explode ('_',$p);
  1611. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1612. //print_r($staffID);
  1613. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1614. array_push($roleArray, $exp);
  1615. }
  1616. $roleArrayCopy[$v[0]]=$roleArray;
  1617. //$verifyList[$k]['roleArray']=$roleArray;
  1618. }
  1619. $verifyList[$k]['date']="";
  1620. $verifyList[$k]['opinion']="";
  1621. $verifyList[$k]['status']="";
  1622. if (empty($verifyStaff)){
  1623. $verifyList[$k]['date']="";
  1624. $verifyList[$k]['opinion']="";
  1625. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1626. $verifyList[$k]['status']=4;
  1627. $flag=false;
  1628. }
  1629. }else{
  1630. foreach ($verifyStaff as $m=>$u){
  1631. if ($v[0]==$m){
  1632. $verifyList[$k]['date']=$u['date'];
  1633. $verifyList[$k]['opinion']=$u['opinion'];
  1634. $verifyList[$k]['status']=$u['status'];
  1635. $flag=false;
  1636. break;
  1637. }
  1638. }
  1639. $endStaffArray=end($verifyStaff);
  1640. if (isset($endStaffArray['ROLE'])){
  1641. }else{
  1642. // $endKey=key($verifyStaff);
  1643. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1644. // $button=4;
  1645. // $verifyList[$k]['status']=4;
  1646. // }
  1647. }
  1648. }
  1649. }
  1650. $rolename['name']='';
  1651. if (!empty($roleId)){
  1652. Doo::loadModel('role');
  1653. $role=new role();
  1654. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1655. }
  1656. if (!empty($verifyStaff))
  1657. $endStaffArray=end($verifyStaff);
  1658. $KOP=false;
  1659. foreach ($roleArrayCopy as $P=>$A){
  1660. foreach ( $A as $MKI=>$AVL){
  1661. if (!empty($verifyStaff)){
  1662. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1663. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1664. $button=4;
  1665. $roleArrayCopy[$P][$MKI]['status']=4;
  1666. }
  1667. foreach ($verifyStaff as $m=>$u){
  1668. $AVLFK=$AVL[0].'_R';
  1669. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1670. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1671. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1672. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1673. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1674. break;
  1675. }
  1676. }
  1677. }else{
  1678. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1679. $button=4;
  1680. $roleArrayCopy[$P][$MKI]['status']=4;
  1681. }
  1682. }
  1683. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1684. $KOP=true;
  1685. }
  1686. }
  1687. foreach ($roleArrayCopy as $k=>$v){
  1688. foreach ($verifyList as $m=>$n){
  1689. if ($n[0]==$k){
  1690. array_splice($verifyList,$m,1,$v);
  1691. }
  1692. }
  1693. }
  1694. $loanList[$key]['verifyList']=$verifyList;
  1695. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1696. $loanList[$key]['button']=$button;
  1697. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1698. }
  1699. $data['loanList']=$loanList;
  1700. $Locate=0;$roleId=0;$button=0;
  1701. foreach ($receiptList as $key=>$value){
  1702. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1703. $receiptList[$key]['reviseDetail']=array();
  1704. if (!empty($value['reviseDetail']))
  1705. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1706. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1707. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1708. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1709. $receiptList[$key]['category']=$categoryDetil['title'];
  1710. //检测编辑状态
  1711. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1712. if($value['status']==8&&$value['Rtype']==1)
  1713. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1714. else
  1715. $verifyList['staff']=$value['verifyBreakup'];
  1716. }else
  1717. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1718. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1719. $verifyStaff=json_decode($value['verifyStaff'],true);
  1720. Doo::loadModel('role');
  1721. $role=new role();
  1722. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1723. foreach ($verifyList as $k=>$v){
  1724. //init verifyStaff
  1725. if ($v[1]=='ROLE'){
  1726. if (!empty($verifyStaff)){
  1727. $endStaffArray=end($verifyStaff);
  1728. // if ($v[0]==$endStaffArray['nextStaff']){
  1729. // $roleId=$v[0];
  1730. // }
  1731. }
  1732. $roleVerify=json_decode($v[3],true);
  1733. $roleKey=$k;$roleArray=array();
  1734. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1735. foreach ($roleVerify as $o=>$p){
  1736. $staffID=explode ('_',$p);
  1737. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1738. //print_r($staffID);
  1739. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1740. array_push($roleArray, $exp);
  1741. }
  1742. $roleArrayCopy[$v[0]]=$roleArray;
  1743. //$verifyList[$k]['roleArray']=$roleArray;
  1744. }
  1745. $verifyList[$k]['date']="";
  1746. $verifyList[$k]['opinion']="";
  1747. $verifyList[$k]['status']="";
  1748. if (empty($verifyStaff)){
  1749. $verifyList[$k]['date']="";
  1750. $verifyList[$k]['opinion']="";
  1751. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1752. $verifyList[$k]['status']=4;
  1753. $flag=false;
  1754. }
  1755. }else{
  1756. foreach ($verifyStaff as $m=>$u){
  1757. if ($v[0]==$m){
  1758. $verifyList[$k]['date']=$u['date'];
  1759. $verifyList[$k]['opinion']=$u['opinion'];
  1760. $verifyList[$k]['status']=$u['status'];
  1761. $flag=false;
  1762. break;
  1763. }
  1764. }
  1765. $endStaffArray=end($verifyStaff);
  1766. if (isset($endStaffArray['ROLE'])){
  1767. }else{
  1768. // $endKey=key($verifyStaff);
  1769. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1770. // $button=4;
  1771. // $verifyList[$k]['status']=4;
  1772. // }
  1773. }
  1774. }
  1775. }
  1776. $rolename['name']='';
  1777. if (!empty($roleId)){
  1778. Doo::loadModel('role');
  1779. $role=new role();
  1780. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1781. }
  1782. if (!empty($verifyStaff))
  1783. $endStaffArray=end($verifyStaff);
  1784. $KOP=false;
  1785. foreach ($roleArrayCopy as $P=>$A){
  1786. foreach ( $A as $MKI=>$AVL){
  1787. if (!empty($verifyStaff)){
  1788. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1789. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1790. $button=4;
  1791. $roleArrayCopy[$P][$MKI]['status']=4;
  1792. }
  1793. foreach ($verifyStaff as $m=>$u){
  1794. $AVLFK=$AVL[0].'_R';
  1795. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1796. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1797. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1798. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1799. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1800. break;
  1801. }
  1802. }
  1803. }else{
  1804. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1805. $button=4;
  1806. $roleArrayCopy[$P][$MKI]['status']=4;
  1807. }
  1808. }
  1809. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1810. $KOP=true;
  1811. }
  1812. }
  1813. foreach ($roleArrayCopy as $k=>$v){
  1814. foreach ($verifyList as $m=>$n){
  1815. if ($n[0]==$k){
  1816. array_splice($verifyList,$m,1,$v);
  1817. }
  1818. }
  1819. }
  1820. $receiptList[$key]['verifyList']=$verifyList;
  1821. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1822. $receiptList[$key]['button']=$button;
  1823. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1824. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1825. $relust=$value['sum']-$value['loanSum'];
  1826. $receiptList[$key]['relust']=$relust;
  1827. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1828. }
  1829. $data['receiptList']=$receiptList;
  1830. $data['memu']="receipt";
  1831. $data['staff']=$this->staff;
  1832. $data['receiptMemu']='expenses';
  1833. $data['verifyId']=$this->verifyId;
  1834. $data['executeId']=$this->executeId;
  1835. $this->render ( "/admin/expensesCollect", $data );
  1836. }
  1837. function approvalExpenses(){
  1838. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1839. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1840. $month=$this->get_args('month')?$this->get_args('month'):"";
  1841. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1842. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1843. if (empty($status))
  1844. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1845. $vidList=array();
  1846. $button=0;
  1847. Doo::loadModel('verify');
  1848. $verify=new verify();
  1849. Doo::loadModel('receipt');
  1850. $receipt=new receipt();
  1851. Doo::loadModel('staff');
  1852. $staff=new staff();
  1853. Doo::loadModel('L_category');
  1854. $Lcategory=new L_category();
  1855. //user verify ID
  1856. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  1857. foreach ($verifyDetail as $key=>$value){
  1858. array_push($vidList, $value['vid']);
  1859. }
  1860. $vid=implode(",", $vidList);
  1861. if(empty($verifyDetail))
  1862. $vid=0;
  1863. $dateCondition=" and Year(date) =".$year;
  1864. if(!empty($month))
  1865. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1866. $categoryList=$Lcategory->find(array('asArray'=>true));
  1867. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1868. $cateCondition="";$staffCondition="";$approvalCondition="";
  1869. if (!empty($cid))
  1870. $cateCondition=' and cid='.$cid;
  1871. if(!empty($sid)){
  1872. $staffCondition=' and staff='.$sid;
  1873. $cateCondition="";
  1874. }
  1875. $approvalCondition=" and status=".$status;
  1876. if($status==2){
  1877. //查找角色审批人
  1878. $approvalCondition=' and status='.$status.' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  1879. }
  1880. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1881. $approvalCondition=' and status=2 ';
  1882. }
  1883. if($status==1){
  1884. $approvalCondition=' and (status='.$status.' or status=6) ';
  1885. }
  1886. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1887. if ($status==0)
  1888. $receiptList=$receipt->find(array('where'=>'1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1889. ,'desc'=>'rid','asArray'=>true));
  1890. else
  1891. $receiptList=$receipt->find(array('where'=>'1 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  1892. ,'desc'=>'rid','asArray'=>true));
  1893. $rLRes=$receipt->find(array('where'=>'status=2 and nowStaff like "%'.$this->staff[0]['sid'].'%" '.$dateCondition.$cateCondition.$staffCondition
  1894. ,'desc'=>'rid','asArray'=>true));
  1895. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  1896. //print_r($receiptList);
  1897. $Locate=0;
  1898. foreach ($receiptList as $key=>$value){
  1899. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1900. $receiptList[$key]['reviseDetail']=array();
  1901. if (!empty($value['reviseDetail']))
  1902. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1903. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1904. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1905. $receiptList[$key]['category']=$categoryDetil['title'];
  1906. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1907. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1908. $verifyStaff=json_decode($value['verifyStaff'],true);
  1909. foreach ($verifyList as $k=>$v){
  1910. //init verifyStaff
  1911. $verifyList[$k]['date']="";
  1912. $verifyList[$k]['opinion']="";
  1913. $verifyList[$k]['status']="";
  1914. if (empty($verifyStaff)){
  1915. $verifyList[$k]['date']="";
  1916. $verifyList[$k]['opinion']="";
  1917. if ($v[0]==$this->staff[0]['sid']){
  1918. $verifyList[$k]['status']=4;
  1919. $button=4;
  1920. }
  1921. }else{
  1922. $flag=true;
  1923. foreach ($verifyStaff as $m=>$u){
  1924. if ($v[0]==$m){
  1925. $verifyList[$k]['date']=$u['date'];
  1926. $verifyList[$k]['opinion']=$u['opinion'];
  1927. $verifyList[$k]['status']=$u['status'];
  1928. $flag=false;
  1929. break;
  1930. }
  1931. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1932. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1933. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1934. }
  1935. if($flag){//检测可编辑
  1936. if($v[0]==$this->staff[0]['sid']){
  1937. $verifyList[$k]['status']=4;$button=4;
  1938. }
  1939. }
  1940. }
  1941. }
  1942. $receiptList[$key]['verifyList']=$verifyList;
  1943. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1944. $receiptList[$key]['button']=$button;
  1945. }
  1946. //print_r($receiptList);die;
  1947. //$data['verifyDetail']=$verifyDetail;
  1948. $mothHtml="";
  1949. for($i=1;$i<=12;$i++){
  1950. if($month==$i)
  1951. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1952. else
  1953. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1954. }
  1955. $data['mothHtml']=$mothHtml;
  1956. $data['receiptList']=$receiptList;
  1957. $data['receiptApprovalCount']=count($rLRes);
  1958. $data['status']=$status;
  1959. $data['year']=$year;
  1960. $data['categoryList']=$categoryList;
  1961. $data['staffList']=$staffList;
  1962. $data['cid']=$cid;
  1963. $data['sid']=$sid;
  1964. $data['memu']="receipt";
  1965. $data['staff']=$this->staff;
  1966. $data['receiptMemu']='approvalExpenses';
  1967. $data['verifyId']=$this->verifyId;
  1968. $data['executeId']=$this->executeId;
  1969. $this->render ( "/admin/approvalExpenses", $data );
  1970. }
  1971. function expensesDoc(){
  1972. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1973. Doo::loadModel('receipt');
  1974. $receipt=new receipt();
  1975. Doo::loadModel('L_category');
  1976. $Lcategory=new L_category();
  1977. Doo::loadModel('verify');
  1978. Doo::loadModel('statistics');
  1979. $statistics=new statistics();
  1980. $verify=new verify();
  1981. Doo::loadModel('staff');
  1982. $staff=new staff();
  1983. Doo::loadModel('loanReceipt');
  1984. $loanReceipt=new loanReceipt();
  1985. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  1986. $loanList=array();
  1987. if (!empty($receiptList))
  1988. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1989. $Locate=0;$roleId=0;$button=0;
  1990. foreach ($loanList as $key=>$value){
  1991. $loanList[$key]['Locate']=$Locate;$Locate++;
  1992. $loanList[$key]['reviseDetail']=array();
  1993. if (!empty($value['reviseDetail']))
  1994. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1995. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1996. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1997. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1998. $loanList[$key]['category']=$categoryDetil['title'];
  1999. //检测编辑状态
  2000. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  2001. $verifyList['staff']=$value['verifyBreakup'];
  2002. else
  2003. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2004. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2005. $verifyStaff=json_decode($value['verifyStaff'],true);
  2006. Doo::loadModel('role');
  2007. $role=new role();
  2008. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2009. foreach ($verifyList as $k=>$v){
  2010. //init verifyStaff
  2011. if ($v[1]=='ROLE'){
  2012. if (!empty($verifyStaff)){
  2013. $endStaffArray=end($verifyStaff);
  2014. // if ($v[0]==$endStaffArray['nextStaff']){
  2015. // $roleId=$v[0];
  2016. // }
  2017. }
  2018. $roleVerify=json_decode($v[3],true);
  2019. $roleKey=$k;$roleArray=array();
  2020. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2021. foreach ($roleVerify as $o=>$p){
  2022. $staffID=explode ('_',$p);
  2023. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2024. //print_r($staffID);
  2025. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2026. array_push($roleArray, $exp);
  2027. }
  2028. $roleArrayCopy[$v[0]]=$roleArray;
  2029. //$verifyList[$k]['roleArray']=$roleArray;
  2030. }
  2031. $verifyList[$k]['date']="";
  2032. $verifyList[$k]['opinion']="";
  2033. $verifyList[$k]['status']="";
  2034. if (empty($verifyStaff)){
  2035. $verifyList[$k]['date']="";
  2036. $verifyList[$k]['opinion']="";
  2037. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2038. $verifyList[$k]['status']=4;
  2039. $flag=false;
  2040. }
  2041. }else{
  2042. foreach ($verifyStaff as $m=>$u){
  2043. if ($v[0]==$m){
  2044. $verifyList[$k]['date']=$u['date'];
  2045. $verifyList[$k]['opinion']=$u['opinion'];
  2046. $verifyList[$k]['status']=$u['status'];
  2047. $flag=false;
  2048. break;
  2049. }
  2050. }
  2051. $endStaffArray=end($verifyStaff);
  2052. if (isset($endStaffArray['ROLE'])){
  2053. }else{
  2054. // $endKey=key($verifyStaff);
  2055. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2056. // $button=4;
  2057. // $verifyList[$k]['status']=4;
  2058. // }
  2059. }
  2060. }
  2061. }
  2062. $rolename['name']='';
  2063. if (!empty($roleId)){
  2064. Doo::loadModel('role');
  2065. $role=new role();
  2066. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2067. }
  2068. if (!empty($verifyStaff))
  2069. $endStaffArray=end($verifyStaff);
  2070. $KOP=false;
  2071. foreach ($roleArrayCopy as $P=>$A){
  2072. foreach ( $A as $MKI=>$AVL){
  2073. if (!empty($verifyStaff)){
  2074. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2075. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2076. $button=4;
  2077. $roleArrayCopy[$P][$MKI]['status']=4;
  2078. }
  2079. foreach ($verifyStaff as $m=>$u){
  2080. $AVLFK=$AVL[0].'_R';
  2081. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2082. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2083. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2084. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2085. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2086. break;
  2087. }
  2088. }
  2089. }else{
  2090. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2091. $button=4;
  2092. $roleArrayCopy[$P][$MKI]['status']=4;
  2093. }
  2094. }
  2095. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2096. $KOP=true;
  2097. }
  2098. }
  2099. foreach ($roleArrayCopy as $k=>$v){
  2100. foreach ($verifyList as $m=>$n){
  2101. if ($n[0]==$k){
  2102. array_splice($verifyList,$m,1,$v);
  2103. }
  2104. }
  2105. }
  2106. $loanList[$key]['verifyList']=$verifyList;
  2107. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2108. $loanList[$key]['button']=$button;
  2109. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2110. }
  2111. $data['loanList']=$loanList;
  2112. $Locate=0;$roleId=0;$button=0;
  2113. foreach ($receiptList as $key=>$value){
  2114. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2115. $receiptList[$key]['reviseDetail']=array();
  2116. if (!empty($value['reviseDetail']))
  2117. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2118. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2119. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2120. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2121. $receiptList[$key]['category']=$categoryDetil['title'];
  2122. //检测编辑状态
  2123. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  2124. $verifyList['staff']=$value['verifyBreakup'];
  2125. }else
  2126. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2127. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2128. $verifyStaff=json_decode($value['verifyStaff'],true);
  2129. Doo::loadModel('role');
  2130. $role=new role();
  2131. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2132. foreach ($verifyList as $k=>$v){
  2133. //init verifyStaff
  2134. if ($v[1]=='ROLE'){
  2135. if (!empty($verifyStaff)){
  2136. $endStaffArray=end($verifyStaff);
  2137. // if ($v[0]==$endStaffArray['nextStaff']){
  2138. // $roleId=$v[0];
  2139. // }
  2140. }
  2141. $roleVerify=json_decode($v[3],true);
  2142. $roleKey=$k;$roleArray=array();
  2143. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2144. foreach ($roleVerify as $o=>$p){
  2145. $staffID=explode ('_',$p);
  2146. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2147. //print_r($staffID);
  2148. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2149. array_push($roleArray, $exp);
  2150. }
  2151. $roleArrayCopy[$v[0]]=$roleArray;
  2152. //$verifyList[$k]['roleArray']=$roleArray;
  2153. }
  2154. $verifyList[$k]['date']="";
  2155. $verifyList[$k]['opinion']="";
  2156. $verifyList[$k]['status']="";
  2157. if (empty($verifyStaff)){
  2158. $verifyList[$k]['date']="";
  2159. $verifyList[$k]['opinion']="";
  2160. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2161. $verifyList[$k]['status']=4;
  2162. $flag=false;
  2163. }
  2164. }else{
  2165. foreach ($verifyStaff as $m=>$u){
  2166. if ($v[0]==$m){
  2167. $verifyList[$k]['date']=$u['date'];
  2168. $verifyList[$k]['opinion']=$u['opinion'];
  2169. $verifyList[$k]['status']=$u['status'];
  2170. $flag=false;
  2171. break;
  2172. }
  2173. }
  2174. $endStaffArray=end($verifyStaff);
  2175. if (isset($endStaffArray['ROLE'])){
  2176. }else{
  2177. // $endKey=key($verifyStaff);
  2178. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2179. // $button=4;
  2180. // $verifyList[$k]['status']=4;
  2181. // }
  2182. }
  2183. }
  2184. }
  2185. $rolename['name']='';
  2186. if (!empty($roleId)){
  2187. Doo::loadModel('role');
  2188. $role=new role();
  2189. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2190. }
  2191. if (!empty($verifyStaff))
  2192. $endStaffArray=end($verifyStaff);
  2193. $KOP=false;
  2194. foreach ($roleArrayCopy as $P=>$A){
  2195. foreach ( $A as $MKI=>$AVL){
  2196. if (!empty($verifyStaff)){
  2197. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2198. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2199. $button=4;
  2200. $roleArrayCopy[$P][$MKI]['status']=4;
  2201. }
  2202. foreach ($verifyStaff as $m=>$u){
  2203. $AVLFK=$AVL[0].'_R';
  2204. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2205. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2206. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2207. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2208. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2209. break;
  2210. }
  2211. }
  2212. }else{
  2213. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2214. $button=4;
  2215. $roleArrayCopy[$P][$MKI]['status']=4;
  2216. }
  2217. }
  2218. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2219. $KOP=true;
  2220. }
  2221. }
  2222. foreach ($roleArrayCopy as $k=>$v){
  2223. foreach ($verifyList as $m=>$n){
  2224. if ($n[0]==$k){
  2225. array_splice($verifyList,$m,1,$v);
  2226. }
  2227. }
  2228. }
  2229. $receiptList[$key]['verifyList']=$verifyList;
  2230. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2231. $receiptList[$key]['button']=$button;
  2232. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2233. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2234. }
  2235. $data['receiptList']=$receiptList;
  2236. $data['memu']="receipt";
  2237. $data['staff']=$this->staff;
  2238. $data['receiptMemu']='approvalExpenses';
  2239. $data['verifyId']=$this->verifyId;
  2240. $data['executeId']=$this->executeId;
  2241. $this->render ( "/admin/expensesDoc", $data );
  2242. }
  2243. function expensesEdi(){
  2244. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2245. $status=isset($this->params['status'])?$this->params['status']:'';
  2246. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2247. $month=$this->get_args('month')?$this->get_args('month'):"";
  2248. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2249. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2250. if (empty($status))
  2251. $status=$this->get_args('status')?$this->get_args('status'):2;
  2252. $vidList=array();
  2253. $button=0;
  2254. Doo::loadModel('verify');
  2255. Doo::loadModel('receipt');
  2256. Doo::loadModel('staff');
  2257. $staff=new staff();
  2258. $receipt=new receipt();
  2259. $verify=new verify();
  2260. Doo::loadModel('L_category');
  2261. $Lcategory=new L_category();
  2262. Doo::loadModel('enclosur');
  2263. $enclosur=new enclosur();
  2264. //user verify ID
  2265. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2266. foreach ($verifyDetail as $key=>$value){
  2267. array_push($vidList, $value['vid']);
  2268. }
  2269. $vid=implode(",", $vidList);
  2270. if(empty($verifyDetail))
  2271. $vid=0;
  2272. $categoryList=$Lcategory->find(array('asArray'=>true));
  2273. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2274. $ap="";
  2275. if($status==4){
  2276. $ap=4;$status=2;
  2277. }
  2278. //get Receipt By verifyID status 2
  2279. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2280. $Locate=0;$roleId=0;
  2281. if($ap==4)
  2282. $status=4;
  2283. foreach ($receiptList as $key=>$value){
  2284. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2285. $receiptList[$key]['reviseDetail']=array();
  2286. if (!empty($value['reviseDetail']))
  2287. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2288. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2289. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2290. $receiptList[$key]['category']=$categoryDetil['title'];
  2291. //检测编辑状态
  2292. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2293. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2294. $verifyStaff=json_decode($value['verifyStaff'],true);
  2295. Doo::loadModel('role');
  2296. $role=new role();
  2297. //print_r($verifyList);
  2298. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2299. foreach ($verifyList as $k=>$v){
  2300. //init verifyStaff
  2301. if ($v[1]=='ROLE'){
  2302. if (!empty($verifyStaff)){
  2303. $endStaffArray=end($verifyStaff);
  2304. if ($v[0]==$endStaffArray['nextStaff']){
  2305. $roleId=$v[0];
  2306. }
  2307. }
  2308. $roleVerify=json_decode($v[3],true);
  2309. $roleKey=$k;$roleArray=array();
  2310. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2311. foreach ($roleVerify as $o=>$p){
  2312. $staffID=explode ('_',$p);
  2313. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2314. //print_r($staffID);
  2315. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2316. array_push($roleArray, $exp);
  2317. }
  2318. $roleArrayCopy[$v[0]]=$roleArray;
  2319. //$verifyList[$k]['roleArray']=$roleArray;
  2320. }
  2321. //print_r($roleArray);
  2322. $verifyList[$k]['date']="";
  2323. $verifyList[$k]['opinion']="";
  2324. $verifyList[$k]['status']="";
  2325. if (empty($verifyStaff)){
  2326. $verifyList[$k]['date']="";
  2327. $verifyList[$k]['opinion']="";
  2328. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2329. $verifyList[$k]['status']=4;
  2330. $button=4;$flag=false;
  2331. }
  2332. }else{
  2333. foreach ($verifyStaff as $m=>$u){
  2334. if ($v[0]==$m){
  2335. $verifyList[$k]['date']=$u['date'];
  2336. $verifyList[$k]['opinion']=$u['opinion'];
  2337. $verifyList[$k]['status']=$u['status'];
  2338. $flag=false;
  2339. break;
  2340. }
  2341. }
  2342. $endStaffArray=end($verifyStaff);
  2343. if (isset($endStaffArray['ROLE'])){
  2344. }else{
  2345. $endKey=key($verifyStaff);
  2346. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2347. $button=4;
  2348. $verifyList[$k]['status']=4;
  2349. }
  2350. }
  2351. }
  2352. }
  2353. $rolename['name']='';
  2354. if (!empty($roleId)){
  2355. Doo::loadModel('role');
  2356. $role=new role();
  2357. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2358. }
  2359. if (!empty($verifyStaff))
  2360. $endStaffArray=end($verifyStaff);
  2361. $KOP=false;
  2362. foreach ($roleArrayCopy as $P=>$A){
  2363. foreach ( $A as $MKI=>$AVL){
  2364. if (!empty($verifyStaff)){
  2365. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2366. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2367. $button=4;
  2368. $roleArrayCopy[$P][$MKI]['status']=4;
  2369. }
  2370. foreach ($verifyStaff as $m=>$u){
  2371. $AVLFK=$AVL[0].'_R';
  2372. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2373. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2374. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2375. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2376. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2377. break;
  2378. }
  2379. }
  2380. }else{
  2381. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2382. $button=4;
  2383. $roleArrayCopy[$P][$MKI]['status']=4;
  2384. }
  2385. }
  2386. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2387. $KOP=true;
  2388. }
  2389. }
  2390. // print_r($roleArrayCopy);
  2391. // echo $roleKey;
  2392. foreach ($roleArrayCopy as $k=>$v){
  2393. foreach ($verifyList as $m=>$n){
  2394. if ($n[0]==$k){
  2395. array_splice($verifyList,$m,1,$v);
  2396. }
  2397. }
  2398. }
  2399. $receiptList[$key]['verifyList']=$verifyList;
  2400. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2401. $receiptList[$key]['button']=$button;
  2402. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2403. }
  2404. //$data['verifyDetail']=$verifyDetail;
  2405. $mothHtml="";
  2406. for($i=1;$i<=12;$i++){
  2407. if($month==$i)
  2408. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2409. else
  2410. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2411. }
  2412. //获取审批日志
  2413. Doo::loadModel('receiptLog');
  2414. $receiptLog=new receiptLog();
  2415. $rlList=array();
  2416. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2417. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2418. if (!empty($rlInfo)){
  2419. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2420. }
  2421. $receiptList[0]['rlList']=$rlList;
  2422. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2423. $enclosurHtml='';
  2424. foreach ($enclosurList as $value){
  2425. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2426. }
  2427. //print_r($receiptList);
  2428. $data['rid']=$rid;
  2429. $data['enclosurHtml']=$enclosurHtml;
  2430. $data['rolename']=$rolename['name'];
  2431. $data['datetij']=$tijdate['date'];
  2432. $data['mothHtml']=$mothHtml;
  2433. $data['receiptList']=$receiptList;
  2434. $data['receiptApprovalCount']=count($receiptList);
  2435. $data['status']=$status;
  2436. $data['year']=$year;
  2437. $data['categoryList']=$categoryList;
  2438. $data['staffList']=$staffList;
  2439. $data['cid']=$cid;
  2440. $data['sid']=$sid;
  2441. $data['ap']=$ap;
  2442. $data['memu']="receipt";
  2443. $data['staff']=$this->staff;
  2444. $data['receiptMemu']='approvalExpenses';
  2445. $data['verifyId']=$this->verifyId;
  2446. $data['executeId']=$this->executeId;
  2447. $this->render ( "/admin/expensesEdi", $data );
  2448. }
  2449. function expensesDefray(){
  2450. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2451. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2452. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2453. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2454. if(!empty($rid)){
  2455. Doo::loadModel("verify");
  2456. $verify=new verify();
  2457. Doo::loadModel("receiptDetail");
  2458. $receiptDetailObj=new receiptDetail();
  2459. Doo::loadModel("itemStatistics");
  2460. Doo::loadModel("statistics");
  2461. $statistics=new statistics();
  2462. $itemStatistics=new itemStatistics();
  2463. Doo::loadModel("receipt");
  2464. $receipt=new receipt();
  2465. Doo::loadModel("loanReceipt");
  2466. $loanReceipt=new loanReceipt();
  2467. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2468. if (empty($receiptDetail))
  2469. return "/approval";
  2470. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2471. $verifyString=$verifyDetail['staff'];
  2472. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2473. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2474. if(empty($opinion)){
  2475. if ($status==3)
  2476. $opinion="终止";
  2477. else
  2478. $opinion="同意支付";
  2479. }
  2480. $nowStaff=0;$nowStaffList=array();
  2481. if(empty($verifyStaff)){
  2482. //还需加入是否已经进入角色审批
  2483. if ($verifyDetail[0][1]=='ROLE'){
  2484. //print_r($verifyDetail);echo "ddd";
  2485. $vStaffString=json_decode($verifyDetail[0][3]);
  2486. foreach ($vStaffString as $key=>$value){
  2487. $staffK=explode("_", $value);
  2488. if ($staffK[0]!=$this->staff[0]['sid'])
  2489. array_push($nowStaffList, $staffK[0]);
  2490. }
  2491. //print_r($verifyDetail);
  2492. //die;
  2493. $nowStaff=implode(',', $nowStaffList);
  2494. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2495. }else{
  2496. if ($verifyDetail[1][1]=='ROLE'){
  2497. $vStaffString=json_decode($verifyDetail[1][3]);
  2498. //echo "dd";
  2499. foreach ($vStaffString as $key=>$value){
  2500. $staffK=explode("_", $value);
  2501. array_push($nowStaffList, $staffK[0]);
  2502. }
  2503. $nowStaff=implode(',', $nowStaffList);
  2504. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2505. }else{
  2506. $nowStaff=$verifyDetail[1][0];
  2507. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2508. }
  2509. }
  2510. if($status==3)
  2511. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2512. $vStaffString=json_encode($verifyStaff);
  2513. $receipt->nowStaff=$nowStaff;
  2514. $receipt->verifyStaff=$vStaffString;
  2515. $loanReceipt->nowStaff=$nowStaff;
  2516. $loanReceipt->verifyStaff=$vStaffString;
  2517. }else{
  2518. $VS=end($verifyStaff);
  2519. //非角色审批
  2520. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2521. $nextStaff=0;$roleSTF=false;
  2522. foreach ($verifyDetail as $key=>$value){
  2523. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2524. if (isset($verifyDetail[$key+1])){
  2525. $nextStaff=$verifyDetail[$key+1][0];
  2526. if ($verifyDetail[$key+1][1]=='ROLE')
  2527. $roleSTF=true;
  2528. }
  2529. break;
  2530. }
  2531. }
  2532. if (!$roleSTF){
  2533. $nowStaff=$nextStaff;
  2534. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2535. }else{
  2536. //获取角色下的所有用户ID
  2537. $nowStaffList=array();
  2538. foreach ($verifyDetail as $vfk){
  2539. if ($vfk[1]=='ROLE'){
  2540. $vStaffString=json_decode($vfk[3]);
  2541. foreach ($vStaffString as $key=>$value){
  2542. $staffK=explode("_", $value);
  2543. array_push($nowStaffList, $staffK[0]);
  2544. }
  2545. }
  2546. }
  2547. $nowStaff=implode(',', $nowStaffList);
  2548. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2549. }
  2550. if($status==3){
  2551. $verifyStaff['final']=$status;
  2552. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2553. }
  2554. $vStaffString=json_encode($verifyStaff);
  2555. $receipt->nowStaff=$nowStaff;
  2556. $receipt->verifyStaff=$vStaffString;
  2557. $loanReceipt->nowStaff=$nowStaff;
  2558. $loanReceipt->verifyStaff=$vStaffString;
  2559. }
  2560. //角色审批
  2561. if (isset($VS['ROLE'])){
  2562. //找出角色人 当前审批角色组
  2563. $verifyJSStaff=array();$nowStaffList2=array();
  2564. foreach ($verifyDetail as $key=>$value){
  2565. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2566. $verifyJSStaff=json_decode($value[3]);
  2567. foreach ($verifyJSStaff as $m){
  2568. $staffK=explode("_", $m);
  2569. array_push($nowStaffList2, $staffK[0]);
  2570. }
  2571. // print_r($nowStaffList2);
  2572. }
  2573. }
  2574. $RoleVerifyStaff=array();
  2575. foreach ($verifyStaff as $key=>$value){
  2576. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2577. foreach ($nowStaffList2 as $m) {
  2578. if ($key==$m."_R")
  2579. $RoleVerifyStaff[$key]=$value;
  2580. }
  2581. }
  2582. }
  2583. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2584. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2585. //下一个审批人ID
  2586. $nextStaff=0;$falg=false;
  2587. foreach ($verifyDetail as $key=>$value){
  2588. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2589. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2590. $falg=true;
  2591. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2592. foreach ($vStaffString as $v){
  2593. $staffK=explode("_", $v);
  2594. array_push($nowStaffList, $staffK[0]);
  2595. }
  2596. $nowStaff=implode(',', $nowStaffList);
  2597. $nextStaff=$verifyDetail[$key+1][0];
  2598. }elseif(isset($verifyDetail[$key+1])){
  2599. $nextStaff=$verifyDetail[$key+1][0];
  2600. $nowStaff=$nextStaff;
  2601. }else
  2602. $nowStaff='';
  2603. break;
  2604. }
  2605. }
  2606. if ($falg)
  2607. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2608. else
  2609. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2610. // print_r($verifyStaff);
  2611. // echo $nowStaff;die;
  2612. }else{ //进入下一个角色或者审批人
  2613. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2614. //
  2615. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2616. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2617. // print_r($verifyStaff);
  2618. // die;
  2619. }
  2620. if($status==3){
  2621. $verifyStaff['final']=$status;
  2622. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2623. }
  2624. $vStaffString=json_encode($verifyStaff);
  2625. $receipt->verifyStaff=$vStaffString;
  2626. $receipt->nowStaff=$nowStaff;
  2627. $loanReceipt->nowStaff=$nowStaff;
  2628. $loanReceipt->verifyStaff=$vStaffString;
  2629. //die;
  2630. //}
  2631. // print_r($verifyStaff);
  2632. // die;
  2633. }
  2634. //print_r($verifyStaff);die;
  2635. }
  2636. //print_r($verifyDetail);
  2637. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2638. foreach ($verifyDetail as $k=>$v){
  2639. if ($v[1]=='ROLE'){
  2640. $roleId=$v[0];
  2641. $roleVerify=json_decode($v[3],true);
  2642. $roleKey=$k;$roleArray=array();
  2643. foreach ($roleVerify as $o=>$p){
  2644. $staffID=explode ('_',$p);
  2645. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2646. array_push($roleArray, $exp);
  2647. }
  2648. $verifyDetailCopy[$v[0]]=$roleArray;
  2649. }
  2650. }
  2651. //print_r($verifyDetail);
  2652. foreach ($verifyDetailCopy as $k=>$v){
  2653. foreach ($verifyDetail as $m=>$n){
  2654. if ($n[0]==$k){
  2655. array_splice($verifyDetail,$m,1,$v);
  2656. }
  2657. }
  2658. }
  2659. //审批日志
  2660. if (!isset($verifyStaff['final'])){
  2661. Doo::loadModel("receiptLog");
  2662. $receiptLog=new receiptLog();
  2663. if (!empty($roleId)){
  2664. Doo::loadModel("role");
  2665. $role=new role();
  2666. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2667. $receiptLog->rolename=$roleInfo['name'];
  2668. }
  2669. $receiptLog->username=$this->staff[0]['username'];
  2670. $receiptLog->uid=$this->staff[0]['sid'];
  2671. $receiptLog->date=date("Y-m-d");
  2672. $receiptLog->opinion=$opinion;
  2673. $receiptLog->img=$this->staff[0]['avatar'];
  2674. $receiptLog->status=1;
  2675. $receiptLog->rid=$rid;
  2676. $receiptLog->insert();
  2677. }
  2678. if (isset($verifyStaff['final'])){//rDetail
  2679. $receipt->status=3;
  2680. $receipt->verifyBreakup=$verifyString;
  2681. $receiptDetailObj->status=3;
  2682. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2683. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2684. $receipt->status=6;
  2685. $receipt->pastDate=date("Y-m-d");
  2686. $receipt->isBK=1;
  2687. $loanReceipt->verifyBreakup=$verifyString;
  2688. $loanReceipt->status=1;
  2689. $loanReceipt->pastDate=date("Y-m-d");
  2690. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2691. }
  2692. $receipt->update(array('where'=>' rid = '.$rid));
  2693. return "/approvalExpenses/2";
  2694. }
  2695. }
  2696. function implement(){
  2697. Doo::loadModel('receipt');
  2698. $receipt=new receipt();
  2699. Doo::loadModel('L_category');
  2700. $Lcategory=new L_category();
  2701. Doo::loadModel('verify');
  2702. $verify=new verify();
  2703. Doo::loadModel('staff');
  2704. $staff=new staff();
  2705. Doo::loadModel("execute");
  2706. $execute=new execute();
  2707. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2708. Doo::loadModel('loanReceipt');
  2709. $loanReceipt=new loanReceipt();
  2710. //print_r($receiptList);
  2711. $loanList=array();
  2712. if (!isset($receiptList))
  2713. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2714. $Locate=0;$roleId=0;$button=0;
  2715. foreach ($loanList as $key=>$value){
  2716. $loanList[$key]['Locate']=$Locate;$Locate++;
  2717. $loanList[$key]['reviseDetail']=array();
  2718. if (!empty($value['reviseDetail']))
  2719. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2720. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2721. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2722. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2723. $loanList[$key]['category']=$categoryDetil['title'];
  2724. //检测编辑状态
  2725. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2726. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2727. $verifyStaff=json_decode($value['verifyStaff'],true);
  2728. Doo::loadModel('role');
  2729. $role=new role();
  2730. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2731. foreach ($verifyList as $k=>$v){
  2732. //init verifyStaff
  2733. if ($v[1]=='ROLE'){
  2734. if (!empty($verifyStaff)){
  2735. $endStaffArray=end($verifyStaff);
  2736. // if ($v[0]==$endStaffArray['nextStaff']){
  2737. // $roleId=$v[0];
  2738. // }
  2739. }
  2740. $roleVerify=json_decode($v[3],true);
  2741. $roleKey=$k;$roleArray=array();
  2742. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2743. foreach ($roleVerify as $o=>$p){
  2744. $staffID=explode ('_',$p);
  2745. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2746. //print_r($staffID);
  2747. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2748. array_push($roleArray, $exp);
  2749. }
  2750. $roleArrayCopy[$v[0]]=$roleArray;
  2751. //$verifyList[$k]['roleArray']=$roleArray;
  2752. }
  2753. $verifyList[$k]['date']="";
  2754. $verifyList[$k]['opinion']="";
  2755. $verifyList[$k]['status']="";
  2756. if (empty($verifyStaff)){
  2757. $verifyList[$k]['date']="";
  2758. $verifyList[$k]['opinion']="";
  2759. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2760. $verifyList[$k]['status']=4;
  2761. $flag=false;
  2762. }
  2763. }else{
  2764. foreach ($verifyStaff as $m=>$u){
  2765. if ($v[0]==$m){
  2766. $verifyList[$k]['date']=$u['date'];
  2767. $verifyList[$k]['opinion']=$u['opinion'];
  2768. $verifyList[$k]['status']=$u['status'];
  2769. $flag=false;
  2770. break;
  2771. }
  2772. }
  2773. $endStaffArray=end($verifyStaff);
  2774. if (isset($endStaffArray['ROLE'])){
  2775. }else{
  2776. // $endKey=key($verifyStaff);
  2777. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2778. // $button=4;
  2779. // $verifyList[$k]['status']=4;
  2780. // }
  2781. }
  2782. }
  2783. }
  2784. $rolename['name']='';
  2785. if (!empty($roleId)){
  2786. Doo::loadModel('role');
  2787. $role=new role();
  2788. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2789. }
  2790. if (!empty($verifyStaff))
  2791. $endStaffArray=end($verifyStaff);
  2792. $KOP=false;
  2793. foreach ($roleArrayCopy as $P=>$A){
  2794. foreach ( $A as $MKI=>$AVL){
  2795. if (!empty($verifyStaff)){
  2796. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2797. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2798. $button=4;
  2799. $roleArrayCopy[$P][$MKI]['status']=4;
  2800. }
  2801. foreach ($verifyStaff as $m=>$u){
  2802. $AVLFK=$AVL[0].'_R';
  2803. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2804. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2805. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2806. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2807. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2808. break;
  2809. }
  2810. }
  2811. }else{
  2812. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2813. $button=4;
  2814. $roleArrayCopy[$P][$MKI]['status']=4;
  2815. }
  2816. }
  2817. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2818. $KOP=true;
  2819. }
  2820. }
  2821. foreach ($roleArrayCopy as $k=>$v){
  2822. foreach ($verifyList as $m=>$n){
  2823. if ($n[0]==$k){
  2824. array_splice($verifyList,$m,1,$v);
  2825. }
  2826. }
  2827. }
  2828. $loanList[$key]['verifyList']=$verifyList;
  2829. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2830. }
  2831. $data['loanList']=$loanList;
  2832. $Locate=0;$roleId=0;$button=0;
  2833. foreach ($receiptList as $key=>$value){
  2834. $button2=0;
  2835. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2836. $receiptList[$key]['reviseDetail']=array();
  2837. if (!empty($value['reviseDetail']))
  2838. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2839. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2840. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2841. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2842. $receiptList[$key]['category']=$categoryDetil['title'];
  2843. $executeList=json_decode($value['executeCopy'],true);
  2844. $executeStaff=array();
  2845. if (!empty($value['executeStaff'] ))
  2846. $executeStaff=json_decode($value['executeStaff'],true);
  2847. if (isset($executeList)){
  2848. foreach ($executeList as $op=>$lo){
  2849. $executeList[$op]['date']="";
  2850. $executeList[$op]['opinion']="";
  2851. $executeList[$op]['status']="";
  2852. foreach ($executeStaff as $m=>$u){
  2853. if ($lo[0]==$m){
  2854. $executeList[$op]['date']=$u['date'];
  2855. $executeList[$op]['opinion']=$u['opinion'];
  2856. $executeList[$op]['status']=$u['status'];
  2857. break;
  2858. }
  2859. }
  2860. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2861. $button2=1;
  2862. $executeList[$op]['status']=4;
  2863. }
  2864. }
  2865. }
  2866. //检测编辑状态
  2867. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2868. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2869. $verifyStaff=json_decode($value['verifyStaff'],true);
  2870. Doo::loadModel('role');
  2871. $role=new role();
  2872. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2873. foreach ($verifyList as $k=>$v){
  2874. //init verifyStaff
  2875. if ($v[1]=='ROLE'){
  2876. if (!empty($verifyStaff)){
  2877. $endStaffArray=end($verifyStaff);
  2878. // if ($v[0]==$endStaffArray['nextStaff']){
  2879. // $roleId=$v[0];
  2880. // }
  2881. }
  2882. $roleVerify=json_decode($v[3],true);
  2883. $roleKey=$k;$roleArray=array();
  2884. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2885. foreach ($roleVerify as $o=>$p){
  2886. $staffID=explode ('_',$p);
  2887. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2888. //print_r($staffID);
  2889. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2890. array_push($roleArray, $exp);
  2891. }
  2892. $roleArrayCopy[$v[0]]=$roleArray;
  2893. //$verifyList[$k]['roleArray']=$roleArray;
  2894. }
  2895. $verifyList[$k]['date']="";
  2896. $verifyList[$k]['opinion']="";
  2897. $verifyList[$k]['status']="";
  2898. if (empty($verifyStaff)){
  2899. $verifyList[$k]['date']="";
  2900. $verifyList[$k]['opinion']="";
  2901. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2902. $verifyList[$k]['status']=4;
  2903. $flag=false;
  2904. }
  2905. }else{
  2906. foreach ($verifyStaff as $m=>$u){
  2907. if ($v[0]==$m){
  2908. $verifyList[$k]['date']=$u['date'];
  2909. $verifyList[$k]['opinion']=$u['opinion'];
  2910. $verifyList[$k]['status']=$u['status'];
  2911. $flag=false;
  2912. break;
  2913. }
  2914. }
  2915. $endStaffArray=end($verifyStaff);
  2916. if (isset($endStaffArray['ROLE'])){
  2917. }else{
  2918. }
  2919. }
  2920. }
  2921. $rolename['name']='';
  2922. if (!empty($roleId)){
  2923. Doo::loadModel('role');
  2924. $role=new role();
  2925. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2926. }
  2927. if (!empty($verifyStaff))
  2928. $endStaffArray=end($verifyStaff);
  2929. $KOP=false;
  2930. foreach ($roleArrayCopy as $P=>$A){
  2931. foreach ( $A as $MKI=>$AVL){
  2932. if (!empty($verifyStaff)){
  2933. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2934. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2935. $button=4;
  2936. $roleArrayCopy[$P][$MKI]['status']=4;
  2937. }
  2938. foreach ($verifyStaff as $m=>$u){
  2939. $AVLFK=$AVL[0].'_R';
  2940. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2941. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2942. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2943. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2944. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2945. break;
  2946. }
  2947. }
  2948. }else{
  2949. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2950. $button=4;
  2951. $roleArrayCopy[$P][$MKI]['status']=4;
  2952. }
  2953. }
  2954. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2955. $KOP=true;
  2956. }
  2957. }
  2958. foreach ($roleArrayCopy as $k=>$v){
  2959. foreach ($verifyList as $m=>$n){
  2960. if ($n[0]==$k){
  2961. array_splice($verifyList,$m,1,$v);
  2962. }
  2963. }
  2964. }
  2965. $receiptList[$key]['executeList']=$executeList;
  2966. $receiptList[$key]['verifyList']=$verifyList;
  2967. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2968. $receiptList[$key]['button2']=$button2;
  2969. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2970. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2971. $relust=$value['sum']-$value['loanSum'];
  2972. $receiptList[$key]['relust']=$relust;
  2973. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  2974. }
  2975. //print_r($receiptList[$key]['executeList']);
  2976. $data['receiptList']=$receiptList;
  2977. $data['memu']="receipt";
  2978. $data['staff']=$this->staff;
  2979. $data['receiptMemu']='implement';
  2980. $data['verifyId']=$this->verifyId;
  2981. $data['executeId']=$this->executeId;
  2982. $this->render ( "/admin/implement", $data );
  2983. }
  2984. function implementDo(){
  2985. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2986. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2987. if (!empty($rid)){
  2988. Doo::loadModel('receipt');
  2989. $receipt=new receipt();
  2990. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  2991. $executeCopy=json_decode($rinfo['executeCopy'],true);
  2992. $executeStaff=json_decode($rinfo['executeStaff'],true);
  2993. if(empty($executeStaff)){
  2994. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  2995. }else{
  2996. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  2997. }
  2998. if (count($executeStaff)==count($executeCopy)){
  2999. $receipt->executeStaff=json_encode($executeStaff);
  3000. $receipt->status=8;
  3001. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3002. $receipt->status=9;
  3003. }else{
  3004. $receipt->executeStaff=json_encode($executeStaff);
  3005. }
  3006. $receipt->update(array('where'=>'rid='.$rid));
  3007. }
  3008. return "/implement";
  3009. }
  3010. function receiptburEdi(){
  3011. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3012. $status=isset($this->params['status'])?$this->params['status']:'';
  3013. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3014. $month=$this->get_args('month')?$this->get_args('month'):"";
  3015. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3016. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3017. if (empty($status))
  3018. $status=$this->get_args('status')?$this->get_args('status'):2;
  3019. $vidList=array();
  3020. $button=0;
  3021. Doo::loadModel('verify');
  3022. Doo::loadModel('receipt');
  3023. Doo::loadModel('staff');
  3024. $staff=new staff();
  3025. $receipt=new receipt();
  3026. $verify=new verify();
  3027. Doo::loadModel('L_category');
  3028. $Lcategory=new L_category();
  3029. Doo::loadModel('enclosur');
  3030. $enclosur=new enclosur();
  3031. Doo::loadModel('loanReceipt');
  3032. $loanReceipt=new loanReceipt();
  3033. //user verify ID
  3034. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3035. foreach ($verifyDetail as $key=>$value){
  3036. array_push($vidList, $value['vid']);
  3037. }
  3038. $vid=implode(",", $vidList);
  3039. if(empty($verifyDetail))
  3040. $vid=0;
  3041. $categoryList=$Lcategory->find(array('asArray'=>true));
  3042. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3043. $ap="";
  3044. if($status==4){
  3045. $ap=4;$status=2;
  3046. }
  3047. //get Receipt By verifyID status 2
  3048. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3049. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3050. $Locate=0;$roleId=0;$button=0;
  3051. foreach ($loanList as $key=>$value){
  3052. $loanList[$key]['Locate']=$Locate;$Locate++;
  3053. $loanList[$key]['reviseDetail']=array();
  3054. if (!empty($value['reviseDetail']))
  3055. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3056. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3057. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3058. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3059. $loanList[$key]['category']=$categoryDetil['title'];
  3060. //检测编辑状态
  3061. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3062. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3063. $verifyStaff=json_decode($value['verifyStaff'],true);
  3064. Doo::loadModel('role');
  3065. $role=new role();
  3066. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3067. foreach ($verifyList as $k=>$v){
  3068. //init verifyStaff
  3069. if ($v[1]=='ROLE'){
  3070. if (!empty($verifyStaff)){
  3071. $endStaffArray=end($verifyStaff);
  3072. }
  3073. $roleVerify=json_decode($v[3],true);
  3074. $roleKey=$k;$roleArray=array();
  3075. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3076. foreach ($roleVerify as $o=>$p){
  3077. $staffID=explode ('_',$p);
  3078. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3079. //print_r($staffID);
  3080. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3081. array_push($roleArray, $exp);
  3082. }
  3083. $roleArrayCopy[$v[0]]=$roleArray;
  3084. //$verifyList[$k]['roleArray']=$roleArray;
  3085. }
  3086. $verifyList[$k]['date']="";
  3087. $verifyList[$k]['opinion']="";
  3088. $verifyList[$k]['status']="";
  3089. if (empty($verifyStaff)){
  3090. $verifyList[$k]['date']="";
  3091. $verifyList[$k]['opinion']="";
  3092. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3093. $verifyList[$k]['status']=4;
  3094. $flag=false;
  3095. }
  3096. }else{
  3097. foreach ($verifyStaff as $m=>$u){
  3098. if ($v[0]==$m){
  3099. $verifyList[$k]['date']=$u['date'];
  3100. $verifyList[$k]['opinion']=$u['opinion'];
  3101. $verifyList[$k]['status']=$u['status'];
  3102. $flag=false;
  3103. break;
  3104. }
  3105. }
  3106. $endStaffArray=end($verifyStaff);
  3107. if (isset($endStaffArray['ROLE'])){
  3108. }else{
  3109. }
  3110. }
  3111. }
  3112. $rolename['name']='';
  3113. if (!empty($roleId)){
  3114. Doo::loadModel('role');
  3115. $role=new role();
  3116. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3117. }
  3118. if (!empty($verifyStaff))
  3119. $endStaffArray=end($verifyStaff);
  3120. $KOP=false;
  3121. foreach ($roleArrayCopy as $P=>$A){
  3122. foreach ( $A as $MKI=>$AVL){
  3123. if (!empty($verifyStaff)){
  3124. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3125. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3126. $button=4;
  3127. $roleArrayCopy[$P][$MKI]['status']=4;
  3128. }
  3129. foreach ($verifyStaff as $m=>$u){
  3130. $AVLFK=$AVL[0].'_R';
  3131. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3132. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3133. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3134. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3135. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3136. break;
  3137. }
  3138. }
  3139. }else{
  3140. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3141. $button=4;
  3142. $roleArrayCopy[$P][$MKI]['status']=4;
  3143. }
  3144. }
  3145. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3146. $KOP=true;
  3147. }
  3148. }
  3149. foreach ($roleArrayCopy as $k=>$v){
  3150. foreach ($verifyList as $m=>$n){
  3151. if ($n[0]==$k){
  3152. array_splice($verifyList,$m,1,$v);
  3153. }
  3154. }
  3155. }
  3156. $loanList[$key]['verifyList']=$verifyList;
  3157. }
  3158. $htmlLoan='';
  3159. if (isset($loanList[0])){
  3160. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3161. if ($value['status']==1)
  3162. $htmlLoan.='<li class="done" >';
  3163. elseif ($value['status']==3)
  3164. $htmlLoan.='<li class="undone" >';
  3165. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3166. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3167. if (isset($value['rolename']))
  3168. $htmlLoan.=$value['rolename'];
  3169. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3170. }
  3171. $data['loanDate']=$loanList[0]['date'];
  3172. }
  3173. $data['htmlLoan']=$htmlLoan;
  3174. /*
  3175. <!-- loop loanList.0.verifyList -->
  3176. <li <!-- if {{loanList' value.status}}==1 --> class="done" <!-- elseif {{loanList' value.status}}==3 --> class="undone" <!-- endif -->>
  3177. <div class="avtra"><img src="{{loanList' value.2}}_2.jpg"></div>
  3178. <div class="comment">
  3179. <p class="colGray"><span class="fR">{{loanList' value.date}}</span>{{loanList' value.1}}<!-- if isset({{loanList' value.rolename}}) --> ({{loanList' value.rolename}}) <!-- endif --></p>
  3180. <p>{{loanList' value.opinion}}</p>
  3181. </div>
  3182. </li>
  3183. <!-- endloop -->
  3184. */
  3185. //print_r($loanList);
  3186. $Locate=0;$roleId=0;
  3187. if($ap==4)
  3188. $status=4;
  3189. foreach ($receiptList as $key=>$value){
  3190. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3191. $receiptList[$key]['reviseDetail']=array();
  3192. if (!empty($value['reviseDetail']))
  3193. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3194. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3195. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3196. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3197. $receiptList[$key]['category']=$categoryDetil['title'];
  3198. //检测编辑状态
  3199. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3200. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3201. $verifyStaff=json_decode($value['verifyStaff'],true);
  3202. Doo::loadModel('role');
  3203. $role=new role();
  3204. //print_r($verifyList);
  3205. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3206. foreach ($verifyList as $k=>$v){
  3207. //init verifyStaff
  3208. if ($v[1]=='ROLE'){
  3209. if (!empty($verifyStaff)){
  3210. $endStaffArray=end($verifyStaff);
  3211. if ($v[0]==$endStaffArray['nextStaff']){
  3212. $roleId=$v[0];
  3213. }
  3214. }
  3215. $roleVerify=json_decode($v[3],true);
  3216. $roleKey=$k;$roleArray=array();
  3217. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3218. foreach ($roleVerify as $o=>$p){
  3219. $staffID=explode ('_',$p);
  3220. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3221. //print_r($staffID);
  3222. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3223. array_push($roleArray, $exp);
  3224. }
  3225. $roleArrayCopy[$v[0]]=$roleArray;
  3226. //$verifyList[$k]['roleArray']=$roleArray;
  3227. }
  3228. //print_r($roleArray);
  3229. $verifyList[$k]['date']="";
  3230. $verifyList[$k]['opinion']="";
  3231. $verifyList[$k]['status']="";
  3232. if (empty($verifyStaff)){
  3233. $verifyList[$k]['date']="";
  3234. $verifyList[$k]['opinion']="";
  3235. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3236. $verifyList[$k]['status']=4;
  3237. $button=4;$flag=false;
  3238. }
  3239. }else{
  3240. foreach ($verifyStaff as $m=>$u){
  3241. if ($v[0]==$m){
  3242. $verifyList[$k]['date']=$u['date'];
  3243. $verifyList[$k]['opinion']=$u['opinion'];
  3244. $verifyList[$k]['status']=$u['status'];
  3245. $flag=false;
  3246. break;
  3247. }
  3248. }
  3249. $endStaffArray=end($verifyStaff);
  3250. if (isset($endStaffArray['ROLE'])){
  3251. }else{
  3252. $endKey=key($verifyStaff);
  3253. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3254. $button=4;
  3255. $verifyList[$k]['status']=4;
  3256. }
  3257. }
  3258. }
  3259. }
  3260. $rolename['name']='';
  3261. if (!empty($roleId)){
  3262. Doo::loadModel('role');
  3263. $role=new role();
  3264. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3265. }
  3266. if (!empty($verifyStaff))
  3267. $endStaffArray=end($verifyStaff);
  3268. $KOP=false;
  3269. foreach ($roleArrayCopy as $P=>$A){
  3270. foreach ( $A as $MKI=>$AVL){
  3271. if (!empty($verifyStaff)){
  3272. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3273. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3274. $button=4;
  3275. $roleArrayCopy[$P][$MKI]['status']=4;
  3276. }
  3277. foreach ($verifyStaff as $m=>$u){
  3278. $AVLFK=$AVL[0].'_R';
  3279. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3280. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3281. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3282. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3283. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3284. break;
  3285. }
  3286. }
  3287. }else{
  3288. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3289. $button=4;
  3290. $roleArrayCopy[$P][$MKI]['status']=4;
  3291. }
  3292. }
  3293. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3294. $KOP=true;
  3295. }
  3296. }
  3297. foreach ($roleArrayCopy as $k=>$v){
  3298. foreach ($verifyList as $m=>$n){
  3299. if ($n[0]==$k){
  3300. array_splice($verifyList,$m,1,$v);
  3301. }
  3302. }
  3303. }
  3304. $receiptList[$key]['verifyList']=$verifyList;
  3305. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3306. $receiptList[$key]['button']=$button;
  3307. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3308. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3309. $relust=$value['sum']-$value['loanSum'];
  3310. $receiptList[$key]['relust']=$relust;
  3311. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3312. }
  3313. //$data['verifyDetail']=$verifyDetail;
  3314. $mothHtml="";
  3315. for($i=1;$i<=12;$i++){
  3316. if($month==$i)
  3317. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3318. else
  3319. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3320. }
  3321. //获取审批日志
  3322. Doo::loadModel('receiptLog');
  3323. $receiptLog=new receiptLog();
  3324. $rlList=array();
  3325. // $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3326. // $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3327. // if (!empty($rlInfo)){
  3328. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3329. // }
  3330. //echo $rid;
  3331. //print_r($receiptList);
  3332. $receiptList[0]['rlList']=$rlList;
  3333. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3334. $enclosurHtml='';
  3335. foreach ($enclosurList as $value){
  3336. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3337. }
  3338. $data['enclosurHtml']=$enclosurHtml;
  3339. $data['rolename']=$rolename['name'];
  3340. // $data['datetij']=$tijdate['date'];
  3341. $data['mothHtml']=$mothHtml;
  3342. //print_r($receiptList);
  3343. $data['rid']=$rid;
  3344. $data['receiptList']=$receiptList;
  3345. $data['receiptApprovalCount']=count($receiptList);
  3346. $data['status']=$status;
  3347. $data['year']=$year;
  3348. $data['categoryList']=$categoryList;
  3349. $data['staffList']=$staffList;
  3350. $data['cid']=$cid;
  3351. $data['sid']=$sid;
  3352. $data['ap']=$ap;
  3353. $data['memu']="receipt";
  3354. $data['staff']=$this->staff;
  3355. $data['receiptMemu']='approvalExpenses';
  3356. $data['verifyId']=$this->verifyId;
  3357. $data['executeId']=$this->executeId;
  3358. $this->render ( "/admin/receiptburEdi", $data );
  3359. }
  3360. function hisImplement(){
  3361. $item=isset($this->params['item'])?$this->params['item']:"";
  3362. if(empty($item))
  3363. $item=$this->get_args('item')?$this->get_args('item'):"";
  3364. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3365. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3366. Doo::loadModel('receipt');
  3367. $receipt=new receipt();
  3368. Doo::loadModel('L_category');
  3369. $Lcategory=new L_category();
  3370. Doo::loadModel('verify');
  3371. Doo::loadModel('statistics');
  3372. $statistics=new statistics();
  3373. $verify=new verify();
  3374. Doo::loadModel('staff');
  3375. $staff=new staff();
  3376. $condition="";
  3377. if($item=="expenses")
  3378. $condition=" and Rtype=1 ";
  3379. elseif ($item=="receipts")
  3380. $condition=" and Rtype=0 ";
  3381. elseif ($item=="remits")
  3382. $condition=" and Rtype=2 ";
  3383. $dateCondition=" and Year(date) =".$year;
  3384. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3385. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3386. $Locate=0;$roleId=0;$button=0;
  3387. foreach ($receiptList as $key=>$value){
  3388. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3389. $receiptList[$key]['reviseDetail']=array();
  3390. if (!empty($value['reviseDetail']))
  3391. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3392. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3393. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3394. $receiptList[$key]['category']=$categoryDetil['title'];
  3395. //检测编辑状态
  3396. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3397. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3398. $verifyStaff=json_decode($value['verifyStaff'],true);
  3399. Doo::loadModel('role');
  3400. $role=new role();
  3401. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3402. foreach ($verifyList as $k=>$v){
  3403. //init verifyStaff
  3404. if ($v[1]=='ROLE'){
  3405. if (!empty($verifyStaff)){
  3406. $endStaffArray=end($verifyStaff);
  3407. }
  3408. $roleVerify=json_decode($v[3],true);
  3409. $roleKey=$k;$roleArray=array();
  3410. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3411. foreach ($roleVerify as $o=>$p){
  3412. $staffID=explode ('_',$p);
  3413. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3414. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3415. array_push($roleArray, $exp);
  3416. }
  3417. $roleArrayCopy[$v[0]]=$roleArray;
  3418. }
  3419. $verifyList[$k]['date']="";
  3420. $verifyList[$k]['opinion']="";
  3421. $verifyList[$k]['status']="";
  3422. if (empty($verifyStaff)){
  3423. $verifyList[$k]['date']="";
  3424. $verifyList[$k]['opinion']="";
  3425. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3426. $verifyList[$k]['status']=4;
  3427. $flag=false;
  3428. }
  3429. }else{
  3430. foreach ($verifyStaff as $m=>$u){
  3431. if ($v[0]==$m){
  3432. $verifyList[$k]['date']=$u['date'];
  3433. $verifyList[$k]['opinion']=$u['opinion'];
  3434. $verifyList[$k]['status']=$u['status'];
  3435. $flag=false;
  3436. break;
  3437. }
  3438. }
  3439. $endStaffArray=end($verifyStaff);
  3440. }
  3441. }
  3442. $rolename['name']='';
  3443. if (!empty($roleId)){
  3444. Doo::loadModel('role');
  3445. $role=new role();
  3446. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3447. }
  3448. if (!empty($verifyStaff))
  3449. $endStaffArray=end($verifyStaff);
  3450. $KOP=false;
  3451. foreach ($roleArrayCopy as $P=>$A){
  3452. foreach ( $A as $MKI=>$AVL){
  3453. if (!empty($verifyStaff)){
  3454. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3455. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3456. $button=4;
  3457. $roleArrayCopy[$P][$MKI]['status']=4;
  3458. }
  3459. foreach ($verifyStaff as $m=>$u){
  3460. $AVLFK=$AVL[0].'_R';
  3461. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3462. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3463. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3464. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3465. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3466. break;
  3467. }
  3468. }
  3469. }else{
  3470. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3471. $button=4;
  3472. $roleArrayCopy[$P][$MKI]['status']=4;
  3473. }
  3474. }
  3475. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3476. $KOP=true;
  3477. }
  3478. }
  3479. foreach ($roleArrayCopy as $k=>$v){
  3480. foreach ($verifyList as $m=>$n){
  3481. if ($n[0]==$k){
  3482. array_splice($verifyList,$m,1,$v);
  3483. }
  3484. }
  3485. }
  3486. $receiptList[$key]['verifyList']=$verifyList;
  3487. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3488. $receiptList[$key]['button']=$button;
  3489. }
  3490. //print_r($receiptList);die;
  3491. $mothHtml="";
  3492. for($i=1;$i<=12;$i++){
  3493. if($moth==$i)
  3494. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3495. else
  3496. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3497. }
  3498. $data['mothHtml']=$mothHtml;
  3499. $data['receiptList']=$receiptList;
  3500. $data['memu']="receipt";
  3501. $data['staff']=$this->staff;
  3502. $data['receiptMemu']='implement';
  3503. $data['verifyId']=$this->verifyId;
  3504. $data['executeId']=$this->executeId;
  3505. $data['item']=$item;
  3506. $data['year']=$year;
  3507. $this->render ( "/admin/hisImplement", $data );
  3508. }
  3509. function ajaxExamine(){
  3510. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3511. Doo::loadModel('receipt');
  3512. $receipt=new receipt();
  3513. if (!empty($rid)){
  3514. $rLRes=$receipt->find(array('where'=>'status=2 and nowStaff like "%'.$this->staff[0]['sid'].'%" and rid!='.$rid
  3515. ,'asArray'=>true));
  3516. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3517. }
  3518. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3519. }
  3520. function myReceipt(){
  3521. //all approval past withdraw
  3522. $item=isset($this->params['item'])?$this->params['item']:"";
  3523. if(empty($item))
  3524. $item=$this->get_args('item')?$this->get_args('item'):"";
  3525. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3526. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3527. Doo::loadModel('receipt');
  3528. $receipt=new receipt();
  3529. //pre-loaded
  3530. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3531. //have cache
  3532. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3533. if(!empty($moth))//yearPage
  3534. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3535. $this->showCache($path);
  3536. }
  3537. Doo::loadModel('L_category');
  3538. $Lcategory=new L_category();
  3539. Doo::loadModel('verify');
  3540. Doo::loadModel('statistics');
  3541. $statistics=new statistics();
  3542. $verify=new verify();
  3543. Doo::loadModel('staff');
  3544. $staff=new staff();
  3545. $condition=" and status!=0 ";
  3546. if($item=="approval")
  3547. $condition=" and status=2 ";
  3548. elseif ($item=="withdraw")
  3549. $condition=" and status=3 ";
  3550. elseif ($item=="past")
  3551. $condition=" and status=1 ";
  3552. elseif ($item=="whdw")
  3553. $condition=" and status=4 ";
  3554. $dateCondition=" and Year(date) =".$year;
  3555. if(!empty($moth)){
  3556. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3557. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3558. }else
  3559. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3560. if(empty($stList))
  3561. $stList=array('rePrice'=>0,'agPrice'=>0);
  3562. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3563. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3564. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3565. $Locate=0;$roleId=0;$button=0;
  3566. foreach ($receiptList as $key=>$value){
  3567. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3568. $receiptList[$key]['reviseDetail']=array();
  3569. if (!empty($value['reviseDetail']))
  3570. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3571. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3572. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3573. $receiptList[$key]['category']=$categoryDetil['title'];
  3574. //检测编辑状态
  3575. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3576. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3577. $verifyStaff=json_decode($value['verifyStaff'],true);
  3578. Doo::loadModel('role');
  3579. $role=new role();
  3580. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3581. foreach ($verifyList as $k=>$v){
  3582. //init verifyStaff
  3583. if ($v[1]=='ROLE'){
  3584. if (!empty($verifyStaff)){
  3585. $endStaffArray=end($verifyStaff);
  3586. // if ($v[0]==$endStaffArray['nextStaff']){
  3587. // $roleId=$v[0];
  3588. // }
  3589. }
  3590. $roleVerify=json_decode($v[3],true);
  3591. $roleKey=$k;$roleArray=array();
  3592. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3593. foreach ($roleVerify as $o=>$p){
  3594. $staffID=explode ('_',$p);
  3595. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3596. //print_r($staffID);
  3597. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3598. array_push($roleArray, $exp);
  3599. }
  3600. $roleArrayCopy[$v[0]]=$roleArray;
  3601. //$verifyList[$k]['roleArray']=$roleArray;
  3602. }
  3603. $verifyList[$k]['date']="";
  3604. $verifyList[$k]['opinion']="";
  3605. $verifyList[$k]['status']="";
  3606. if (empty($verifyStaff)){
  3607. $verifyList[$k]['date']="";
  3608. $verifyList[$k]['opinion']="";
  3609. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3610. $verifyList[$k]['status']=4;
  3611. $flag=false;
  3612. }
  3613. }else{
  3614. foreach ($verifyStaff as $m=>$u){
  3615. if ($v[0]==$m){
  3616. $verifyList[$k]['date']=$u['date'];
  3617. $verifyList[$k]['opinion']=$u['opinion'];
  3618. $verifyList[$k]['status']=$u['status'];
  3619. $flag=false;
  3620. break;
  3621. }
  3622. }
  3623. $endStaffArray=end($verifyStaff);
  3624. if (isset($endStaffArray['ROLE'])){
  3625. }else{
  3626. // $endKey=key($verifyStaff);
  3627. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3628. // $button=4;
  3629. // $verifyList[$k]['status']=4;
  3630. // }
  3631. }
  3632. }
  3633. }
  3634. $rolename['name']='';
  3635. if (!empty($roleId)){
  3636. Doo::loadModel('role');
  3637. $role=new role();
  3638. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3639. }
  3640. if (!empty($verifyStaff))
  3641. $endStaffArray=end($verifyStaff);
  3642. $KOP=false;
  3643. foreach ($roleArrayCopy as $P=>$A){
  3644. foreach ( $A as $MKI=>$AVL){
  3645. if (!empty($verifyStaff)){
  3646. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3647. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3648. $button=4;
  3649. $roleArrayCopy[$P][$MKI]['status']=4;
  3650. }
  3651. foreach ($verifyStaff as $m=>$u){
  3652. $AVLFK=$AVL[0].'_R';
  3653. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3654. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3655. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3656. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3657. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3658. break;
  3659. }
  3660. }
  3661. }else{
  3662. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3663. $button=4;
  3664. $roleArrayCopy[$P][$MKI]['status']=4;
  3665. }
  3666. }
  3667. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3668. $KOP=true;
  3669. }
  3670. }
  3671. foreach ($roleArrayCopy as $k=>$v){
  3672. foreach ($verifyList as $m=>$n){
  3673. if ($n[0]==$k){
  3674. array_splice($verifyList,$m,1,$v);
  3675. }
  3676. }
  3677. }
  3678. $receiptList[$key]['verifyList']=$verifyList;
  3679. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3680. $receiptList[$key]['button']=$button;
  3681. }
  3682. //print_r($receiptList);die;
  3683. $mothHtml="";
  3684. for($i=1;$i<=12;$i++){
  3685. if($moth==$i)
  3686. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3687. else
  3688. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3689. }
  3690. $data['mothHtml']=$mothHtml;
  3691. $data['receiptList']=$receiptList;
  3692. $data['memu']="receipt";
  3693. $data['staff']=$this->staff;
  3694. $data['receiptMemu']='receipt';
  3695. $data['verifyId']=$this->verifyId;
  3696. $data['executeId']=$this->executeId;
  3697. $data['item']=$item;
  3698. $data['year']=$year;
  3699. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3700. //sufficient condition to generate cache
  3701. if(empty($moth)&&($year<date("Y"))){
  3702. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3703. if(empty($receiptList)){ //generated files
  3704. ob_start();
  3705. $this->render ( "/admin/saea_myList", $data );
  3706. $this->cacheFile($path);die;
  3707. // $content = ob_get_contents();
  3708. // $fp = fopen($path, "w");
  3709. // fwrite($fp, $content);
  3710. // fclose($fp);
  3711. }
  3712. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3713. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$moth,'asArray'=>true));
  3714. if(empty($receiptList)){ //generated files
  3715. ob_start();
  3716. $this->render ( "/admin/saea_myList", $data );
  3717. $this->cacheFile($path);die;
  3718. }
  3719. }
  3720. }
  3721. $this->render ( "/admin/saea_myList", $data );
  3722. }
  3723. function saeaCreate(){
  3724. Doo::loadModel('accountItem');
  3725. Doo::loadModel('verify');
  3726. Doo::loadModel('receipt');
  3727. Doo::loadModel('L_category');
  3728. $lCategory=new L_category();
  3729. $receipt=new receipt();
  3730. $verify=new verify();
  3731. $accountItem=new accountItem();
  3732. Doo::loadModel("role");
  3733. $role=new role();
  3734. $acItem=$accountItem->find(array('asArray'=>true));
  3735. $veList=$verify->find(array('asArray'=>true));
  3736. foreach ($veList as $key=>$value){
  3737. $v=json_decode($value['staff']);
  3738. $list=array();
  3739. foreach ($v as $n=>$m){
  3740. if ($m['1']=='ROLE'){
  3741. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3742. $v[$n][1]=$roleInfo['name'];
  3743. array_push($list, $roleInfo['name']);
  3744. }else{
  3745. array_push($list, $v[$n][1]);
  3746. }
  3747. }
  3748. $veList[$key]['staff']=implode('>', $list);
  3749. }
  3750. $data['category']=$lCategory->find(array('asArray'=>true));
  3751. $data['veList']=$veList;
  3752. $data['acItem']=$acItem;
  3753. $data['memu']="receipt";
  3754. $data['staff']=$this->staff;
  3755. $data['receiptMemu']='saeaCreate';
  3756. $data['verifyId']=$this->verifyId;
  3757. $data['executeId']=$this->executeId;
  3758. $this->render ( "/admin/saea_create", $data );
  3759. }
  3760. function addReceipt(){
  3761. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3762. $agency=$this->get_args('agency');
  3763. $travel=$this->get_args('travel');
  3764. $train=$this->get_args('train');
  3765. $other=$this->get_args('other');
  3766. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3767. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3768. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3769. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3770. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3771. Doo::loadModel('receipt');
  3772. Doo::loadModel('receiptDetail');
  3773. Doo::loadModel('accountItem');
  3774. $accountItem=new accountItem();
  3775. $receipt=new receipt();
  3776. Doo::loadModel('enclosur');
  3777. Doo::loadModel('execute');
  3778. $execute=new execute();
  3779. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3780. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3781. // if(!empty($receiptDetail))
  3782. // return "/referReceipt/".$receiptDetail['rid'];
  3783. $aItem=$accountItem->find(array('asArray'=>true));
  3784. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3785. $ag=$tr=$ta=$ot=0;
  3786. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3787. foreach ($aItem as $key=>$value){
  3788. if ($value['category']==$this->AGENCY){
  3789. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3790. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3791. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3792. }
  3793. $ag++;
  3794. }
  3795. if($value['category']==$this->TRAVEL){
  3796. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3797. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3798. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3799. }
  3800. $tr++;
  3801. }
  3802. if($value['category']==$this->TRAIN){
  3803. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3804. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3805. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3806. }
  3807. $ta++;
  3808. }
  3809. if($value['category']==$this->OTHER){
  3810. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3811. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3812. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3813. }
  3814. $ot++;
  3815. }
  3816. }
  3817. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3818. //报销单
  3819. $receipt->accountItem=json_encode($accountJson);
  3820. $receipt->staff=$this->staff[0]['sid'];
  3821. $receipt->sum=number_format($sum, 2, '.', '');
  3822. $receipt->date=date("Y-m-d");
  3823. $receipt->cid=$cid;
  3824. $receipt->status=5;
  3825. //修改审批流程加入角色
  3826. $receipt->verify=$verify;
  3827. $receipt->executeCopy=$executeDetail['staff'];
  3828. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3829. $receipt->explanation=$explanation;
  3830. $rid=$receipt->insert();
  3831. //附件
  3832. if (!empty($enclosurName)){
  3833. $enclosurArray=explode('-', $enclosurName);
  3834. foreach ($enclosurArray as $value){
  3835. $enclosur=new enclosur();
  3836. $enclosur->name=$value;
  3837. $enclosur->rid=$rid;
  3838. $enclosur->insert();
  3839. }
  3840. //print_r($enclosurArray);die;
  3841. }
  3842. //报销详情
  3843. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3844. $receiptDetail=new receiptDetail();
  3845. $receiptDetail->staff=$this->staff[0]['sid'];
  3846. $receiptDetail->item=$value['name'];
  3847. $receiptDetail->itemCategory=$this->AGENCY;
  3848. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3849. $receiptDetail->date=date("Y-m-d");
  3850. $receiptDetail->cid=$cid;
  3851. $receiptDetail->rid=$rid;
  3852. $receiptDetail->status=4;
  3853. $receiptDetail->insert();
  3854. }
  3855. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3856. $receiptDetail=new receiptDetail();
  3857. $receiptDetail->staff=$this->staff[0]['sid'];
  3858. $receiptDetail->item=$value['name'];
  3859. $receiptDetail->itemCategory=$this->TRAVEL;
  3860. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3861. $receiptDetail->date=date("Y-m-d");
  3862. $receiptDetail->cid=$cid;
  3863. $receiptDetail->rid=$rid;
  3864. $receiptDetail->status=4;
  3865. $receiptDetail->insert();
  3866. }
  3867. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3868. $receiptDetail=new receiptDetail();
  3869. $receiptDetail->staff=$this->staff[0]['sid'];
  3870. $receiptDetail->item=$value['name'];
  3871. $receiptDetail->itemCategory=$this->TRAIN;
  3872. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3873. $receiptDetail->date=date("Y-m-d");
  3874. $receiptDetail->cid=$cid;
  3875. $receiptDetail->rid=$rid;
  3876. $receiptDetail->status=4;
  3877. $receiptDetail->insert();
  3878. }
  3879. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3880. $receiptDetail=new receiptDetail();
  3881. $receiptDetail->staff=$this->staff[0]['sid'];
  3882. $receiptDetail->item=$value['name'];
  3883. $receiptDetail->itemCategory=$this->OTHER;
  3884. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3885. $receiptDetail->date=date("Y-m-d");
  3886. $receiptDetail->cid=$cid;
  3887. $receiptDetail->rid=$rid;
  3888. $receiptDetail->status=4;
  3889. $receiptDetail->insert();
  3890. }
  3891. //return "/referReceipt/".$rid;
  3892. }
  3893. return "/saeaBorad";
  3894. }
  3895. function referReceipt(){
  3896. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3897. Doo::loadModel('receipt');
  3898. Doo::loadModel('verify');
  3899. $verify=new verify();
  3900. $receipt=new receipt();
  3901. Doo::loadModel('L_category');
  3902. $lCategory=new L_category();
  3903. Doo::loadModel("role");
  3904. $role=new role();
  3905. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  3906. if(empty($receiptDetail))
  3907. return "/addReceipt";
  3908. foreach ($receiptDetail as $key=>$value){
  3909. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  3910. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3911. $v=json_decode($veList['staff']);
  3912. array_push($v[0], $veList['description']);
  3913. foreach ($v as $n=>$m){
  3914. if ($m['1']=='ROLE'){
  3915. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3916. $v[$n][1]=$roleInfo['name'];
  3917. }
  3918. }
  3919. $receiptDetail[$key]['staff']=$v;
  3920. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3921. $receiptDetail[$key]['category']=$category['title'];
  3922. }
  3923. //print_r($receiptDetail);
  3924. $data['receiptDetail']=$receiptDetail;
  3925. $data['memu']="receipt";
  3926. $data['staff']=$this->staff;
  3927. $data['receiptMemu']='saeaCreate';
  3928. $data['verifyId']=$this->verifyId;
  3929. $data['executeId']=$this->executeId;
  3930. $this->render ( "/admin/saea_confirm", $data );
  3931. }
  3932. function editReceipt(){
  3933. //edit status 4
  3934. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3935. //echo $rid;
  3936. Doo::loadModel('accountItem');
  3937. Doo::loadModel('verify');
  3938. Doo::loadModel('receipt');
  3939. $receipt=new receipt();
  3940. $verify=new verify();
  3941. $accountItem=new accountItem();
  3942. Doo::loadModel('L_category');
  3943. $lCategory=new L_category();
  3944. Doo::loadModel("role");
  3945. $role=new role();
  3946. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  3947. if(empty($receiptDetail))
  3948. return "/saeaCreate";
  3949. $acItem=$accountItem->find(array('asArray'=>true));
  3950. $veList=$verify->find(array('asArray'=>true));
  3951. foreach ($veList as $key=>$value){
  3952. $v=json_decode($value['staff']);
  3953. $list=array();
  3954. foreach ($v as $n=>$m){
  3955. if ($m['1']=='ROLE'){
  3956. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3957. $v[$n][1]=$roleInfo['name'];
  3958. array_push($list, $roleInfo['name']);
  3959. }else{
  3960. array_push($list, $v[$n][1]);
  3961. }
  3962. }
  3963. $veList[$key]['staff']=implode('>', $list);
  3964. }
  3965. //配置编辑信息
  3966. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  3967. foreach ($acItem as $key=>$value){
  3968. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  3969. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  3970. $acItem[$key]['price']=$v['price'];
  3971. }
  3972. }
  3973. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  3974. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  3975. $acItem[$key]['price']=$v['price'];
  3976. }
  3977. }
  3978. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  3979. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  3980. $acItem[$key]['price']=$v['price'];
  3981. }
  3982. }
  3983. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  3984. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  3985. $acItem[$key]['price']=$v['price'];
  3986. }
  3987. }
  3988. }
  3989. $data['category']=$lCategory->find(array('asArray'=>true));
  3990. $data['cSum']=$accountItemList['cSum'];
  3991. $data['sum']=$receiptDetail['sum'];
  3992. $data['receiptDetail']=$receiptDetail;
  3993. $data['veList']=$veList;
  3994. $data['acItem']=$acItem;
  3995. $data['memu']="receipt";
  3996. $data['staff']=$this->staff;
  3997. $data['receiptMemu']='saeaBorad';
  3998. $data['verify']=$receiptDetail['verify'];
  3999. $data['verifyId']=$this->verifyId;
  4000. $data['executeId']=$this->executeId;
  4001. $data['rid']=$rid;
  4002. $this->render ( "/admin/saea_edit", $data );
  4003. }
  4004. function updateReceipt(){
  4005. $agency=$this->get_args('agency');
  4006. $travel=$this->get_args('travel');
  4007. $train=$this->get_args('train');
  4008. $other=$this->get_args('other');
  4009. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4010. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4011. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4012. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4013. if(!empty($verify)&&!empty($explanation)){
  4014. Doo::loadModel('receipt');
  4015. Doo::loadModel('receiptDetail');
  4016. Doo::loadModel('accountItem');
  4017. $accountItem=new accountItem();
  4018. $receipt=new receipt();
  4019. Doo::loadModel('execute');
  4020. $execute=new execute();
  4021. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4022. if(empty($receiptDetail))
  4023. return "/saeaBorad";
  4024. if ($receiptDetail['Rtype']==1)
  4025. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4026. else
  4027. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4028. $aItem=$accountItem->find(array('asArray'=>true));
  4029. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4030. $ag=$tr=$ta=$ot=0;
  4031. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4032. foreach ($aItem as $key=>$value){
  4033. if ($value['category']==$this->AGENCY){
  4034. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4035. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4036. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4037. }
  4038. $ag++;
  4039. }
  4040. if($value['category']==$this->TRAVEL){
  4041. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4042. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4043. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4044. }
  4045. $tr++;
  4046. }
  4047. if($value['category']==$this->TRAIN){
  4048. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4049. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4050. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4051. }
  4052. $ta++;
  4053. }
  4054. if($value['category']==$this->OTHER){
  4055. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4056. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4057. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4058. }
  4059. $ot++;
  4060. }
  4061. }
  4062. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4063. //报销单
  4064. $rid=$receipt->rid=$receiptDetail['rid'];
  4065. $receipt->accountItem=json_encode($accountJson);
  4066. $receipt->staff=$this->staff[0]['sid'];
  4067. $receipt->sum=number_format($sum, 2, '.', '');
  4068. $receipt->date=date("Y-m-d");
  4069. $receipt->cid=$cid;
  4070. if (($receiptDetail['status']!=4)){
  4071. if ($receiptDetail['Rtype']==1)
  4072. $receipt->status=7;
  4073. else
  4074. $receipt->status=5;
  4075. }
  4076. $receipt->verify=$verify;
  4077. $receipt->executeCopy=$executeDetail['staff'];
  4078. $receipt->explanation=$explanation;
  4079. $receipt->update();
  4080. $receiptDetail=new receiptDetail();
  4081. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4082. //报销详情
  4083. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4084. $receiptDetail=new receiptDetail();
  4085. $receiptDetail->staff=$this->staff[0]['sid'];
  4086. $receiptDetail->item=$value['name'];
  4087. $receiptDetail->itemCategory=$this->AGENCY;
  4088. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4089. $receiptDetail->date=date("Y-m-d");
  4090. $receiptDetail->cid=$cid;
  4091. $receiptDetail->rid=$rid;
  4092. $receiptDetail->status=4;
  4093. $receiptDetail->insert();
  4094. }
  4095. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4096. $receiptDetail=new receiptDetail();
  4097. $receiptDetail->staff=$this->staff[0]['sid'];
  4098. $receiptDetail->item=$value['name'];
  4099. $receiptDetail->itemCategory=$this->TRAVEL;
  4100. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4101. $receiptDetail->date=date("Y-m-d");
  4102. $receiptDetail->cid=$cid;
  4103. $receiptDetail->rid=$rid;
  4104. $receiptDetail->status=4;
  4105. $receiptDetail->insert();
  4106. }
  4107. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4108. $receiptDetail=new receiptDetail();
  4109. $receiptDetail->staff=$this->staff[0]['sid'];
  4110. $receiptDetail->item=$value['name'];
  4111. $receiptDetail->itemCategory=$this->TRAIN;
  4112. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4113. $receiptDetail->date=date("Y-m-d");
  4114. $receiptDetail->cid=$cid;
  4115. $receiptDetail->rid=$rid;
  4116. $receiptDetail->status=4;
  4117. $receiptDetail->insert();
  4118. }
  4119. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4120. $receiptDetail=new receiptDetail();
  4121. $receiptDetail->staff=$this->staff[0]['sid'];
  4122. $receiptDetail->item=$value['name'];
  4123. $receiptDetail->itemCategory=$this->OTHER;
  4124. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4125. $receiptDetail->date=date("Y-m-d");
  4126. $receiptDetail->cid=$cid;
  4127. $receiptDetail->rid=$rid;
  4128. $receiptDetail->status=4;
  4129. $receiptDetail->insert();
  4130. }
  4131. //return "/referReceipt/".$rid;
  4132. }
  4133. return "/saeaBorad";
  4134. }
  4135. function approvedReceipt(){
  4136. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4137. Doo::loadModel('receipt');
  4138. Doo::loadModel('receiptDetail');
  4139. $receipt=new receipt();
  4140. $receiptDetail=new receiptDetail();
  4141. Doo::loadModel('statistics');
  4142. Doo::loadModel('itemStatistics');
  4143. $statistics=new statistics();
  4144. $itemStatistics=new itemStatistics();
  4145. Doo::loadModel("verify");
  4146. $verify=new verify();
  4147. //审批状态的判定
  4148. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4149. if(empty($receiptDetailList))
  4150. return "/saeaBorad";
  4151. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4152. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4153. if (empty($receiptDetailList['nowStaff'])){
  4154. $nowStaff="";$nowStaffList=array();
  4155. if ($verifyDetail[0][1]=='ROLE'){
  4156. $vStaffString=json_decode($verifyDetail[0][3]);
  4157. foreach ($vStaffString as $key=>$value){
  4158. $staffK=explode("_", $value);
  4159. array_push($nowStaffList, $staffK[0]);
  4160. }
  4161. $nowStaff=implode(',', $nowStaffList);
  4162. }else{
  4163. $nowStaff=$verifyDetail[0][0];
  4164. }
  4165. $receipt->nowStaff=$nowStaff;
  4166. }
  4167. // echo $nowStaff;
  4168. // print_r($verifyDetail);die;
  4169. $receipt->rid=$receiptDetailList['rid'];
  4170. $receipt->date=date("Y-m-d");
  4171. $receipt->status=2;
  4172. $receipt->update();
  4173. $receiptDetail->status=2;
  4174. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4175. Doo::loadModel("receiptLog");
  4176. $receiptLog=new receiptLog();
  4177. Doo::loadModel("verify");
  4178. $verify=new verify();
  4179. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4180. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4181. $jd=json_decode($vr['staff']);$roleId=0;
  4182. foreach ($jd as $key=>$value){
  4183. if ($value[1]=='ROLE'){
  4184. $pos = strpos($value[3], $this->staff[0]['sid']);
  4185. if ($pos !== false) {
  4186. $roleId=$value[0];
  4187. }
  4188. }
  4189. }
  4190. //审批日志
  4191. //echo $roleId;die;
  4192. if (!empty($roleId)){
  4193. Doo::loadModel("role");
  4194. $role=new role();
  4195. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4196. $receiptLog->rolename=$roleInfo['name'];
  4197. }
  4198. $receiptLog->username=$this->staff[0]['username'];
  4199. $receiptLog->uid=$this->staff[0]['sid'];
  4200. $receiptLog->date=date("Y-m-d");
  4201. $receiptLog->opinion='提交审批';
  4202. $receiptLog->img=$this->staff[0]['avatar'];
  4203. $receiptLog->status=2;
  4204. $receiptLog->rid=$rid;
  4205. $receiptLog->insert();
  4206. //statistics item
  4207. $dateArray=explode("-", $receiptDetailList['date']);
  4208. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4209. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4210. //print_r($accountItem['cSum']['agencySum']);die;
  4211. // foreach ($accountItem['cSum'] as $key=>$value){
  4212. // if($key=="agencySum"){
  4213. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4214. // if(empty($iStatistics)){
  4215. // $itemStatistics->cid=$this->staff[0]['cid'];
  4216. // $itemStatistics->staff=$this->staff[0]['sid'];
  4217. // $itemStatistics->price=$value;
  4218. // $itemStatistics->itemCategory=$this->AGENCY;
  4219. // $itemStatistics->date=date("Y-m-d");
  4220. // $itemStatistics->insert();
  4221. // }else{
  4222. // if (!empty($value)){
  4223. // $itemStatistics->price=$value+$iStatistics['price'];
  4224. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4225. // }
  4226. // }
  4227. // }elseif($key=="travelSum"){
  4228. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4229. // if(empty($iStatistics)){
  4230. // $itemStatistics->cid=$this->staff[0]['cid'];
  4231. // $itemStatistics->staff=$this->staff[0]['sid'];
  4232. // $itemStatistics->price=$value;
  4233. // $itemStatistics->itemCategory=$this->TRAVEL;
  4234. // $itemStatistics->date=date("Y-m-d");
  4235. // $itemStatistics->insert();
  4236. // }else{
  4237. // if (!empty($value)){
  4238. // $itemStatistics->price=$value+$iStatistics['price'];
  4239. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4240. // }
  4241. // }
  4242. // }elseif($key=="trainSum"){
  4243. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4244. // if(empty($iStatistics)){
  4245. // $itemStatistics->cid=$this->staff[0]['cid'];
  4246. // $itemStatistics->staff=$this->staff[0]['sid'];
  4247. // $itemStatistics->price=$value;
  4248. // $itemStatistics->itemCategory=$this->TRAIN;
  4249. // $itemStatistics->date=date("Y-m-d");
  4250. // $itemStatistics->insert();
  4251. // }else{
  4252. // if (!empty($value)){
  4253. // $itemStatistics->price=$value+$iStatistics['price'];
  4254. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4255. // }
  4256. // }
  4257. // }elseif($key=="otherSum"){
  4258. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4259. // if(empty($iStatistics)){
  4260. // $itemStatistics->cid=$this->staff[0]['cid'];
  4261. // $itemStatistics->staff=$this->staff[0]['sid'];
  4262. // $itemStatistics->price=$value;
  4263. // $itemStatistics->itemCategory=$this->OTHER;
  4264. // $itemStatistics->date=date("Y-m-d");
  4265. // $itemStatistics->insert();
  4266. // }else{
  4267. // if (!empty($value)){
  4268. // $itemStatistics->price=$value+$iStatistics['price'];
  4269. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4270. // }
  4271. // }
  4272. // }
  4273. // }
  4274. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4275. if(empty($stat)){
  4276. $statistics->date=date("Y-m-d");
  4277. $statistics->cid=$this->staff[0]['cid'];
  4278. $statistics->staff=$this->staff[0]['sid'];
  4279. $statistics->agPrice=0;
  4280. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4281. $statistics->insert();
  4282. }else{
  4283. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4284. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4285. }
  4286. return "/expenses";
  4287. }
  4288. function approval(){
  4289. $status=isset($this->params['status'])?$this->params['status']:'';
  4290. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4291. $month=$this->get_args('month')?$this->get_args('month'):"";
  4292. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4293. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4294. if (empty($status))
  4295. $status=$this->get_args('status')?$this->get_args('status'):2;
  4296. $vidList=array();
  4297. $button=0;
  4298. Doo::loadModel('verify');
  4299. $verify=new verify();
  4300. Doo::loadModel('receipt');
  4301. $receipt=new receipt();
  4302. Doo::loadModel('staff');
  4303. $staff=new staff();
  4304. Doo::loadModel('L_category');
  4305. $Lcategory=new L_category();
  4306. //user verify ID
  4307. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4308. foreach ($verifyDetail as $key=>$value){
  4309. array_push($vidList, $value['vid']);
  4310. }
  4311. $vid=implode(",", $vidList);
  4312. if(empty($verifyDetail))
  4313. $vid=0;
  4314. /*
  4315. */
  4316. $dateCondition=" and Year(date) =".$year;
  4317. if(!empty($month))
  4318. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4319. $categoryList=$Lcategory->find(array('asArray'=>true));
  4320. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4321. $cateCondition="";$staffCondition="";$approvalCondition="";
  4322. if (!empty($cid))
  4323. $cateCondition=' and cid='.$cid;
  4324. if(!empty($sid)){
  4325. $staffCondition=' and staff='.$sid;
  4326. $cateCondition="";
  4327. }
  4328. // elseif($status==1){
  4329. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4330. // }
  4331. if($status==2){
  4332. //查找角色审批人
  4333. $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  4334. }
  4335. $ap="";
  4336. if($status==4){
  4337. $ap=4;$status=2;
  4338. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4339. }
  4340. if($status==5){
  4341. $status=4;$ap=5;
  4342. }
  4343. //echo $vid;
  4344. //get Receipt By verifyID status 2 .$approvalCondition
  4345. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4346. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4347. ,'desc'=>'rid','asArray'=>true));
  4348. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4349. $Locate=0;
  4350. if($ap==4)
  4351. $status=4;
  4352. elseif ($ap==5)
  4353. $status=5;
  4354. foreach ($receiptList as $key=>$value){
  4355. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4356. $receiptList[$key]['reviseDetail']=array();
  4357. if (!empty($value['reviseDetail']))
  4358. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4359. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4360. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4361. $receiptList[$key]['category']=$categoryDetil['title'];
  4362. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4363. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4364. $verifyStaff=json_decode($value['verifyStaff'],true);
  4365. foreach ($verifyList as $k=>$v){
  4366. //init verifyStaff
  4367. $verifyList[$k]['date']="";
  4368. $verifyList[$k]['opinion']="";
  4369. $verifyList[$k]['status']="";
  4370. if (empty($verifyStaff)){
  4371. $verifyList[$k]['date']="";
  4372. $verifyList[$k]['opinion']="";
  4373. if ($v[0]==$this->staff[0]['sid']){
  4374. $verifyList[$k]['status']=4;
  4375. $button=4;
  4376. }
  4377. }else{
  4378. $flag=true;
  4379. foreach ($verifyStaff as $m=>$u){
  4380. if ($v[0]==$m){
  4381. $verifyList[$k]['date']=$u['date'];
  4382. $verifyList[$k]['opinion']=$u['opinion'];
  4383. $verifyList[$k]['status']=$u['status'];
  4384. $flag=false;
  4385. break;
  4386. }
  4387. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4388. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4389. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4390. }
  4391. if($flag){//检测可编辑
  4392. if($v[0]==$this->staff[0]['sid']){
  4393. $verifyList[$k]['status']=4;$button=4;
  4394. }
  4395. }
  4396. }
  4397. }
  4398. $receiptList[$key]['verifyList']=$verifyList;
  4399. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4400. $receiptList[$key]['button']=$button;
  4401. }
  4402. //print_r($receiptList);die;
  4403. //$data['verifyDetail']=$verifyDetail;
  4404. $mothHtml="";
  4405. for($i=1;$i<=12;$i++){
  4406. if($month==$i)
  4407. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4408. else
  4409. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4410. }
  4411. $data['mothHtml']=$mothHtml;
  4412. $data['receiptList']=$receiptList;
  4413. $data['receiptApprovalCount']=count($receiptList);
  4414. $data['status']=$status;
  4415. $data['year']=$year;
  4416. $data['categoryList']=$categoryList;
  4417. $data['staffList']=$staffList;
  4418. $data['cid']=$cid;
  4419. $data['sid']=$sid;
  4420. $data['ap']=$ap;
  4421. $data['memu']="receipt";
  4422. $data['staff']=$this->staff;
  4423. $data['receiptMemu']='approval';
  4424. $data['verifyId']=$this->verifyId;
  4425. $data['executeId']=$this->executeId;
  4426. $this->render ( "/admin/saea_reportList", $data );
  4427. }
  4428. function approvalDetails(){
  4429. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4430. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4431. $month=$this->get_args('month')?$this->get_args('month'):"";
  4432. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4433. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4434. Doo::loadModel('verify');
  4435. $verify=new verify();
  4436. Doo::loadModel('receipt');
  4437. $receipt=new receipt();
  4438. Doo::loadModel('staff');
  4439. $staff=new staff();
  4440. Doo::loadModel('L_category');
  4441. $Lcategory=new L_category();
  4442. Doo::loadModel('enclosur');
  4443. $enclosur=new enclosur();
  4444. $vidList=array();
  4445. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4446. foreach ($verifyDetail as $key=>$value){
  4447. array_push($vidList, $value['vid']);
  4448. }
  4449. $vid=implode(",", $vidList);
  4450. if(empty($verifyDetail))
  4451. $vid=0;
  4452. $categoryList=$Lcategory->find(array('asArray'=>true));
  4453. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4454. $ap=0;
  4455. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4456. $Locate=0;$roleId=0;$button=0;
  4457. foreach ($receiptList as $key=>$value){
  4458. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4459. $receiptList[$key]['reviseDetail']=array();
  4460. if (!empty($value['reviseDetail']))
  4461. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4462. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4463. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4464. $receiptList[$key]['category']=$categoryDetil['title'];
  4465. //检测编辑状态
  4466. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4467. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4468. $verifyStaff=json_decode($value['verifyStaff'],true);
  4469. Doo::loadModel('role');
  4470. $role=new role();
  4471. //print_r($verifyList);
  4472. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4473. foreach ($verifyList as $k=>$v){
  4474. //init verifyStaff
  4475. if ($v[1]=='ROLE'){
  4476. if (!empty($verifyStaff)){
  4477. $endStaffArray=end($verifyStaff);
  4478. if ($v[0]==$endStaffArray['nextStaff']){
  4479. $roleId=$v[0];
  4480. }
  4481. }
  4482. $roleVerify=json_decode($v[3],true);
  4483. $roleKey=$k;$roleArray=array();
  4484. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4485. foreach ($roleVerify as $o=>$p){
  4486. $staffID=explode ('_',$p);
  4487. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4488. //print_r($staffID);
  4489. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4490. array_push($roleArray, $exp);
  4491. }
  4492. $roleArrayCopy[$v[0]]=$roleArray;
  4493. //$verifyList[$k]['roleArray']=$roleArray;
  4494. }
  4495. //print_r($roleArray);
  4496. $verifyList[$k]['date']="";
  4497. $verifyList[$k]['opinion']="";
  4498. $verifyList[$k]['status']="";
  4499. if (empty($verifyStaff)){
  4500. $verifyList[$k]['date']="";
  4501. $verifyList[$k]['opinion']="";
  4502. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4503. $verifyList[$k]['status']=4;
  4504. $button=4;$flag=false;
  4505. }
  4506. }else{
  4507. foreach ($verifyStaff as $m=>$u){
  4508. if ($v[0]==$m){
  4509. $verifyList[$k]['date']=$u['date'];
  4510. $verifyList[$k]['opinion']=$u['opinion'];
  4511. $verifyList[$k]['status']=$u['status'];
  4512. $flag=false;
  4513. break;
  4514. }
  4515. }
  4516. $endStaffArray=end($verifyStaff);
  4517. if (isset($endStaffArray['ROLE'])){
  4518. }else{
  4519. $endKey=key($verifyStaff);
  4520. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4521. $button=4;
  4522. $verifyList[$k]['status']=4;
  4523. }
  4524. }
  4525. }
  4526. }
  4527. $rolename['name']='';
  4528. if (!empty($roleId)){
  4529. Doo::loadModel('role');
  4530. $role=new role();
  4531. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4532. }
  4533. if (!empty($verifyStaff))
  4534. $endStaffArray=end($verifyStaff);
  4535. $KOP=false;
  4536. foreach ($roleArrayCopy as $P=>$A){
  4537. foreach ( $A as $MKI=>$AVL){
  4538. if (!empty($verifyStaff)){
  4539. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4540. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4541. $button=4;
  4542. $roleArrayCopy[$P][$MKI]['status']=4;
  4543. }
  4544. foreach ($verifyStaff as $m=>$u){
  4545. $AVLFK=$AVL[0].'_R';
  4546. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4547. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4548. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4549. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4550. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4551. break;
  4552. }
  4553. }
  4554. }else{
  4555. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4556. $button=4;
  4557. $roleArrayCopy[$P][$MKI]['status']=4;
  4558. }
  4559. }
  4560. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4561. $KOP=true;
  4562. }
  4563. }
  4564. foreach ($roleArrayCopy as $k=>$v){
  4565. foreach ($verifyList as $m=>$n){
  4566. if ($n[0]==$k){
  4567. array_splice($verifyList,$m,1,$v);
  4568. }
  4569. }
  4570. }
  4571. $receiptList[$key]['verifyList']=$verifyList;
  4572. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4573. $receiptList[$key]['button']=$button;
  4574. }
  4575. $mothHtml="";
  4576. for($i=1;$i<=12;$i++){
  4577. if($month==$i)
  4578. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4579. else
  4580. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4581. }
  4582. //获取审批日志
  4583. Doo::loadModel('receiptLog');
  4584. $receiptLog=new receiptLog();
  4585. $rlList=array();
  4586. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4587. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4588. if (!empty($rlInfo)){
  4589. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4590. }
  4591. $receiptList[0]['rlList']=$rlList;
  4592. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4593. $enclosurHtml='';
  4594. foreach ($enclosurList as $value){
  4595. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4596. }
  4597. $data['enclosurHtml']=$enclosurHtml;
  4598. $data['rolename']=$rolename['name'];
  4599. $data['datetij']=$tijdate['date'];
  4600. $data['mothHtml']=$mothHtml;
  4601. $data['receiptList']=$receiptList;
  4602. $data['receiptApprovalCount']=count($receiptList);
  4603. $data['year']=$year;
  4604. $data['categoryList']=$categoryList;
  4605. $data['staffList']=$staffList;
  4606. $data['cid']=$cid;
  4607. $data['sid']=$sid;
  4608. $data['status']=0;
  4609. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4610. $ap=4;
  4611. }else
  4612. $data['status']=$receiptList[0]['status'];
  4613. if ($receiptList[0]['status']==4){
  4614. $data['status']=5;
  4615. $ap=0;
  4616. }
  4617. $data['ap']=$ap;
  4618. $data['memu']="receipt";
  4619. $data['staff']=$this->staff;
  4620. $data['receiptMemu']='approval';
  4621. $data['verifyId']=$this->verifyId;
  4622. $data['executeId']=$this->executeId;
  4623. $this->render ( "/admin/saeaReportListReport", $data );
  4624. }
  4625. function approvalEdi(){
  4626. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4627. $status=isset($this->params['status'])?$this->params['status']:'';
  4628. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4629. $month=$this->get_args('month')?$this->get_args('month'):"";
  4630. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4631. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4632. if (empty($status))
  4633. $status=$this->get_args('status')?$this->get_args('status'):2;
  4634. $vidList=array();
  4635. $button=0;
  4636. Doo::loadModel('verify');
  4637. Doo::loadModel('receipt');
  4638. Doo::loadModel('staff');
  4639. $staff=new staff();
  4640. $receipt=new receipt();
  4641. $verify=new verify();
  4642. Doo::loadModel('L_category');
  4643. $Lcategory=new L_category();
  4644. Doo::loadModel('enclosur');
  4645. $enclosur=new enclosur();
  4646. //user verify ID
  4647. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4648. foreach ($verifyDetail as $key=>$value){
  4649. array_push($vidList, $value['vid']);
  4650. }
  4651. $vid=implode(",", $vidList);
  4652. if(empty($verifyDetail))
  4653. $vid=0;
  4654. $categoryList=$Lcategory->find(array('asArray'=>true));
  4655. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4656. $ap="";
  4657. if($status==4){
  4658. $ap=4;$status=2;
  4659. }
  4660. //get Receipt By verifyID status 2
  4661. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4662. $Locate=0;$roleId=0;
  4663. if($ap==4)
  4664. $status=4;
  4665. foreach ($receiptList as $key=>$value){
  4666. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4667. $receiptList[$key]['reviseDetail']=array();
  4668. if (!empty($value['reviseDetail']))
  4669. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4670. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4671. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4672. $receiptList[$key]['category']=$categoryDetil['title'];
  4673. //检测编辑状态
  4674. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4675. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4676. $verifyStaff=json_decode($value['verifyStaff'],true);
  4677. // print_r($verifyList);
  4678. //
  4679. // if (empty($verifyStaff)){
  4680. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4681. // $verifyList[0]['status']=4;$button=4;
  4682. // }
  4683. //
  4684. // }else{
  4685. //
  4686. // }
  4687. // die;
  4688. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4689. // echo array_search("green",$a);
  4690. //
  4691. Doo::loadModel('role');
  4692. $role=new role();
  4693. //print_r($verifyList);
  4694. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4695. foreach ($verifyList as $k=>$v){
  4696. //init verifyStaff
  4697. if ($v[1]=='ROLE'){
  4698. if (!empty($verifyStaff)){
  4699. $endStaffArray=end($verifyStaff);
  4700. if ($v[0]==$endStaffArray['nextStaff']){
  4701. $roleId=$v[0];
  4702. }
  4703. }
  4704. $roleVerify=json_decode($v[3],true);
  4705. $roleKey=$k;$roleArray=array();
  4706. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4707. foreach ($roleVerify as $o=>$p){
  4708. $staffID=explode ('_',$p);
  4709. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4710. //print_r($staffID);
  4711. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4712. array_push($roleArray, $exp);
  4713. }
  4714. $roleArrayCopy[$v[0]]=$roleArray;
  4715. //$verifyList[$k]['roleArray']=$roleArray;
  4716. }
  4717. //print_r($roleArray);
  4718. $verifyList[$k]['date']="";
  4719. $verifyList[$k]['opinion']="";
  4720. $verifyList[$k]['status']="";
  4721. if (empty($verifyStaff)){
  4722. $verifyList[$k]['date']="";
  4723. $verifyList[$k]['opinion']="";
  4724. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4725. $verifyList[$k]['status']=4;
  4726. $button=4;$flag=false;
  4727. }
  4728. }else{
  4729. foreach ($verifyStaff as $m=>$u){
  4730. if ($v[0]==$m){
  4731. $verifyList[$k]['date']=$u['date'];
  4732. $verifyList[$k]['opinion']=$u['opinion'];
  4733. $verifyList[$k]['status']=$u['status'];
  4734. $flag=false;
  4735. break;
  4736. }
  4737. }
  4738. $endStaffArray=end($verifyStaff);
  4739. if (isset($endStaffArray['ROLE'])){
  4740. }else{
  4741. $endKey=key($verifyStaff);
  4742. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4743. $button=4;
  4744. $verifyList[$k]['status']=4;
  4745. }
  4746. }
  4747. //print_r($endStaffArray);die;
  4748. // if (empty($verifyStaff)){
  4749. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4750. // $verifyList[$k]['status']=4;$button=4;
  4751. // }
  4752. //
  4753. // }else{
  4754. //
  4755. // }
  4756. // if($flag){//检测可编辑
  4757. // if($v[0]==$this->staff[0]['sid']){
  4758. // $verifyList[$k]['status']=4;$button=4;
  4759. // }
  4760. // }
  4761. }
  4762. }
  4763. $rolename['name']='';
  4764. if (!empty($roleId)){
  4765. Doo::loadModel('role');
  4766. $role=new role();
  4767. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4768. }
  4769. if (!empty($verifyStaff))
  4770. $endStaffArray=end($verifyStaff);
  4771. $KOP=false;
  4772. foreach ($roleArrayCopy as $P=>$A){
  4773. foreach ( $A as $MKI=>$AVL){
  4774. if (!empty($verifyStaff)){
  4775. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4776. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4777. $button=4;
  4778. $roleArrayCopy[$P][$MKI]['status']=4;
  4779. }
  4780. foreach ($verifyStaff as $m=>$u){
  4781. $AVLFK=$AVL[0].'_R';
  4782. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4783. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4784. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4785. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4786. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4787. break;
  4788. }
  4789. }
  4790. }else{
  4791. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4792. $button=4;
  4793. $roleArrayCopy[$P][$MKI]['status']=4;
  4794. }
  4795. }
  4796. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4797. $KOP=true;
  4798. }
  4799. }
  4800. // print_r($roleArrayCopy);
  4801. // echo $roleKey;
  4802. foreach ($roleArrayCopy as $k=>$v){
  4803. foreach ($verifyList as $m=>$n){
  4804. if ($n[0]==$k){
  4805. array_splice($verifyList,$m,1,$v);
  4806. }
  4807. }
  4808. }
  4809. // if ($KOP)
  4810. // array_splice($verifyList,$roleKey,1,$roleArray);
  4811. //print_r($verifyList);
  4812. $receiptList[$key]['verifyList']=$verifyList;
  4813. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4814. $receiptList[$key]['button']=$button;
  4815. }
  4816. //$data['verifyDetail']=$verifyDetail;
  4817. $mothHtml="";
  4818. for($i=1;$i<=12;$i++){
  4819. if($month==$i)
  4820. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4821. else
  4822. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4823. }
  4824. //获取审批日志
  4825. Doo::loadModel('receiptLog');
  4826. $receiptLog=new receiptLog();
  4827. $rlList=array();
  4828. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4829. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4830. if (!empty($rlInfo)){
  4831. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4832. }
  4833. $receiptList[0]['rlList']=$rlList;
  4834. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4835. $enclosurHtml='';
  4836. foreach ($enclosurList as $value){
  4837. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4838. }
  4839. $data['enclosurHtml']=$enclosurHtml;
  4840. $data['rolename']=$rolename['name'];
  4841. $data['datetij']=$tijdate['date'];
  4842. $data['mothHtml']=$mothHtml;
  4843. $data['receiptList']=$receiptList;
  4844. $data['receiptApprovalCount']=count($receiptList);
  4845. $data['status']=$status;
  4846. $data['year']=$year;
  4847. $data['categoryList']=$categoryList;
  4848. $data['staffList']=$staffList;
  4849. $data['cid']=$cid;
  4850. $data['sid']=$sid;
  4851. $data['ap']=$ap;
  4852. $data['memu']="receipt";
  4853. $data['staff']=$this->staff;
  4854. $data['receiptMemu']='approval';
  4855. $data['verifyId']=$this->verifyId;
  4856. $data['executeId']=$this->executeId;
  4857. $this->render ( "/admin/saeaReportListReport", $data );
  4858. }
  4859. function remittance(){
  4860. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4861. $month=$this->get_args('month')?$this->get_args('month'):"";
  4862. Doo::loadModel('receipt');
  4863. $receipt=new receipt();
  4864. Doo::loadModel('staff');
  4865. $staff=new staff();
  4866. $dateCondition=" and Year(pastDate) =".$year;
  4867. if(!empty($month))
  4868. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4869. //get Receipt By verifyID status 1
  4870. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4871. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4872. $dataList=array();
  4873. foreach ($dateList as $d=>$a){
  4874. $dataList[$a['pastDate']]=array();$daySum=0;
  4875. foreach ($receiptList as $key=>$value){
  4876. if($a['pastDate']==$value['pastDate']){
  4877. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4878. $list=array();$html="";
  4879. foreach ($oderList as $v){
  4880. array_push($list, $v['receiptOrder']);
  4881. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4882. }
  4883. $receiptList[$key]['receiptOrder']=$html;
  4884. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4885. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4886. $receiptList[$key]['username']=$sinfo['username'];
  4887. $daySum+=$value['sum'];
  4888. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4889. }
  4890. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4891. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4892. }
  4893. }
  4894. //print_r($dataList);
  4895. $data['dataList']=$dataList;
  4896. $mothHtml="";
  4897. for($i=1;$i<=12;$i++){
  4898. if($month==$i)
  4899. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4900. else
  4901. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4902. }
  4903. $data['year']=$year;
  4904. $data['mothHtml']=$mothHtml;
  4905. $data['memu']="receipt";
  4906. $data['staff']=$this->staff;
  4907. $data['receiptMemu']='approval';
  4908. $data['verifyId']=$this->verifyId;
  4909. $data['executeId']=$this->executeId;
  4910. $this->render ( "/admin/saeaReportListPay", $data );
  4911. }
  4912. function revocationAdjustment(){
  4913. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  4914. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  4915. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4916. //echo $price;die;
  4917. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  4918. Doo::loadModel('receipt');
  4919. $receipt=new receipt();
  4920. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4921. if (empty($receiptDetail['reviseDetail']))
  4922. return "/approval";
  4923. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  4924. $RD=array();
  4925. foreach ($reviseDetail as $key=>$value){
  4926. if ($value['price']==$price&&$value['sid']==$sid)
  4927. continue;
  4928. array_push($RD, $value);
  4929. }
  4930. $reviseDetailString=json_encode($RD);
  4931. $receipt->reviseDetail=$reviseDetailString;
  4932. $receipt->sum=$receiptDetail['sum']-$price;
  4933. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  4934. $receipt->update(array('where'=>'rid='.$rid));
  4935. }
  4936. //approvalEdi/37
  4937. return "/approvalEdi/".$rid;
  4938. }
  4939. function updateApprovalReceipt(){
  4940. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  4941. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  4942. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4943. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  4944. if(!empty($rid)){
  4945. Doo::loadModel("verify");
  4946. $verify=new verify();
  4947. Doo::loadModel("receiptDetail");
  4948. $receiptDetailObj=new receiptDetail();
  4949. Doo::loadModel("itemStatistics");
  4950. Doo::loadModel("statistics");
  4951. $statistics=new statistics();
  4952. $itemStatistics=new itemStatistics();
  4953. Doo::loadModel("receipt");
  4954. $receipt=new receipt();
  4955. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  4956. if (empty($receiptDetail))
  4957. return "/approval";
  4958. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  4959. $verifyString=$verifyDetail['staff'];
  4960. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4961. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  4962. if(empty($opinion)){
  4963. if ($status==3)
  4964. $opinion="终止";
  4965. else
  4966. $opinion="同意支付";
  4967. }
  4968. $nowStaff=0;$nowStaffList=array();
  4969. if(empty($verifyStaff)){
  4970. //还需加入是否已经进入角色审批
  4971. if ($verifyDetail[0][1]=='ROLE'){
  4972. //print_r($verifyDetail);echo "ddd";
  4973. $vStaffString=json_decode($verifyDetail[0][3]);
  4974. foreach ($vStaffString as $key=>$value){
  4975. $staffK=explode("_", $value);
  4976. if ($staffK[0]!=$this->staff[0]['sid'])
  4977. array_push($nowStaffList, $staffK[0]);
  4978. }
  4979. //print_r($verifyDetail);
  4980. //die;
  4981. $nowStaff=implode(',', $nowStaffList);
  4982. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  4983. }else{
  4984. if ($verifyDetail[1][1]=='ROLE'){
  4985. $vStaffString=json_decode($verifyDetail[1][3]);
  4986. //echo "dd";
  4987. foreach ($vStaffString as $key=>$value){
  4988. $staffK=explode("_", $value);
  4989. array_push($nowStaffList, $staffK[0]);
  4990. }
  4991. $nowStaff=implode(',', $nowStaffList);
  4992. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  4993. }else{
  4994. $nowStaff=$verifyDetail[1][0];
  4995. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  4996. }
  4997. }
  4998. if($status==3)
  4999. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5000. $vStaffString=json_encode($verifyStaff);
  5001. $receipt->nowStaff=$nowStaff;
  5002. $receipt->verifyStaff=$vStaffString;
  5003. }else{
  5004. $VS=end($verifyStaff);
  5005. //非角色审批
  5006. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5007. $nextStaff=0;$roleSTF=false;
  5008. foreach ($verifyDetail as $key=>$value){
  5009. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5010. if (isset($verifyDetail[$key+1])){
  5011. $nextStaff=$verifyDetail[$key+1][0];
  5012. if ($verifyDetail[$key+1][1]=='ROLE')
  5013. $roleSTF=true;
  5014. }
  5015. break;
  5016. }
  5017. }
  5018. if (!$roleSTF){
  5019. $nowStaff=$nextStaff;
  5020. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5021. }else{
  5022. //获取角色下的所有用户ID
  5023. $nowStaffList=array();
  5024. foreach ($verifyDetail as $vfk){
  5025. if ($vfk[1]=='ROLE'){
  5026. $vStaffString=json_decode($vfk[3]);
  5027. foreach ($vStaffString as $key=>$value){
  5028. $staffK=explode("_", $value);
  5029. array_push($nowStaffList, $staffK[0]);
  5030. }
  5031. }
  5032. }
  5033. $nowStaff=implode(',', $nowStaffList);
  5034. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5035. }
  5036. if($status==3){
  5037. $verifyStaff['final']=$status;
  5038. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5039. }
  5040. $vStaffString=json_encode($verifyStaff);
  5041. $receipt->nowStaff=$nowStaff;
  5042. $receipt->verifyStaff=$vStaffString;
  5043. }
  5044. //角色审批
  5045. if (isset($VS['ROLE'])){
  5046. //找出角色人 当前审批角色组
  5047. $verifyJSStaff=array();$nowStaffList2=array();
  5048. foreach ($verifyDetail as $key=>$value){
  5049. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5050. $verifyJSStaff=json_decode($value[3]);
  5051. foreach ($verifyJSStaff as $m){
  5052. $staffK=explode("_", $m);
  5053. array_push($nowStaffList2, $staffK[0]);
  5054. }
  5055. // print_r($nowStaffList2);
  5056. }
  5057. }
  5058. $RoleVerifyStaff=array();
  5059. foreach ($verifyStaff as $key=>$value){
  5060. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5061. foreach ($nowStaffList2 as $m) {
  5062. if ($key==$m."_R")
  5063. $RoleVerifyStaff[$key]=$value;
  5064. }
  5065. }
  5066. }
  5067. // print_r($verifyStaff);
  5068. // print_r($nowStaffList2);
  5069. // print_r($RoleVerifyStaff);
  5070. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5071. //print_r($verifyJSStaff);
  5072. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5073. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5074. //下一个审批人ID
  5075. $nextStaff=0;$falg=false;
  5076. foreach ($verifyDetail as $key=>$value){
  5077. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5078. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5079. $falg=true;
  5080. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5081. foreach ($vStaffString as $v){
  5082. $staffK=explode("_", $v);
  5083. array_push($nowStaffList, $staffK[0]);
  5084. }
  5085. $nowStaff=implode(',', $nowStaffList);
  5086. $nextStaff=$verifyDetail[$key+1][0];
  5087. }elseif(isset($verifyDetail[$key+1])){
  5088. $nextStaff=$verifyDetail[$key+1][0];
  5089. $nowStaff=$nextStaff;
  5090. }else
  5091. $nowStaff='';
  5092. break;
  5093. }
  5094. }
  5095. if ($falg)
  5096. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5097. else
  5098. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5099. // print_r($verifyStaff);
  5100. // echo $nowStaff;die;
  5101. }else{ //进入下一个角色或者审批人
  5102. /*
  5103. */
  5104. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5105. //
  5106. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5107. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5108. // print_r($verifyStaff);
  5109. // die;
  5110. }
  5111. if($status==3){
  5112. $verifyStaff['final']=$status;
  5113. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5114. }
  5115. $vStaffString=json_encode($verifyStaff);
  5116. $receipt->verifyStaff=$vStaffString;
  5117. $receipt->nowStaff=$nowStaff;
  5118. //die;
  5119. //}
  5120. // print_r($verifyStaff);
  5121. // die;
  5122. }
  5123. //print_r($verifyStaff);die;
  5124. }
  5125. //print_r($verifyDetail);
  5126. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5127. foreach ($verifyDetail as $k=>$v){
  5128. if ($v[1]=='ROLE'){
  5129. $roleId=$v[0];
  5130. $roleVerify=json_decode($v[3],true);
  5131. $roleKey=$k;$roleArray=array();
  5132. foreach ($roleVerify as $o=>$p){
  5133. $staffID=explode ('_',$p);
  5134. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5135. array_push($roleArray, $exp);
  5136. }
  5137. $verifyDetailCopy[$v[0]]=$roleArray;
  5138. }
  5139. }
  5140. //print_r($verifyDetail);
  5141. foreach ($verifyDetailCopy as $k=>$v){
  5142. foreach ($verifyDetail as $m=>$n){
  5143. if ($n[0]==$k){
  5144. array_splice($verifyDetail,$m,1,$v);
  5145. }
  5146. }
  5147. }
  5148. // die;
  5149. // if (!empty($roleArray))
  5150. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5151. // echo $roleId;
  5152. // print_r($verifyStaff);
  5153. // print_r($verifyDetail);
  5154. // die;
  5155. //审批日志
  5156. if (!isset($verifyStaff['final'])){
  5157. Doo::loadModel("receiptLog");
  5158. $receiptLog=new receiptLog();
  5159. if (!empty($roleId)){
  5160. Doo::loadModel("role");
  5161. $role=new role();
  5162. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5163. $receiptLog->rolename=$roleInfo['name'];
  5164. }
  5165. $receiptLog->username=$this->staff[0]['username'];
  5166. $receiptLog->uid=$this->staff[0]['sid'];
  5167. $receiptLog->date=date("Y-m-d");
  5168. $receiptLog->opinion=$opinion;
  5169. $receiptLog->img=$this->staff[0]['avatar'];
  5170. $receiptLog->status=1;
  5171. $receiptLog->rid=$rid;
  5172. $receiptLog->insert();
  5173. }
  5174. if (isset($verifyStaff['final'])){//rDetail
  5175. $receipt->verifyBreakup=$verifyString;
  5176. $receipt->status=3;
  5177. $receiptDetailObj->status=3;
  5178. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5179. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5180. $receipt->status=1;$reviseSum=0;
  5181. $receipt->verifyBreakup=$verifyString;
  5182. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5183. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5184. foreach ($reviseDetail as $key=>$value){
  5185. $receiptDetailObj=new receiptDetail();
  5186. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5187. $receiptDetailObj->item=$value['description'];
  5188. $receiptDetailObj->itemCategory="报销金额调整";
  5189. $receiptDetailObj->price=$value['price'];
  5190. $receiptDetailObj->date=$receiptDetail['date'];
  5191. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5192. $receiptDetailObj->rid=$rid;
  5193. $receiptDetailObj->status=1;
  5194. $receiptDetailObj->insert();
  5195. $reviseSum+=$value['price'];
  5196. }
  5197. $itemStatistics=new itemStatistics();
  5198. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5199. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5200. $itemStatistics->price=$reviseSum;
  5201. $itemStatistics->itemCategory="报销金额调整";
  5202. $itemStatistics->date=$receiptDetail['date'];
  5203. $itemStatistics->insert();
  5204. }
  5205. $receiptDetailObj=new receiptDetail();
  5206. $receiptDetailObj->status=1;
  5207. $receiptDetailObj->pastDate=date("Y-m-d");
  5208. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5209. $dateArray=explode("-", $receiptDetail['date']);
  5210. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5211. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5212. if(empty($stat)){
  5213. $statistics->date=$receiptDetail['date'];
  5214. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5215. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5216. $statistics->agPrice=$receiptDetail['sum'];
  5217. $statistics->rePrice=$reviseSum;
  5218. $statistics->insert();
  5219. }else{
  5220. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5221. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5222. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5223. }
  5224. $dateArray=explode("-", $receiptDetail['date']);
  5225. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5226. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5227. foreach ($accountItem['cSum'] as $key=>$value){
  5228. if($key=="agencySum"){
  5229. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5230. if(empty($iStatistics)){
  5231. $itemStatistics->cid=$receiptDetail['cid'];;
  5232. $itemStatistics->staff=$receiptDetail['staff'];
  5233. $itemStatistics->price=$value;
  5234. $itemStatistics->itemCategory=$this->AGENCY;
  5235. $itemStatistics->date=$receiptDetail['date'];
  5236. $itemStatistics->insert();
  5237. }else{
  5238. if (!empty($value)){
  5239. $itemStatistics->price=$value+$iStatistics['price'];
  5240. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5241. }
  5242. }
  5243. }elseif($key=="travelSum"){
  5244. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5245. if(empty($iStatistics)){
  5246. $itemStatistics->cid=$receiptDetail['cid'];
  5247. $itemStatistics->staff=$receiptDetail['staff'];
  5248. $itemStatistics->price=$value;
  5249. $itemStatistics->itemCategory=$this->TRAVEL;
  5250. $itemStatistics->date=$receiptDetail['date'];
  5251. $itemStatistics->insert();
  5252. }else{
  5253. if (!empty($value)){
  5254. $itemStatistics->price=$value+$iStatistics['price'];
  5255. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5256. }
  5257. }
  5258. }elseif($key=="trainSum"){
  5259. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5260. if(empty($iStatistics)){
  5261. $itemStatistics->cid=$receiptDetail['cid'];
  5262. $itemStatistics->staff=$receiptDetail['staff'];
  5263. $itemStatistics->price=$value;
  5264. $itemStatistics->itemCategory=$this->TRAIN;
  5265. $itemStatistics->date=$receiptDetail['date'];
  5266. $itemStatistics->insert();
  5267. }else{
  5268. if (!empty($value)){
  5269. $itemStatistics->price=$value+$iStatistics['price'];
  5270. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5271. }
  5272. }
  5273. }elseif($key=="otherSum"){
  5274. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5275. if(empty($iStatistics)){
  5276. $itemStatistics->cid=$receiptDetail['cid'];
  5277. $itemStatistics->staff=$receiptDetail['staff'];
  5278. $itemStatistics->price=$value;
  5279. $itemStatistics->itemCategory=$this->OTHER;
  5280. $itemStatistics->date=$receiptDetail['date'];
  5281. $itemStatistics->insert();
  5282. }else{
  5283. if (!empty($value)){
  5284. $itemStatistics->price=$value+$iStatistics['price'];
  5285. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5286. }
  5287. }
  5288. }
  5289. }
  5290. $receipt->pastDate=date("Y-m-d");
  5291. }
  5292. $receipt->update(array('where'=>' rid = '.$rid));
  5293. return "/approvalExpenses/2";
  5294. }
  5295. }
  5296. function expensesRetreats(){
  5297. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5298. if (!empty($rid)){
  5299. //操作记录
  5300. Doo::loadModel("receipt");
  5301. $receipt=new receipt();
  5302. Doo::loadModel("receiptLog");
  5303. $receiptLog=new receiptLog();
  5304. Doo::loadModel("verify");
  5305. $verify=new verify();
  5306. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5307. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5308. $jd=json_decode($vr['staff']);$roleId=0;
  5309. foreach ($jd as $key=>$value){
  5310. if ($value[1]=='ROLE'){
  5311. $pos = strpos($value[3], $this->staff[0]['sid']);
  5312. if ($pos !== false) {
  5313. $roleId=$value[0];
  5314. }
  5315. }
  5316. }
  5317. //审批日志
  5318. //echo $roleId;die;
  5319. if (!empty($roleId)){
  5320. Doo::loadModel("role");
  5321. $role=new role();
  5322. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5323. $receiptLog->rolename=$roleInfo['name'];
  5324. }
  5325. $receiptLog->username=$this->staff[0]['username'];
  5326. $receiptLog->uid=$this->staff[0]['sid'];
  5327. $receiptLog->date=date("Y-m-d");
  5328. $receiptLog->opinion='撤回';
  5329. $receiptLog->img=$this->staff[0]['avatar'];
  5330. $receiptLog->status=4;
  5331. $receiptLog->rid=$rid;
  5332. $receiptLog->insert();
  5333. $receipt->status=4;
  5334. $receipt->update(array('where'=>'rid='.$rid));
  5335. }
  5336. //echo "ddd";
  5337. return '/approvalExpenses';
  5338. }
  5339. function updateCheReceipt(){
  5340. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5341. if (!empty($rid)){
  5342. //操作记录
  5343. Doo::loadModel("receipt");
  5344. $receipt=new receipt();
  5345. Doo::loadModel("receiptLog");
  5346. $receiptLog=new receiptLog();
  5347. Doo::loadModel("verify");
  5348. $verify=new verify();
  5349. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5350. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5351. $jd=json_decode($vr['staff']);$roleId=0;
  5352. foreach ($jd as $key=>$value){
  5353. if ($value[1]=='ROLE'){
  5354. $pos = strpos($value[3], $this->staff[0]['sid']);
  5355. if ($pos !== false) {
  5356. $roleId=$value[0];
  5357. }
  5358. }
  5359. }
  5360. //审批日志
  5361. //echo $roleId;die;
  5362. if (!empty($roleId)){
  5363. Doo::loadModel("role");
  5364. $role=new role();
  5365. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5366. $receiptLog->rolename=$roleInfo['name'];
  5367. }
  5368. $receiptLog->username=$this->staff[0]['username'];
  5369. $receiptLog->uid=$this->staff[0]['sid'];
  5370. $receiptLog->date=date("Y-m-d");
  5371. $receiptLog->opinion='撤回';
  5372. $receiptLog->img=$this->staff[0]['avatar'];
  5373. $receiptLog->status=4;
  5374. $receiptLog->rid=$rid;
  5375. $receiptLog->insert();
  5376. $receipt->status=4;
  5377. $receipt->update(array('where'=>'rid='.$rid));
  5378. }
  5379. //echo "ddd";
  5380. return '/saeaBorad';
  5381. }
  5382. function revisePrice(){
  5383. $description=$this->get_args('description')?$this->get_args('description'):"";
  5384. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5385. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5386. //echo $price;die;
  5387. if (!empty($rid)){
  5388. Doo::loadModel("receipt");
  5389. $receipt=new receipt();
  5390. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5391. if (empty($receiptDetail))
  5392. return "/approval";
  5393. $reviseDetail=array();
  5394. if (empty($receiptDetail['reviseDetail'])){
  5395. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5396. $reviseDetailString=json_encode($reviseDetail);
  5397. $receipt->reviseDetail=$reviseDetailString;
  5398. $receipt->revisePrice=$price;
  5399. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5400. }else{
  5401. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5402. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5403. $reviseDetailString=json_encode($reviseDetail);
  5404. $receipt->reviseDetail=$reviseDetailString;
  5405. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5406. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5407. }
  5408. $receipt->update(array('where'=>'rid='.$rid));
  5409. }
  5410. return '/approvalEdi/'.$rid;
  5411. }
  5412. function personalCollect(){
  5413. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5414. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5415. $this->showCache($path);
  5416. Doo::loadModel("receiptDetail");
  5417. Doo::loadModel("itemStatistics");
  5418. Doo::loadModel('statistics');
  5419. $statistics=new statistics();
  5420. $itemStatistics=new itemStatistics();
  5421. $receiptDetail=new receiptDetail();
  5422. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5423. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5424. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5425. //create collect html
  5426. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5427. $adjustment=array();
  5428. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5429. array_push($collectArray['日常相关费用'], $collectHtml);
  5430. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5431. array_push($collectArray['差旅相关费用'], $collectHtml);
  5432. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5433. array_push($collectArray['培训班费用'], $collectHtml);
  5434. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5435. array_push($collectArray['其他'], $collectHtml);
  5436. $data['collectArray']=$collectArray;
  5437. //statistics html
  5438. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5439. if(empty($stList))
  5440. $stList=array('rePrice'=>0,'agPrice'=>0);
  5441. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5442. //Adjustment price html
  5443. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5444. array_push($adjustment, $collectHtml);
  5445. $data['adjustment']=$adjustment;
  5446. //total price html
  5447. $collectHtml="";$total=0;
  5448. for ($i=1;$i<=12;$i++){
  5449. $sumPrice=0;
  5450. foreach ($receiptCollectList as $key=>$value){
  5451. if($value['month']==$i){
  5452. $sumPrice+=$value['price'];
  5453. }
  5454. }
  5455. if ($sumPrice==0)
  5456. $collectHtml.='<td class="taR">-</td>';
  5457. else
  5458. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5459. $total+=$sumPrice;
  5460. }
  5461. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5462. $data['totalPrice']=$collectHtml;
  5463. $data['year']=$year;
  5464. $data['totalYear']=$total;
  5465. $data['memu']="receipt";
  5466. $data['staff']=$this->staff;
  5467. $data['receiptMemu']='personalCollect';
  5468. $data['verifyId']=$this->verifyId;
  5469. $data['executeId']=$this->executeId;
  5470. //year staff status 2,4
  5471. if($year<date("Y")){
  5472. Doo::loadModel('receipt');
  5473. $receipt=new receipt();
  5474. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5475. if(empty($receiptList)){
  5476. ob_start();
  5477. $this->render ( "/admin/saea_slist_collect", $data );
  5478. $this->cacheFile($path);die;
  5479. }
  5480. }
  5481. $this->render ( "/admin/saea_slist_collect", $data );
  5482. }
  5483. function personalCollectDetail(){
  5484. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5485. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5486. $this->showCache($path);
  5487. Doo::loadModel("receiptDetail");
  5488. Doo::loadModel("itemStatistics");
  5489. Doo::loadModel('statistics');
  5490. Doo::loadModel('accountItem');
  5491. $accountItem=new accountItem();
  5492. $statistics=new statistics();
  5493. $itemStatistics=new itemStatistics();
  5494. $receiptDetail=new receiptDetail();
  5495. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5496. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5497. $accountList=$accountItem->find(array('asArray'=>true));
  5498. //create CollectDetail HTML
  5499. $collectHtml=array();
  5500. foreach ($accountList as $key=>$value){
  5501. $html="";$asum=0;
  5502. for ($i=1;$i<=12;$i++){
  5503. $falg=true;
  5504. foreach ($receiptCollectList as $v) {
  5505. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5506. $asum+=$v['price'];
  5507. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5508. }
  5509. }
  5510. if($falg)
  5511. $html.='<td class="taR">-</td>';
  5512. }
  5513. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5514. $collectHtml[$value['category']][$value['name']]=$html;
  5515. }
  5516. $data['collectHtml']=$collectHtml;
  5517. //create Adjustment price html
  5518. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5519. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5520. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5521. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5522. array_push($collectArray['日常相关费用'], $collectHtml);
  5523. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5524. array_push($collectArray['差旅相关费用'], $collectHtml);
  5525. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5526. array_push($collectArray['培训班费用'], $collectHtml);
  5527. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5528. array_push($collectArray['其他'], $collectHtml);
  5529. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5530. array_push($adjustment, $collectHtml);
  5531. //total price html
  5532. $collectHtml="";$total=0;
  5533. for ($i=1;$i<=12;$i++){
  5534. $sumPrice=0;
  5535. foreach ($receiptCollectList as $key=>$value){
  5536. if($value['month']==$i){
  5537. $sumPrice+=$value['price'];
  5538. }
  5539. }
  5540. if ($sumPrice==0)
  5541. $collectHtml.='<td class="taR">-</td>';
  5542. else
  5543. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5544. $total+=$sumPrice;
  5545. }
  5546. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5547. //statistics html
  5548. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5549. if(empty($stList))
  5550. $stList=array('rePrice'=>0,'agPrice'=>0);
  5551. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5552. $data['collectArray']=$collectArray;
  5553. $data['adjustment']=$adjustment;
  5554. $data['totalPrice']=$collectHtml;
  5555. $data['totalYear']=$total;
  5556. $data['year']=$year;
  5557. $data['memu']="receipt";
  5558. $data['staff']=$this->staff;
  5559. $data['receiptMemu']='personalCollect';
  5560. $data['verifyId']=$this->verifyId;
  5561. $data['executeId']=$this->executeId;
  5562. //year staff status 2,4
  5563. if($year<date("Y")){
  5564. Doo::loadModel('receipt');
  5565. $receipt=new receipt();
  5566. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5567. if(empty($receiptList)){
  5568. ob_start();
  5569. $this->render ( "/admin/saeaCollectArticles", $data );
  5570. $this->cacheFile($path);die;
  5571. }
  5572. }
  5573. $this->render ( "/admin/saeaCollectArticles", $data );
  5574. }
  5575. function companyCategoryCollect(){
  5576. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5577. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5578. $this->showCache($path);
  5579. Doo::loadModel('L_category');
  5580. Doo::loadModel('itemStatistics');
  5581. Doo::loadModel('statistics');
  5582. $statistics=new statistics();
  5583. $Lcategory=new L_category();
  5584. $itemStatistics=new itemStatistics();
  5585. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5586. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5587. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5588. //ceatre companyCollectHtml
  5589. foreach ($LcategoryList as $value){
  5590. $html="";$asum=0;
  5591. for ($i=1;$i<=12;$i++){
  5592. $falg=true;
  5593. foreach ($itemStatisticsList as $v){
  5594. if($value['cid']==$v['cid']&&$i==$v['month']){
  5595. $asum+=$v['price'];
  5596. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5597. }
  5598. }
  5599. if($falg)
  5600. $html.='<td class="taR">-</td>';
  5601. }
  5602. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5603. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5604. }
  5605. $data['companyHtml']=$collectHtml;
  5606. //total price html
  5607. $collectHtml="";$total=0;
  5608. for ($i=1;$i<=12;$i++){
  5609. $sumPrice=0;
  5610. foreach ($itemStatisticsList as $key=>$value){
  5611. if($value['month']==$i){
  5612. $sumPrice+=$value['price'];
  5613. }
  5614. }
  5615. if ($sumPrice==0)
  5616. $collectHtml.='<td class="taR">-</td>';
  5617. else
  5618. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5619. $total+=$sumPrice;
  5620. }
  5621. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5622. $data['companyTotalHtml']=$collectHtml;
  5623. $data['total']=$total;
  5624. //statistics html
  5625. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5626. if(empty($stList))
  5627. $stList=array('rePrice'=>0,'agPrice'=>0);
  5628. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5629. $data['year']=$year;
  5630. $data['memu']="receipt";
  5631. $data['staff']=$this->staff;
  5632. $data['receiptMemu']='companyCategoryCollect';
  5633. $data['verifyId']=$this->verifyId;
  5634. $data['executeId']=$this->executeId;
  5635. //year staff status 2,4
  5636. if($year<date("Y")){
  5637. Doo::loadModel('receipt');
  5638. $receipt=new receipt();
  5639. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5640. if(empty($receiptList)){
  5641. ob_start();
  5642. $this->render ( "/admin/saeaCompanyCollect", $data );
  5643. $this->cacheFile($path);die;
  5644. }
  5645. }
  5646. $this->render ( "/admin/saeaCompanyCollect", $data );
  5647. }
  5648. function categoryCollectDetail(){
  5649. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5650. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5651. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5652. $this->showCache($path);
  5653. Doo::loadModel('statistics');
  5654. $statistics=new statistics();
  5655. Doo::loadModel("receiptDetail");
  5656. $receiptDetail=new receiptDetail();
  5657. Doo::loadModel('L_category');
  5658. $Lcategory=new L_category();
  5659. Doo::loadModel('accountItem');
  5660. $accountItem=new accountItem();
  5661. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5662. if ($cid==0){
  5663. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5664. if ($cid==0)
  5665. $cid=$LcategoryList[0]['cid'];
  5666. }
  5667. $data['LcategoryList']=$LcategoryList;
  5668. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5669. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5670. $accountList=$accountItem->find(array('asArray'=>true));
  5671. //create CollectDetail HTML
  5672. $collectHtml=array();
  5673. foreach ($accountList as $key=>$value){
  5674. $html="";$asum=0;
  5675. for ($i=1;$i<=12;$i++){
  5676. $falg=true;
  5677. foreach ($receiptCollectList as $v) {
  5678. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5679. $asum+=$v['price'];
  5680. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5681. }
  5682. }
  5683. if($falg)
  5684. $html.='<td class="taR">-</td>';
  5685. }
  5686. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5687. $collectHtml[$value['category']][$value['name']]=$html;
  5688. }
  5689. $data['collectHtml']=$collectHtml;
  5690. //create Adjustment price html
  5691. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5692. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5693. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5694. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5695. array_push($collectArray['日常相关费用'], $collectHtml);
  5696. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5697. array_push($collectArray['差旅相关费用'], $collectHtml);
  5698. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5699. array_push($collectArray['培训班费用'], $collectHtml);
  5700. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5701. array_push($collectArray['其他'], $collectHtml);
  5702. $data['collectArray']=$collectArray;
  5703. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5704. array_push($adjustment, $collectHtml);
  5705. $data['adjustment']=$adjustment;
  5706. //total price html
  5707. $collectHtml="";$total=0;
  5708. for ($i=1;$i<=12;$i++){
  5709. $sumPrice=0;
  5710. foreach ($receiptCollectList as $key=>$value){
  5711. if($value['month']==$i){
  5712. $sumPrice+=$value['price'];
  5713. }
  5714. }
  5715. if ($sumPrice==0)
  5716. $collectHtml.='<td class="taR">-</td>';
  5717. else
  5718. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5719. $total+=$sumPrice;
  5720. }
  5721. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5722. //statistics html
  5723. $stList=$statistics->statisticsByCid($year,$cid);
  5724. if(empty($stList))
  5725. $stList=array('rePrice'=>0,'agPrice'=>0);
  5726. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5727. $data['totalYear']=$total;
  5728. $data['year']=$year;
  5729. $data['cid']=$cid;
  5730. $data['memu']="receipt";
  5731. $data['staff']=$this->staff;
  5732. $data['receiptMemu']='companyCategoryCollect';
  5733. $data['verifyId']=$this->verifyId;
  5734. $data['executeId']=$this->executeId;
  5735. //year staff status 2,4
  5736. if($year<date("Y")){
  5737. Doo::loadModel('receipt');
  5738. $receipt=new receipt();
  5739. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5740. if(empty($receiptList)){
  5741. ob_start();
  5742. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5743. $this->cacheFile($path);die;
  5744. }
  5745. }
  5746. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5747. }
  5748. function staffCollect(){
  5749. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5750. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5751. //$this->showCache($path);
  5752. Doo::loadModel('statistics');
  5753. $statistics=new statistics();
  5754. Doo::loadModel("receiptDetail");
  5755. $receiptDetail=new receiptDetail();
  5756. Doo::loadModel('L_category');
  5757. $Lcategory=new L_category();
  5758. Doo::loadModel('accountItem');
  5759. $accountItem=new accountItem();
  5760. Doo::loadModel('staff');
  5761. $staff=new staff();
  5762. Doo::loadModel('itemStatistics');
  5763. $itemStatistics=new itemStatistics();
  5764. /*
  5765. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5766. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5767. if(empty($stList))
  5768. $stList=array('rePrice'=>0,'agPrice'=>0);
  5769. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5770. */
  5771. //statistics html
  5772. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5773. if(empty($stList))
  5774. $stList=array('rePrice'=>0,'agPrice'=>0);
  5775. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5776. //---
  5777. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5778. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5779. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5780. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5781. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5782. //print_r($itemStatisticsList);die;
  5783. //ceatre companyCollectHtml
  5784. foreach ($categoryList as $vlu){
  5785. $count=$vlu['count']+1;
  5786. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5787. $m1=0;$m2=0;$m3=0;$m4=0;$m5=0;$m6=0;$m7=0;$m8=0;$m9=0;$m10=0;$m11=0;$m12=0;$m13=0;
  5788. foreach ($staffList as $value){
  5789. if ($vlu['cid']==$value['cid']){
  5790. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5791. $asum=0;
  5792. for ($i=1;$i<=12;$i++){
  5793. $falg=true;
  5794. foreach ($itemStatisticsList as $v){
  5795. if($value['sid']==$v['staff']&&$i==$v['month']){
  5796. if ($v['month']==1)
  5797. $m1+=$v['price'];
  5798. if ($v['month']==2)
  5799. $m2+=$v['price'];
  5800. if ($v['month']==3)
  5801. $m3+=$v['price'];
  5802. if ($v['month']==4)
  5803. $m4+=$v['price'];
  5804. if ($v['month']==5)
  5805. $m5+=$v['price'];
  5806. if ($v['month']==6)
  5807. $m6+=$v['price'];
  5808. if ($v['month']==7)
  5809. $m7+=$v['price'];
  5810. if ($v['month']==8)
  5811. $m8+=$v['price'];
  5812. if ($v['month']==9)
  5813. $m9+=$v['price'];
  5814. if ($v['month']==10)
  5815. $m10+=$v['price'];
  5816. if ($v['month']==11)
  5817. $m11+=$v['price'];
  5818. if ($v['month']==12)
  5819. $m12+=$v['price'];
  5820. $asum+=$v['price'];
  5821. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5822. }
  5823. }
  5824. if($falg)
  5825. $html.='<td class="taR">-</td>';
  5826. }
  5827. $m13+=$asum;
  5828. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5829. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5830. $html="";
  5831. }
  5832. }
  5833. $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>
  5834. <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>
  5835. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5836. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5837. }
  5838. $data['companyHtml']=$collectHtml;
  5839. //total price html
  5840. $collectHtml="";$total=0;
  5841. for ($i=1;$i<=12;$i++){
  5842. $sumPrice=0;
  5843. foreach ($itemStatisticsList as $key=>$value){
  5844. if($value['month']==$i){
  5845. $sumPrice+=$value['price'];
  5846. }
  5847. }
  5848. if ($sumPrice==0)
  5849. $collectHtml.='<td class="taR">-</td>';
  5850. else
  5851. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5852. $total+=$sumPrice;
  5853. }
  5854. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5855. $data['companyTotalHtml']=$collectHtml;
  5856. $data['total']=$total;
  5857. $data['year']=$year;
  5858. $data['memu']="receipt";
  5859. $data['staff']=$this->staff;
  5860. $data['receiptMemu']='companyCategoryCollect';
  5861. $data['verifyId']=$this->verifyId;
  5862. $data['executeId']=$this->executeId;
  5863. if ($year<=date("Y")){
  5864. Doo::loadModel('receipt');
  5865. $receipt=new receipt();
  5866. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5867. if(empty($receiptList)){ //generated files
  5868. ob_start();
  5869. $this->render ( "/admin/saeaStaffCollectB", $data );
  5870. $this->cacheFile($path);die;
  5871. }
  5872. }
  5873. $this->render ( "/admin/saeaStaffCollectB", $data );
  5874. }
  5875. function staffCollectBak(){
  5876. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5877. $month=$this->get_args('month')?$this->get_args('month'):1;
  5878. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  5879. $this->showCache($path);
  5880. Doo::loadModel('statistics');
  5881. $statistics=new statistics();
  5882. Doo::loadModel("receiptDetail");
  5883. $receiptDetail=new receiptDetail();
  5884. Doo::loadModel('L_category');
  5885. $Lcategory=new L_category();
  5886. Doo::loadModel('accountItem');
  5887. $accountItem=new accountItem();
  5888. Doo::loadModel('staff');
  5889. $staff=new staff();
  5890. Doo::loadModel('itemStatistics');
  5891. $itemStatistics=new itemStatistics();
  5892. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5893. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  5894. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5895. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  5896. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5897. $staffList=$staff->find(array('asArray'=>true));
  5898. $htmlArray=array();
  5899. foreach ($LcategoryList as $value){
  5900. $htmlArray[$value['title']]=array();
  5901. foreach ($staffList as $v){
  5902. if($value['cid']==$v['cid']){
  5903. $html="";$falg=true;$staffSumPrice=0;
  5904. foreach ($itemStatisticsList as $a){
  5905. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  5906. if(empty($a['price'])){
  5907. $html.='<td class="taR">-</td>';$falg=false;break;
  5908. }else{
  5909. $staffSumPrice+=$a['price'];
  5910. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5911. }
  5912. }
  5913. }
  5914. if ($falg){
  5915. $html.='<td class="taR">-</td>';$falg=true;
  5916. }
  5917. $falg=true;
  5918. foreach ($itemStatisticsList as $a){
  5919. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  5920. if(empty($a['price'])){
  5921. $html.='<td class="taR">-</td>';$falg=false;break;
  5922. }else{
  5923. $staffSumPrice+=$a['price'];
  5924. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5925. }
  5926. }
  5927. }
  5928. if ($falg){
  5929. $html.='<td class="taR">-</td>';$falg=true;
  5930. }
  5931. $falg=true;
  5932. foreach ($itemStatisticsList as $a){
  5933. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  5934. if(empty($a['price'])){
  5935. $html.='<td class="taR">-</td>';$falg=false;break;
  5936. }else{
  5937. $staffSumPrice+=$a['price'];
  5938. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5939. }
  5940. }
  5941. }
  5942. if ($falg){
  5943. $html.='<td class="taR">-</td>';$falg=true;
  5944. }
  5945. $falg=true;
  5946. foreach ($itemStatisticsList as $a){
  5947. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  5948. if(!empty($a['price'])){
  5949. $staffSumPrice+=$a['price'];
  5950. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5951. }else{
  5952. $html.='<td class="taR">-</td>';$falg=false;break;
  5953. }
  5954. }
  5955. }
  5956. if ($falg){
  5957. $html.='<td class="taR">-</td>';$falg=true;
  5958. }
  5959. $falg=true;
  5960. foreach ($itemStatisticsList as $a){
  5961. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  5962. if(!empty($a['price'])){
  5963. $staffSumPrice+=$a['price'];
  5964. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5965. }else{
  5966. $html.='<td class="taR">-</td>';$falg=false;break;
  5967. }
  5968. }
  5969. }
  5970. if ($falg){
  5971. $html.='<td class="taR">-</td>';$falg=true;
  5972. }
  5973. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  5974. $htmlArray[$value['title']][$v['username']]=$html;
  5975. }
  5976. }
  5977. /*-- ---*/
  5978. //合计费用
  5979. $cateHtml="";$catePrice=0;$cateFalg=true;
  5980. foreach ($itemCategoryList as $l){
  5981. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  5982. if(empty($l['price'])){
  5983. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  5984. }else{
  5985. $catePrice+=$l['price'];
  5986. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  5987. }
  5988. }
  5989. }
  5990. if ($cateFalg){
  5991. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  5992. }
  5993. $cateFalg=true;
  5994. foreach ($itemCategoryList as $l){
  5995. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  5996. if(empty($l['price'])){
  5997. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  5998. }else{
  5999. $catePrice+=$l['price'];
  6000. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6001. }
  6002. }
  6003. }
  6004. if ($cateFalg){
  6005. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6006. }
  6007. $cateFalg=true;
  6008. foreach ($itemCategoryList as $l){
  6009. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6010. if(empty($l['price'])){
  6011. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6012. }else{
  6013. $catePrice+=$l['price'];
  6014. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6015. }
  6016. }
  6017. }
  6018. if ($cateFalg){
  6019. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6020. }
  6021. $cateFalg=true;
  6022. foreach ($itemCategoryList as $l){
  6023. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6024. if(empty($l['price'])){
  6025. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6026. }else{
  6027. $catePrice+=$l['price'];
  6028. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6029. }
  6030. }
  6031. }
  6032. if ($cateFalg){
  6033. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6034. }
  6035. $cateFalg=true;
  6036. foreach ($itemCategoryList as $l){
  6037. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6038. if(empty($l['price'])){
  6039. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6040. }else{
  6041. $catePrice+=$l['price'];
  6042. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6043. }
  6044. }
  6045. }
  6046. if ($cateFalg){
  6047. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6048. }
  6049. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6050. $htmlArray[$value['title']]['合计']=$cateHtml;
  6051. /*-- ---*/
  6052. }
  6053. //print_r($htmlArray);die;
  6054. $data['htmlArray']=$htmlArray;
  6055. //statistics html
  6056. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6057. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6058. if(empty($stList))
  6059. $stList=array('rePrice'=>0,'agPrice'=>0);
  6060. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6061. $monthHtml="";
  6062. for ($i=1;$i<=12;$i++){
  6063. if ($i==$month)
  6064. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6065. else
  6066. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6067. }
  6068. $data['monthHtml']=$monthHtml;
  6069. $data['year']=$year;
  6070. $data['month']=$month;
  6071. $data['memu']="receipt";
  6072. $data['staff']=$this->staff;
  6073. $data['receiptMemu']='companyCategoryCollect';
  6074. $data['verifyId']=$this->verifyId;
  6075. $data['executeId']=$this->executeId;
  6076. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6077. Doo::loadModel('receipt');
  6078. $receipt=new receipt();
  6079. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6080. if(empty($receiptList)){ //generated files
  6081. ob_start();
  6082. $this->render ( "/admin/saeaStaffCollect", $data );
  6083. $this->cacheFile($path);die;
  6084. }
  6085. }
  6086. $this->render ( "/admin/saeaStaffCollect", $data );
  6087. }
  6088. function lyt(){
  6089. Doo::loadModel("receiptDetail");
  6090. $receiptDetail=new receiptDetail();
  6091. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6092. foreach ($receiptCollectList as $key=>$value){
  6093. $receiptDetail=new receiptDetail();
  6094. $receiptDetail->pastDate=$value['date'];
  6095. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6096. }
  6097. }
  6098. function staffCollectMonthDetail(){
  6099. $year=$this->get_args('year')?$this->get_args('year'):"";
  6100. $month=$this->get_args('month')?$this->get_args('month'):"";
  6101. if(!$year)
  6102. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6103. if(!$month)
  6104. $month=isset($this->params['month'])?$this->params['month']:1;
  6105. Doo::loadModel('staff');
  6106. $staff=new staff();
  6107. Doo::loadModel("receiptDetail");
  6108. $receiptDetail=new receiptDetail();
  6109. Doo::loadModel('accountItem');
  6110. $accountItem=new accountItem();
  6111. Doo::loadModel('statistics');
  6112. $statistics=new statistics();
  6113. Doo::loadModel('L_category');
  6114. $lCategory=new L_category();
  6115. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6116. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6117. $list=array();
  6118. foreach ($categoryList as $vlu){
  6119. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6120. $r1=0;$r2=0;$r3=0;$r4=0;$r5=0;$r6=0;$r7=0;$r8=0;$r9=0;$r10=0;$r11=0;$r12=0;$r13=0;$r14=0;$r15=0;
  6121. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6122. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6123. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6124. $s1=0;
  6125. $m1=0;
  6126. foreach ($staffList as $value){
  6127. if ($vlu['cid']==$value['cid']){
  6128. //pastDate
  6129. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6130. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6131. // if ($value['sid']==42){
  6132. // print_r($receiptCollectList);die;
  6133. // }
  6134. if(!empty($receiptCollectList)){
  6135. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6136. $html="";
  6137. $psum=0;
  6138. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6139. foreach ($item as $va){
  6140. $falg=true;
  6141. foreach ($receiptCollectList as $v){
  6142. if($v['itemCategory']=='日常相关费用'){
  6143. if($v['item']==$va){
  6144. if ($va=='市内交通费')
  6145. $r1+=$v['price'];
  6146. if ($va=='市内出租费')
  6147. $r2+=$v['price'];
  6148. if ($va=='办事处房租')
  6149. $r3+=$v['price'];
  6150. if ($va=='电话费')
  6151. $r4+=$v['price'];
  6152. if ($va=='水费')
  6153. $r5+=$v['price'];
  6154. if ($va=='电费')
  6155. $r6+=$v['price'];
  6156. if ($va=='办公费用')
  6157. $r7+=$v['price'];
  6158. if ($va=='邮寄费')
  6159. $r8+=$v['price'];
  6160. if ($va=='其他费用')
  6161. $r9+=$v['price'];
  6162. if ($va=='车辆费用')
  6163. $r10+=$v['price'];
  6164. if ($va=='广告费')
  6165. $r11+=$v['price'];
  6166. if ($va=='团队建设费')
  6167. $r13+=$v['price'];
  6168. if ($va=='物业管理费')
  6169. $r14+=$v['price'];
  6170. if ($va=='宽带费')
  6171. $r15+=$v['price'];
  6172. $psum+=$v['price'];
  6173. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6174. }
  6175. }
  6176. }
  6177. if($falg)
  6178. $html.='<td class="taR">-</td>';
  6179. }
  6180. $r12+=$psum;
  6181. if(!empty($psum))
  6182. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6183. else
  6184. $psum='<td class="colGreen taR">-</td>';
  6185. $receiptL['日常相关费用']=$psum.$html;
  6186. /*-----------------------------------*/
  6187. $html="";
  6188. $psum=0;
  6189. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6190. foreach ($item as $va){
  6191. $falg=true;
  6192. foreach ($receiptCollectList as $v){
  6193. if($v['itemCategory']=='差旅相关费用'){
  6194. if($v['item']==$va){
  6195. if ($va=='往来交通费')
  6196. $c1+=$v['price'];
  6197. if ($va=='市内交通费')
  6198. $c2+=$v['price'];
  6199. if ($va=='出差住宿费')
  6200. $c3+=$v['price'];
  6201. if ($va=='出差补助')
  6202. $c4+=$v['price'];
  6203. if ($va=='其他费用')
  6204. $c5+=$v['price'];
  6205. $psum+=$v['price'];
  6206. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6207. }
  6208. }
  6209. }
  6210. if($falg)
  6211. $html.='<td class="taR">-</td>';
  6212. }
  6213. $c6+=$psum;
  6214. if(!empty($psum))
  6215. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6216. else
  6217. $psum='<td class="colGreen taR">-</td>';
  6218. $receiptL['差旅相关费用']=$psum.$html;
  6219. /*-------------------------------------*/
  6220. $html="";
  6221. $psum=0;
  6222. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6223. foreach ($item as $va){
  6224. $falg=true;
  6225. foreach ($receiptCollectList as $v){
  6226. if($v['itemCategory']=='培训班费用'){
  6227. if($v['item']==$va){
  6228. if ($va=='场租费')
  6229. $p1+=$v['price'];
  6230. if ($va=='薪酬')
  6231. $p2+=$v['price'];
  6232. if ($va=='住宿费')
  6233. $p3+=$v['price'];
  6234. if ($va=='交通费')
  6235. $p4+=$v['price'];
  6236. if ($va=='餐饮费')
  6237. $p5+=$v['price'];
  6238. if ($va=='办公费')
  6239. $p6+=$v['price'];
  6240. if ($va=='公关费')
  6241. $p7+=$v['price'];
  6242. if ($va=='其他')
  6243. $p8+=$v['price'];
  6244. $psum+=$v['price'];
  6245. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6246. }
  6247. }
  6248. }
  6249. if($falg)
  6250. $html.='<td class="taR">-</td>';
  6251. }
  6252. $p9+=$psum;
  6253. if(!empty($psum))
  6254. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6255. else
  6256. $psum='<td class="colGreen taR">-</td>';
  6257. $receiptL['培训班费用']=$psum.$html;
  6258. /*-------------------------------------*/
  6259. $html="";
  6260. $psum=0;
  6261. $item=array('公关费','广告费','借款','可自加费用');
  6262. foreach ($item as $va){
  6263. $falg=true;
  6264. foreach ($receiptCollectList as $v){
  6265. if($v['itemCategory']=='其他'){
  6266. // if ($value['sid']==42){
  6267. //
  6268. // echo var_dump($v['item']);
  6269. // echo var_dump($va);
  6270. // echo var_dump($v['item']==" ".$va);
  6271. // echo $v['item']."==".$va."/<br/>";
  6272. // //print_r( $receiptCollectList);//echo $va;
  6273. // }
  6274. if(trim($v['item'])==$va){
  6275. if ($va=='公关费')
  6276. $t1+=$v['price'];
  6277. if ($va=='广告费'){
  6278. $t2+=$v['price'];
  6279. }
  6280. if ($va=='借款')
  6281. $t3+=$v['price'];
  6282. if ($va=='可自加费用')
  6283. $t4+=$v['price'];
  6284. $psum+=$v['price'];
  6285. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6286. }
  6287. }
  6288. }
  6289. if($falg)
  6290. $html.='<td class="taR">-</td>';
  6291. }
  6292. $t5+=$psum;
  6293. if(!empty($psum))
  6294. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6295. else
  6296. $psum='<td class="colGreen taR">-</td>';
  6297. $receiptL['其他']=$psum.$html;
  6298. /*-------------------------------------*/
  6299. $html="";
  6300. $psum=0;
  6301. foreach ($receiptCollectList as $v){
  6302. if($v['itemCategory']=='报销金额调整'){
  6303. if (!empty($v['price'])){
  6304. $psum+=$v['price'];
  6305. }
  6306. }
  6307. }
  6308. $s1+=$psum;
  6309. if(!empty($psum))
  6310. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6311. else
  6312. $psum='<td class="taR colOrange">-</td>';
  6313. $receiptL['报销金额调整']=$psum.$html;
  6314. }else{
  6315. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6316. <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>
  6317. <td class="taR">-</td><td class="taR">-</td>';
  6318. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6319. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6320. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6321. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6322. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6323. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6324. }
  6325. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6326. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6327. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6328. if(!empty($monthStaffPrice[0]['price'])){
  6329. $m1+=$monthStaffPrice[0]['price'];
  6330. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6331. }else
  6332. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6333. $list[$value['username']]=$receiptL;
  6334. }
  6335. }
  6336. $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>
  6337. <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>
  6338. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6339. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6340. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6341. $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>
  6342. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6343. $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>';
  6344. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6345. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6346. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6347. }
  6348. $data['list']=$list;
  6349. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6350. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6351. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6352. //statistics html
  6353. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6354. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6355. if(empty($stList))
  6356. $stList=array('rePrice'=>0,'agPrice'=>0);
  6357. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6358. $monthHtml="";
  6359. for ($i=1;$i<=12;$i++){
  6360. if ($i==$month)
  6361. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6362. else
  6363. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6364. }
  6365. $data['monthHtml']=$monthHtml;
  6366. $data['year']=$year;
  6367. $data['month']=$month;
  6368. $data['memu']="receipt";
  6369. $data['staff']=$this->staff;
  6370. $data['receiptMemu']='companyCategoryCollect';
  6371. $data['verifyId']=$this->verifyId;
  6372. $data['executeId']=$this->executeId;
  6373. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6374. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6375. }
  6376. function staffCollectMonthDetail2(){
  6377. $year=$this->get_args('year')?$this->get_args('year'):"";
  6378. $month=$this->get_args('month')?$this->get_args('month'):"";
  6379. if(!$year)
  6380. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6381. if(!$month)
  6382. $month=isset($this->params['month'])?$this->params['month']:1;
  6383. Doo::loadModel('staff');
  6384. $staff=new staff();
  6385. Doo::loadModel("receiptDetail");
  6386. $receiptDetail=new receiptDetail();
  6387. Doo::loadModel('accountItem');
  6388. $accountItem=new accountItem();
  6389. Doo::loadModel('statistics');
  6390. $statistics=new statistics();
  6391. Doo::loadModel('L_category');
  6392. $lCategory=new L_category();
  6393. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6394. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6395. $list=array();
  6396. foreach ($categoryList as $vlu){
  6397. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6398. $r1=0;$r2=0;$r3=0;$r4=0;$r5=0;$r6=0;$r7=0;$r8=0;$r9=0;$r10=0;$r11=0;$r12=0;$r13=0;$r14=0;$r15=0;
  6399. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6400. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6401. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6402. $s1=0;
  6403. $m1=0;
  6404. foreach ($staffList as $value){
  6405. if ($vlu['cid']==$value['cid']){
  6406. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6407. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6408. if(!empty($receiptCollectList)){
  6409. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6410. $html="";
  6411. $psum=0;
  6412. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6413. foreach ($item as $va){
  6414. $falg=true;
  6415. foreach ($receiptCollectList as $v){
  6416. if($v['itemCategory']=='日常相关费用'){
  6417. if($v['item']==$va){
  6418. if ($va=='市内交通费')
  6419. $r1+=$v['price'];
  6420. if ($va=='市内出租费')
  6421. $r2+=$v['price'];
  6422. if ($va=='办事处房租')
  6423. $r3+=$v['price'];
  6424. if ($va=='电话费')
  6425. $r4+=$v['price'];
  6426. if ($va=='水费')
  6427. $r5+=$v['price'];
  6428. if ($va=='电费')
  6429. $r6+=$v['price'];
  6430. if ($va=='办公费用')
  6431. $r7+=$v['price'];
  6432. if ($va=='邮寄费')
  6433. $r8+=$v['price'];
  6434. if ($va=='其他费用')
  6435. $r9+=$v['price'];
  6436. if ($va=='车辆费用')
  6437. $r10+=$v['price'];
  6438. if ($va=='广告费')
  6439. $r11+=$v['price'];
  6440. if ($va=='团队建设费')
  6441. $r13+=$v['price'];
  6442. if ($va=='物业管理费')
  6443. $r14+=$v['price'];
  6444. if ($va=='宽带费')
  6445. $r15+=$v['price'];
  6446. $psum+=$v['price'];
  6447. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6448. }
  6449. }
  6450. }
  6451. if($falg)
  6452. $html.='<td class="taR">-</td>';
  6453. }
  6454. $r12+=$psum;
  6455. if(!empty($psum))
  6456. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6457. else
  6458. $psum='<td class="colGreen taR">-</td>';
  6459. $receiptL['日常相关费用']=$psum.$html;
  6460. /*-----------------------------------*/
  6461. $html="";
  6462. $psum=0;
  6463. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6464. foreach ($item as $va){
  6465. $falg=true;
  6466. foreach ($receiptCollectList as $v){
  6467. if($v['itemCategory']=='差旅相关费用'){
  6468. if($v['item']==$va){
  6469. if ($va=='往来交通费')
  6470. $c1+=$v['price'];
  6471. if ($va=='市内交通费')
  6472. $c2+=$v['price'];
  6473. if ($va=='出差住宿费')
  6474. $c3+=$v['price'];
  6475. if ($va=='出差补助')
  6476. $c4+=$v['price'];
  6477. if ($va=='其他费用')
  6478. $c5+=$v['price'];
  6479. $psum+=$v['price'];
  6480. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6481. }
  6482. }
  6483. }
  6484. if($falg)
  6485. $html.='<td class="taR">-</td>';
  6486. }
  6487. $c6+=$psum;
  6488. if(!empty($psum))
  6489. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6490. else
  6491. $psum='<td class="colGreen taR">-</td>';
  6492. $receiptL['差旅相关费用']=$psum.$html;
  6493. /*-------------------------------------*/
  6494. $html="";
  6495. $psum=0;
  6496. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6497. foreach ($item as $va){
  6498. $falg=true;
  6499. foreach ($receiptCollectList as $v){
  6500. if($v['itemCategory']=='培训班费用'){
  6501. if($v['item']==$va){
  6502. if ($va=='场租费')
  6503. $p1+=$v['price'];
  6504. if ($va=='薪酬')
  6505. $p2+=$v['price'];
  6506. if ($va=='住宿费')
  6507. $p3+=$v['price'];
  6508. if ($va=='交通费')
  6509. $p4+=$v['price'];
  6510. if ($va=='餐饮费')
  6511. $p5+=$v['price'];
  6512. if ($va=='办公费')
  6513. $p6+=$v['price'];
  6514. if ($va=='公关费')
  6515. $p7+=$v['price'];
  6516. if ($va=='其他')
  6517. $p8+=$v['price'];
  6518. $psum+=$v['price'];
  6519. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6520. }
  6521. }
  6522. }
  6523. if($falg)
  6524. $html.='<td class="taR">-</td>';
  6525. }
  6526. $p9+=$psum;
  6527. if(!empty($psum))
  6528. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6529. else
  6530. $psum='<td class="colGreen taR">-</td>';
  6531. $receiptL['培训班费用']=$psum.$html;
  6532. /*-------------------------------------*/
  6533. $html="";
  6534. $psum=0;
  6535. $item=array('公关费','广告费','借款','可自加费用');
  6536. foreach ($item as $va){
  6537. $falg=true;
  6538. foreach ($receiptCollectList as $v){
  6539. if($v['itemCategory']=='其他'){
  6540. if($v['item']==$va){
  6541. if ($va=='公关费')
  6542. $t1+=$v['price'];
  6543. if ($va=='广告费')
  6544. $t2+=$v['price'];
  6545. if ($va=='借款')
  6546. $t3+=$v['price'];
  6547. if ($va=='可自加费用')
  6548. $t4+=$v['price'];
  6549. $psum+=$v['price'];
  6550. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6551. }
  6552. }
  6553. }
  6554. if($falg)
  6555. $html.='<td class="taR">-</td>';
  6556. }
  6557. $t5+=$psum;
  6558. if(!empty($psum))
  6559. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6560. else
  6561. $psum='<td class="colGreen taR">-</td>';
  6562. $receiptL['其他']=$psum.$html;
  6563. /*-------------------------------------*/
  6564. $html="";
  6565. $psum=0;
  6566. foreach ($receiptCollectList as $v){
  6567. if($v['itemCategory']=='报销金额调整'){
  6568. if (!empty($v['price'])){
  6569. $psum+=$v['price'];
  6570. }
  6571. }
  6572. }
  6573. $s1+=$psum;
  6574. if(!empty($psum))
  6575. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6576. else
  6577. $psum='<td class="taR colOrange">-</td>';
  6578. $receiptL['报销金额调整']=$psum.$html;
  6579. }else{
  6580. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6581. <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>';
  6582. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6583. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6584. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6585. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6586. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6587. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6588. }
  6589. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6590. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6591. if(!empty($monthStaffPrice[0]['price'])){
  6592. $m1+=$monthStaffPrice[0]['price'];
  6593. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6594. }else
  6595. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6596. $list[$value['username']]=$receiptL;
  6597. }
  6598. }
  6599. $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>
  6600. <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>
  6601. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6602. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6603. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6604. $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>
  6605. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6606. $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>';
  6607. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6608. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6609. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6610. }
  6611. $data['list']=$list;
  6612. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6613. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6614. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6615. //statistics html
  6616. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6617. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6618. if(empty($stList))
  6619. $stList=array('rePrice'=>0,'agPrice'=>0);
  6620. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6621. $monthHtml="";
  6622. for ($i=1;$i<=12;$i++){
  6623. if ($i==$month)
  6624. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6625. else
  6626. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6627. }
  6628. $data['monthHtml']=$monthHtml;
  6629. $data['year']=$year;
  6630. $data['month']=$month;
  6631. $data['memu']="receipt";
  6632. $data['staff']=$this->staff;
  6633. $data['receiptMemu']='companyCategoryCollect';
  6634. $data['verifyId']=$this->verifyId;
  6635. $data['executeId']=$this->executeId;
  6636. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6637. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6638. }
  6639. function companyMonthCollectDetail(){
  6640. $year=$this->get_args('year')?$this->get_args('year'):"";
  6641. $month=$this->get_args('month')?$this->get_args('month'):"";
  6642. if(!$year)
  6643. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6644. if(!$month)
  6645. $month=isset($this->params['month'])?$this->params['month']:1;
  6646. Doo::loadModel('staff');
  6647. $staff=new staff();
  6648. Doo::loadModel("receiptDetail");
  6649. $receiptDetail=new receiptDetail();
  6650. Doo::loadModel('accountItem');
  6651. $accountItem=new accountItem();
  6652. Doo::loadModel('statistics');
  6653. $statistics=new statistics();
  6654. Doo::loadModel('L_category');
  6655. $lCategory=new L_category();
  6656. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6657. $categoryList=$lCategory->find(array('asArray'=>true));
  6658. $list=array();
  6659. foreach ($categoryList as $value){
  6660. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6661. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6662. if(!empty($receiptCollectList)){
  6663. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6664. $html="";
  6665. $psum=0;
  6666. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6667. foreach ($item as $va){
  6668. $falg=true;
  6669. foreach ($receiptCollectList as $v){
  6670. if($v['itemCategory']=='日常相关费用'){
  6671. if($v['item']==$va){
  6672. $psum+=$v['price'];
  6673. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6674. }
  6675. }
  6676. }
  6677. if($falg)
  6678. $html.='<td class="taR">-</td>';
  6679. }
  6680. if(!empty($psum))
  6681. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6682. else
  6683. $psum='<td class="colGreen taR">-</td>';
  6684. $receiptL['日常相关费用']=$psum.$html;
  6685. /*-----------------------------------*/
  6686. $html="";
  6687. $psum=0;
  6688. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6689. foreach ($item as $va){
  6690. $falg=true;
  6691. foreach ($receiptCollectList as $v){
  6692. if($v['itemCategory']=='差旅相关费用'){
  6693. if($v['item']==$va){
  6694. $psum+=$v['price'];
  6695. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6696. }
  6697. }
  6698. }
  6699. if($falg)
  6700. $html.='<td class="taR">-</td>';
  6701. }
  6702. if(!empty($psum))
  6703. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6704. else
  6705. $psum='<td class="colGreen taR">-</td>';
  6706. $receiptL['差旅相关费用']=$psum.$html;
  6707. /*-------------------------------------*/
  6708. $html="";
  6709. $psum=0;
  6710. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6711. foreach ($item as $va){
  6712. $falg=true;
  6713. foreach ($receiptCollectList as $v){
  6714. if($v['itemCategory']=='培训班费用'){
  6715. if($v['item']==$va){
  6716. $psum+=$v['price'];
  6717. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6718. }
  6719. }
  6720. }
  6721. if($falg)
  6722. $html.='<td class="taR">-</td>';
  6723. }
  6724. if(!empty($psum))
  6725. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6726. else
  6727. $psum='<td class="colGreen taR">-</td>';
  6728. $receiptL['培训班费用']=$psum.$html;
  6729. /*-------------------------------------*/
  6730. $html="";
  6731. $psum=0;
  6732. $item=array('公关费','广告费','借款','可自加费用');
  6733. foreach ($item as $va){
  6734. $falg=true;
  6735. foreach ($receiptCollectList as $v){
  6736. if($v['itemCategory']=='其他'){
  6737. if($v['item']==$va){
  6738. $psum+=$v['price'];
  6739. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6740. }
  6741. }
  6742. }
  6743. if($falg)
  6744. $html.='<td class="taR">-</td>';
  6745. }
  6746. if(!empty($psum))
  6747. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6748. else
  6749. $psum='<td class="colGreen taR">-</td>';
  6750. $receiptL['其他']=$psum.$html;
  6751. /*-------------------------------------*/
  6752. $html="";
  6753. $psum=0;
  6754. foreach ($receiptCollectList as $v){
  6755. if($v['itemCategory']=='报销金额调整'){
  6756. if (!empty($v['price']))
  6757. $psum+=$v['price'];
  6758. }
  6759. }
  6760. if(!empty($psum))
  6761. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6762. else
  6763. $psum='<td class="taR colOrange">-</td>';
  6764. $receiptL['报销金额调整']=$psum.$html;
  6765. }else{
  6766. $receiptL['日常相关费用']='<td class="colGreen 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>
  6767. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6768. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6769. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6770. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6771. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6772. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6773. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6774. }
  6775. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6776. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6777. if(!empty($monthStaffPrice[0]['price']))
  6778. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6779. else
  6780. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6781. $list[$value['title']]=$receiptL;
  6782. }
  6783. $data['list']=$list;
  6784. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6785. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6786. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6787. //print_r($data['monthPriceHtml']);
  6788. // foreach ($data['monthPriceHtml'] as $value){
  6789. // echo $value;
  6790. // }
  6791. // die;
  6792. //statistics html
  6793. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6794. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6795. if(empty($stList))
  6796. $stList=array('rePrice'=>0,'agPrice'=>0);
  6797. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6798. $monthHtml="";
  6799. for ($i=1;$i<=12;$i++){
  6800. if ($i==$month)
  6801. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6802. else
  6803. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6804. }
  6805. $data['monthHtml']=$monthHtml;
  6806. $data['year']=$year;
  6807. $data['month']=$month;
  6808. $data['memu']="receipt";
  6809. $data['staff']=$this->staff;
  6810. $data['receiptMemu']='companyCategoryCollect';
  6811. $data['verifyId']=$this->verifyId;
  6812. $data['executeId']=$this->executeId;
  6813. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6814. }
  6815. function staffCollectDetail(){
  6816. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6817. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6818. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6819. if(!$staffname){
  6820. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6821. $staffname= urldecode($staffname);
  6822. }
  6823. Doo::loadModel('staff');
  6824. $staff=new staff();
  6825. Doo::loadModel("receiptDetail");
  6826. $receiptDetail=new receiptDetail();
  6827. Doo::loadModel('accountItem');
  6828. $accountItem=new accountItem();
  6829. Doo::loadModel('statistics');
  6830. $statistics=new statistics();
  6831. Doo::loadModel('L_category');
  6832. $lCategory=new L_category();
  6833. $staffList=$staff->find(array('asArray'=>true));
  6834. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6835. foreach ($staffList as $value){
  6836. if ($value['username']==$staffname&&$value['username']!='admin'){
  6837. $stTitle=$value['category'].'-'.$value['username'];
  6838. $staffId=$value['sid'];
  6839. $cid=$value['cid'];
  6840. $ocid=$value['cid'];
  6841. if (!empty($value['othercid']))
  6842. $cid=$value['cid'].','.$value['othercid'];
  6843. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6844. }elseif ($value['username']!='admin')
  6845. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6846. }
  6847. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6848. if(empty($pcid))
  6849. $pcid=$ocid;
  6850. $data['ocid']=$pcid;
  6851. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6852. $this->showCache($path);
  6853. //
  6854. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6855. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6856. $accountList=$accountItem->find(array('asArray'=>true));
  6857. //create CollectDetail HTML
  6858. $collectHtml=array();
  6859. foreach ($accountList as $key=>$value){
  6860. $html="";$asum=0;
  6861. for ($i=1;$i<=12;$i++){
  6862. $falg=true;
  6863. foreach ($receiptCollectList as $v) {
  6864. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  6865. $asum+=$v['price'];
  6866. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  6867. }
  6868. }
  6869. if($falg)
  6870. $html.='<td class="taR">-</td>';
  6871. }
  6872. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  6873. $collectHtml[$value['category']][$value['name']]=$html;
  6874. }
  6875. $data['collectHtml']=$collectHtml;
  6876. //create Adjustment price html
  6877. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  6878. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  6879. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6880. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  6881. array_push($collectArray['日常相关费用'], $collectHtml);
  6882. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  6883. array_push($collectArray['差旅相关费用'], $collectHtml);
  6884. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  6885. array_push($collectArray['培训班费用'], $collectHtml);
  6886. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  6887. array_push($collectArray['其他'], $collectHtml);
  6888. $data['collectArray']=$collectArray;
  6889. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  6890. array_push($adjustment, $collectHtml);
  6891. $data['adjustment']=$adjustment;
  6892. //total price html
  6893. $collectHtml="";$total=0;
  6894. for ($i=1;$i<=12;$i++){
  6895. $sumPrice=0;
  6896. foreach ($receiptCollectList as $key=>$value){
  6897. if($value['month']==$i){
  6898. $sumPrice+=$value['price'];
  6899. }
  6900. }
  6901. if ($sumPrice==0)
  6902. $collectHtml.='<td class="taR">-</td>';
  6903. else
  6904. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  6905. $total+=$sumPrice;
  6906. }
  6907. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  6908. //statistics html
  6909. $stList=$statistics->statisticsByYear($year,$staffId);
  6910. if(empty($stList))
  6911. $stList=array('rePrice'=>0,'agPrice'=>0);
  6912. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6913. $data['totalPrice']=$collectHtml;
  6914. $data['totalYear']=$total;
  6915. $data['stHtml']=$stHtml;
  6916. $data['year']=$year;
  6917. $data['stTitle']=$stTitle;
  6918. $data['memu']="receipt";
  6919. $data['staff']=$this->staff;
  6920. $data['receiptMemu']='companyCategoryCollect';
  6921. $data['verifyId']=$this->verifyId;
  6922. $data['executeId']=$this->executeId;
  6923. if ($year<date("Y")){
  6924. Doo::loadModel('receipt');
  6925. $receipt=new receipt();
  6926. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  6927. if(empty($receiptList)){ //generated files
  6928. ob_start();
  6929. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6930. $this->cacheFile($path);die;
  6931. }
  6932. }
  6933. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6934. }
  6935. function ajaxGetReceiptOrder(){
  6936. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  6937. if (!empty($receiptOrder)){
  6938. Doo::loadModel('receipt');
  6939. $receipt=new receipt();
  6940. Doo::loadModel ( 'staff' );
  6941. $staff = new staff ();
  6942. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  6943. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  6944. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  6945. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  6946. </tbody></table><table class="table table table-bordered"><tbody>';
  6947. foreach ($verifyStaff as $key=>$value){
  6948. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  6949. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  6950. }
  6951. $html.='</tbody></table></div></div>';
  6952. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  6953. }
  6954. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  6955. }
  6956. function _getMonthCollectDetail($receiptCollectList){
  6957. if(!empty($receiptCollectList)){
  6958. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6959. $html="";
  6960. $psum=0;
  6961. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6962. foreach ($item as $value){
  6963. $falg=true;
  6964. foreach ($receiptCollectList as $v){
  6965. if($v['itemCategory']=='日常相关费用'){
  6966. if($v['item']==$value){
  6967. $psum+=$v['price'];
  6968. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6969. }
  6970. }
  6971. }
  6972. if($falg)
  6973. $html.='<td class="taR">-</td>';
  6974. }
  6975. if(!empty($psum))
  6976. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6977. else
  6978. $psum='<td class="colGreen taR">-</td>';
  6979. $receiptL['日常相关费用']=$psum.$html;
  6980. /*-----------------------------------*/
  6981. $html="";
  6982. $psum=0;
  6983. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6984. foreach ($item as $value){
  6985. $falg=true;
  6986. foreach ($receiptCollectList as $v){
  6987. if($v['itemCategory']=='差旅相关费用'){
  6988. if($v['item']==$value){
  6989. $psum+=$v['price'];
  6990. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6991. }
  6992. }
  6993. }
  6994. if($falg)
  6995. $html.='<td class="taR">-</td>';
  6996. }
  6997. if(!empty($psum))
  6998. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6999. else
  7000. $psum='<td class="colGreen taR">-</td>';
  7001. $receiptL['差旅相关费用']=$psum.$html;
  7002. /*-------------------------------------*/
  7003. $html="";
  7004. $psum=0;
  7005. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7006. foreach ($item as $value){
  7007. $falg=true;
  7008. foreach ($receiptCollectList as $v){
  7009. if($v['itemCategory']=='培训班费用'){
  7010. if($v['item']==$value){
  7011. $psum+=$v['price'];
  7012. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7013. }
  7014. }
  7015. }
  7016. if($falg)
  7017. $html.='<td class="taR">-</td>';
  7018. }
  7019. if(!empty($psum))
  7020. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7021. else
  7022. $psum='<td class="colGreen taR">-</td>';
  7023. $receiptL['培训班费用']=$psum.$html;
  7024. /*-------------------------------------*/
  7025. $html="";
  7026. $psum=0;
  7027. $item=array('公关费','广告费','借款','可自加费用');
  7028. foreach ($item as $value){
  7029. $falg=true;
  7030. foreach ($receiptCollectList as $v){
  7031. if($v['itemCategory']=='其他'){
  7032. if($v['item']==$value){
  7033. $psum+=$v['price'];
  7034. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7035. }
  7036. }
  7037. }
  7038. if($falg)
  7039. $html.='<td class="taR">-</td>';
  7040. }
  7041. if(!empty($psum))
  7042. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7043. else
  7044. $psum='<td class="colGreen taR">-</td>';
  7045. $receiptL['其他']=$psum.$html;
  7046. /*-------------------------------------*/
  7047. $html="";
  7048. $psum=0;
  7049. foreach ($receiptCollectList as $v){
  7050. if($v['itemCategory']=='报销金额调整'){
  7051. if (!empty($v['price']))
  7052. $psum+=$v['price'];
  7053. }
  7054. }
  7055. if(!empty($psum))
  7056. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7057. else
  7058. $psum='<td class="taR colOrange">-</td>';
  7059. $receiptL['报销金额调整']=$psum.$html;
  7060. }else{
  7061. $receiptL['日常相关费用']='<td class="colGreen 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>
  7062. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7063. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7064. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7065. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7066. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7067. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7068. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7069. }
  7070. return $receiptL;
  7071. }
  7072. function eMail(){
  7073. Doo::loadModel('staff');
  7074. $staff=new staff();
  7075. Doo::loadModel('receipt');
  7076. $receipt=new receipt();
  7077. Doo::loadModel('L_category');
  7078. $Lcategory=new L_category();
  7079. Doo::loadModel("verify");
  7080. $verify=new verify();
  7081. $staffList=$staff->find(array('asArray'=>true));
  7082. foreach ($staffList as $key=>$value){
  7083. if($value['username']!='admin'){
  7084. //提交人
  7085. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7086. if(!empty($receiptList)){
  7087. $html='<br><div><style></style>
  7088. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7089. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7090. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7091. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7092. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7093. <tbody><tr>
  7094. <td style="padding: 0 40px;" align="left">
  7095. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7096. </td></tr><tr>
  7097. <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>
  7098. </tr>
  7099. </tbody> </table></td> </tr> <tr><td>
  7100. <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">
  7101. <tbody> <tr><td>
  7102. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7103. 以下报销单完成了审批,等着收款吧:</p>
  7104. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7105. foreach ($receiptList as $k=>$v){
  7106. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7107. $html.='
  7108. <tr>
  7109. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7110. <td align="left">
  7111. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7112. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7113. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7114. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7115. </tr>';
  7116. }
  7117. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7118. <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>
  7119. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7120. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7121. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7122. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7123. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7124. $receipt=new receipt();
  7125. $receipt->notice=1;
  7126. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7127. }
  7128. }
  7129. //审批人
  7130. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7131. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7132. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7133. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7134. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7135. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7136. <tbody><tr><td style="padding: 0 40px;" align="left">
  7137. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7138. </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>
  7139. </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">
  7140. <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>
  7141. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7142. foreach ($verifyList as $k=>$v){
  7143. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7144. foreach ($receiptList as $r=>$l){
  7145. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7146. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7147. $html.='
  7148. <tr>
  7149. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7150. <td align="left">
  7151. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7152. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7153. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7154. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7155. </tr>';
  7156. }
  7157. }
  7158. $html.='
  7159. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7160. <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>
  7161. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7162. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7163. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7164. // $receipt=new receipt();
  7165. // $receipt->notice=1;
  7166. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7167. }
  7168. }
  7169. }
  7170. }
  7171. // Email发送函数
  7172. function SMail($toemail, $subject, $contents) {
  7173. Doo::loadClass('class.phpmailer');
  7174. $mail = new PHPMailer();
  7175. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7176. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7177. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7178. $mail->Password = "cDO1GjtY1seH"; //密码
  7179. $mail->CharSet = "UTF8";
  7180. $mail->SMTPAuth = true;
  7181. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7182. $mail->Mailer = "smtp";
  7183. $mail->Port = 25;
  7184. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7185. $mail->MsgHTML($contents);
  7186. $mail->AddAddress($toemail);
  7187. $mail->CharSet = "UTF-8";
  7188. return $mail->Send();
  7189. }
  7190. function swfupload(){
  7191. $POST_MAX_SIZE = ini_get('post_max_size');
  7192. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7193. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7194. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7195. header("HTTP/1.1 500 Internal Server Error");
  7196. echo "POST exceeded maximum allowed size.";
  7197. exit(0);
  7198. }
  7199. // Settings
  7200. $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)
  7201. $upload_name = "Filedata";
  7202. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7203. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7204. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7205. // Other variables
  7206. $MAX_FILENAME_LENGTH = 260;
  7207. $file_name = "";
  7208. $file_extension = "";
  7209. $uploadErrors = array(
  7210. 0=>"文件上传成功",
  7211. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7212. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7213. 3=>"上传的文件仅为部分文件",
  7214. 4=>"没有文件上传",
  7215. 6=>"缺少临时文件夹"
  7216. );
  7217. $nk= time();
  7218. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7219. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7220. echo "文件无法保存.";
  7221. exit(0);
  7222. }
  7223. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7224. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7225. exit(0);
  7226. }
  7227. function _GetFileEXT($filename) {
  7228. $pics = explode ( '.', $filename );
  7229. $num = count ( $pics );
  7230. return $pics [$num - 1];
  7231. }
  7232. /**
  7233. * 获取get或者POST值
  7234. * @param string $name 属性名称
  7235. * @return fixed 值
  7236. */
  7237. function get_args($name) {
  7238. if (isset ( $_GET [$name] )) {
  7239. if (is_array ( $_GET [$name] ))
  7240. return $_GET [$name];
  7241. else
  7242. return addslashes ( $_GET [$name] );
  7243. } elseif (isset ( $_POST [$name] )) {
  7244. if (is_array ( $_POST [$name] ))
  7245. return $_POST [$name];
  7246. else
  7247. return addslashes ( $_POST [$name] );
  7248. } else
  7249. return false;
  7250. }
  7251. function num_to_rmb($num){
  7252. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7253. $c2 = "分角元拾佰仟万拾佰仟亿";
  7254. //精确到分后面就不要了,所以只留两个小数位
  7255. $num = round($num, 2);
  7256. //将数字转化为整数
  7257. $num = $num * 100;
  7258. if (strlen($num) > 10) {
  7259. return "金额太大,请检查";
  7260. }
  7261. $i = 0;
  7262. $c = "";
  7263. while (1) {
  7264. if ($i == 0) {
  7265. //获取最后一位数字
  7266. $n = substr($num, strlen($num)-1, 1);
  7267. } else {
  7268. $n = $num % 10;
  7269. }
  7270. //每次将最后一位数字转化为中文
  7271. $p1 = substr($c1, 3 * $n, 3);
  7272. $p2 = substr($c2, 3 * $i, 3);
  7273. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7274. $c = $p1 . $p2 . $c;
  7275. } else {
  7276. $c = $p1 . $c;
  7277. }
  7278. $i = $i + 1;
  7279. //去掉数字最后一位了
  7280. $num = $num / 10;
  7281. $num = (int)$num;
  7282. //结束循环
  7283. if ($num == 0) {
  7284. break;
  7285. }
  7286. }
  7287. $j = 0;
  7288. $slen = strlen($c);
  7289. while ($j < $slen) {
  7290. //utf8一个汉字相当3个字符
  7291. $m = substr($c, $j, 6);
  7292. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7293. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7294. $left = substr($c, 0, $j);
  7295. $right = substr($c, $j + 3);
  7296. $c = $left . $right;
  7297. $j = $j-3;
  7298. $slen = $slen-3;
  7299. }
  7300. $j = $j + 3;
  7301. }
  7302. //这个是为了去掉类似23.0中最后一个“零”字
  7303. if (substr($c, strlen($c)-3, 3) == '零') {
  7304. $c = substr($c, 0, strlen($c)-3);
  7305. }
  7306. //将处理的汉字加上“整”
  7307. if (empty($c)) {
  7308. return "零元整";
  7309. }else{
  7310. return $c . "整";
  7311. }
  7312. }
  7313. }
  7314. ?>