ReceiptController.php 303 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. //public static $NEW2 = 0;
  10. public $AGENCY="日常相关费用";
  11. public $TRAVEL="差旅相关费用";
  12. public $TRAIN="培训班费用";
  13. public $OTHER="其他";
  14. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  18. private function showCache($path){
  19. if(file_exists($path)){
  20. echo "<!DOCTYPE html>";
  21. include $path;die;
  22. }
  23. }
  24. private function cacheFile($path){
  25. $content = ob_get_contents();
  26. $fp = fopen($path, "w");
  27. fwrite($fp, $content);
  28. fclose($fp);
  29. }
  30. // private function getExeCount(){
  31. // Doo::loadModel('receipt');
  32. // $receipt=new receipt();
  33. // $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));
  34. // return count($receiptList);
  35. // }
  36. // private function getReceiptCount(){
  37. // $status=2;
  38. // $year=date('Y');
  39. // Doo::loadModel('receipt');
  40. // $receipt=new receipt();
  41. // $dateCondition=" and Year(date) =".$year;
  42. // $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  43. // $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  44. // return count($receiptList);
  45. // }
  46. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  47. $collectHtml="";$sumPrice=0.00;
  48. for ($i=1;$i<=12;$i++){
  49. $falg=true;
  50. foreach ($receiptCollectList as $key=>$value){
  51. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  52. $sumPrice+=$value['price'];
  53. if ($classType=="b"){
  54. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  55. }else{
  56. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  57. }
  58. }
  59. }
  60. if ($falg)
  61. $collectHtml.='<td class="taR">-</td>';
  62. }
  63. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  64. return $collectHtml;
  65. }
  66. function __construct() {
  67. if(isset($_COOKIE["staff"])){
  68. if(!empty($_COOKIE["staff"])){
  69. Doo::loadModel ( 'staff' );
  70. Doo::loadModel('verify');
  71. $verify=new verify();
  72. $staff = new staff ();
  73. Doo::loadModel("execute");
  74. $execute=new execute();
  75. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  76. $list=array();
  77. //判断角色的审批权限
  78. foreach ($verifyList as $key=>$value){
  79. $ver=json_decode($value['staff']);
  80. foreach ($ver as $k=>$v){
  81. if ($v[1]=='ROLE'){
  82. $roleList=json_decode($v[3]);
  83. foreach ($roleList as $t=>$g){
  84. $gList=explode("_", $g);
  85. array_push($list, $gList[0]);
  86. //print_r($list);
  87. }
  88. }else
  89. array_push($list, $v[0]);
  90. }
  91. }
  92. //判断执行人的审批权限
  93. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  94. $list2=array();
  95. foreach ($executeList as $key=>$value){
  96. $ver=json_decode($value['staff']);
  97. foreach ($ver as $k=>$v){
  98. array_push($list2, $v[0]);
  99. }
  100. }
  101. $eidList=file_get_contents("protected/config/execute/execute.ini");
  102. $eidList=array_filter(explode(",", $eidList));
  103. $this->executeId= array_merge($list2,$eidList);
  104. $this->verifyId=$list;
  105. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  106. return "/";
  107. }
  108. }
  109. Doo::loadCore ( 'uri/DooUriRouter' );
  110. $router = new DooUriRouter ();
  111. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  112. if($routeRs['1']!="login"){
  113. header ( 'Content-Type:text/html;charset=utf-8' );
  114. @header ( "Location: /login" );
  115. }
  116. }
  117. function saeaBorad(){
  118. Doo::loadModel('receipt');
  119. Doo::loadModel('verify');
  120. $verify=new verify();
  121. $receipt=new receipt();
  122. Doo::loadModel('L_category');
  123. $lCategory=new L_category();
  124. Doo::loadModel("role");
  125. $role=new role();
  126. Doo::loadModel("receiptLog");
  127. $receiptLog=new receiptLog();
  128. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  129. $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));
  130. foreach ($receiptDetail as $key=>$value){
  131. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  132. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  133. $v=json_decode($veList['staff']);
  134. array_push($v[0], $veList['description']);
  135. foreach ($v as $n=>$m){
  136. if ($m['1']=='ROLE'){
  137. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  138. $v[$n][1]=$roleInfo['name'];
  139. }
  140. }
  141. $receiptDetail[$key]['staff']=$v;
  142. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  143. $receiptDetail[$key]['category']=$category['title'];
  144. }
  145. //print_r($receiptLogList);
  146. $data['receiptLogList']=$receiptLogList;
  147. $data['receiptDetail']=$receiptDetail;
  148. $data['memu']="receipt";
  149. $data['staff']=$this->staff;
  150. $data['receiptMemu']='saeaBorad';
  151. $data['verifyId']=$this->verifyId;
  152. $data['executeId']=$this->executeId;
  153. $this->render ( "/admin/saeaBorad", $data );
  154. }
  155. function remitAdd(){
  156. Doo::loadModel('accountItem');
  157. Doo::loadModel('verify');
  158. Doo::loadModel('receipt');
  159. Doo::loadModel('L_category');
  160. $lCategory=new L_category();
  161. $receipt=new receipt();
  162. $verify=new verify();
  163. $accountItem=new accountItem();
  164. Doo::loadModel("role");
  165. $role=new role();
  166. $acItem=$accountItem->find(array('asArray'=>true));
  167. $veList=$verify->find(array('asArray'=>true));
  168. foreach ($veList as $key=>$value){
  169. $v=json_decode($value['staff']);
  170. $list=array();
  171. foreach ($v as $n=>$m){
  172. if ($m['1']=='ROLE'){
  173. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  174. $v[$n][1]=$roleInfo['name'];
  175. array_push($list, $roleInfo['name']);
  176. }else{
  177. array_push($list, $v[$n][1]);
  178. }
  179. }
  180. $veList[$key]['staff']=implode('>', $list);
  181. }
  182. $data['category']=$lCategory->find(array('asArray'=>true));
  183. $data['veList']=$veList;
  184. $data['acItem']=$acItem;
  185. $data['memu']="receipt";
  186. $data['staff']=$this->staff;
  187. $data['receiptMemu']='saeaBorad';
  188. $data['verifyId']=$this->verifyId;
  189. $data['executeId']=$this->executeId;
  190. $this->render ( "/admin/remitAdd", $data );
  191. }
  192. function remitAddDo(){
  193. $agency=$this->get_args('agency');
  194. $travel=$this->get_args('travel');
  195. $train=$this->get_args('train');
  196. $other=$this->get_args('other');
  197. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  198. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  199. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  200. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  201. //print_r($agency);die;
  202. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  203. Doo::loadModel('receipt');
  204. Doo::loadModel('receiptDetail');
  205. Doo::loadModel('accountItem');
  206. $accountItem=new accountItem();
  207. $receipt=new receipt();
  208. Doo::loadModel('enclosur');
  209. Doo::loadModel('execute');
  210. $execute=new execute();
  211. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  212. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  213. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  214. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  215. $ag=$tr=$ta=$ot=0;
  216. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  217. foreach ($aItem as $key=>$value){
  218. if ($value['category']==$this->AGENCY){
  219. if (isset($agency[$ag])){
  220. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  221. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  222. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  223. }
  224. }
  225. $ag++;
  226. }
  227. }
  228. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  229. //报销单
  230. $receipt->accountItem=json_encode($accountJson);
  231. $receipt->staff=$this->staff[0]['sid'];
  232. $receipt->sum=number_format($sum, 2, '.', '');
  233. $receipt->date=date("Y-m-d");
  234. $receipt->cid=$cid;
  235. $receipt->status=5;
  236. $receipt->Rtype=2;
  237. //修改审批流程加入角色
  238. $receipt->verify=$verify;
  239. $receipt->executeCopy=$executeDetail['staff'];
  240. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  241. $receipt->explanation=$explanation;
  242. $rid=$receipt->insert();
  243. //附件
  244. if (!empty($enclosurName)){
  245. $enclosurArray=explode('-', $enclosurName);
  246. foreach ($enclosurArray as $value){
  247. $enclosur=new enclosur();
  248. $enclosur->name=$value;
  249. $enclosur->rid=$rid;
  250. $enclosur->insert();
  251. }
  252. //print_r($enclosurArray);die;
  253. }
  254. //报销详情
  255. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  256. $receiptDetail=new receiptDetail();
  257. $receiptDetail->staff=$this->staff[0]['sid'];
  258. $receiptDetail->item=$value['name'];
  259. $receiptDetail->itemCategory=$this->AGENCY;
  260. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  261. $receiptDetail->date=date("Y-m-d");
  262. $receiptDetail->cid=$cid;
  263. $receiptDetail->rid=$rid;
  264. $receiptDetail->status=4;
  265. $receiptDetail->insert();
  266. }
  267. }
  268. return "/saeaBorad";
  269. }
  270. function remitEdit(){
  271. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  272. //echo $rid;
  273. Doo::loadModel('accountItem');
  274. Doo::loadModel('verify');
  275. Doo::loadModel('receipt');
  276. $receipt=new receipt();
  277. $verify=new verify();
  278. $accountItem=new accountItem();
  279. Doo::loadModel('L_category');
  280. $lCategory=new L_category();
  281. Doo::loadModel("role");
  282. $role=new role();
  283. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  284. if(empty($receiptDetail))
  285. return "/saeaCreate";
  286. $acItem=$accountItem->find(array('asArray'=>true));
  287. $veList=$verify->find(array('asArray'=>true));
  288. foreach ($veList as $key=>$value){
  289. $v=json_decode($value['staff']);
  290. $list=array();
  291. foreach ($v as $n=>$m){
  292. if ($m['1']=='ROLE'){
  293. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  294. $v[$n][1]=$roleInfo['name'];
  295. array_push($list, $roleInfo['name']);
  296. }else{
  297. array_push($list, $v[$n][1]);
  298. }
  299. }
  300. $veList[$key]['staff']=implode('>', $list);
  301. }
  302. //配置编辑信息
  303. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  304. foreach ($acItem as $key=>$value){
  305. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  306. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  307. $acItem[$key]['price']=$v['price'];
  308. }
  309. }
  310. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  311. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  312. $acItem[$key]['price']=$v['price'];
  313. }
  314. }
  315. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  316. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  317. $acItem[$key]['price']=$v['price'];
  318. }
  319. }
  320. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  321. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  322. $acItem[$key]['price']=$v['price'];
  323. }
  324. }
  325. }
  326. $data['category']=$lCategory->find(array('asArray'=>true));
  327. $data['cSum']=$accountItemList['cSum'];
  328. $data['sum']=$receiptDetail['sum'];
  329. $data['receiptDetail']=$receiptDetail;
  330. $data['veList']=$veList;
  331. $data['acItem']=$acItem;
  332. $data['memu']="receipt";
  333. $data['staff']=$this->staff;
  334. $data['receiptMemu']='saeaBorad';
  335. $data['verify']=$receiptDetail['verify'];
  336. $data['verifyId']=$this->verifyId;
  337. $data['executeId']=$this->executeId;
  338. $data['rid']=$rid;
  339. $this->render ( "/admin/remitEdit", $data );
  340. }
  341. function remitEdiDo(){
  342. $agency=$this->get_args('agency');
  343. $travel=$this->get_args('travel');
  344. $train=$this->get_args('train');
  345. $other=$this->get_args('other');
  346. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  347. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  348. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  349. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  350. if(!empty($verify)&&!empty($explanation)){
  351. Doo::loadModel('receipt');
  352. Doo::loadModel('receiptDetail');
  353. Doo::loadModel('accountItem');
  354. $accountItem=new accountItem();
  355. $receipt=new receipt();
  356. Doo::loadModel('execute');
  357. $execute=new execute();
  358. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  359. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  360. if(empty($receiptDetail))
  361. return "/saeaBorad";
  362. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  363. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  364. $ag=$tr=$ta=$ot=0;
  365. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  366. foreach ($aItem as $key=>$value){
  367. if ($value['category']==$this->AGENCY){
  368. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  369. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  370. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  371. }
  372. $ag++;
  373. }
  374. }
  375. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  376. //报销单
  377. $rid=$receipt->rid=$receiptDetail['rid'];
  378. $receipt->accountItem=json_encode($accountJson);
  379. $receipt->staff=$this->staff[0]['sid'];
  380. $receipt->sum=number_format($sum, 2, '.', '');
  381. $receipt->date=date("Y-m-d");
  382. $receipt->cid=$cid;
  383. if ($receiptDetail['Rtype']==1)
  384. $receipt->status=7;
  385. else
  386. $receipt->status=5;
  387. $receipt->verify=$verify;
  388. $receipt->executeCopy=$executeDetail['staff'];
  389. $receipt->explanation=$explanation;
  390. $receipt->update();
  391. $receiptDetail=new receiptDetail();
  392. $receiptDetail->delete(array('where'=>'rid='.$rid));
  393. //报销详情
  394. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  395. $receiptDetail=new receiptDetail();
  396. $receiptDetail->staff=$this->staff[0]['sid'];
  397. $receiptDetail->item=$value['name'];
  398. $receiptDetail->itemCategory=$this->AGENCY;
  399. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  400. $receiptDetail->date=date("Y-m-d");
  401. $receiptDetail->cid=$cid;
  402. $receiptDetail->rid=$rid;
  403. $receiptDetail->status=4;
  404. $receiptDetail->insert();
  405. }
  406. //return "/referReceipt/".$rid;
  407. }
  408. return "/saeaBorad";
  409. }
  410. function remitApproval(){
  411. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  412. $status=isset($this->params['status'])?$this->params['status']:'';
  413. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  414. $month=$this->get_args('month')?$this->get_args('month'):"";
  415. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  416. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  417. if (empty($status))
  418. $status=$this->get_args('status')?$this->get_args('status'):2;
  419. $vidList=array();
  420. $button=0;
  421. Doo::loadModel('verify');
  422. Doo::loadModel('receipt');
  423. Doo::loadModel('staff');
  424. $staff=new staff();
  425. $receipt=new receipt();
  426. $verify=new verify();
  427. Doo::loadModel('L_category');
  428. $Lcategory=new L_category();
  429. Doo::loadModel('enclosur');
  430. $enclosur=new enclosur();
  431. //user verify ID
  432. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  433. foreach ($verifyDetail as $key=>$value){
  434. array_push($vidList, $value['vid']);
  435. }
  436. $vid=implode(",", $vidList);
  437. if(empty($verifyDetail))
  438. $vid=0;
  439. $categoryList=$Lcategory->find(array('asArray'=>true));
  440. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  441. $ap="";
  442. if($status==4){
  443. $ap=4;$status=2;
  444. }
  445. //get Receipt By verifyID status 2
  446. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  447. $Locate=0;$roleId=0;
  448. if($ap==4)
  449. $status=4;
  450. foreach ($receiptList as $key=>$value){
  451. $receiptList[$key]['Locate']=$Locate;$Locate++;
  452. $receiptList[$key]['reviseDetail']=array();
  453. if (!empty($value['reviseDetail']))
  454. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  455. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  456. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  457. $receiptList[$key]['category']=$categoryDetil['title'];
  458. //检测编辑状态
  459. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  460. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  461. $verifyStaff=json_decode($value['verifyStaff'],true);
  462. Doo::loadModel('role');
  463. $role=new role();
  464. //print_r($verifyList);
  465. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  466. foreach ($verifyList as $k=>$v){
  467. //init verifyStaff
  468. if ($v[1]=='ROLE'){
  469. if (!empty($verifyStaff)){
  470. $endStaffArray=end($verifyStaff);
  471. if ($v[0]==$endStaffArray['nextStaff']){
  472. $roleId=$v[0];
  473. }
  474. }
  475. $roleVerify=json_decode($v[3],true);
  476. $roleKey=$k;$roleArray=array();
  477. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  478. foreach ($roleVerify as $o=>$p){
  479. $staffID=explode ('_',$p);
  480. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  481. //print_r($staffID);
  482. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  483. array_push($roleArray, $exp);
  484. }
  485. $roleArrayCopy[$v[0]]=$roleArray;
  486. //$verifyList[$k]['roleArray']=$roleArray;
  487. }
  488. //print_r($roleArray);
  489. $verifyList[$k]['date']="";
  490. $verifyList[$k]['opinion']="";
  491. $verifyList[$k]['status']="";
  492. if (empty($verifyStaff)){
  493. $verifyList[$k]['date']="";
  494. $verifyList[$k]['opinion']="";
  495. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  496. $verifyList[$k]['status']=4;
  497. $button=4;$flag=false;
  498. }
  499. }else{
  500. foreach ($verifyStaff as $m=>$u){
  501. if ($v[0]==$m){
  502. $verifyList[$k]['date']=$u['date'];
  503. $verifyList[$k]['opinion']=$u['opinion'];
  504. $verifyList[$k]['status']=$u['status'];
  505. $flag=false;
  506. break;
  507. }
  508. }
  509. $endStaffArray=end($verifyStaff);
  510. if (isset($endStaffArray['ROLE'])){
  511. }else{
  512. $endKey=key($verifyStaff);
  513. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  514. $button=4;
  515. $verifyList[$k]['status']=4;
  516. }
  517. }
  518. }
  519. }
  520. $rolename['name']='';
  521. if (!empty($roleId)){
  522. Doo::loadModel('role');
  523. $role=new role();
  524. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  525. }
  526. if (!empty($verifyStaff))
  527. $endStaffArray=end($verifyStaff);
  528. $KOP=false;
  529. foreach ($roleArrayCopy as $P=>$A){
  530. foreach ( $A as $MKI=>$AVL){
  531. if (!empty($verifyStaff)){
  532. //&&$rolename['rid']==$endStaffArray['nextStaff']
  533. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  534. $button=4;
  535. $roleArrayCopy[$P][$MKI]['status']=4;
  536. }
  537. foreach ($verifyStaff as $m=>$u){
  538. $AVLFK=$AVL[0].'_R';
  539. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  540. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  541. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  542. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  543. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  544. break;
  545. }
  546. }
  547. }else{
  548. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  549. $button=4;
  550. $roleArrayCopy[$P][$MKI]['status']=4;
  551. }
  552. }
  553. //$roleArray[$MKI]['rolename']=$rolename['name'];
  554. $KOP=true;
  555. }
  556. }
  557. foreach ($roleArrayCopy as $k=>$v){
  558. foreach ($verifyList as $m=>$n){
  559. if ($n[0]==$k){
  560. array_splice($verifyList,$m,1,$v);
  561. }
  562. }
  563. }
  564. $receiptList[$key]['verifyList']= $verifyList;
  565. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  566. $receiptList[$key]['button']=$button;
  567. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  568. }
  569. $mothHtml="";
  570. for($i=1;$i<=12;$i++){
  571. if($month==$i)
  572. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  573. else
  574. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  575. }
  576. //获取审批日志
  577. Doo::loadModel('receiptLog');
  578. $receiptLog=new receiptLog();
  579. $rlList=array();
  580. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  581. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  582. if (!empty($rlInfo)){
  583. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  584. }
  585. $receiptList[0]['rlList']=$rlList;
  586. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  587. $enclosurHtml='';
  588. foreach ($enclosurList as $value){
  589. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  590. }
  591. //print_r($receiptList);
  592. $data['enclosurHtml']=$enclosurHtml;
  593. $data['rolename']=$rolename['name'];
  594. $data['datetij']=$tijdate['date'];
  595. $data['mothHtml']=$mothHtml;
  596. $data['rid']=$rid;
  597. $data['receiptList']=$receiptList;
  598. $data['receiptApprovalCount']=count($receiptList);
  599. $data['status']=$status;
  600. $data['year']=$year;
  601. $data['categoryList']=$categoryList;
  602. $data['staffList']=$staffList;
  603. $data['cid']=$cid;
  604. $data['sid']=$sid;
  605. $data['ap']=$ap;
  606. $data['memu']="receipt";
  607. $data['staff']=$this->staff;
  608. $data['receiptMemu']='approvalExpenses';
  609. $data['verifyId']=$this->verifyId;
  610. $data['executeId']=$this->executeId;
  611. $this->render ( "/admin/remitApproval", $data );
  612. }
  613. function saeaLoanAdd(){
  614. Doo::loadModel('verify');
  615. $verify=new verify();
  616. Doo::loadModel("role");
  617. $role=new role();
  618. Doo::loadModel('L_category');
  619. $lCategory=new L_category();
  620. $veList=$verify->find(array('asArray'=>true));
  621. foreach ($veList as $key=>$value){
  622. $v=json_decode($value['staff']);
  623. $list=array();
  624. foreach ($v as $n=>$m){
  625. if ($m['1']=='ROLE'){
  626. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  627. $v[$n][1]=$roleInfo['name'];
  628. array_push($list, $roleInfo['name']);
  629. }else{
  630. array_push($list, $v[$n][1]);
  631. }
  632. }
  633. $veList[$key]['staff']=implode('>', $list);
  634. }
  635. $data['category']=$lCategory->find(array('asArray'=>true));
  636. $data['veList']=$veList;
  637. $data['memu']="receipt";
  638. $data['staff']=$this->staff;
  639. $data['receiptMemu']='saeaBorad';
  640. $data['verifyId']=$this->verifyId;
  641. $data['executeId']=$this->executeId;
  642. $this->render ( "/admin/saeaLoanAdd", $data );
  643. }
  644. function saeaLoanAddDo(){
  645. $agency=$this->get_args('agency');
  646. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  647. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  648. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  649. //die;
  650. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  651. Doo::loadModel('receipt');
  652. Doo::loadModel('receiptDetail');
  653. Doo::loadModel('accountItem');
  654. $accountItem=new accountItem();
  655. $receipt=new receipt();
  656. Doo::loadModel('loanReceipt');
  657. $loanReceipt=new loanReceipt();
  658. Doo::loadModel('execute');
  659. $execute=new execute();
  660. Doo::loadModel('enclosur');
  661. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  662. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  663. // if(!empty($receiptDetail))
  664. // return "/referReceipt/".$receiptDetail['rid'];
  665. $aItem=$accountItem->find(array('asArray'=>true));
  666. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  667. $ag=$tr=$ta=$ot=0;
  668. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  669. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  670. $sum+=$agency;$agencySum+=$agency;
  671. $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, '.', ''));
  672. //借款数据备份
  673. $loanReceipt->loanItem=json_encode($accountJson);
  674. $loanReceipt->staff=$this->staff[0]['sid'];
  675. $loanReceipt->sum=number_format($sum, 2, '.', '');
  676. $loanReceipt->date=date("Y-m-d");
  677. $loanReceipt->cid=$cid;
  678. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  679. $loanReceipt->status=5;
  680. $loanReceipt->Rtype=1;
  681. $loanReceipt->verify=$verify;
  682. $receipt->receiptOrder=$receipt->receiptOrder;
  683. $loanReceipt->explanation=$explanation;
  684. $loanRid=$loanReceipt->insert();
  685. //报销单
  686. $receipt->loanItem=json_encode($accountJson);
  687. $receipt->staff=$this->staff[0]['sid'];
  688. $receipt->sum=number_format($sum, 2, '.', '');
  689. $receipt->date=date("Y-m-d");
  690. $receipt->cid=$cid;
  691. //特殊状态
  692. $receipt->status=5;
  693. $receipt->Rtype=1;
  694. $receipt->loanRid=$loanRid;
  695. //修改审批流程加入角色
  696. $receipt->verify=$verify;
  697. $receipt->executeCopy=$executeDetail['staff'];
  698. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  699. $receipt->explanation=$explanation;
  700. $rid=$receipt->insert();
  701. //执行数据备份
  702. // $executeCopy->rid=$rid;
  703. // $executeCopy->staff=$executeDetail['staff'];
  704. // $executeCopy->eid=$executeDetail['eid'];
  705. // $ecid=$executeCopy->insert();
  706. }
  707. return "/saeaBorad";
  708. }
  709. function saeaLoanEdi(){
  710. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  711. Doo::loadModel('verify');
  712. $verify=new verify();
  713. Doo::loadModel("role");
  714. $role=new role();
  715. Doo::loadModel('L_category');
  716. $lCategory=new L_category();
  717. Doo::loadModel('receipt');
  718. $receipt=new receipt();
  719. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  720. $veList=$verify->find(array('asArray'=>true));
  721. foreach ($veList as $key=>$value){
  722. $v=json_decode($value['staff']);
  723. $list=array();
  724. foreach ($v as $n=>$m){
  725. if ($m['1']=='ROLE'){
  726. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  727. $v[$n][1]=$roleInfo['name'];
  728. array_push($list, $roleInfo['name']);
  729. }else{
  730. array_push($list, $v[$n][1]);
  731. }
  732. }
  733. $veList[$key]['staff']=implode('>', $list);
  734. }
  735. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  736. $data['receiptInfo']=$receiptInfo;
  737. $data['category']=$lCategory->find(array('asArray'=>true));
  738. $data['veList']=$veList;
  739. $data['memu']="receipt";
  740. $data['staff']=$this->staff;
  741. $data['receiptMemu']='saeaBorad';
  742. $data['verifyId']=$this->verifyId;
  743. $data['executeId']=$this->executeId;
  744. $this->render ( "/admin/saeaLoanEdi", $data );
  745. }
  746. function saeaLoanEdiDo(){
  747. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  748. $agency=$this->get_args('agency');
  749. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  750. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  751. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  752. //die;
  753. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  754. Doo::loadModel('receipt');
  755. Doo::loadModel('receiptDetail');
  756. Doo::loadModel('accountItem');
  757. $accountItem=new accountItem();
  758. $receipt=new receipt();
  759. Doo::loadModel('loanReceipt');
  760. $loanReceipt=new loanReceipt();
  761. Doo::loadModel('enclosur');
  762. Doo::loadModel('execute');
  763. $execute=new execute();
  764. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  765. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 and rid='.$rid,'asArray'=>true));
  766. if(empty($receiptDetail))
  767. die('参数错误');
  768. $aItem=$accountItem->find(array('asArray'=>true));
  769. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  770. $ag=$tr=$ta=$ot=0;
  771. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  772. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  773. $sum+=$agency;$agencySum+=$agency;
  774. $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, '.', ''));
  775. //报销单
  776. $receipt->loanItem=json_encode($accountJson);
  777. $receipt->sum=number_format($sum, 2, '.', '');
  778. $receipt->cid=$cid;
  779. //特殊状态
  780. //修改审批流程加入角色
  781. $receipt->verify=$verify;
  782. $receipt->explanation=$explanation;
  783. $receipt->update(array('where'=>'rid='.$rid));
  784. //借款数据更新
  785. $loanReceipt->loanItem=json_encode($accountJson);
  786. $loanReceipt->sum=number_format($sum, 2, '.', '');
  787. $loanReceipt->cid=$cid;
  788. $loanReceipt->verify=$verify;
  789. $loanReceipt->explanation=$explanation;
  790. $receipt->executeCopy=$executeDetail['staff'];
  791. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  792. }
  793. return "/saeaBorad";
  794. }
  795. function saeaLoanReceiptAdd(){
  796. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  797. Doo::loadModel('receipt');
  798. $receipt=new receipt();
  799. Doo::loadModel('loanReceipt');
  800. $loanReceipt=new loanReceipt();
  801. Doo::loadModel('L_category');
  802. $Lcategory=new L_category();
  803. Doo::loadModel('verify');
  804. Doo::loadModel('statistics');
  805. $statistics=new statistics();
  806. $verify=new verify();
  807. Doo::loadModel('staff');
  808. $staff=new staff();
  809. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  810. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  811. $Locate=0;$roleId=0;$button=0;
  812. foreach ($receiptList as $key=>$value){
  813. $receiptList[$key]['Locate']=$Locate;$Locate++;
  814. $receiptList[$key]['reviseDetail']=array();
  815. if (!empty($value['reviseDetail']))
  816. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  817. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  818. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  819. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  820. $receiptList[$key]['category']=$categoryDetil['title'];
  821. //检测编辑状态
  822. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  823. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  824. $verifyStaff=json_decode($value['verifyStaff'],true);
  825. Doo::loadModel('role');
  826. $role=new role();
  827. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  828. foreach ($verifyList as $k=>$v){
  829. //init verifyStaff
  830. if ($v[1]=='ROLE'){
  831. if (!empty($verifyStaff)){
  832. $endStaffArray=end($verifyStaff);
  833. // if ($v[0]==$endStaffArray['nextStaff']){
  834. // $roleId=$v[0];
  835. // }
  836. }
  837. $roleVerify=json_decode($v[3],true);
  838. $roleKey=$k;$roleArray=array();
  839. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  840. foreach ($roleVerify as $o=>$p){
  841. $staffID=explode ('_',$p);
  842. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  843. //print_r($staffID);
  844. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  845. array_push($roleArray, $exp);
  846. }
  847. $roleArrayCopy[$v[0]]=$roleArray;
  848. //$verifyList[$k]['roleArray']=$roleArray;
  849. }
  850. $verifyList[$k]['date']="";
  851. $verifyList[$k]['opinion']="";
  852. $verifyList[$k]['status']="";
  853. if (empty($verifyStaff)){
  854. $verifyList[$k]['date']="";
  855. $verifyList[$k]['opinion']="";
  856. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  857. $verifyList[$k]['status']=4;
  858. $flag=false;
  859. }
  860. }else{
  861. foreach ($verifyStaff as $m=>$u){
  862. if ($v[0]==$m){
  863. $verifyList[$k]['date']=$u['date'];
  864. $verifyList[$k]['opinion']=$u['opinion'];
  865. $verifyList[$k]['status']=$u['status'];
  866. $flag=false;
  867. break;
  868. }
  869. }
  870. $endStaffArray=end($verifyStaff);
  871. if (isset($endStaffArray['ROLE'])){
  872. }else{
  873. // $endKey=key($verifyStaff);
  874. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  875. // $button=4;
  876. // $verifyList[$k]['status']=4;
  877. // }
  878. }
  879. }
  880. }
  881. $rolename['name']='';
  882. if (!empty($roleId)){
  883. Doo::loadModel('role');
  884. $role=new role();
  885. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  886. }
  887. if (!empty($verifyStaff))
  888. $endStaffArray=end($verifyStaff);
  889. $KOP=false;
  890. foreach ($roleArrayCopy as $P=>$A){
  891. foreach ( $A as $MKI=>$AVL){
  892. if (!empty($verifyStaff)){
  893. //&&$rolename['rid']==$endStaffArray['nextStaff']
  894. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  895. $button=4;
  896. $roleArrayCopy[$P][$MKI]['status']=4;
  897. }
  898. foreach ($verifyStaff as $m=>$u){
  899. $AVLFK=$AVL[0].'_R';
  900. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  901. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  902. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  903. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  904. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  905. break;
  906. }
  907. }
  908. }else{
  909. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  910. $button=4;
  911. $roleArrayCopy[$P][$MKI]['status']=4;
  912. }
  913. }
  914. //$roleArray[$MKI]['rolename']=$rolename['name'];
  915. $KOP=true;
  916. }
  917. }
  918. foreach ($roleArrayCopy as $k=>$v){
  919. foreach ($verifyList as $m=>$n){
  920. if ($n[0]==$k){
  921. array_splice($verifyList,$m,1,$v);
  922. }
  923. }
  924. }
  925. $receiptList[$key]['verifyList']=$verifyList;
  926. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  927. $receiptList[$key]['button']=$button;
  928. //
  929. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  930. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  931. }
  932. $data['receiptList']=$receiptList;
  933. Doo::loadModel('L_category');
  934. $lCategory=new L_category();
  935. Doo::loadModel('accountItem');
  936. $accountItem=new accountItem();
  937. $acItem=$accountItem->find(array('asArray'=>true));
  938. $veList=$verify->find(array('asArray'=>true));
  939. foreach ($veList as $key=>$value){
  940. $v=json_decode($value['staff']);
  941. $list=array();
  942. foreach ($v as $n=>$m){
  943. if ($m['1']=='ROLE'){
  944. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  945. $v[$n][1]=$roleInfo['name'];
  946. array_push($list, $roleInfo['name']);
  947. }else{
  948. array_push($list, $v[$n][1]);
  949. }
  950. }
  951. $veList[$key]['staff']=implode('>', $list);
  952. }
  953. $data['rid']=$rid;
  954. $data['category']=$lCategory->find(array('asArray'=>true));
  955. $data['veList']=$veList;
  956. $data['acItem']=$acItem;
  957. $data['memu']="receipt";
  958. $data['staff']=$this->staff;
  959. $data['receiptMemu']='saeaBorad';
  960. $data['verifyId']=$this->verifyId;
  961. $data['executeId']=$this->executeId;
  962. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  963. }
  964. function saeaLoanReceiptAddDo(){
  965. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  966. $agency=$this->get_args('agency');
  967. $travel=$this->get_args('travel');
  968. $train=$this->get_args('train');
  969. $other=$this->get_args('other');
  970. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  971. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  972. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  973. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  974. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  975. Doo::loadModel('receipt');
  976. Doo::loadModel('receiptDetail');
  977. Doo::loadModel('accountItem');
  978. $accountItem=new accountItem();
  979. $receipt=new receipt();
  980. Doo::loadModel('enclosur');
  981. Doo::loadModel('execute');
  982. $execute=new execute();
  983. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  984. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  985. // if(!empty($receiptDetail))
  986. // return "/referReceipt/".$receiptDetail['rid'];
  987. $aItem=$accountItem->find(array('asArray'=>true));
  988. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  989. $ag=$tr=$ta=$ot=0;
  990. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  991. foreach ($aItem as $key=>$value){
  992. if ($value['category']==$this->AGENCY){
  993. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  994. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  995. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  996. }
  997. $ag++;
  998. }
  999. if($value['category']==$this->TRAVEL){
  1000. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1001. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1002. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1003. }
  1004. $tr++;
  1005. }
  1006. if($value['category']==$this->TRAIN){
  1007. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1008. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1009. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1010. }
  1011. $ta++;
  1012. }
  1013. if($value['category']==$this->OTHER){
  1014. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1015. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1016. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1017. }
  1018. $ot++;
  1019. }
  1020. }
  1021. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1022. //报销单
  1023. $receipt->accountItem=json_encode($accountJson);
  1024. $receipt->staff=$this->staff[0]['sid'];
  1025. $receipt->loanSum=$receiptDet['sum'];
  1026. $receipt->sum=number_format($sum, 2, '.', '');
  1027. $receipt->date=date("Y-m-d");
  1028. $receipt->pastDate='';
  1029. $receipt->cid=$cid;
  1030. $receipt->status=7;
  1031. //修改审批流程加入角色
  1032. $receipt->verify=$verify;
  1033. $receipt->verifyStaff='';
  1034. $receipt->executeStaff='';
  1035. $receipt->executeCopy=$executeDetail['staff'];
  1036. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1037. $receipt->explanation=$explanation;
  1038. $receipt->update(array('where'=>'rid='.$rid));
  1039. //附件
  1040. if (!empty($enclosurName)){
  1041. $enclosurArray=explode('-', $enclosurName);
  1042. foreach ($enclosurArray as $value){
  1043. $enclosur=new enclosur();
  1044. $enclosur->name=$value;
  1045. $enclosur->rid=$rid;
  1046. $enclosur->insert();
  1047. }
  1048. //print_r($enclosurArray);die;
  1049. }
  1050. //报销详情
  1051. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1052. $receiptDetail=new receiptDetail();
  1053. $receiptDetail->staff=$this->staff[0]['sid'];
  1054. $receiptDetail->item=$value['name'];
  1055. $receiptDetail->itemCategory=$this->AGENCY;
  1056. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1057. $receiptDetail->date=date("Y-m-d");
  1058. $receiptDetail->cid=$cid;
  1059. $receiptDetail->rid=$rid;
  1060. $receiptDetail->status=4;
  1061. $receiptDetail->insert();
  1062. }
  1063. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1064. $receiptDetail=new receiptDetail();
  1065. $receiptDetail->staff=$this->staff[0]['sid'];
  1066. $receiptDetail->item=$value['name'];
  1067. $receiptDetail->itemCategory=$this->TRAVEL;
  1068. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1069. $receiptDetail->date=date("Y-m-d");
  1070. $receiptDetail->cid=$cid;
  1071. $receiptDetail->rid=$rid;
  1072. $receiptDetail->status=4;
  1073. $receiptDetail->insert();
  1074. }
  1075. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1076. $receiptDetail=new receiptDetail();
  1077. $receiptDetail->staff=$this->staff[0]['sid'];
  1078. $receiptDetail->item=$value['name'];
  1079. $receiptDetail->itemCategory=$this->TRAIN;
  1080. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1081. $receiptDetail->date=date("Y-m-d");
  1082. $receiptDetail->cid=$cid;
  1083. $receiptDetail->rid=$rid;
  1084. $receiptDetail->status=4;
  1085. $receiptDetail->insert();
  1086. }
  1087. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1088. $receiptDetail=new receiptDetail();
  1089. $receiptDetail->staff=$this->staff[0]['sid'];
  1090. $receiptDetail->item=$value['name'];
  1091. $receiptDetail->itemCategory=$this->OTHER;
  1092. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1093. $receiptDetail->date=date("Y-m-d");
  1094. $receiptDetail->cid=$cid;
  1095. $receiptDetail->rid=$rid;
  1096. $receiptDetail->status=4;
  1097. $receiptDetail->insert();
  1098. }
  1099. return "/saeaBorad";
  1100. }
  1101. return "/saeaLoanReceiptAdd/".$rid;
  1102. }
  1103. function saeaLoanReceiptEdi(){
  1104. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1105. //echo $rid;
  1106. Doo::loadModel('accountItem');
  1107. Doo::loadModel('verify');
  1108. Doo::loadModel('receipt');
  1109. $receipt=new receipt();
  1110. $verify=new verify();
  1111. $accountItem=new accountItem();
  1112. Doo::loadModel('L_category');
  1113. $Lcategory=new L_category();
  1114. Doo::loadModel("role");
  1115. $role=new role();
  1116. Doo::loadModel('loanReceipt');
  1117. $loanReceipt=new loanReceipt();
  1118. Doo::loadModel('staff');
  1119. $staff=new staff();
  1120. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1121. if(empty($receiptDetail))
  1122. return "/saeaBorad";
  1123. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1124. $Locate=0;$roleId=0;$button=0;
  1125. foreach ($receiptList as $key=>$value){
  1126. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1127. $receiptList[$key]['reviseDetail']=array();
  1128. if (!empty($value['reviseDetail']))
  1129. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1130. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1131. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1132. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1133. $receiptList[$key]['category']=$categoryDetil['title'];
  1134. //检测编辑状态
  1135. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1136. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1137. $verifyStaff=json_decode($value['verifyStaff'],true);
  1138. Doo::loadModel('role');
  1139. $role=new role();
  1140. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1141. foreach ($verifyList as $k=>$v){
  1142. //init verifyStaff
  1143. if ($v[1]=='ROLE'){
  1144. if (!empty($verifyStaff)){
  1145. $endStaffArray=end($verifyStaff);
  1146. // if ($v[0]==$endStaffArray['nextStaff']){
  1147. // $roleId=$v[0];
  1148. // }
  1149. }
  1150. $roleVerify=json_decode($v[3],true);
  1151. $roleKey=$k;$roleArray=array();
  1152. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1153. foreach ($roleVerify as $o=>$p){
  1154. $staffID=explode ('_',$p);
  1155. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1156. //print_r($staffID);
  1157. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1158. array_push($roleArray, $exp);
  1159. }
  1160. $roleArrayCopy[$v[0]]=$roleArray;
  1161. //$verifyList[$k]['roleArray']=$roleArray;
  1162. }
  1163. $verifyList[$k]['date']="";
  1164. $verifyList[$k]['opinion']="";
  1165. $verifyList[$k]['status']="";
  1166. if (empty($verifyStaff)){
  1167. $verifyList[$k]['date']="";
  1168. $verifyList[$k]['opinion']="";
  1169. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1170. $verifyList[$k]['status']=4;
  1171. $flag=false;
  1172. }
  1173. }else{
  1174. foreach ($verifyStaff as $m=>$u){
  1175. if ($v[0]==$m){
  1176. $verifyList[$k]['date']=$u['date'];
  1177. $verifyList[$k]['opinion']=$u['opinion'];
  1178. $verifyList[$k]['status']=$u['status'];
  1179. $flag=false;
  1180. break;
  1181. }
  1182. }
  1183. $endStaffArray=end($verifyStaff);
  1184. if (isset($endStaffArray['ROLE'])){
  1185. }else{
  1186. // $endKey=key($verifyStaff);
  1187. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1188. // $button=4;
  1189. // $verifyList[$k]['status']=4;
  1190. // }
  1191. }
  1192. }
  1193. }
  1194. $rolename['name']='';
  1195. if (!empty($roleId)){
  1196. Doo::loadModel('role');
  1197. $role=new role();
  1198. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1199. }
  1200. if (!empty($verifyStaff))
  1201. $endStaffArray=end($verifyStaff);
  1202. $KOP=false;
  1203. foreach ($roleArrayCopy as $P=>$A){
  1204. foreach ( $A as $MKI=>$AVL){
  1205. if (!empty($verifyStaff)){
  1206. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1207. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1208. $button=4;
  1209. $roleArrayCopy[$P][$MKI]['status']=4;
  1210. }
  1211. foreach ($verifyStaff as $m=>$u){
  1212. $AVLFK=$AVL[0].'_R';
  1213. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1214. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1215. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1216. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1217. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1218. break;
  1219. }
  1220. }
  1221. }else{
  1222. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1223. $button=4;
  1224. $roleArrayCopy[$P][$MKI]['status']=4;
  1225. }
  1226. }
  1227. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1228. $KOP=true;
  1229. }
  1230. }
  1231. foreach ($roleArrayCopy as $k=>$v){
  1232. foreach ($verifyList as $m=>$n){
  1233. if ($n[0]==$k){
  1234. array_splice($verifyList,$m,1,$v);
  1235. }
  1236. }
  1237. }
  1238. $receiptList[$key]['verifyList']=$verifyList;
  1239. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1240. $receiptList[$key]['button']=$button;
  1241. //
  1242. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1243. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1244. }
  1245. $data['receiptList']=$receiptList;
  1246. $acItem=$accountItem->find(array('asArray'=>true));
  1247. $veList=$verify->find(array('asArray'=>true));
  1248. foreach ($veList as $key=>$value){
  1249. $v=json_decode($value['staff']);
  1250. $list=array();
  1251. foreach ($v as $n=>$m){
  1252. if ($m['1']=='ROLE'){
  1253. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1254. $v[$n][1]=$roleInfo['name'];
  1255. array_push($list, $roleInfo['name']);
  1256. }else{
  1257. array_push($list, $v[$n][1]);
  1258. }
  1259. }
  1260. $veList[$key]['staff']=implode('>', $list);
  1261. }
  1262. //配置编辑信息
  1263. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1264. foreach ($acItem as $key=>$value){
  1265. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1266. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1267. $acItem[$key]['price']=$v['price'];
  1268. }
  1269. }
  1270. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1271. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1272. $acItem[$key]['price']=$v['price'];
  1273. }
  1274. }
  1275. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1276. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1277. $acItem[$key]['price']=$v['price'];
  1278. }
  1279. }
  1280. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1281. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1282. $acItem[$key]['price']=$v['price'];
  1283. }
  1284. }
  1285. }
  1286. $data['category']=$Lcategory->find(array('asArray'=>true));
  1287. $data['cSum']=$accountItemList['cSum'];
  1288. $data['sum']=$receiptDetail['sum'];
  1289. $data['receiptDetail']=$receiptDetail;
  1290. $data['veList']=$veList;
  1291. $data['acItem']=$acItem;
  1292. $data['memu']="receipt";
  1293. $data['staff']=$this->staff;
  1294. $data['receiptMemu']='saeaBorad';
  1295. $data['verify']=$receiptDetail['verify'];
  1296. $data['verifyId']=$this->verifyId;
  1297. $data['executeId']=$this->executeId;
  1298. $data['rid']=$rid;
  1299. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1300. }
  1301. function confirmation(){
  1302. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1303. Doo::loadModel('receipt');
  1304. Doo::loadModel('receiptDetail');
  1305. $receipt=new receipt();
  1306. $receiptDetail=new receiptDetail();
  1307. Doo::loadModel('statistics');
  1308. Doo::loadModel('itemStatistics');
  1309. $statistics=new statistics();
  1310. $itemStatistics=new itemStatistics();
  1311. Doo::loadModel("verify");
  1312. $verify=new verify();
  1313. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1314. if(empty($receiptDetailList))
  1315. return "/saeaBorad";
  1316. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1317. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1318. if (empty($receiptDetailList['nowStaff'])){
  1319. $nowStaff="";$nowStaffList=array();
  1320. if ($verifyDetail[0][1]=='ROLE'){
  1321. $vStaffString=json_decode($verifyDetail[0][3]);
  1322. foreach ($vStaffString as $key=>$value){
  1323. $staffK=explode("_", $value);
  1324. array_push($nowStaffList, $staffK[0]);
  1325. }
  1326. $nowStaff=implode(',', $nowStaffList);
  1327. }else{
  1328. $nowStaff=$verifyDetail[0][0];
  1329. }
  1330. $receipt->nowStaff=$nowStaff;
  1331. }
  1332. // echo $nowStaff;
  1333. // print_r($verifyDetail);die;
  1334. $receipt->rid=$receiptDetailList['rid'];
  1335. $receipt->status=2;
  1336. $receipt->update();
  1337. //操作日志
  1338. Doo::loadModel("receiptLog");
  1339. $receiptLog=new receiptLog();
  1340. $verify=new verify();
  1341. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1342. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1343. $jd=json_decode($vr['staff']);$roleId=0;
  1344. foreach ($jd as $key=>$value){
  1345. if ($value[1]=='ROLE'){
  1346. $pos = strpos($value[3], $this->staff[0]['sid']);
  1347. if ($pos !== false) {
  1348. $roleId=$value[0];
  1349. }
  1350. }
  1351. }
  1352. //审批日志
  1353. //echo $roleId;die;
  1354. if (!empty($roleId)){
  1355. Doo::loadModel("role");
  1356. $role=new role();
  1357. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1358. $receiptLog->rolename=$roleInfo['name'];
  1359. }
  1360. $receiptLog->username=$this->staff[0]['username'];
  1361. $receiptLog->uid=$this->staff[0]['sid'];
  1362. $receiptLog->date=date("Y-m-d");
  1363. $receiptLog->opinion='提交审批';
  1364. $receiptLog->img=$this->staff[0]['avatar'];
  1365. $receiptLog->status=2;
  1366. $receiptLog->rid=$rid;
  1367. $receiptLog->insert();
  1368. return "/expenses";
  1369. }
  1370. function expenses(){
  1371. $item=isset($this->params['item'])?$this->params['item']:"";
  1372. if(empty($item))
  1373. $item=$this->get_args('item')?$this->get_args('item'):"";
  1374. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1375. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1376. Doo::loadModel('receipt');
  1377. $receipt=new receipt();
  1378. Doo::loadModel('L_category');
  1379. $Lcategory=new L_category();
  1380. Doo::loadModel('verify');
  1381. Doo::loadModel('statistics');
  1382. $statistics=new statistics();
  1383. $verify=new verify();
  1384. Doo::loadModel('staff');
  1385. $staff=new staff();
  1386. $condition="";
  1387. if($item=="expenses")
  1388. $condition=" and Rtype=1 ";
  1389. elseif ($item=="receipts")
  1390. $condition=" and Rtype=0 ";
  1391. elseif ($item=="remits")
  1392. $condition=" and Rtype=2 ";
  1393. $dateCondition=" and Year(date) =".$year;
  1394. if(!empty($moth)){
  1395. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1396. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1397. }else
  1398. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1399. if(empty($stList))
  1400. $stList=array('rePrice'=>0,'agPrice'=>0);
  1401. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  1402. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  1403. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1404. $Locate=0;$roleId=0;$button=0;
  1405. foreach ($receiptList as $key=>$value){
  1406. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1407. $receiptList[$key]['reviseDetail']=array();
  1408. if (!empty($value['reviseDetail']))
  1409. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1410. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1411. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1412. $receiptList[$key]['category']=$categoryDetil['title'];
  1413. //检测编辑状态
  1414. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1415. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1416. $verifyStaff=json_decode($value['verifyStaff'],true);
  1417. Doo::loadModel('role');
  1418. $role=new role();
  1419. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1420. foreach ($verifyList as $k=>$v){
  1421. //init verifyStaff
  1422. if ($v[1]=='ROLE'){
  1423. if (!empty($verifyStaff)){
  1424. $endStaffArray=end($verifyStaff);
  1425. // if ($v[0]==$endStaffArray['nextStaff']){
  1426. // $roleId=$v[0];
  1427. // }
  1428. }
  1429. $roleVerify=json_decode($v[3],true);
  1430. $roleKey=$k;$roleArray=array();
  1431. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1432. foreach ($roleVerify as $o=>$p){
  1433. $staffID=explode ('_',$p);
  1434. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1435. //print_r($staffID);
  1436. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1437. array_push($roleArray, $exp);
  1438. }
  1439. $roleArrayCopy[$v[0]]=$roleArray;
  1440. //$verifyList[$k]['roleArray']=$roleArray;
  1441. }
  1442. $verifyList[$k]['date']="";
  1443. $verifyList[$k]['opinion']="";
  1444. $verifyList[$k]['status']="";
  1445. if (empty($verifyStaff)){
  1446. $verifyList[$k]['date']="";
  1447. $verifyList[$k]['opinion']="";
  1448. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1449. $verifyList[$k]['status']=4;
  1450. $flag=false;
  1451. }
  1452. }else{
  1453. foreach ($verifyStaff as $m=>$u){
  1454. if ($v[0]==$m){
  1455. $verifyList[$k]['date']=$u['date'];
  1456. $verifyList[$k]['opinion']=$u['opinion'];
  1457. $verifyList[$k]['status']=$u['status'];
  1458. $flag=false;
  1459. break;
  1460. }
  1461. }
  1462. $endStaffArray=end($verifyStaff);
  1463. if (isset($endStaffArray['ROLE'])){
  1464. }else{
  1465. // $endKey=key($verifyStaff);
  1466. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1467. // $button=4;
  1468. // $verifyList[$k]['status']=4;
  1469. // }
  1470. }
  1471. }
  1472. }
  1473. $rolename['name']='';
  1474. if (!empty($roleId)){
  1475. Doo::loadModel('role');
  1476. $role=new role();
  1477. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1478. }
  1479. if (!empty($verifyStaff))
  1480. $endStaffArray=end($verifyStaff);
  1481. $KOP=false;
  1482. foreach ($roleArrayCopy as $P=>$A){
  1483. foreach ( $A as $MKI=>$AVL){
  1484. if (!empty($verifyStaff)){
  1485. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1486. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1487. $button=4;
  1488. $roleArrayCopy[$P][$MKI]['status']=4;
  1489. }
  1490. foreach ($verifyStaff as $m=>$u){
  1491. $AVLFK=$AVL[0].'_R';
  1492. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1493. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1494. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1495. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1496. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1497. break;
  1498. }
  1499. }
  1500. }else{
  1501. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1502. $button=4;
  1503. $roleArrayCopy[$P][$MKI]['status']=4;
  1504. }
  1505. }
  1506. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1507. $KOP=true;
  1508. }
  1509. }
  1510. foreach ($roleArrayCopy as $k=>$v){
  1511. foreach ($verifyList as $m=>$n){
  1512. if ($n[0]==$k){
  1513. array_splice($verifyList,$m,1,$v);
  1514. }
  1515. }
  1516. }
  1517. $receiptList[$key]['verifyList']=$verifyList;
  1518. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1519. $receiptList[$key]['button']=$button;
  1520. }
  1521. //print_r($receiptList);die;
  1522. $mothHtml="";
  1523. for($i=1;$i<=12;$i++){
  1524. if($moth==$i)
  1525. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1526. else
  1527. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1528. }
  1529. $data['mothHtml']=$mothHtml;
  1530. $data['receiptList']=$receiptList;
  1531. $data['memu']="receipt";
  1532. $data['staff']=$this->staff;
  1533. $data['receiptMemu']='expenses';
  1534. $data['verifyId']=$this->verifyId;
  1535. $data['executeId']=$this->executeId;
  1536. $data['item']=$item;
  1537. $data['year']=$year;
  1538. $this->render ( "/admin/expenses", $data );
  1539. }
  1540. function expensesCollect(){
  1541. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1542. Doo::loadModel('receipt');
  1543. $receipt=new receipt();
  1544. Doo::loadModel('L_category');
  1545. $Lcategory=new L_category();
  1546. Doo::loadModel('verify');
  1547. Doo::loadModel('statistics');
  1548. $statistics=new statistics();
  1549. $verify=new verify();
  1550. Doo::loadModel('staff');
  1551. $staff=new staff();
  1552. Doo::loadModel('loanReceipt');
  1553. $loanReceipt=new loanReceipt();
  1554. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1555. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1556. $Locate=0;$roleId=0;$button=0;
  1557. foreach ($loanList as $key=>$value){
  1558. $loanList[$key]['Locate']=$Locate;$Locate++;
  1559. $loanList[$key]['reviseDetail']=array();
  1560. if (!empty($value['reviseDetail']))
  1561. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1562. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1563. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1564. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1565. $loanList[$key]['category']=$categoryDetil['title'];
  1566. //检测编辑状态
  1567. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1568. $verifyList['staff']=$value['verifyBreakup'];
  1569. else
  1570. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1571. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1572. $verifyStaff=json_decode($value['verifyStaff'],true);
  1573. Doo::loadModel('role');
  1574. $role=new role();
  1575. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1576. foreach ($verifyList as $k=>$v){
  1577. //init verifyStaff
  1578. if ($v[1]=='ROLE'){
  1579. if (!empty($verifyStaff)){
  1580. $endStaffArray=end($verifyStaff);
  1581. // if ($v[0]==$endStaffArray['nextStaff']){
  1582. // $roleId=$v[0];
  1583. // }
  1584. }
  1585. $roleVerify=json_decode($v[3],true);
  1586. $roleKey=$k;$roleArray=array();
  1587. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1588. foreach ($roleVerify as $o=>$p){
  1589. $staffID=explode ('_',$p);
  1590. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1591. //print_r($staffID);
  1592. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1593. array_push($roleArray, $exp);
  1594. }
  1595. $roleArrayCopy[$v[0]]=$roleArray;
  1596. //$verifyList[$k]['roleArray']=$roleArray;
  1597. }
  1598. $verifyList[$k]['date']="";
  1599. $verifyList[$k]['opinion']="";
  1600. $verifyList[$k]['status']="";
  1601. if (empty($verifyStaff)){
  1602. $verifyList[$k]['date']="";
  1603. $verifyList[$k]['opinion']="";
  1604. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1605. $verifyList[$k]['status']=4;
  1606. $flag=false;
  1607. }
  1608. }else{
  1609. foreach ($verifyStaff as $m=>$u){
  1610. if ($v[0]==$m){
  1611. $verifyList[$k]['date']=$u['date'];
  1612. $verifyList[$k]['opinion']=$u['opinion'];
  1613. $verifyList[$k]['status']=$u['status'];
  1614. $flag=false;
  1615. break;
  1616. }
  1617. }
  1618. $endStaffArray=end($verifyStaff);
  1619. if (isset($endStaffArray['ROLE'])){
  1620. }else{
  1621. // $endKey=key($verifyStaff);
  1622. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1623. // $button=4;
  1624. // $verifyList[$k]['status']=4;
  1625. // }
  1626. }
  1627. }
  1628. }
  1629. $rolename['name']='';
  1630. if (!empty($roleId)){
  1631. Doo::loadModel('role');
  1632. $role=new role();
  1633. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1634. }
  1635. if (!empty($verifyStaff))
  1636. $endStaffArray=end($verifyStaff);
  1637. $KOP=false;
  1638. foreach ($roleArrayCopy as $P=>$A){
  1639. foreach ( $A as $MKI=>$AVL){
  1640. if (!empty($verifyStaff)){
  1641. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1642. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1643. $button=4;
  1644. $roleArrayCopy[$P][$MKI]['status']=4;
  1645. }
  1646. foreach ($verifyStaff as $m=>$u){
  1647. $AVLFK=$AVL[0].'_R';
  1648. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1649. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1650. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1651. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1652. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1653. break;
  1654. }
  1655. }
  1656. }else{
  1657. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1658. $button=4;
  1659. $roleArrayCopy[$P][$MKI]['status']=4;
  1660. }
  1661. }
  1662. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1663. $KOP=true;
  1664. }
  1665. }
  1666. foreach ($roleArrayCopy as $k=>$v){
  1667. foreach ($verifyList as $m=>$n){
  1668. if ($n[0]==$k){
  1669. array_splice($verifyList,$m,1,$v);
  1670. }
  1671. }
  1672. }
  1673. $loanList[$key]['verifyList']=$verifyList;
  1674. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1675. $loanList[$key]['button']=$button;
  1676. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1677. }
  1678. $data['loanList']=$loanList;
  1679. $Locate=0;$roleId=0;$button=0;
  1680. foreach ($receiptList as $key=>$value){
  1681. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1682. $receiptList[$key]['reviseDetail']=array();
  1683. if (!empty($value['reviseDetail']))
  1684. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1685. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1686. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1687. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1688. $receiptList[$key]['category']=$categoryDetil['title'];
  1689. //检测编辑状态
  1690. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1691. if($value['status']==8&&$value['Rtype']==1)
  1692. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1693. else
  1694. $verifyList['staff']=$value['verifyBreakup'];
  1695. }else
  1696. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1697. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1698. $verifyStaff=json_decode($value['verifyStaff'],true);
  1699. Doo::loadModel('role');
  1700. $role=new role();
  1701. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1702. foreach ($verifyList as $k=>$v){
  1703. //init verifyStaff
  1704. if ($v[1]=='ROLE'){
  1705. if (!empty($verifyStaff)){
  1706. $endStaffArray=end($verifyStaff);
  1707. // if ($v[0]==$endStaffArray['nextStaff']){
  1708. // $roleId=$v[0];
  1709. // }
  1710. }
  1711. $roleVerify=json_decode($v[3],true);
  1712. $roleKey=$k;$roleArray=array();
  1713. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1714. foreach ($roleVerify as $o=>$p){
  1715. $staffID=explode ('_',$p);
  1716. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1717. //print_r($staffID);
  1718. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1719. array_push($roleArray, $exp);
  1720. }
  1721. $roleArrayCopy[$v[0]]=$roleArray;
  1722. //$verifyList[$k]['roleArray']=$roleArray;
  1723. }
  1724. $verifyList[$k]['date']="";
  1725. $verifyList[$k]['opinion']="";
  1726. $verifyList[$k]['status']="";
  1727. if (empty($verifyStaff)){
  1728. $verifyList[$k]['date']="";
  1729. $verifyList[$k]['opinion']="";
  1730. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1731. $verifyList[$k]['status']=4;
  1732. $flag=false;
  1733. }
  1734. }else{
  1735. foreach ($verifyStaff as $m=>$u){
  1736. if ($v[0]==$m){
  1737. $verifyList[$k]['date']=$u['date'];
  1738. $verifyList[$k]['opinion']=$u['opinion'];
  1739. $verifyList[$k]['status']=$u['status'];
  1740. $flag=false;
  1741. break;
  1742. }
  1743. }
  1744. $endStaffArray=end($verifyStaff);
  1745. if (isset($endStaffArray['ROLE'])){
  1746. }else{
  1747. // $endKey=key($verifyStaff);
  1748. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1749. // $button=4;
  1750. // $verifyList[$k]['status']=4;
  1751. // }
  1752. }
  1753. }
  1754. }
  1755. $rolename['name']='';
  1756. if (!empty($roleId)){
  1757. Doo::loadModel('role');
  1758. $role=new role();
  1759. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1760. }
  1761. if (!empty($verifyStaff))
  1762. $endStaffArray=end($verifyStaff);
  1763. $KOP=false;
  1764. foreach ($roleArrayCopy as $P=>$A){
  1765. foreach ( $A as $MKI=>$AVL){
  1766. if (!empty($verifyStaff)){
  1767. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1768. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1769. $button=4;
  1770. $roleArrayCopy[$P][$MKI]['status']=4;
  1771. }
  1772. foreach ($verifyStaff as $m=>$u){
  1773. $AVLFK=$AVL[0].'_R';
  1774. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1775. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1776. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1777. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1778. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1779. break;
  1780. }
  1781. }
  1782. }else{
  1783. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1784. $button=4;
  1785. $roleArrayCopy[$P][$MKI]['status']=4;
  1786. }
  1787. }
  1788. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1789. $KOP=true;
  1790. }
  1791. }
  1792. foreach ($roleArrayCopy as $k=>$v){
  1793. foreach ($verifyList as $m=>$n){
  1794. if ($n[0]==$k){
  1795. array_splice($verifyList,$m,1,$v);
  1796. }
  1797. }
  1798. }
  1799. //费用执行人相关数据
  1800. $executeCopy=json_decode($value['executeCopy'],true);
  1801. $executeStaff=json_decode($value['executeStaff'],true);
  1802. foreach ($executeCopy as $k=>$v){
  1803. $executeCopy[$k]['date']='';
  1804. $executeCopy[$k]['opinion']='';
  1805. $executeCopy[$k]['status']='';
  1806. if (!empty($executeStaff))
  1807. foreach ($executeStaff as $m=>$u){
  1808. if ($v[0]==$m){
  1809. $executeCopy[$k]['date']=$u['date'];
  1810. $executeCopy[$k]['opinion']=$u['opinion'];
  1811. $executeCopy[$k]['status']=$u['status'];
  1812. break;
  1813. }
  1814. }
  1815. }
  1816. $receiptList[$key]['executeCopy']=$executeCopy;
  1817. $receiptList[$key]['verifyList']=$verifyList;
  1818. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1819. $receiptList[$key]['button']=$button;
  1820. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1821. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1822. $relust=$value['sum']-$value['loanSum'];
  1823. $receiptList[$key]['relust']=$relust;
  1824. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1825. }
  1826. $data['receiptList']=$receiptList;
  1827. $data['memu']="receipt";
  1828. $data['staff']=$this->staff;
  1829. $data['receiptMemu']='expenses';
  1830. $data['verifyId']=$this->verifyId;
  1831. $data['executeId']=$this->executeId;
  1832. $this->render ( "/admin/expensesCollect", $data );
  1833. }
  1834. function approvalExpenses(){
  1835. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1836. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1837. $month=$this->get_args('month')?$this->get_args('month'):"";
  1838. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1839. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1840. if (empty($status))
  1841. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1842. $page_size=12;
  1843. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1844. $vidList=array();
  1845. $button=0;
  1846. Doo::loadModel('verify');
  1847. $verify=new verify();
  1848. Doo::loadModel('receipt');
  1849. $receipt=new receipt();
  1850. Doo::loadModel('staff');
  1851. $staff=new staff();
  1852. Doo::loadModel('L_category');
  1853. $Lcategory=new L_category();
  1854. //user verify ID
  1855. $verifyDetail=$verify->find(array('where'=>' (staff not like "%\"'.$this->staff[0]['sid'].'\",\"ROLE%") and (staff like "%[\"'.$this->staff[0]['sid'].'\",%" or staff like "%\"'.$this->staff[0]['sid'].'\_%" )','asArray'=>true));
  1856. foreach ($verifyDetail as $key=>$value){
  1857. array_push($vidList, $value['vid']);
  1858. }
  1859. $vid=implode(",", $vidList);
  1860. if(empty($verifyDetail))
  1861. $vid=0;
  1862. // if ($status==0)
  1863. // $dateCondition="";
  1864. // else
  1865. $dateCondition=" and Year(date) =".$year;
  1866. if(!empty($month))
  1867. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1868. $categoryList=$Lcategory->find(array('asArray'=>true));
  1869. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1870. $cateCondition="";$staffCondition="";$approvalCondition="";
  1871. if (!empty($cid))
  1872. $cateCondition=' and cid='.$cid;
  1873. if(!empty($sid)){
  1874. $staffCondition=' and staff='.$sid;
  1875. $cateCondition="";
  1876. }
  1877. $approvalCondition=" and status=".$status;
  1878. if($status==2){
  1879. //查找角色审批人
  1880. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1881. }
  1882. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1883. $approvalCondition=' and status=2 ';
  1884. }
  1885. if($status==1){
  1886. $approvalCondition=' and (status='.$status.' or status=6) ';
  1887. }
  1888. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1889. $pageinfo['page']=array('previous'=>'');
  1890. if ($status==0){
  1891. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1892. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1893. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1894. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1895. }else
  1896. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1897. ,'desc'=>'rid','asArray'=>true));
  1898. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )'.$cateCondition.$staffCondition
  1899. ,'desc'=>'rid','asArray'=>true));
  1900. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1901. //print_r($pageinfo);
  1902. $Locate=0;
  1903. foreach ($receiptList as $key=>$value){
  1904. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1905. $receiptList[$key]['reviseDetail']=array();
  1906. if (!empty($value['reviseDetail']))
  1907. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1908. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1909. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1910. $receiptList[$key]['category']=$categoryDetil['title'];
  1911. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1912. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1913. $verifyStaff=json_decode($value['verifyStaff'],true);
  1914. foreach ($verifyList as $k=>$v){
  1915. //init verifyStaff
  1916. $verifyList[$k]['date']="";
  1917. $verifyList[$k]['opinion']="";
  1918. $verifyList[$k]['status']="";
  1919. if (empty($verifyStaff)){
  1920. $verifyList[$k]['date']="";
  1921. $verifyList[$k]['opinion']="";
  1922. if ($v[0]==$this->staff[0]['sid']){
  1923. $verifyList[$k]['status']=4;
  1924. $button=4;
  1925. }
  1926. }else{
  1927. $flag=true;
  1928. foreach ($verifyStaff as $m=>$u){
  1929. if ($v[0]==$m){
  1930. $verifyList[$k]['date']=$u['date'];
  1931. $verifyList[$k]['opinion']=$u['opinion'];
  1932. $verifyList[$k]['status']=$u['status'];
  1933. $flag=false;
  1934. break;
  1935. }
  1936. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1937. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1938. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1939. }
  1940. if($flag){//检测可编辑
  1941. if($v[0]==$this->staff[0]['sid']){
  1942. $verifyList[$k]['status']=4;$button=4;
  1943. }
  1944. }
  1945. }
  1946. }
  1947. $receiptList[$key]['verifyList']=$verifyList;
  1948. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1949. $receiptList[$key]['button']=$button;
  1950. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1951. }
  1952. //print_r($receiptList);die;
  1953. //$data['verifyDetail']=$verifyDetail;
  1954. $mothHtml="";
  1955. for($i=1;$i<=12;$i++){
  1956. if($month==$i)
  1957. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1958. else
  1959. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1960. }
  1961. $data['mothHtml']=$mothHtml;
  1962. $data['page']=$pageinfo;
  1963. $data['receiptList']=$receiptList;
  1964. $data['receiptApprovalCount']=count($rLRes);
  1965. $data['status']=$status;
  1966. $data['year']=$year;
  1967. $data['categoryList']=$categoryList;
  1968. $data['staffList']=$staffList;
  1969. $data['cid']=$cid;
  1970. $data['sid']=$sid;
  1971. //print_r($receiptList);
  1972. $data['memu']="receipt";
  1973. $data['staff']=$this->staff;
  1974. $data['receiptMemu']='approvalExpenses';
  1975. $data['verifyId']=$this->verifyId;
  1976. $data['executeId']=$this->executeId;
  1977. $this->render ( "/admin/approvalExpenses", $data );
  1978. }
  1979. function expensesDoc(){
  1980. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1981. Doo::loadModel('receipt');
  1982. $receipt=new receipt();
  1983. Doo::loadModel('L_category');
  1984. $Lcategory=new L_category();
  1985. Doo::loadModel('verify');
  1986. Doo::loadModel('statistics');
  1987. $statistics=new statistics();
  1988. $verify=new verify();
  1989. Doo::loadModel('staff');
  1990. $staff=new staff();
  1991. Doo::loadModel('loanReceipt');
  1992. $loanReceipt=new loanReceipt();
  1993. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  1994. $loanList=array();
  1995. if (!empty($receiptList))
  1996. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1997. $Locate=0;$roleId=0;$button=0;
  1998. foreach ($loanList as $key=>$value){
  1999. $loanList[$key]['Locate']=$Locate;$Locate++;
  2000. $loanList[$key]['reviseDetail']=array();
  2001. if (!empty($value['reviseDetail']))
  2002. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2003. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2004. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2005. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2006. $loanList[$key]['category']=$categoryDetil['title'];
  2007. //检测编辑状态
  2008. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  2009. $verifyList['staff']=$value['verifyBreakup'];
  2010. else
  2011. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2012. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2013. $verifyStaff=json_decode($value['verifyStaff'],true);
  2014. Doo::loadModel('role');
  2015. $role=new role();
  2016. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2017. foreach ($verifyList as $k=>$v){
  2018. //init verifyStaff
  2019. if ($v[1]=='ROLE'){
  2020. if (!empty($verifyStaff)){
  2021. $endStaffArray=end($verifyStaff);
  2022. // if ($v[0]==$endStaffArray['nextStaff']){
  2023. // $roleId=$v[0];
  2024. // }
  2025. }
  2026. $roleVerify=json_decode($v[3],true);
  2027. $roleKey=$k;$roleArray=array();
  2028. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2029. foreach ($roleVerify as $o=>$p){
  2030. $staffID=explode ('_',$p);
  2031. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2032. //print_r($staffID);
  2033. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2034. array_push($roleArray, $exp);
  2035. }
  2036. $roleArrayCopy[$v[0]]=$roleArray;
  2037. //$verifyList[$k]['roleArray']=$roleArray;
  2038. }
  2039. $verifyList[$k]['date']="";
  2040. $verifyList[$k]['opinion']="";
  2041. $verifyList[$k]['status']="";
  2042. if (empty($verifyStaff)){
  2043. $verifyList[$k]['date']="";
  2044. $verifyList[$k]['opinion']="";
  2045. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2046. $verifyList[$k]['status']=4;
  2047. $flag=false;
  2048. }
  2049. }else{
  2050. foreach ($verifyStaff as $m=>$u){
  2051. if ($v[0]==$m){
  2052. $verifyList[$k]['date']=$u['date'];
  2053. $verifyList[$k]['opinion']=$u['opinion'];
  2054. $verifyList[$k]['status']=$u['status'];
  2055. $flag=false;
  2056. break;
  2057. }
  2058. }
  2059. $endStaffArray=end($verifyStaff);
  2060. if (isset($endStaffArray['ROLE'])){
  2061. }else{
  2062. // $endKey=key($verifyStaff);
  2063. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2064. // $button=4;
  2065. // $verifyList[$k]['status']=4;
  2066. // }
  2067. }
  2068. }
  2069. }
  2070. $rolename['name']='';
  2071. if (!empty($roleId)){
  2072. Doo::loadModel('role');
  2073. $role=new role();
  2074. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2075. }
  2076. if (!empty($verifyStaff))
  2077. $endStaffArray=end($verifyStaff);
  2078. $KOP=false;
  2079. foreach ($roleArrayCopy as $P=>$A){
  2080. foreach ( $A as $MKI=>$AVL){
  2081. if (!empty($verifyStaff)){
  2082. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2083. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2084. $button=4;
  2085. $roleArrayCopy[$P][$MKI]['status']=4;
  2086. }
  2087. foreach ($verifyStaff as $m=>$u){
  2088. $AVLFK=$AVL[0].'_R';
  2089. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2090. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2091. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2092. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2093. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2094. break;
  2095. }
  2096. }
  2097. }else{
  2098. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2099. $button=4;
  2100. $roleArrayCopy[$P][$MKI]['status']=4;
  2101. }
  2102. }
  2103. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2104. $KOP=true;
  2105. }
  2106. }
  2107. foreach ($roleArrayCopy as $k=>$v){
  2108. foreach ($verifyList as $m=>$n){
  2109. if ($n[0]==$k){
  2110. array_splice($verifyList,$m,1,$v);
  2111. }
  2112. }
  2113. }
  2114. $loanList[$key]['verifyList']=$verifyList;
  2115. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2116. $loanList[$key]['button']=$button;
  2117. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2118. }
  2119. $data['loanList']=$loanList;
  2120. //print_r($loanList);
  2121. $Locate=0;$roleId=0;$button=0;
  2122. foreach ($receiptList as $key=>$value){
  2123. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2124. $receiptList[$key]['reviseDetail']=array();
  2125. if (!empty($value['reviseDetail']))
  2126. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2127. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2128. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2129. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2130. $receiptList[$key]['category']=$categoryDetil['title'];
  2131. //检测编辑状态
  2132. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2133. $verifyList['staff']=$value['verifyBreakup'];
  2134. }else
  2135. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2136. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2137. $verifyStaff=json_decode($value['verifyStaff'],true);
  2138. Doo::loadModel('role');
  2139. $role=new role();
  2140. if ($verifyList==NULL)
  2141. $verifyList=array();
  2142. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2143. foreach ($verifyList as $k=>$v){
  2144. //init verifyStaff
  2145. if ($v[1]=='ROLE'){
  2146. if (!empty($verifyStaff)){
  2147. $endStaffArray=end($verifyStaff);
  2148. // if ($v[0]==$endStaffArray['nextStaff']){
  2149. // $roleId=$v[0];
  2150. // }
  2151. }
  2152. $roleVerify=json_decode($v[3],true);
  2153. $roleKey=$k;$roleArray=array();
  2154. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2155. foreach ($roleVerify as $o=>$p){
  2156. $staffID=explode ('_',$p);
  2157. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2158. //print_r($staffID);
  2159. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2160. array_push($roleArray, $exp);
  2161. }
  2162. $roleArrayCopy[$v[0]]=$roleArray;
  2163. //$verifyList[$k]['roleArray']=$roleArray;
  2164. }
  2165. $verifyList[$k]['date']="";
  2166. $verifyList[$k]['opinion']="";
  2167. $verifyList[$k]['status']="";
  2168. if (empty($verifyStaff)){
  2169. $verifyList[$k]['date']="";
  2170. $verifyList[$k]['opinion']="";
  2171. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2172. $verifyList[$k]['status']=4;
  2173. $flag=false;
  2174. }
  2175. }else{
  2176. foreach ($verifyStaff as $m=>$u){
  2177. if ($v[0]==$m){
  2178. $verifyList[$k]['date']=$u['date'];
  2179. $verifyList[$k]['opinion']=$u['opinion'];
  2180. $verifyList[$k]['status']=$u['status'];
  2181. $flag=false;
  2182. break;
  2183. }
  2184. }
  2185. $endStaffArray=end($verifyStaff);
  2186. if (isset($endStaffArray['ROLE'])){
  2187. }else{
  2188. // $endKey=key($verifyStaff);
  2189. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2190. // $button=4;
  2191. // $verifyList[$k]['status']=4;
  2192. // }
  2193. }
  2194. }
  2195. }
  2196. $rolename['name']='';
  2197. if (!empty($roleId)){
  2198. Doo::loadModel('role');
  2199. $role=new role();
  2200. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2201. }
  2202. if (!empty($verifyStaff))
  2203. $endStaffArray=end($verifyStaff);
  2204. $KOP=false;
  2205. foreach ($roleArrayCopy as $P=>$A){
  2206. foreach ( $A as $MKI=>$AVL){
  2207. if (!empty($verifyStaff)){
  2208. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2209. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2210. $button=4;
  2211. $roleArrayCopy[$P][$MKI]['status']=4;
  2212. }
  2213. foreach ($verifyStaff as $m=>$u){
  2214. $AVLFK=$AVL[0].'_R';
  2215. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2216. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2217. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2218. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2219. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2220. break;
  2221. }
  2222. }
  2223. }else{
  2224. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2225. $button=4;
  2226. $roleArrayCopy[$P][$MKI]['status']=4;
  2227. }
  2228. }
  2229. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2230. $KOP=true;
  2231. }
  2232. }
  2233. foreach ($roleArrayCopy as $k=>$v){
  2234. foreach ($verifyList as $m=>$n){
  2235. if ($n[0]==$k){
  2236. array_splice($verifyList,$m,1,$v);
  2237. }
  2238. }
  2239. }
  2240. //费用执行人相关数据
  2241. $executeCopy=json_decode($value['executeCopy'],true);
  2242. $executeStaff=json_decode($value['executeStaff'],true);
  2243. foreach ($executeCopy as $k=>$v){
  2244. $executeCopy[$k]['date']='';
  2245. $executeCopy[$k]['opinion']='';
  2246. $executeCopy[$k]['status']='';
  2247. if (!empty($executeStaff))
  2248. foreach ($executeStaff as $m=>$u){
  2249. if ($v[0]==$m){
  2250. $executeCopy[$k]['date']=$u['date'];
  2251. $executeCopy[$k]['opinion']=$u['opinion'];
  2252. $executeCopy[$k]['status']=$u['status'];
  2253. break;
  2254. }
  2255. }
  2256. }
  2257. $receiptList[$key]['executeCopy']=$executeCopy;
  2258. $receiptList[$key]['verifyList']=$verifyList;
  2259. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2260. $receiptList[$key]['button']=$button;
  2261. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2262. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2263. }
  2264. //print_r($receiptList);
  2265. //获取审批日志
  2266. Doo::loadModel('receiptLog');
  2267. $receiptLog=new receiptLog();
  2268. $rlList=array();
  2269. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2270. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2271. if (!empty($rlInfo)){
  2272. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2273. }
  2274. $receiptList[0]['rlList']=$rlList;
  2275. $data['receiptList']=$receiptList;
  2276. $data['memu']="receipt";
  2277. $data['staff']=$this->staff;
  2278. $data['receiptMemu']='approvalExpenses';
  2279. $data['verifyId']=$this->verifyId;
  2280. $data['executeId']=$this->executeId;
  2281. $this->render ( "/admin/expensesDoc", $data );
  2282. }
  2283. function expensesEdi(){
  2284. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2285. $status=isset($this->params['status'])?$this->params['status']:'';
  2286. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2287. $month=$this->get_args('month')?$this->get_args('month'):"";
  2288. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2289. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2290. if (empty($status))
  2291. $status=$this->get_args('status')?$this->get_args('status'):2;
  2292. $vidList=array();
  2293. $button=0;
  2294. Doo::loadModel('verify');
  2295. Doo::loadModel('receipt');
  2296. Doo::loadModel('staff');
  2297. $staff=new staff();
  2298. $receipt=new receipt();
  2299. $verify=new verify();
  2300. Doo::loadModel('L_category');
  2301. $Lcategory=new L_category();
  2302. Doo::loadModel('enclosur');
  2303. $enclosur=new enclosur();
  2304. //user verify ID
  2305. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2306. foreach ($verifyDetail as $key=>$value){
  2307. array_push($vidList, $value['vid']);
  2308. }
  2309. $vid=implode(",", $vidList);
  2310. if(empty($verifyDetail))
  2311. $vid=0;
  2312. $categoryList=$Lcategory->find(array('asArray'=>true));
  2313. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2314. $ap="";
  2315. if($status==4){
  2316. $ap=4;$status=2;
  2317. }
  2318. //get Receipt By verifyID status 2
  2319. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2320. $Locate=0;$roleId=0;
  2321. if($ap==4)
  2322. $status=4;
  2323. foreach ($receiptList as $key=>$value){
  2324. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2325. $receiptList[$key]['reviseDetail']=array();
  2326. if (!empty($value['reviseDetail']))
  2327. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2328. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2329. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2330. $receiptList[$key]['category']=$categoryDetil['title'];
  2331. //检测编辑状态
  2332. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2333. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2334. $verifyStaff=json_decode($value['verifyStaff'],true);
  2335. Doo::loadModel('role');
  2336. $role=new role();
  2337. //print_r($verifyList);
  2338. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2339. foreach ($verifyList as $k=>$v){
  2340. //init verifyStaff
  2341. if ($v[1]=='ROLE'){
  2342. if (!empty($verifyStaff)){
  2343. $endStaffArray=end($verifyStaff);
  2344. if ($v[0]==$endStaffArray['nextStaff']){
  2345. $roleId=$v[0];
  2346. }
  2347. }
  2348. $roleVerify=json_decode($v[3],true);
  2349. $roleKey=$k;$roleArray=array();
  2350. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2351. foreach ($roleVerify as $o=>$p){
  2352. $staffID=explode ('_',$p);
  2353. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2354. //print_r($staffID);
  2355. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2356. array_push($roleArray, $exp);
  2357. }
  2358. $roleArrayCopy[$v[0]]=$roleArray;
  2359. //$verifyList[$k]['roleArray']=$roleArray;
  2360. }
  2361. //print_r($roleArray);
  2362. $verifyList[$k]['date']="";
  2363. $verifyList[$k]['opinion']="";
  2364. $verifyList[$k]['status']="";
  2365. if (empty($verifyStaff)){
  2366. $verifyList[$k]['date']="";
  2367. $verifyList[$k]['opinion']="";
  2368. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2369. $verifyList[$k]['status']=4;
  2370. $button=4;$flag=false;
  2371. }
  2372. }else{
  2373. foreach ($verifyStaff as $m=>$u){
  2374. if ($v[0]==$m){
  2375. $verifyList[$k]['date']=$u['date'];
  2376. $verifyList[$k]['opinion']=$u['opinion'];
  2377. $verifyList[$k]['status']=$u['status'];
  2378. $flag=false;
  2379. break;
  2380. }
  2381. }
  2382. $endStaffArray=end($verifyStaff);
  2383. if (isset($endStaffArray['ROLE'])){
  2384. }else{
  2385. $endKey=key($verifyStaff);
  2386. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2387. $button=4;
  2388. $verifyList[$k]['status']=4;
  2389. }
  2390. }
  2391. }
  2392. }
  2393. $rolename['name']='';
  2394. if (!empty($roleId)){
  2395. Doo::loadModel('role');
  2396. $role=new role();
  2397. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2398. }
  2399. if (!empty($verifyStaff))
  2400. $endStaffArray=end($verifyStaff);
  2401. $KOP=false;
  2402. foreach ($roleArrayCopy as $P=>$A){
  2403. foreach ( $A as $MKI=>$AVL){
  2404. if (!empty($verifyStaff)){
  2405. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2406. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2407. $button=4;
  2408. $roleArrayCopy[$P][$MKI]['status']=4;
  2409. }
  2410. foreach ($verifyStaff as $m=>$u){
  2411. $AVLFK=$AVL[0].'_R';
  2412. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2413. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2414. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2415. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2416. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2417. break;
  2418. }
  2419. }
  2420. }else{
  2421. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2422. $button=4;
  2423. $roleArrayCopy[$P][$MKI]['status']=4;
  2424. }
  2425. }
  2426. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2427. $KOP=true;
  2428. }
  2429. }
  2430. // print_r($roleArrayCopy);
  2431. // echo $roleKey;
  2432. foreach ($roleArrayCopy as $k=>$v){
  2433. foreach ($verifyList as $m=>$n){
  2434. if ($n[0]==$k){
  2435. array_splice($verifyList,$m,1,$v);
  2436. }
  2437. }
  2438. }
  2439. $receiptList[$key]['verifyList']=$verifyList;
  2440. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2441. $receiptList[$key]['button']=$button;
  2442. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2443. }
  2444. //$data['verifyDetail']=$verifyDetail;
  2445. $mothHtml="";
  2446. for($i=1;$i<=12;$i++){
  2447. if($month==$i)
  2448. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2449. else
  2450. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2451. }
  2452. //获取审批日志
  2453. Doo::loadModel('receiptLog');
  2454. $receiptLog=new receiptLog();
  2455. $rlList=array();
  2456. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2457. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2458. if (!empty($rlInfo)){
  2459. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2460. }
  2461. $receiptList[0]['rlList']=$rlList;
  2462. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2463. $enclosurHtml='';
  2464. foreach ($enclosurList as $value){
  2465. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2466. }
  2467. //print_r($receiptList);
  2468. $data['rid']=$rid;
  2469. $data['enclosurHtml']=$enclosurHtml;
  2470. $data['rolename']=$rolename['name'];
  2471. $data['datetij']=$tijdate['date'];
  2472. $data['mothHtml']=$mothHtml;
  2473. $data['receiptList']=$receiptList;
  2474. $data['receiptApprovalCount']=count($receiptList);
  2475. $data['status']=$status;
  2476. $data['year']=$year;
  2477. $data['categoryList']=$categoryList;
  2478. $data['staffList']=$staffList;
  2479. $data['cid']=$cid;
  2480. $data['sid']=$sid;
  2481. $data['ap']=$ap;
  2482. $data['memu']="receipt";
  2483. $data['staff']=$this->staff;
  2484. $data['receiptMemu']='approvalExpenses';
  2485. $data['verifyId']=$this->verifyId;
  2486. $data['executeId']=$this->executeId;
  2487. $this->render ( "/admin/expensesEdi", $data );
  2488. }
  2489. function expensesDefray(){
  2490. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2491. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2492. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2493. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2494. if(!empty($rid)){
  2495. Doo::loadModel("verify");
  2496. $verify=new verify();
  2497. Doo::loadModel("receiptDetail");
  2498. $receiptDetailObj=new receiptDetail();
  2499. Doo::loadModel("itemStatistics");
  2500. Doo::loadModel("statistics");
  2501. $statistics=new statistics();
  2502. $itemStatistics=new itemStatistics();
  2503. Doo::loadModel("receipt");
  2504. $receipt=new receipt();
  2505. Doo::loadModel("loanReceipt");
  2506. $loanReceipt=new loanReceipt();
  2507. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2508. if (empty($receiptDetail))
  2509. return "/approval";
  2510. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2511. $verifyString=$verifyDetail['staff'];
  2512. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2513. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2514. if(empty($opinion)){
  2515. if ($status==3)
  2516. $opinion="终止";
  2517. else
  2518. $opinion="同意支付";
  2519. }
  2520. $nowStaff=0;$nowStaffList=array();
  2521. if(empty($verifyStaff)){
  2522. //还需加入是否已经进入角色审批
  2523. if ($verifyDetail[0][1]=='ROLE'){
  2524. //print_r($verifyDetail);echo "ddd";
  2525. $vStaffString=json_decode($verifyDetail[0][3]);
  2526. foreach ($vStaffString as $key=>$value){
  2527. $staffK=explode("_", $value);
  2528. if ($staffK[0]!=$this->staff[0]['sid'])
  2529. array_push($nowStaffList, $staffK[0]);
  2530. }
  2531. //print_r($verifyDetail);
  2532. //die;
  2533. $nowStaff=implode(',', $nowStaffList);
  2534. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2535. }else{
  2536. if ($verifyDetail[1][1]=='ROLE'){
  2537. $vStaffString=json_decode($verifyDetail[1][3]);
  2538. //echo "dd";
  2539. foreach ($vStaffString as $key=>$value){
  2540. $staffK=explode("_", $value);
  2541. array_push($nowStaffList, $staffK[0]);
  2542. }
  2543. $nowStaff=implode(',', $nowStaffList);
  2544. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2545. }else{
  2546. $nowStaff=$verifyDetail[1][0];
  2547. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2548. }
  2549. }
  2550. if($status==3)
  2551. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2552. $vStaffString=json_encode($verifyStaff);
  2553. $receipt->nowStaff=$nowStaff;
  2554. $receipt->verifyStaff=$vStaffString;
  2555. $loanReceipt->nowStaff=$nowStaff;
  2556. $loanReceipt->verifyStaff=$vStaffString;
  2557. }else{
  2558. $VS=end($verifyStaff);
  2559. //非角色审批
  2560. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2561. $nextStaff=0;$roleSTF=false;
  2562. foreach ($verifyDetail as $key=>$value){
  2563. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2564. if (isset($verifyDetail[$key+1])){
  2565. $nextStaff=$verifyDetail[$key+1][0];
  2566. if ($verifyDetail[$key+1][1]=='ROLE')
  2567. $roleSTF=true;
  2568. }
  2569. break;
  2570. }
  2571. }
  2572. if (!$roleSTF){
  2573. $nowStaff=$nextStaff;
  2574. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2575. }else{
  2576. //获取角色下的所有用户ID
  2577. $nowStaffList=array();
  2578. foreach ($verifyDetail as $vfk){
  2579. if ($vfk[1]=='ROLE'){
  2580. $vStaffString=json_decode($vfk[3]);
  2581. foreach ($vStaffString as $key=>$value){
  2582. $staffK=explode("_", $value);
  2583. array_push($nowStaffList, $staffK[0]);
  2584. }
  2585. }
  2586. }
  2587. $nowStaff=implode(',', $nowStaffList);
  2588. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2589. }
  2590. if($status==3){
  2591. $verifyStaff['final']=$status;
  2592. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2593. }
  2594. $vStaffString=json_encode($verifyStaff);
  2595. $receipt->nowStaff=$nowStaff;
  2596. $receipt->verifyStaff=$vStaffString;
  2597. $loanReceipt->nowStaff=$nowStaff;
  2598. $loanReceipt->verifyStaff=$vStaffString;
  2599. }
  2600. //角色审批
  2601. if (isset($VS['ROLE'])){
  2602. //找出角色人 当前审批角色组
  2603. $verifyJSStaff=array();$nowStaffList2=array();
  2604. foreach ($verifyDetail as $key=>$value){
  2605. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2606. $verifyJSStaff=json_decode($value[3]);
  2607. foreach ($verifyJSStaff as $m){
  2608. $staffK=explode("_", $m);
  2609. array_push($nowStaffList2, $staffK[0]);
  2610. }
  2611. // print_r($nowStaffList2);
  2612. }
  2613. }
  2614. $RoleVerifyStaff=array();
  2615. foreach ($verifyStaff as $key=>$value){
  2616. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2617. foreach ($nowStaffList2 as $m) {
  2618. if ($key==$m."_R")
  2619. $RoleVerifyStaff[$key]=$value;
  2620. }
  2621. }
  2622. }
  2623. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2624. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2625. //下一个审批人ID
  2626. $nextStaff=0;$falg=false;
  2627. foreach ($verifyDetail as $key=>$value){
  2628. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2629. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2630. $falg=true;
  2631. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2632. foreach ($vStaffString as $v){
  2633. $staffK=explode("_", $v);
  2634. array_push($nowStaffList, $staffK[0]);
  2635. }
  2636. $nowStaff=implode(',', $nowStaffList);
  2637. $nextStaff=$verifyDetail[$key+1][0];
  2638. }elseif(isset($verifyDetail[$key+1])){
  2639. $nextStaff=$verifyDetail[$key+1][0];
  2640. $nowStaff=$nextStaff;
  2641. }else
  2642. $nowStaff='';
  2643. break;
  2644. }
  2645. }
  2646. if ($falg)
  2647. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2648. else
  2649. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2650. // print_r($verifyStaff);
  2651. // echo $nowStaff;die;
  2652. }else{ //进入下一个角色或者审批人
  2653. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2654. //
  2655. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2656. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2657. // print_r($verifyStaff);
  2658. // die;
  2659. }
  2660. if($status==3){
  2661. $verifyStaff['final']=$status;
  2662. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2663. }
  2664. $vStaffString=json_encode($verifyStaff);
  2665. $receipt->verifyStaff=$vStaffString;
  2666. $receipt->nowStaff=$nowStaff;
  2667. $loanReceipt->nowStaff=$nowStaff;
  2668. $loanReceipt->verifyStaff=$vStaffString;
  2669. //die;
  2670. //}
  2671. // print_r($verifyStaff);
  2672. // die;
  2673. }
  2674. //print_r($verifyStaff);die;
  2675. }
  2676. //print_r($verifyDetail);
  2677. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2678. foreach ($verifyDetail as $k=>$v){
  2679. if ($v[1]=='ROLE'){
  2680. $roleId=$v[0];
  2681. $roleVerify=json_decode($v[3],true);
  2682. $roleKey=$k;$roleArray=array();
  2683. foreach ($roleVerify as $o=>$p){
  2684. $staffID=explode ('_',$p);
  2685. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2686. array_push($roleArray, $exp);
  2687. }
  2688. $verifyDetailCopy[$v[0]]=$roleArray;
  2689. }
  2690. }
  2691. //print_r($verifyDetail);
  2692. foreach ($verifyDetailCopy as $k=>$v){
  2693. foreach ($verifyDetail as $m=>$n){
  2694. if ($n[0]==$k){
  2695. array_splice($verifyDetail,$m,1,$v);
  2696. }
  2697. }
  2698. }
  2699. //审批日志
  2700. if (!isset($verifyStaff['final'])){
  2701. Doo::loadModel("receiptLog");
  2702. $receiptLog=new receiptLog();
  2703. if (!empty($roleId)){
  2704. Doo::loadModel("role");
  2705. $role=new role();
  2706. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2707. $receiptLog->rolename=$roleInfo['name'];
  2708. }
  2709. $receiptLog->username=$this->staff[0]['username'];
  2710. $receiptLog->uid=$this->staff[0]['sid'];
  2711. $receiptLog->date=date("Y-m-d");
  2712. $receiptLog->opinion=$opinion;
  2713. $receiptLog->img=$this->staff[0]['avatar'];
  2714. $receiptLog->status=1;
  2715. $receiptLog->rid=$rid;
  2716. $receiptLog->insert();
  2717. }
  2718. if (isset($verifyStaff['final'])){//rDetail
  2719. $receipt->status=3;
  2720. $receipt->verifyBreakup=$verifyString;
  2721. $receiptDetailObj->status=3;
  2722. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2723. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2724. $receipt->status=6;
  2725. $receipt->pastDate=date("Y-m-d");
  2726. $receipt->isBK=1;
  2727. $loanReceipt->verifyBreakup=$verifyString;
  2728. $loanReceipt->status=1;
  2729. $loanReceipt->pastDate=date("Y-m-d");
  2730. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2731. }
  2732. $receipt->update(array('where'=>' rid = '.$rid));
  2733. return "/approvalExpenses/2";
  2734. }
  2735. }
  2736. function implement(){
  2737. Doo::loadModel('receipt');
  2738. $receipt=new receipt();
  2739. Doo::loadModel('L_category');
  2740. $Lcategory=new L_category();
  2741. Doo::loadModel('verify');
  2742. $verify=new verify();
  2743. Doo::loadModel('staff');
  2744. $staff=new staff();
  2745. Doo::loadModel("execute");
  2746. $execute=new execute();
  2747. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2748. Doo::loadModel('loanReceipt');
  2749. $loanReceipt=new loanReceipt();
  2750. //print_r($receiptList);
  2751. $loanList=array();
  2752. if (!isset($receiptList))
  2753. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2754. $Locate=0;$roleId=0;$button=0;
  2755. foreach ($loanList as $key=>$value){
  2756. $loanList[$key]['Locate']=$Locate;$Locate++;
  2757. $loanList[$key]['reviseDetail']=array();
  2758. if (!empty($value['reviseDetail']))
  2759. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2760. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2761. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2762. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2763. $loanList[$key]['category']=$categoryDetil['title'];
  2764. //检测编辑状态
  2765. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2766. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2767. $verifyStaff=json_decode($value['verifyStaff'],true);
  2768. Doo::loadModel('role');
  2769. $role=new role();
  2770. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2771. foreach ($verifyList as $k=>$v){
  2772. //init verifyStaff
  2773. if ($v[1]=='ROLE'){
  2774. if (!empty($verifyStaff)){
  2775. $endStaffArray=end($verifyStaff);
  2776. // if ($v[0]==$endStaffArray['nextStaff']){
  2777. // $roleId=$v[0];
  2778. // }
  2779. }
  2780. $roleVerify=json_decode($v[3],true);
  2781. $roleKey=$k;$roleArray=array();
  2782. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2783. foreach ($roleVerify as $o=>$p){
  2784. $staffID=explode ('_',$p);
  2785. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2786. //print_r($staffID);
  2787. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2788. array_push($roleArray, $exp);
  2789. }
  2790. $roleArrayCopy[$v[0]]=$roleArray;
  2791. //$verifyList[$k]['roleArray']=$roleArray;
  2792. }
  2793. $verifyList[$k]['date']="";
  2794. $verifyList[$k]['opinion']="";
  2795. $verifyList[$k]['status']="";
  2796. if (empty($verifyStaff)){
  2797. $verifyList[$k]['date']="";
  2798. $verifyList[$k]['opinion']="";
  2799. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2800. $verifyList[$k]['status']=4;
  2801. $flag=false;
  2802. }
  2803. }else{
  2804. foreach ($verifyStaff as $m=>$u){
  2805. if ($v[0]==$m){
  2806. $verifyList[$k]['date']=$u['date'];
  2807. $verifyList[$k]['opinion']=$u['opinion'];
  2808. $verifyList[$k]['status']=$u['status'];
  2809. $flag=false;
  2810. break;
  2811. }
  2812. }
  2813. $endStaffArray=end($verifyStaff);
  2814. if (isset($endStaffArray['ROLE'])){
  2815. }else{
  2816. // $endKey=key($verifyStaff);
  2817. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2818. // $button=4;
  2819. // $verifyList[$k]['status']=4;
  2820. // }
  2821. }
  2822. }
  2823. }
  2824. $rolename['name']='';
  2825. if (!empty($roleId)){
  2826. Doo::loadModel('role');
  2827. $role=new role();
  2828. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2829. }
  2830. if (!empty($verifyStaff))
  2831. $endStaffArray=end($verifyStaff);
  2832. $KOP=false;
  2833. foreach ($roleArrayCopy as $P=>$A){
  2834. foreach ( $A as $MKI=>$AVL){
  2835. if (!empty($verifyStaff)){
  2836. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2837. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2838. $button=4;
  2839. $roleArrayCopy[$P][$MKI]['status']=4;
  2840. }
  2841. foreach ($verifyStaff as $m=>$u){
  2842. $AVLFK=$AVL[0].'_R';
  2843. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2844. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2845. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2846. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2847. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2848. break;
  2849. }
  2850. }
  2851. }else{
  2852. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2853. $button=4;
  2854. $roleArrayCopy[$P][$MKI]['status']=4;
  2855. }
  2856. }
  2857. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2858. $KOP=true;
  2859. }
  2860. }
  2861. foreach ($roleArrayCopy as $k=>$v){
  2862. foreach ($verifyList as $m=>$n){
  2863. if ($n[0]==$k){
  2864. array_splice($verifyList,$m,1,$v);
  2865. }
  2866. }
  2867. }
  2868. $loanList[$key]['verifyList']=$verifyList;
  2869. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2870. }
  2871. $data['loanList']=$loanList;
  2872. $Locate=0;$roleId=0;$button=0;
  2873. foreach ($receiptList as $key=>$value){
  2874. $button2=0;
  2875. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2876. $receiptList[$key]['reviseDetail']=array();
  2877. if (!empty($value['reviseDetail']))
  2878. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2879. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2880. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2881. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2882. $receiptList[$key]['category']=$categoryDetil['title'];
  2883. $executeList=json_decode($value['executeCopy'],true);
  2884. $executeStaff=array();
  2885. if (!empty($value['executeStaff'] ))
  2886. $executeStaff=json_decode($value['executeStaff'],true);
  2887. if (isset($executeList)){
  2888. foreach ($executeList as $op=>$lo){
  2889. $executeList[$op]['date']="";
  2890. $executeList[$op]['opinion']="";
  2891. $executeList[$op]['status']="";
  2892. foreach ($executeStaff as $m=>$u){
  2893. if ($lo[0]==$m){
  2894. $executeList[$op]['date']=$u['date'];
  2895. $executeList[$op]['opinion']=$u['opinion'];
  2896. $executeList[$op]['status']=$u['status'];
  2897. break;
  2898. }
  2899. }
  2900. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2901. $button2=1;
  2902. $executeList[$op]['status']=4;
  2903. }
  2904. }
  2905. }
  2906. //检测编辑状态
  2907. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2908. $verifyList['staff']=$value['verifyBreakup'];
  2909. }else
  2910. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2911. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2912. $verifyStaff=json_decode($value['verifyStaff'],true);
  2913. Doo::loadModel('role');
  2914. $role=new role();
  2915. if ($verifyList==NULL)
  2916. $verifyList=array();
  2917. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2918. foreach ($verifyList as $k=>$v){
  2919. //init verifyStaff
  2920. if ($v[1]=='ROLE'){
  2921. if (!empty($verifyStaff)){
  2922. $endStaffArray=end($verifyStaff);
  2923. // if ($v[0]==$endStaffArray['nextStaff']){
  2924. // $roleId=$v[0];
  2925. // }
  2926. }
  2927. $roleVerify=json_decode($v[3],true);
  2928. $roleKey=$k;$roleArray=array();
  2929. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2930. foreach ($roleVerify as $o=>$p){
  2931. $staffID=explode ('_',$p);
  2932. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2933. //print_r($staffID);
  2934. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2935. array_push($roleArray, $exp);
  2936. }
  2937. $roleArrayCopy[$v[0]]=$roleArray;
  2938. //$verifyList[$k]['roleArray']=$roleArray;
  2939. }
  2940. $verifyList[$k]['date']="";
  2941. $verifyList[$k]['opinion']="";
  2942. $verifyList[$k]['status']="";
  2943. if (empty($verifyStaff)){
  2944. $verifyList[$k]['date']="";
  2945. $verifyList[$k]['opinion']="";
  2946. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2947. $verifyList[$k]['status']=4;
  2948. $flag=false;
  2949. }
  2950. }else{
  2951. foreach ($verifyStaff as $m=>$u){
  2952. if ($v[0]==$m){
  2953. $verifyList[$k]['date']=$u['date'];
  2954. $verifyList[$k]['opinion']=$u['opinion'];
  2955. $verifyList[$k]['status']=$u['status'];
  2956. $flag=false;
  2957. break;
  2958. }
  2959. }
  2960. $endStaffArray=end($verifyStaff);
  2961. if (isset($endStaffArray['ROLE'])){
  2962. }else{
  2963. // $endKey=key($verifyStaff);
  2964. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2965. // $button=4;
  2966. // $verifyList[$k]['status']=4;
  2967. // }
  2968. }
  2969. }
  2970. }
  2971. $rolename['name']='';
  2972. if (!empty($roleId)){
  2973. Doo::loadModel('role');
  2974. $role=new role();
  2975. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2976. }
  2977. if (!empty($verifyStaff))
  2978. $endStaffArray=end($verifyStaff);
  2979. $KOP=false;
  2980. foreach ($roleArrayCopy as $P=>$A){
  2981. foreach ( $A as $MKI=>$AVL){
  2982. if (!empty($verifyStaff)){
  2983. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2984. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2985. $button=4;
  2986. $roleArrayCopy[$P][$MKI]['status']=4;
  2987. }
  2988. foreach ($verifyStaff as $m=>$u){
  2989. $AVLFK=$AVL[0].'_R';
  2990. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2991. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2992. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2993. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2994. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2995. break;
  2996. }
  2997. }
  2998. }else{
  2999. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3000. $button=4;
  3001. $roleArrayCopy[$P][$MKI]['status']=4;
  3002. }
  3003. }
  3004. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3005. $KOP=true;
  3006. }
  3007. }
  3008. foreach ($roleArrayCopy as $k=>$v){
  3009. foreach ($verifyList as $m=>$n){
  3010. if ($n[0]==$k){
  3011. array_splice($verifyList,$m,1,$v);
  3012. }
  3013. }
  3014. }
  3015. $receiptList[$key]['verifyList']=$verifyList;
  3016. $receiptList[$key]['executeList']=$executeList;
  3017. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3018. $receiptList[$key]['button2']=$button2;
  3019. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3020. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3021. $relust=$value['sum']-$value['loanSum'];
  3022. $receiptList[$key]['relust']=$relust;
  3023. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3024. }
  3025. //print_r($receiptList[$key]['executeList']);
  3026. $data['receiptList']=$receiptList;
  3027. $data['memu']="receipt";
  3028. $data['staff']=$this->staff;
  3029. $data['receiptMemu']='implement';
  3030. $data['verifyId']=$this->verifyId;
  3031. $data['executeId']=$this->executeId;
  3032. $this->render ( "/admin/implement", $data );
  3033. }
  3034. function implementDo(){
  3035. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3036. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  3037. if (!empty($rid)){
  3038. Doo::loadModel('receipt');
  3039. $receipt=new receipt();
  3040. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  3041. $executeCopy=json_decode($rinfo['executeCopy'],true);
  3042. $executeStaff=json_decode($rinfo['executeStaff'],true);
  3043. if(empty($executeStaff)){
  3044. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3045. }else{
  3046. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3047. }
  3048. if (count($executeStaff)==count($executeCopy)){
  3049. $receipt->executeStaff=json_encode($executeStaff);
  3050. $receipt->status=8;
  3051. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3052. $receipt->status=9;
  3053. $receipt->executeDate= date("Y-m-d");
  3054. }else{
  3055. $receipt->executeStaff=json_encode($executeStaff);
  3056. }
  3057. $receipt->update(array('where'=>'rid='.$rid));
  3058. }
  3059. return "/implement";
  3060. }
  3061. function receiptburEdi(){
  3062. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3063. $status=isset($this->params['status'])?$this->params['status']:'';
  3064. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3065. $month=$this->get_args('month')?$this->get_args('month'):"";
  3066. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3067. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3068. if (empty($status))
  3069. $status=$this->get_args('status')?$this->get_args('status'):2;
  3070. $vidList=array();
  3071. $button=0;
  3072. Doo::loadModel('verify');
  3073. Doo::loadModel('receipt');
  3074. Doo::loadModel('staff');
  3075. $staff=new staff();
  3076. $receipt=new receipt();
  3077. $verify=new verify();
  3078. Doo::loadModel('L_category');
  3079. $Lcategory=new L_category();
  3080. Doo::loadModel('enclosur');
  3081. $enclosur=new enclosur();
  3082. Doo::loadModel('loanReceipt');
  3083. $loanReceipt=new loanReceipt();
  3084. //user verify ID
  3085. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3086. foreach ($verifyDetail as $key=>$value){
  3087. array_push($vidList, $value['vid']);
  3088. }
  3089. $vid=implode(",", $vidList);
  3090. if(empty($verifyDetail))
  3091. $vid=0;
  3092. $categoryList=$Lcategory->find(array('asArray'=>true));
  3093. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3094. $ap="";
  3095. if($status==4){
  3096. $ap=4;$status=2;
  3097. }
  3098. //get Receipt By verifyID status 2
  3099. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3100. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3101. $Locate=0;$roleId=0;$button=0;
  3102. foreach ($loanList as $key=>$value){
  3103. $loanList[$key]['Locate']=$Locate;$Locate++;
  3104. $loanList[$key]['reviseDetail']=array();
  3105. if (!empty($value['reviseDetail']))
  3106. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3107. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3108. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3109. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3110. $loanList[$key]['category']=$categoryDetil['title'];
  3111. //检测编辑状态
  3112. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3113. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3114. $verifyStaff=json_decode($value['verifyStaff'],true);
  3115. Doo::loadModel('role');
  3116. $role=new role();
  3117. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3118. foreach ($verifyList as $k=>$v){
  3119. //init verifyStaff
  3120. if ($v[1]=='ROLE'){
  3121. if (!empty($verifyStaff)){
  3122. $endStaffArray=end($verifyStaff);
  3123. }
  3124. $roleVerify=json_decode($v[3],true);
  3125. $roleKey=$k;$roleArray=array();
  3126. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3127. foreach ($roleVerify as $o=>$p){
  3128. $staffID=explode ('_',$p);
  3129. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3130. //print_r($staffID);
  3131. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3132. array_push($roleArray, $exp);
  3133. }
  3134. $roleArrayCopy[$v[0]]=$roleArray;
  3135. //$verifyList[$k]['roleArray']=$roleArray;
  3136. }
  3137. $verifyList[$k]['date']="";
  3138. $verifyList[$k]['opinion']="";
  3139. $verifyList[$k]['status']="";
  3140. if (empty($verifyStaff)){
  3141. $verifyList[$k]['date']="";
  3142. $verifyList[$k]['opinion']="";
  3143. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3144. $verifyList[$k]['status']=4;
  3145. $flag=false;
  3146. }
  3147. }else{
  3148. foreach ($verifyStaff as $m=>$u){
  3149. if ($v[0]==$m){
  3150. $verifyList[$k]['date']=$u['date'];
  3151. $verifyList[$k]['opinion']=$u['opinion'];
  3152. $verifyList[$k]['status']=$u['status'];
  3153. $flag=false;
  3154. break;
  3155. }
  3156. }
  3157. $endStaffArray=end($verifyStaff);
  3158. if (isset($endStaffArray['ROLE'])){
  3159. }else{
  3160. }
  3161. }
  3162. }
  3163. $rolename['name']='';
  3164. if (!empty($roleId)){
  3165. Doo::loadModel('role');
  3166. $role=new role();
  3167. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3168. }
  3169. if (!empty($verifyStaff))
  3170. $endStaffArray=end($verifyStaff);
  3171. $KOP=false;
  3172. foreach ($roleArrayCopy as $P=>$A){
  3173. foreach ( $A as $MKI=>$AVL){
  3174. if (!empty($verifyStaff)){
  3175. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3176. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3177. $button=4;
  3178. $roleArrayCopy[$P][$MKI]['status']=4;
  3179. }
  3180. foreach ($verifyStaff as $m=>$u){
  3181. $AVLFK=$AVL[0].'_R';
  3182. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3183. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3184. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3185. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3186. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3187. break;
  3188. }
  3189. }
  3190. }else{
  3191. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3192. $button=4;
  3193. $roleArrayCopy[$P][$MKI]['status']=4;
  3194. }
  3195. }
  3196. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3197. $KOP=true;
  3198. }
  3199. }
  3200. foreach ($roleArrayCopy as $k=>$v){
  3201. foreach ($verifyList as $m=>$n){
  3202. if ($n[0]==$k){
  3203. array_splice($verifyList,$m,1,$v);
  3204. }
  3205. }
  3206. }
  3207. $loanList[$key]['verifyList']=$verifyList;
  3208. }
  3209. $htmlLoan='';
  3210. if (isset($loanList[0])){
  3211. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3212. if ($value['status']==1)
  3213. $htmlLoan.='<li class="done" >';
  3214. elseif ($value['status']==3)
  3215. $htmlLoan.='<li class="undone" >';
  3216. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3217. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3218. if (isset($value['rolename']))
  3219. $htmlLoan.=$value['rolename'];
  3220. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3221. }
  3222. $data['loanDate']=$loanList[0]['date'];
  3223. }
  3224. $data['htmlLoan']=$htmlLoan;
  3225. //print_r($loanList);
  3226. $Locate=0;$roleId=0;$button=0;
  3227. if($ap==4)
  3228. $status=4;
  3229. foreach ($receiptList as $key=>$value){
  3230. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3231. $receiptList[$key]['reviseDetail']=array();
  3232. if (!empty($value['reviseDetail']))
  3233. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3234. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3235. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3236. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3237. $receiptList[$key]['category']=$categoryDetil['title'];
  3238. //检测编辑状态
  3239. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3240. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3241. $verifyStaff=json_decode($value['verifyStaff'],true);
  3242. Doo::loadModel('role');
  3243. $role=new role();
  3244. //print_r($verifyList);
  3245. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3246. foreach ($verifyList as $k=>$v){
  3247. //init verifyStaff
  3248. if ($v[1]=='ROLE'){
  3249. if (!empty($verifyStaff)){
  3250. $endStaffArray=end($verifyStaff);
  3251. if ($v[0]==$endStaffArray['nextStaff']){
  3252. $roleId=$v[0];
  3253. }
  3254. }
  3255. $roleVerify=json_decode($v[3],true);
  3256. $roleKey=$k;$roleArray=array();
  3257. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3258. foreach ($roleVerify as $o=>$p){
  3259. $staffID=explode ('_',$p);
  3260. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3261. //print_r($staffID);
  3262. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3263. array_push($roleArray, $exp);
  3264. }
  3265. $roleArrayCopy[$v[0]]=$roleArray;
  3266. //$verifyList[$k]['roleArray']=$roleArray;
  3267. }
  3268. //print_r($roleArray);
  3269. $verifyList[$k]['date']="";
  3270. $verifyList[$k]['opinion']="";
  3271. $verifyList[$k]['status']="";
  3272. if (empty($verifyStaff)){
  3273. $verifyList[$k]['date']="";
  3274. $verifyList[$k]['opinion']="";
  3275. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3276. $verifyList[$k]['status']=4;
  3277. $button=4;$flag=false;
  3278. }
  3279. }else{
  3280. foreach ($verifyStaff as $m=>$u){
  3281. if ($v[0]==$m){
  3282. $verifyList[$k]['date']=$u['date'];
  3283. $verifyList[$k]['opinion']=$u['opinion'];
  3284. $verifyList[$k]['status']=$u['status'];
  3285. $flag=false;
  3286. break;
  3287. }
  3288. }
  3289. $endStaffArray=end($verifyStaff);
  3290. if (isset($endStaffArray['ROLE'])){
  3291. }else{
  3292. $endKey=key($verifyStaff);
  3293. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3294. $button=4;
  3295. $verifyList[$k]['status']=4;
  3296. }
  3297. }
  3298. }
  3299. }
  3300. $rolename['name']='';
  3301. if (!empty($roleId)){
  3302. Doo::loadModel('role');
  3303. $role=new role();
  3304. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3305. }
  3306. if (!empty($verifyStaff))
  3307. $endStaffArray=end($verifyStaff);
  3308. $KOP=false;
  3309. foreach ($roleArrayCopy as $P=>$A){
  3310. foreach ( $A as $MKI=>$AVL){
  3311. if (!empty($verifyStaff)){
  3312. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3313. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3314. $button=4;
  3315. $roleArrayCopy[$P][$MKI]['status']=4;
  3316. }
  3317. foreach ($verifyStaff as $m=>$u){
  3318. $AVLFK=$AVL[0].'_R';
  3319. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3320. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3321. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3322. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3323. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3324. break;
  3325. }
  3326. }
  3327. }else{
  3328. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3329. $button=4;
  3330. $roleArrayCopy[$P][$MKI]['status']=4;
  3331. }
  3332. }
  3333. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3334. $KOP=true;
  3335. }
  3336. }
  3337. foreach ($roleArrayCopy as $k=>$v){
  3338. foreach ($verifyList as $m=>$n){
  3339. if ($n[0]==$k){
  3340. array_splice($verifyList,$m,1,$v);
  3341. }
  3342. }
  3343. }
  3344. //print_r($verifyList);
  3345. $receiptList[$key]['verifyList']=$verifyList;
  3346. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3347. $receiptList[$key]['button']=$button;
  3348. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3349. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3350. $relust=$value['sum']-$value['loanSum'];
  3351. $receiptList[$key]['relust']=$relust;
  3352. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3353. }
  3354. //print_r($receiptList);die;
  3355. //$data['verifyDetail']=$verifyDetail;
  3356. $mothHtml="";
  3357. for($i=1;$i<=12;$i++){
  3358. if($month==$i)
  3359. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3360. else
  3361. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3362. }
  3363. //获取审批日志
  3364. Doo::loadModel('receiptLog');
  3365. $receiptLog=new receiptLog();
  3366. $rlList=array();
  3367. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3368. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3369. if (!empty($rlInfo)){
  3370. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3371. }
  3372. //echo $rid;
  3373. //print_r($receiptList);
  3374. $receiptList[0]['rlList']=$rlList;
  3375. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3376. $enclosurHtml='';
  3377. foreach ($enclosurList as $value){
  3378. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3379. }
  3380. $data['enclosurHtml']=$enclosurHtml;
  3381. $data['rolename']=$rolename['name'];
  3382. // $data['datetij']=$tijdate['date'];
  3383. $data['mothHtml']=$mothHtml;
  3384. //print_r($receiptList);
  3385. $data['rid']=$rid;
  3386. $data['tijdate']=$tijdate['date'];
  3387. $data['receiptList']=$receiptList;
  3388. $data['receiptApprovalCount']=count($receiptList);
  3389. $data['status']=$status;
  3390. $data['year']=$year;
  3391. $data['categoryList']=$categoryList;
  3392. $data['staffList']=$staffList;
  3393. $data['cid']=$cid;
  3394. $data['sid']=$sid;
  3395. $data['ap']=$ap;
  3396. $data['memu']="receipt";
  3397. $data['staff']=$this->staff;
  3398. $data['receiptMemu']='approvalExpenses';
  3399. $data['verifyId']=$this->verifyId;
  3400. $data['executeId']=$this->executeId;
  3401. $this->render ( "/admin/receiptburEdi", $data );
  3402. }
  3403. function hisImplement(){
  3404. $item=isset($this->params['item'])?$this->params['item']:"";
  3405. if(empty($item))
  3406. $item=$this->get_args('item')?$this->get_args('item'):"";
  3407. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3408. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3409. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3410. $sop=$this->get_args('sop')?$this->get_args('sop'):'SOP';
  3411. Doo::loadModel('receipt');
  3412. $receipt=new receipt();
  3413. Doo::loadModel('L_category');
  3414. $Lcategory=new L_category();
  3415. Doo::loadModel('verify');
  3416. Doo::loadModel('statistics');
  3417. $statistics=new statistics();
  3418. $verify=new verify();
  3419. Doo::loadModel('staff');
  3420. $staff=new staff();
  3421. $condition="";
  3422. if($item=="expenses")
  3423. $condition=" and Rtype=1 ";
  3424. elseif ($item=="receipts")
  3425. $condition=" and Rtype=0 ";
  3426. elseif ($item=="remits")
  3427. $condition=" and Rtype=2 ";
  3428. $sopString="";
  3429. $dateCondition=" and Year(executeDate) =".$year;
  3430. if($moth!='MONTH'){
  3431. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3432. }
  3433. if($day!='DAY')
  3434. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3435. if ($sop!='SOP')
  3436. $sopString=" and staff=".$sop;
  3437. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3438. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition.$sopString,'desc'=>'rid','asArray'=>true));
  3439. //员工筛选
  3440. $receiptList2=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3441. $sopStaff=array();
  3442. foreach ($receiptList2 as $key=>$value){
  3443. $staffDetail=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3444. $sopStaff[$value['staff']]=$staffDetail['username'];
  3445. }
  3446. $Locate=0;$roleId=0;$button=0;
  3447. foreach ($receiptList as $key=>$value){
  3448. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3449. $receiptList[$key]['reviseDetail']=array();
  3450. if (!empty($value['reviseDetail']))
  3451. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3452. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3453. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3454. $receiptList[$key]['category']=$categoryDetil['title'];
  3455. //检测编辑状态
  3456. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3457. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3458. $verifyStaff=json_decode($value['verifyStaff'],true);
  3459. Doo::loadModel('role');
  3460. $role=new role();
  3461. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3462. foreach ($verifyList as $k=>$v){
  3463. //init verifyStaff
  3464. if ($v[1]=='ROLE'){
  3465. if (!empty($verifyStaff)){
  3466. $endStaffArray=end($verifyStaff);
  3467. }
  3468. $roleVerify=json_decode($v[3],true);
  3469. $roleKey=$k;$roleArray=array();
  3470. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3471. foreach ($roleVerify as $o=>$p){
  3472. $staffID=explode ('_',$p);
  3473. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3474. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3475. array_push($roleArray, $exp);
  3476. }
  3477. $roleArrayCopy[$v[0]]=$roleArray;
  3478. }
  3479. $verifyList[$k]['date']="";
  3480. $verifyList[$k]['opinion']="";
  3481. $verifyList[$k]['status']="";
  3482. if (empty($verifyStaff)){
  3483. $verifyList[$k]['date']="";
  3484. $verifyList[$k]['opinion']="";
  3485. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3486. $verifyList[$k]['status']=4;
  3487. $flag=false;
  3488. }
  3489. }else{
  3490. foreach ($verifyStaff as $m=>$u){
  3491. if ($v[0]==$m){
  3492. $verifyList[$k]['date']=$u['date'];
  3493. $verifyList[$k]['opinion']=$u['opinion'];
  3494. $verifyList[$k]['status']=$u['status'];
  3495. $flag=false;
  3496. break;
  3497. }
  3498. }
  3499. $endStaffArray=end($verifyStaff);
  3500. }
  3501. }
  3502. $rolename['name']='';
  3503. if (!empty($roleId)){
  3504. Doo::loadModel('role');
  3505. $role=new role();
  3506. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3507. }
  3508. if (!empty($verifyStaff))
  3509. $endStaffArray=end($verifyStaff);
  3510. $KOP=false;
  3511. foreach ($roleArrayCopy as $P=>$A){
  3512. foreach ( $A as $MKI=>$AVL){
  3513. if (!empty($verifyStaff)){
  3514. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3515. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3516. $button=4;
  3517. $roleArrayCopy[$P][$MKI]['status']=4;
  3518. }
  3519. foreach ($verifyStaff as $m=>$u){
  3520. $AVLFK=$AVL[0].'_R';
  3521. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3522. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3523. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3524. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3525. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3526. break;
  3527. }
  3528. }
  3529. }else{
  3530. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3531. $button=4;
  3532. $roleArrayCopy[$P][$MKI]['status']=4;
  3533. }
  3534. }
  3535. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3536. $KOP=true;
  3537. }
  3538. }
  3539. foreach ($roleArrayCopy as $k=>$v){
  3540. foreach ($verifyList as $m=>$n){
  3541. if ($n[0]==$k){
  3542. array_splice($verifyList,$m,1,$v);
  3543. }
  3544. }
  3545. }
  3546. $receiptList[$key]['verifyList']=$verifyList;
  3547. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3548. $receiptList[$key]['button']=$button;
  3549. }
  3550. //print_r($sopStaff);
  3551. $mothHtml="";
  3552. for($i=1;$i<=12;$i++){
  3553. if($moth==$i)
  3554. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3555. else
  3556. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3557. }
  3558. $dayHtml="";
  3559. if ($day!="DAY"||$moth!="MONTH"){
  3560. for($i = 1; $i <= 31; $i ++) {
  3561. if($day==$i)
  3562. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3563. else
  3564. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3565. }
  3566. }
  3567. $sopHtml="";
  3568. foreach ($sopStaff as $key=>$value){
  3569. if($sop==$key)
  3570. $sopHtml.='<option value="'.$key.'" selected >'.$value.'</option>';
  3571. else
  3572. $sopHtml.='<option value="'.$key.'" >'.$value.'</option>';
  3573. }
  3574. $data['sopHtml']=$sopHtml;
  3575. $data['dayHtml']=$dayHtml;
  3576. $data['mothHtml']=$mothHtml;
  3577. $data['receiptList']=$receiptList;
  3578. $data['memu']="receipt";
  3579. $data['staff']=$this->staff;
  3580. $data['receiptMemu']='implement';
  3581. $data['verifyId']=$this->verifyId;
  3582. $data['executeId']=$this->executeId;
  3583. $data['item']=$item;
  3584. $data['year']=$year;
  3585. $data['moth']=$moth;
  3586. $data['day']=$day;
  3587. $data['sop']=$sop;
  3588. $this->render ( "/admin/hisImplement", $data );
  3589. }
  3590. function ajaxExamine(){
  3591. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3592. Doo::loadModel('receipt');
  3593. $receipt=new receipt();
  3594. if (!empty($rid)){
  3595. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) and rid!='.$rid
  3596. ,'asArray'=>true));
  3597. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3598. }
  3599. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3600. }
  3601. function myReceipt(){
  3602. //all approval past withdraw
  3603. $item=isset($this->params['item'])?$this->params['item']:"";
  3604. if(empty($item))
  3605. $item=$this->get_args('item')?$this->get_args('item'):"";
  3606. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3607. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3608. Doo::loadModel('receipt');
  3609. $receipt=new receipt();
  3610. //pre-loaded
  3611. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3612. //have cache
  3613. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3614. if(!empty($moth))//yearPage
  3615. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3616. $this->showCache($path);
  3617. }
  3618. Doo::loadModel('L_category');
  3619. $Lcategory=new L_category();
  3620. Doo::loadModel('verify');
  3621. Doo::loadModel('statistics');
  3622. $statistics=new statistics();
  3623. $verify=new verify();
  3624. Doo::loadModel('staff');
  3625. $staff=new staff();
  3626. $condition=" and status!=0 ";
  3627. if($item=="approval")
  3628. $condition=" and status=2 ";
  3629. elseif ($item=="withdraw")
  3630. $condition=" and status=3 ";
  3631. elseif ($item=="past")
  3632. $condition=" and status=1 ";
  3633. elseif ($item=="whdw")
  3634. $condition=" and status=4 ";
  3635. $dateCondition=" and Year(date) =".$year;
  3636. if(!empty($moth)){
  3637. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3638. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3639. }else
  3640. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3641. if(empty($stList))
  3642. $stList=array('rePrice'=>0,'agPrice'=>0);
  3643. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3644. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3645. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3646. $Locate=0;$roleId=0;$button=0;
  3647. foreach ($receiptList as $key=>$value){
  3648. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3649. $receiptList[$key]['reviseDetail']=array();
  3650. if (!empty($value['reviseDetail']))
  3651. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3652. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3653. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3654. $receiptList[$key]['category']=$categoryDetil['title'];
  3655. //检测编辑状态
  3656. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3657. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3658. $verifyStaff=json_decode($value['verifyStaff'],true);
  3659. Doo::loadModel('role');
  3660. $role=new role();
  3661. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3662. foreach ($verifyList as $k=>$v){
  3663. //init verifyStaff
  3664. if ($v[1]=='ROLE'){
  3665. if (!empty($verifyStaff)){
  3666. $endStaffArray=end($verifyStaff);
  3667. // if ($v[0]==$endStaffArray['nextStaff']){
  3668. // $roleId=$v[0];
  3669. // }
  3670. }
  3671. $roleVerify=json_decode($v[3],true);
  3672. $roleKey=$k;$roleArray=array();
  3673. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3674. foreach ($roleVerify as $o=>$p){
  3675. $staffID=explode ('_',$p);
  3676. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3677. //print_r($staffID);
  3678. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3679. array_push($roleArray, $exp);
  3680. }
  3681. $roleArrayCopy[$v[0]]=$roleArray;
  3682. //$verifyList[$k]['roleArray']=$roleArray;
  3683. }
  3684. $verifyList[$k]['date']="";
  3685. $verifyList[$k]['opinion']="";
  3686. $verifyList[$k]['status']="";
  3687. if (empty($verifyStaff)){
  3688. $verifyList[$k]['date']="";
  3689. $verifyList[$k]['opinion']="";
  3690. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3691. $verifyList[$k]['status']=4;
  3692. $flag=false;
  3693. }
  3694. }else{
  3695. foreach ($verifyStaff as $m=>$u){
  3696. if ($v[0]==$m){
  3697. $verifyList[$k]['date']=$u['date'];
  3698. $verifyList[$k]['opinion']=$u['opinion'];
  3699. $verifyList[$k]['status']=$u['status'];
  3700. $flag=false;
  3701. break;
  3702. }
  3703. }
  3704. $endStaffArray=end($verifyStaff);
  3705. if (isset($endStaffArray['ROLE'])){
  3706. }else{
  3707. // $endKey=key($verifyStaff);
  3708. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3709. // $button=4;
  3710. // $verifyList[$k]['status']=4;
  3711. // }
  3712. }
  3713. }
  3714. }
  3715. $rolename['name']='';
  3716. if (!empty($roleId)){
  3717. Doo::loadModel('role');
  3718. $role=new role();
  3719. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3720. }
  3721. if (!empty($verifyStaff))
  3722. $endStaffArray=end($verifyStaff);
  3723. $KOP=false;
  3724. foreach ($roleArrayCopy as $P=>$A){
  3725. foreach ( $A as $MKI=>$AVL){
  3726. if (!empty($verifyStaff)){
  3727. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3728. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3729. $button=4;
  3730. $roleArrayCopy[$P][$MKI]['status']=4;
  3731. }
  3732. foreach ($verifyStaff as $m=>$u){
  3733. $AVLFK=$AVL[0].'_R';
  3734. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3735. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3736. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3737. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3738. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3739. break;
  3740. }
  3741. }
  3742. }else{
  3743. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3744. $button=4;
  3745. $roleArrayCopy[$P][$MKI]['status']=4;
  3746. }
  3747. }
  3748. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3749. $KOP=true;
  3750. }
  3751. }
  3752. foreach ($roleArrayCopy as $k=>$v){
  3753. foreach ($verifyList as $m=>$n){
  3754. if ($n[0]==$k){
  3755. array_splice($verifyList,$m,1,$v);
  3756. }
  3757. }
  3758. }
  3759. $receiptList[$key]['verifyList']=$verifyList;
  3760. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3761. $receiptList[$key]['button']=$button;
  3762. }
  3763. //print_r($receiptList);die;
  3764. $mothHtml="";
  3765. for($i=1;$i<=12;$i++){
  3766. if($moth==$i)
  3767. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3768. else
  3769. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3770. }
  3771. $data['mothHtml']=$mothHtml;
  3772. $data['receiptList']=$receiptList;
  3773. $data['memu']="receipt";
  3774. $data['staff']=$this->staff;
  3775. $data['receiptMemu']='receipt';
  3776. $data['verifyId']=$this->verifyId;
  3777. $data['executeId']=$this->executeId;
  3778. $data['item']=$item;
  3779. $data['year']=$year;
  3780. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3781. //sufficient condition to generate cache
  3782. if(empty($moth)&&($year<date("Y"))){
  3783. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3784. if(empty($receiptList)){ //generated files
  3785. ob_start();
  3786. $this->render ( "/admin/saea_myList", $data );
  3787. $this->cacheFile($path);die;
  3788. // $content = ob_get_contents();
  3789. // $fp = fopen($path, "w");
  3790. // fwrite($fp, $content);
  3791. // fclose($fp);
  3792. }
  3793. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3794. $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));
  3795. if(empty($receiptList)){ //generated files
  3796. ob_start();
  3797. $this->render ( "/admin/saea_myList", $data );
  3798. $this->cacheFile($path);die;
  3799. }
  3800. }
  3801. }
  3802. $this->render ( "/admin/saea_myList", $data );
  3803. }
  3804. function saeaCreate(){
  3805. Doo::loadModel('accountItem');
  3806. Doo::loadModel('verify');
  3807. Doo::loadModel('receipt');
  3808. Doo::loadModel('L_category');
  3809. $lCategory=new L_category();
  3810. $receipt=new receipt();
  3811. $verify=new verify();
  3812. $accountItem=new accountItem();
  3813. Doo::loadModel("role");
  3814. $role=new role();
  3815. $acItem=$accountItem->find(array('asArray'=>true));
  3816. $veList=$verify->find(array('asArray'=>true));
  3817. foreach ($veList as $key=>$value){
  3818. $v=json_decode($value['staff']);
  3819. $list=array();
  3820. foreach ($v as $n=>$m){
  3821. if ($m['1']=='ROLE'){
  3822. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3823. $v[$n][1]=$roleInfo['name'];
  3824. array_push($list, $roleInfo['name']);
  3825. }else{
  3826. array_push($list, $v[$n][1]);
  3827. }
  3828. }
  3829. $veList[$key]['staff']=implode('>', $list);
  3830. }
  3831. $data['category']=$lCategory->find(array('asArray'=>true));
  3832. $data['veList']=$veList;
  3833. $data['acItem']=$acItem;
  3834. $data['memu']="receipt";
  3835. $data['staff']=$this->staff;
  3836. $data['receiptMemu']='saeaBorad';
  3837. $data['verifyId']=$this->verifyId;
  3838. $data['executeId']=$this->executeId;
  3839. $this->render ( "/admin/saea_create", $data );
  3840. }
  3841. function addReceipt(){
  3842. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3843. $agency=$this->get_args('agency');
  3844. $travel=$this->get_args('travel');
  3845. $train=$this->get_args('train');
  3846. $other=$this->get_args('other');
  3847. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3848. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3849. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3850. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3851. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3852. Doo::loadModel('receipt');
  3853. Doo::loadModel('receiptDetail');
  3854. Doo::loadModel('accountItem');
  3855. $accountItem=new accountItem();
  3856. $receipt=new receipt();
  3857. Doo::loadModel('enclosur');
  3858. Doo::loadModel('execute');
  3859. $execute=new execute();
  3860. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3861. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3862. // if(!empty($receiptDetail))
  3863. // return "/referReceipt/".$receiptDetail['rid'];
  3864. $aItem=$accountItem->find(array('asArray'=>true));
  3865. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3866. $ag=$tr=$ta=$ot=0;
  3867. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3868. foreach ($aItem as $key=>$value){
  3869. if ($value['category']==$this->AGENCY){
  3870. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3871. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3872. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3873. }
  3874. $ag++;
  3875. }
  3876. if($value['category']==$this->TRAVEL){
  3877. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3878. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3879. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3880. }
  3881. $tr++;
  3882. }
  3883. if($value['category']==$this->TRAIN){
  3884. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3885. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3886. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3887. }
  3888. $ta++;
  3889. }
  3890. if($value['category']==$this->OTHER){
  3891. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3892. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3893. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3894. }
  3895. $ot++;
  3896. }
  3897. }
  3898. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3899. //报销单
  3900. $receipt->accountItem=json_encode($accountJson);
  3901. $receipt->staff=$this->staff[0]['sid'];
  3902. $receipt->sum=number_format($sum, 2, '.', '');
  3903. $receipt->date=date("Y-m-d");
  3904. $receipt->cid=$cid;
  3905. $receipt->status=5;
  3906. //修改审批流程加入角色
  3907. $receipt->verify=$verify;
  3908. $receipt->executeCopy=$executeDetail['staff'];
  3909. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3910. $receipt->explanation=$explanation;
  3911. $rid=$receipt->insert();
  3912. //附件
  3913. if (!empty($enclosurName)){
  3914. $enclosurArray=explode('-', $enclosurName);
  3915. foreach ($enclosurArray as $value){
  3916. $enclosur=new enclosur();
  3917. $enclosur->name=$value;
  3918. $enclosur->rid=$rid;
  3919. $enclosur->insert();
  3920. }
  3921. //print_r($enclosurArray);die;
  3922. }
  3923. //报销详情
  3924. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3925. $receiptDetail=new receiptDetail();
  3926. $receiptDetail->staff=$this->staff[0]['sid'];
  3927. $receiptDetail->item=$value['name'];
  3928. $receiptDetail->itemCategory=$this->AGENCY;
  3929. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3930. $receiptDetail->date=date("Y-m-d");
  3931. $receiptDetail->cid=$cid;
  3932. $receiptDetail->rid=$rid;
  3933. $receiptDetail->status=4;
  3934. $receiptDetail->insert();
  3935. }
  3936. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3937. $receiptDetail=new receiptDetail();
  3938. $receiptDetail->staff=$this->staff[0]['sid'];
  3939. $receiptDetail->item=$value['name'];
  3940. $receiptDetail->itemCategory=$this->TRAVEL;
  3941. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3942. $receiptDetail->date=date("Y-m-d");
  3943. $receiptDetail->cid=$cid;
  3944. $receiptDetail->rid=$rid;
  3945. $receiptDetail->status=4;
  3946. $receiptDetail->insert();
  3947. }
  3948. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3949. $receiptDetail=new receiptDetail();
  3950. $receiptDetail->staff=$this->staff[0]['sid'];
  3951. $receiptDetail->item=$value['name'];
  3952. $receiptDetail->itemCategory=$this->TRAIN;
  3953. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3954. $receiptDetail->date=date("Y-m-d");
  3955. $receiptDetail->cid=$cid;
  3956. $receiptDetail->rid=$rid;
  3957. $receiptDetail->status=4;
  3958. $receiptDetail->insert();
  3959. }
  3960. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3961. $receiptDetail=new receiptDetail();
  3962. $receiptDetail->staff=$this->staff[0]['sid'];
  3963. $receiptDetail->item=$value['name'];
  3964. $receiptDetail->itemCategory=$this->OTHER;
  3965. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3966. $receiptDetail->date=date("Y-m-d");
  3967. $receiptDetail->cid=$cid;
  3968. $receiptDetail->rid=$rid;
  3969. $receiptDetail->status=4;
  3970. $receiptDetail->insert();
  3971. }
  3972. //return "/referReceipt/".$rid;
  3973. }
  3974. return "/saeaBorad";
  3975. }
  3976. function referReceipt(){
  3977. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3978. Doo::loadModel('receipt');
  3979. Doo::loadModel('verify');
  3980. $verify=new verify();
  3981. $receipt=new receipt();
  3982. Doo::loadModel('L_category');
  3983. $lCategory=new L_category();
  3984. Doo::loadModel("role");
  3985. $role=new role();
  3986. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  3987. if(empty($receiptDetail))
  3988. return "/addReceipt";
  3989. foreach ($receiptDetail as $key=>$value){
  3990. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  3991. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3992. $v=json_decode($veList['staff']);
  3993. array_push($v[0], $veList['description']);
  3994. foreach ($v as $n=>$m){
  3995. if ($m['1']=='ROLE'){
  3996. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3997. $v[$n][1]=$roleInfo['name'];
  3998. }
  3999. }
  4000. $receiptDetail[$key]['staff']=$v;
  4001. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4002. $receiptDetail[$key]['category']=$category['title'];
  4003. }
  4004. //print_r($receiptDetail);
  4005. $data['receiptDetail']=$receiptDetail;
  4006. $data['memu']="receipt";
  4007. $data['staff']=$this->staff;
  4008. $data['receiptMemu']='saeaCreate';
  4009. $data['verifyId']=$this->verifyId;
  4010. $data['executeId']=$this->executeId;
  4011. $this->render ( "/admin/saea_confirm", $data );
  4012. }
  4013. function editReceipt(){
  4014. //edit status 4
  4015. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4016. //echo $rid;
  4017. Doo::loadModel('accountItem');
  4018. Doo::loadModel('verify');
  4019. Doo::loadModel('receipt');
  4020. $receipt=new receipt();
  4021. $verify=new verify();
  4022. $accountItem=new accountItem();
  4023. Doo::loadModel('L_category');
  4024. $lCategory=new L_category();
  4025. Doo::loadModel("role");
  4026. $role=new role();
  4027. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  4028. if(empty($receiptDetail))
  4029. return "/saeaCreate";
  4030. $acItem=$accountItem->find(array('asArray'=>true));
  4031. $veList=$verify->find(array('asArray'=>true));
  4032. foreach ($veList as $key=>$value){
  4033. $v=json_decode($value['staff']);
  4034. $list=array();
  4035. foreach ($v as $n=>$m){
  4036. if ($m['1']=='ROLE'){
  4037. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4038. $v[$n][1]=$roleInfo['name'];
  4039. array_push($list, $roleInfo['name']);
  4040. }else{
  4041. array_push($list, $v[$n][1]);
  4042. }
  4043. }
  4044. $veList[$key]['staff']=implode('>', $list);
  4045. }
  4046. //配置编辑信息
  4047. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4048. foreach ($acItem as $key=>$value){
  4049. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4050. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4051. $acItem[$key]['price']=$v['price'];
  4052. }
  4053. }
  4054. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4055. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4056. $acItem[$key]['price']=$v['price'];
  4057. }
  4058. }
  4059. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4060. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4061. $acItem[$key]['price']=$v['price'];
  4062. }
  4063. }
  4064. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4065. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4066. $acItem[$key]['price']=$v['price'];
  4067. }
  4068. }
  4069. }
  4070. $data['category']=$lCategory->find(array('asArray'=>true));
  4071. $data['cSum']=$accountItemList['cSum'];
  4072. $data['sum']=$receiptDetail['sum'];
  4073. $data['receiptDetail']=$receiptDetail;
  4074. $data['veList']=$veList;
  4075. $data['acItem']=$acItem;
  4076. $data['memu']="receipt";
  4077. $data['staff']=$this->staff;
  4078. $data['receiptMemu']='saeaBorad';
  4079. $data['verify']=$receiptDetail['verify'];
  4080. $data['verifyId']=$this->verifyId;
  4081. $data['executeId']=$this->executeId;
  4082. $data['rid']=$rid;
  4083. $this->render ( "/admin/saea_edit", $data );
  4084. }
  4085. function updateReceipt(){
  4086. $agency=$this->get_args('agency');
  4087. $travel=$this->get_args('travel');
  4088. $train=$this->get_args('train');
  4089. $other=$this->get_args('other');
  4090. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4091. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4092. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4093. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4094. if(!empty($verify)&&!empty($explanation)){
  4095. Doo::loadModel('receipt');
  4096. Doo::loadModel('receiptDetail');
  4097. Doo::loadModel('accountItem');
  4098. $accountItem=new accountItem();
  4099. $receipt=new receipt();
  4100. Doo::loadModel('execute');
  4101. $execute=new execute();
  4102. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4103. if(empty($receiptDetail))
  4104. return "/saeaBorad";
  4105. if ($receiptDetail['Rtype']==1)
  4106. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4107. else
  4108. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4109. $aItem=$accountItem->find(array('asArray'=>true));
  4110. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4111. $ag=$tr=$ta=$ot=0;
  4112. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4113. foreach ($aItem as $key=>$value){
  4114. if ($value['category']==$this->AGENCY){
  4115. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4116. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4117. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4118. }
  4119. $ag++;
  4120. }
  4121. if($value['category']==$this->TRAVEL){
  4122. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4123. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4124. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4125. }
  4126. $tr++;
  4127. }
  4128. if($value['category']==$this->TRAIN){
  4129. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4130. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4131. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4132. }
  4133. $ta++;
  4134. }
  4135. if($value['category']==$this->OTHER){
  4136. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4137. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4138. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4139. }
  4140. $ot++;
  4141. }
  4142. }
  4143. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4144. //报销单
  4145. $rid=$receipt->rid=$receiptDetail['rid'];
  4146. $receipt->accountItem=json_encode($accountJson);
  4147. $receipt->staff=$this->staff[0]['sid'];
  4148. $receipt->sum=number_format($sum, 2, '.', '');
  4149. $receipt->date=date("Y-m-d");
  4150. $receipt->cid=$cid;
  4151. if (($receiptDetail['status']!=4)){
  4152. if ($receiptDetail['Rtype']==1)
  4153. $receipt->status=7;
  4154. else
  4155. $receipt->status=5;
  4156. }
  4157. $receipt->verify=$verify;
  4158. $receipt->executeCopy=$executeDetail['staff'];
  4159. $receipt->explanation=$explanation;
  4160. $receipt->update();
  4161. $receiptDetail=new receiptDetail();
  4162. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4163. //报销详情
  4164. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4165. $receiptDetail=new receiptDetail();
  4166. $receiptDetail->staff=$this->staff[0]['sid'];
  4167. $receiptDetail->item=$value['name'];
  4168. $receiptDetail->itemCategory=$this->AGENCY;
  4169. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4170. $receiptDetail->date=date("Y-m-d");
  4171. $receiptDetail->cid=$cid;
  4172. $receiptDetail->rid=$rid;
  4173. $receiptDetail->status=4;
  4174. $receiptDetail->insert();
  4175. }
  4176. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4177. $receiptDetail=new receiptDetail();
  4178. $receiptDetail->staff=$this->staff[0]['sid'];
  4179. $receiptDetail->item=$value['name'];
  4180. $receiptDetail->itemCategory=$this->TRAVEL;
  4181. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4182. $receiptDetail->date=date("Y-m-d");
  4183. $receiptDetail->cid=$cid;
  4184. $receiptDetail->rid=$rid;
  4185. $receiptDetail->status=4;
  4186. $receiptDetail->insert();
  4187. }
  4188. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4189. $receiptDetail=new receiptDetail();
  4190. $receiptDetail->staff=$this->staff[0]['sid'];
  4191. $receiptDetail->item=$value['name'];
  4192. $receiptDetail->itemCategory=$this->TRAIN;
  4193. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4194. $receiptDetail->date=date("Y-m-d");
  4195. $receiptDetail->cid=$cid;
  4196. $receiptDetail->rid=$rid;
  4197. $receiptDetail->status=4;
  4198. $receiptDetail->insert();
  4199. }
  4200. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4201. $receiptDetail=new receiptDetail();
  4202. $receiptDetail->staff=$this->staff[0]['sid'];
  4203. $receiptDetail->item=$value['name'];
  4204. $receiptDetail->itemCategory=$this->OTHER;
  4205. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4206. $receiptDetail->date=date("Y-m-d");
  4207. $receiptDetail->cid=$cid;
  4208. $receiptDetail->rid=$rid;
  4209. $receiptDetail->status=4;
  4210. $receiptDetail->insert();
  4211. }
  4212. //return "/referReceipt/".$rid;
  4213. }
  4214. return "/saeaBorad";
  4215. }
  4216. function approvedReceipt(){
  4217. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4218. Doo::loadModel('receipt');
  4219. Doo::loadModel('receiptDetail');
  4220. $receipt=new receipt();
  4221. $receiptDetail=new receiptDetail();
  4222. Doo::loadModel('statistics');
  4223. Doo::loadModel('itemStatistics');
  4224. $statistics=new statistics();
  4225. $itemStatistics=new itemStatistics();
  4226. Doo::loadModel("verify");
  4227. $verify=new verify();
  4228. //审批状态的判定
  4229. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4230. if(empty($receiptDetailList))
  4231. return "/saeaBorad";
  4232. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4233. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4234. if (empty($receiptDetailList['nowStaff'])){
  4235. $nowStaff="";$nowStaffList=array();
  4236. if ($verifyDetail[0][1]=='ROLE'){
  4237. $vStaffString=json_decode($verifyDetail[0][3]);
  4238. foreach ($vStaffString as $key=>$value){
  4239. $staffK=explode("_", $value);
  4240. array_push($nowStaffList, $staffK[0]);
  4241. }
  4242. $nowStaff=implode(',', $nowStaffList);
  4243. }else{
  4244. $nowStaff=$verifyDetail[0][0];
  4245. }
  4246. $receipt->nowStaff=$nowStaff;
  4247. }
  4248. // echo $nowStaff;
  4249. // print_r($verifyDetail);die;
  4250. $receipt->rid=$receiptDetailList['rid'];
  4251. $receipt->date=date("Y-m-d");
  4252. $receipt->status=2;
  4253. $receipt->update();
  4254. $receiptDetail->status=2;
  4255. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4256. Doo::loadModel("receiptLog");
  4257. $receiptLog=new receiptLog();
  4258. Doo::loadModel("verify");
  4259. $verify=new verify();
  4260. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4261. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4262. $jd=json_decode($vr['staff']);$roleId=0;
  4263. foreach ($jd as $key=>$value){
  4264. if ($value[1]=='ROLE'){
  4265. $pos = strpos($value[3], $this->staff[0]['sid']);
  4266. if ($pos !== false) {
  4267. $roleId=$value[0];
  4268. }
  4269. }
  4270. }
  4271. //审批日志
  4272. //echo $roleId;die;
  4273. if (!empty($roleId)){
  4274. Doo::loadModel("role");
  4275. $role=new role();
  4276. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4277. $receiptLog->rolename=$roleInfo['name'];
  4278. }
  4279. $receiptLog->username=$this->staff[0]['username'];
  4280. $receiptLog->uid=$this->staff[0]['sid'];
  4281. $receiptLog->date=date("Y-m-d");
  4282. $receiptLog->opinion='提交审批';
  4283. $receiptLog->img=$this->staff[0]['avatar'];
  4284. $receiptLog->status=2;
  4285. $receiptLog->rid=$rid;
  4286. $receiptLog->insert();
  4287. //statistics item
  4288. $dateArray=explode("-", $receiptDetailList['date']);
  4289. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4290. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4291. //print_r($accountItem['cSum']['agencySum']);die;
  4292. // foreach ($accountItem['cSum'] as $key=>$value){
  4293. // if($key=="agencySum"){
  4294. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4295. // if(empty($iStatistics)){
  4296. // $itemStatistics->cid=$this->staff[0]['cid'];
  4297. // $itemStatistics->staff=$this->staff[0]['sid'];
  4298. // $itemStatistics->price=$value;
  4299. // $itemStatistics->itemCategory=$this->AGENCY;
  4300. // $itemStatistics->date=date("Y-m-d");
  4301. // $itemStatistics->insert();
  4302. // }else{
  4303. // if (!empty($value)){
  4304. // $itemStatistics->price=$value+$iStatistics['price'];
  4305. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4306. // }
  4307. // }
  4308. // }elseif($key=="travelSum"){
  4309. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4310. // if(empty($iStatistics)){
  4311. // $itemStatistics->cid=$this->staff[0]['cid'];
  4312. // $itemStatistics->staff=$this->staff[0]['sid'];
  4313. // $itemStatistics->price=$value;
  4314. // $itemStatistics->itemCategory=$this->TRAVEL;
  4315. // $itemStatistics->date=date("Y-m-d");
  4316. // $itemStatistics->insert();
  4317. // }else{
  4318. // if (!empty($value)){
  4319. // $itemStatistics->price=$value+$iStatistics['price'];
  4320. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4321. // }
  4322. // }
  4323. // }elseif($key=="trainSum"){
  4324. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4325. // if(empty($iStatistics)){
  4326. // $itemStatistics->cid=$this->staff[0]['cid'];
  4327. // $itemStatistics->staff=$this->staff[0]['sid'];
  4328. // $itemStatistics->price=$value;
  4329. // $itemStatistics->itemCategory=$this->TRAIN;
  4330. // $itemStatistics->date=date("Y-m-d");
  4331. // $itemStatistics->insert();
  4332. // }else{
  4333. // if (!empty($value)){
  4334. // $itemStatistics->price=$value+$iStatistics['price'];
  4335. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4336. // }
  4337. // }
  4338. // }elseif($key=="otherSum"){
  4339. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4340. // if(empty($iStatistics)){
  4341. // $itemStatistics->cid=$this->staff[0]['cid'];
  4342. // $itemStatistics->staff=$this->staff[0]['sid'];
  4343. // $itemStatistics->price=$value;
  4344. // $itemStatistics->itemCategory=$this->OTHER;
  4345. // $itemStatistics->date=date("Y-m-d");
  4346. // $itemStatistics->insert();
  4347. // }else{
  4348. // if (!empty($value)){
  4349. // $itemStatistics->price=$value+$iStatistics['price'];
  4350. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4351. // }
  4352. // }
  4353. // }
  4354. // }
  4355. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4356. if(empty($stat)){
  4357. $statistics->date=date("Y-m-d");
  4358. $statistics->cid=$this->staff[0]['cid'];
  4359. $statistics->staff=$this->staff[0]['sid'];
  4360. $statistics->agPrice=0;
  4361. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4362. $statistics->insert();
  4363. }else{
  4364. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4365. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4366. }
  4367. return "/expenses";
  4368. }
  4369. function approval(){
  4370. $status=isset($this->params['status'])?$this->params['status']:'';
  4371. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4372. $month=$this->get_args('month')?$this->get_args('month'):"";
  4373. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4374. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4375. if (empty($status))
  4376. $status=$this->get_args('status')?$this->get_args('status'):2;
  4377. $vidList=array();
  4378. $button=0;
  4379. Doo::loadModel('verify');
  4380. $verify=new verify();
  4381. Doo::loadModel('receipt');
  4382. $receipt=new receipt();
  4383. Doo::loadModel('staff');
  4384. $staff=new staff();
  4385. Doo::loadModel('L_category');
  4386. $Lcategory=new L_category();
  4387. //user verify ID
  4388. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4389. foreach ($verifyDetail as $key=>$value){
  4390. array_push($vidList, $value['vid']);
  4391. }
  4392. $vid=implode(",", $vidList);
  4393. if(empty($verifyDetail))
  4394. $vid=0;
  4395. /*
  4396. */
  4397. $dateCondition=" and Year(date) =".$year;
  4398. if(!empty($month))
  4399. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4400. $categoryList=$Lcategory->find(array('asArray'=>true));
  4401. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4402. $cateCondition="";$staffCondition="";$approvalCondition="";
  4403. if (!empty($cid))
  4404. $cateCondition=' and cid='.$cid;
  4405. if(!empty($sid)){
  4406. $staffCondition=' and staff='.$sid;
  4407. $cateCondition="";
  4408. }
  4409. // elseif($status==1){
  4410. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4411. // }
  4412. if($status==2){
  4413. //查找角色审批人
  4414. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4415. }
  4416. $ap="";
  4417. if($status==4){
  4418. $ap=4;$status=2;
  4419. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4420. }
  4421. if($status==5){
  4422. $status=4;$ap=5;
  4423. }
  4424. //echo $vid;
  4425. //get Receipt By verifyID status 2 .$approvalCondition
  4426. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4427. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4428. ,'desc'=>'rid','asArray'=>true));
  4429. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4430. $Locate=0;
  4431. if($ap==4)
  4432. $status=4;
  4433. elseif ($ap==5)
  4434. $status=5;
  4435. foreach ($receiptList as $key=>$value){
  4436. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4437. $receiptList[$key]['reviseDetail']=array();
  4438. if (!empty($value['reviseDetail']))
  4439. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4440. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4441. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4442. $receiptList[$key]['category']=$categoryDetil['title'];
  4443. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4444. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4445. $verifyStaff=json_decode($value['verifyStaff'],true);
  4446. foreach ($verifyList as $k=>$v){
  4447. //init verifyStaff
  4448. $verifyList[$k]['date']="";
  4449. $verifyList[$k]['opinion']="";
  4450. $verifyList[$k]['status']="";
  4451. if (empty($verifyStaff)){
  4452. $verifyList[$k]['date']="";
  4453. $verifyList[$k]['opinion']="";
  4454. if ($v[0]==$this->staff[0]['sid']){
  4455. $verifyList[$k]['status']=4;
  4456. $button=4;
  4457. }
  4458. }else{
  4459. $flag=true;
  4460. foreach ($verifyStaff as $m=>$u){
  4461. if ($v[0]==$m){
  4462. $verifyList[$k]['date']=$u['date'];
  4463. $verifyList[$k]['opinion']=$u['opinion'];
  4464. $verifyList[$k]['status']=$u['status'];
  4465. $flag=false;
  4466. break;
  4467. }
  4468. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4469. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4470. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4471. }
  4472. if($flag){//检测可编辑
  4473. if($v[0]==$this->staff[0]['sid']){
  4474. $verifyList[$k]['status']=4;$button=4;
  4475. }
  4476. }
  4477. }
  4478. }
  4479. $receiptList[$key]['verifyList']=$verifyList;
  4480. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4481. $receiptList[$key]['button']=$button;
  4482. }
  4483. //print_r($receiptList);die;
  4484. //$data['verifyDetail']=$verifyDetail;
  4485. $mothHtml="";
  4486. for($i=1;$i<=12;$i++){
  4487. if($month==$i)
  4488. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4489. else
  4490. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4491. }
  4492. $data['mothHtml']=$mothHtml;
  4493. $data['receiptList']=$receiptList;
  4494. $data['receiptApprovalCount']=count($receiptList);
  4495. $data['status']=$status;
  4496. $data['year']=$year;
  4497. $data['categoryList']=$categoryList;
  4498. $data['staffList']=$staffList;
  4499. $data['cid']=$cid;
  4500. $data['sid']=$sid;
  4501. $data['ap']=$ap;
  4502. $data['memu']="receipt";
  4503. $data['staff']=$this->staff;
  4504. $data['receiptMemu']='approval';
  4505. $data['verifyId']=$this->verifyId;
  4506. $data['executeId']=$this->executeId;
  4507. $this->render ( "/admin/saea_reportList", $data );
  4508. }
  4509. function approvalDetails(){
  4510. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4511. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4512. $month=$this->get_args('month')?$this->get_args('month'):"";
  4513. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4514. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4515. Doo::loadModel('verify');
  4516. $verify=new verify();
  4517. Doo::loadModel('receipt');
  4518. $receipt=new receipt();
  4519. Doo::loadModel('staff');
  4520. $staff=new staff();
  4521. Doo::loadModel('L_category');
  4522. $Lcategory=new L_category();
  4523. Doo::loadModel('enclosur');
  4524. $enclosur=new enclosur();
  4525. $vidList=array();
  4526. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4527. foreach ($verifyDetail as $key=>$value){
  4528. array_push($vidList, $value['vid']);
  4529. }
  4530. $vid=implode(",", $vidList);
  4531. if(empty($verifyDetail))
  4532. $vid=0;
  4533. $categoryList=$Lcategory->find(array('asArray'=>true));
  4534. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4535. $ap=0;
  4536. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4537. $Locate=0;$roleId=0;$button=0;
  4538. foreach ($receiptList as $key=>$value){
  4539. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4540. $receiptList[$key]['reviseDetail']=array();
  4541. if (!empty($value['reviseDetail']))
  4542. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4543. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4544. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4545. $receiptList[$key]['category']=$categoryDetil['title'];
  4546. //检测编辑状态
  4547. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4548. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4549. $verifyStaff=json_decode($value['verifyStaff'],true);
  4550. Doo::loadModel('role');
  4551. $role=new role();
  4552. //print_r($verifyList);
  4553. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4554. foreach ($verifyList as $k=>$v){
  4555. //init verifyStaff
  4556. if ($v[1]=='ROLE'){
  4557. if (!empty($verifyStaff)){
  4558. $endStaffArray=end($verifyStaff);
  4559. if ($v[0]==$endStaffArray['nextStaff']){
  4560. $roleId=$v[0];
  4561. }
  4562. }
  4563. $roleVerify=json_decode($v[3],true);
  4564. $roleKey=$k;$roleArray=array();
  4565. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4566. foreach ($roleVerify as $o=>$p){
  4567. $staffID=explode ('_',$p);
  4568. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4569. //print_r($staffID);
  4570. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4571. array_push($roleArray, $exp);
  4572. }
  4573. $roleArrayCopy[$v[0]]=$roleArray;
  4574. //$verifyList[$k]['roleArray']=$roleArray;
  4575. }
  4576. //print_r($roleArray);
  4577. $verifyList[$k]['date']="";
  4578. $verifyList[$k]['opinion']="";
  4579. $verifyList[$k]['status']="";
  4580. if (empty($verifyStaff)){
  4581. $verifyList[$k]['date']="";
  4582. $verifyList[$k]['opinion']="";
  4583. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4584. $verifyList[$k]['status']=4;
  4585. $button=4;$flag=false;
  4586. }
  4587. }else{
  4588. foreach ($verifyStaff as $m=>$u){
  4589. if ($v[0]==$m){
  4590. $verifyList[$k]['date']=$u['date'];
  4591. $verifyList[$k]['opinion']=$u['opinion'];
  4592. $verifyList[$k]['status']=$u['status'];
  4593. $flag=false;
  4594. break;
  4595. }
  4596. }
  4597. $endStaffArray=end($verifyStaff);
  4598. if (isset($endStaffArray['ROLE'])){
  4599. }else{
  4600. $endKey=key($verifyStaff);
  4601. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4602. $button=4;
  4603. $verifyList[$k]['status']=4;
  4604. }
  4605. }
  4606. }
  4607. }
  4608. $rolename['name']='';
  4609. if (!empty($roleId)){
  4610. Doo::loadModel('role');
  4611. $role=new role();
  4612. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4613. }
  4614. if (!empty($verifyStaff))
  4615. $endStaffArray=end($verifyStaff);
  4616. $KOP=false;
  4617. foreach ($roleArrayCopy as $P=>$A){
  4618. foreach ( $A as $MKI=>$AVL){
  4619. if (!empty($verifyStaff)){
  4620. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4621. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4622. $button=4;
  4623. $roleArrayCopy[$P][$MKI]['status']=4;
  4624. }
  4625. foreach ($verifyStaff as $m=>$u){
  4626. $AVLFK=$AVL[0].'_R';
  4627. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4628. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4629. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4630. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4631. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4632. break;
  4633. }
  4634. }
  4635. }else{
  4636. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4637. $button=4;
  4638. $roleArrayCopy[$P][$MKI]['status']=4;
  4639. }
  4640. }
  4641. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4642. $KOP=true;
  4643. }
  4644. }
  4645. foreach ($roleArrayCopy as $k=>$v){
  4646. foreach ($verifyList as $m=>$n){
  4647. if ($n[0]==$k){
  4648. array_splice($verifyList,$m,1,$v);
  4649. }
  4650. }
  4651. }
  4652. $receiptList[$key]['verifyList']=$verifyList;
  4653. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4654. $receiptList[$key]['button']=$button;
  4655. }
  4656. $mothHtml="";
  4657. for($i=1;$i<=12;$i++){
  4658. if($month==$i)
  4659. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4660. else
  4661. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4662. }
  4663. //获取审批日志
  4664. Doo::loadModel('receiptLog');
  4665. $receiptLog=new receiptLog();
  4666. $rlList=array();
  4667. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4668. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4669. if (!empty($rlInfo)){
  4670. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4671. }
  4672. $receiptList[0]['rlList']=$rlList;
  4673. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4674. $enclosurHtml='';
  4675. foreach ($enclosurList as $value){
  4676. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4677. }
  4678. $data['enclosurHtml']=$enclosurHtml;
  4679. $data['rolename']=$rolename['name'];
  4680. $data['datetij']=$tijdate['date'];
  4681. $data['mothHtml']=$mothHtml;
  4682. $data['receiptList']=$receiptList;
  4683. $data['receiptApprovalCount']=count($receiptList);
  4684. $data['year']=$year;
  4685. $data['categoryList']=$categoryList;
  4686. $data['staffList']=$staffList;
  4687. $data['cid']=$cid;
  4688. $data['sid']=$sid;
  4689. $data['status']=0;
  4690. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4691. $ap=4;
  4692. }else
  4693. $data['status']=$receiptList[0]['status'];
  4694. if ($receiptList[0]['status']==4){
  4695. $data['status']=5;
  4696. $ap=0;
  4697. }
  4698. $data['ap']=$ap;
  4699. $data['memu']="receipt";
  4700. $data['staff']=$this->staff;
  4701. $data['receiptMemu']='approval';
  4702. $data['verifyId']=$this->verifyId;
  4703. $data['executeId']=$this->executeId;
  4704. $this->render ( "/admin/saeaReportListReport", $data );
  4705. }
  4706. function approvalEdi(){
  4707. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4708. $status=isset($this->params['status'])?$this->params['status']:'';
  4709. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4710. $month=$this->get_args('month')?$this->get_args('month'):"";
  4711. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4712. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4713. if (empty($status))
  4714. $status=$this->get_args('status')?$this->get_args('status'):2;
  4715. $vidList=array();
  4716. $button=0;
  4717. Doo::loadModel('verify');
  4718. Doo::loadModel('receipt');
  4719. Doo::loadModel('staff');
  4720. $staff=new staff();
  4721. $receipt=new receipt();
  4722. $verify=new verify();
  4723. Doo::loadModel('L_category');
  4724. $Lcategory=new L_category();
  4725. Doo::loadModel('enclosur');
  4726. $enclosur=new enclosur();
  4727. //user verify ID
  4728. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4729. foreach ($verifyDetail as $key=>$value){
  4730. array_push($vidList, $value['vid']);
  4731. }
  4732. $vid=implode(",", $vidList);
  4733. if(empty($verifyDetail))
  4734. $vid=0;
  4735. $categoryList=$Lcategory->find(array('asArray'=>true));
  4736. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4737. $ap="";
  4738. if($status==4){
  4739. $ap=4;$status=2;
  4740. }
  4741. //get Receipt By verifyID status 2
  4742. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4743. $Locate=0;$roleId=0;
  4744. if($ap==4)
  4745. $status=4;
  4746. foreach ($receiptList as $key=>$value){
  4747. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4748. $receiptList[$key]['reviseDetail']=array();
  4749. if (!empty($value['reviseDetail']))
  4750. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4751. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4752. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4753. $receiptList[$key]['category']=$categoryDetil['title'];
  4754. //检测编辑状态
  4755. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4756. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4757. $verifyStaff=json_decode($value['verifyStaff'],true);
  4758. // print_r($verifyList);
  4759. //
  4760. // if (empty($verifyStaff)){
  4761. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4762. // $verifyList[0]['status']=4;$button=4;
  4763. // }
  4764. //
  4765. // }else{
  4766. //
  4767. // }
  4768. // die;
  4769. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4770. // echo array_search("green",$a);
  4771. //
  4772. Doo::loadModel('role');
  4773. $role=new role();
  4774. //print_r($verifyList);
  4775. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4776. foreach ($verifyList as $k=>$v){
  4777. //init verifyStaff
  4778. if ($v[1]=='ROLE'){
  4779. if (!empty($verifyStaff)){
  4780. $endStaffArray=end($verifyStaff);
  4781. if ($v[0]==$endStaffArray['nextStaff']){
  4782. $roleId=$v[0];
  4783. }
  4784. }
  4785. $roleVerify=json_decode($v[3],true);
  4786. $roleKey=$k;$roleArray=array();
  4787. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4788. foreach ($roleVerify as $o=>$p){
  4789. $staffID=explode ('_',$p);
  4790. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4791. //print_r($staffID);
  4792. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4793. array_push($roleArray, $exp);
  4794. }
  4795. $roleArrayCopy[$v[0]]=$roleArray;
  4796. //$verifyList[$k]['roleArray']=$roleArray;
  4797. }
  4798. //print_r($roleArray);
  4799. $verifyList[$k]['date']="";
  4800. $verifyList[$k]['opinion']="";
  4801. $verifyList[$k]['status']="";
  4802. if (empty($verifyStaff)){
  4803. $verifyList[$k]['date']="";
  4804. $verifyList[$k]['opinion']="";
  4805. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4806. $verifyList[$k]['status']=4;
  4807. $button=4;$flag=false;
  4808. }
  4809. }else{
  4810. foreach ($verifyStaff as $m=>$u){
  4811. if ($v[0]==$m){
  4812. $verifyList[$k]['date']=$u['date'];
  4813. $verifyList[$k]['opinion']=$u['opinion'];
  4814. $verifyList[$k]['status']=$u['status'];
  4815. $flag=false;
  4816. break;
  4817. }
  4818. }
  4819. $endStaffArray=end($verifyStaff);
  4820. if (isset($endStaffArray['ROLE'])){
  4821. }else{
  4822. $endKey=key($verifyStaff);
  4823. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4824. $button=4;
  4825. $verifyList[$k]['status']=4;
  4826. }
  4827. }
  4828. //print_r($endStaffArray);die;
  4829. // if (empty($verifyStaff)){
  4830. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4831. // $verifyList[$k]['status']=4;$button=4;
  4832. // }
  4833. //
  4834. // }else{
  4835. //
  4836. // }
  4837. // if($flag){//检测可编辑
  4838. // if($v[0]==$this->staff[0]['sid']){
  4839. // $verifyList[$k]['status']=4;$button=4;
  4840. // }
  4841. // }
  4842. }
  4843. }
  4844. $rolename['name']='';
  4845. if (!empty($roleId)){
  4846. Doo::loadModel('role');
  4847. $role=new role();
  4848. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4849. }
  4850. if (!empty($verifyStaff))
  4851. $endStaffArray=end($verifyStaff);
  4852. $KOP=false;
  4853. foreach ($roleArrayCopy as $P=>$A){
  4854. foreach ( $A as $MKI=>$AVL){
  4855. if (!empty($verifyStaff)){
  4856. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4857. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4858. $button=4;
  4859. $roleArrayCopy[$P][$MKI]['status']=4;
  4860. }
  4861. foreach ($verifyStaff as $m=>$u){
  4862. $AVLFK=$AVL[0].'_R';
  4863. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4864. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4865. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4866. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4867. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4868. break;
  4869. }
  4870. }
  4871. }else{
  4872. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4873. $button=4;
  4874. $roleArrayCopy[$P][$MKI]['status']=4;
  4875. }
  4876. }
  4877. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4878. $KOP=true;
  4879. }
  4880. }
  4881. // print_r($roleArrayCopy);
  4882. // echo $roleKey;
  4883. foreach ($roleArrayCopy as $k=>$v){
  4884. foreach ($verifyList as $m=>$n){
  4885. if ($n[0]==$k){
  4886. array_splice($verifyList,$m,1,$v);
  4887. }
  4888. }
  4889. }
  4890. // if ($KOP)
  4891. // array_splice($verifyList,$roleKey,1,$roleArray);
  4892. //print_r($verifyList);
  4893. $receiptList[$key]['verifyList']=$verifyList;
  4894. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4895. $receiptList[$key]['button']=$button;
  4896. }
  4897. //$data['verifyDetail']=$verifyDetail;
  4898. $mothHtml="";
  4899. for($i=1;$i<=12;$i++){
  4900. if($month==$i)
  4901. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4902. else
  4903. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4904. }
  4905. //获取审批日志
  4906. Doo::loadModel('receiptLog');
  4907. $receiptLog=new receiptLog();
  4908. $rlList=array();
  4909. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4910. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4911. if (!empty($rlInfo)){
  4912. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4913. }
  4914. $receiptList[0]['rlList']=$rlList;
  4915. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4916. $enclosurHtml='';
  4917. foreach ($enclosurList as $value){
  4918. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4919. }
  4920. $data['enclosurHtml']=$enclosurHtml;
  4921. $data['rolename']=$rolename['name'];
  4922. $data['datetij']=$tijdate['date'];
  4923. $data['mothHtml']=$mothHtml;
  4924. $data['receiptList']=$receiptList;
  4925. $data['receiptApprovalCount']=count($receiptList);
  4926. $data['status']=$status;
  4927. $data['year']=$year;
  4928. $data['categoryList']=$categoryList;
  4929. $data['staffList']=$staffList;
  4930. $data['cid']=$cid;
  4931. $data['sid']=$sid;
  4932. $data['ap']=$ap;
  4933. $data['memu']="receipt";
  4934. $data['staff']=$this->staff;
  4935. $data['receiptMemu']='approval';
  4936. $data['verifyId']=$this->verifyId;
  4937. $data['executeId']=$this->executeId;
  4938. $this->render ( "/admin/saeaReportListReport", $data );
  4939. }
  4940. function remittance(){
  4941. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4942. $month=$this->get_args('month')?$this->get_args('month'):"";
  4943. Doo::loadModel('receipt');
  4944. $receipt=new receipt();
  4945. Doo::loadModel('staff');
  4946. $staff=new staff();
  4947. $dateCondition=" and Year(pastDate) =".$year;
  4948. if(!empty($month))
  4949. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4950. //get Receipt By verifyID status 1
  4951. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4952. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4953. $dataList=array();
  4954. foreach ($dateList as $d=>$a){
  4955. $dataList[$a['pastDate']]=array();$daySum=0;
  4956. foreach ($receiptList as $key=>$value){
  4957. if($a['pastDate']==$value['pastDate']){
  4958. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4959. $list=array();$html="";
  4960. foreach ($oderList as $v){
  4961. array_push($list, $v['receiptOrder']);
  4962. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4963. }
  4964. $receiptList[$key]['receiptOrder']=$html;
  4965. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4966. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4967. $receiptList[$key]['username']=$sinfo['username'];
  4968. $daySum+=$value['sum'];
  4969. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4970. }
  4971. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4972. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4973. }
  4974. }
  4975. //print_r($dataList);
  4976. $data['dataList']=$dataList;
  4977. $mothHtml="";
  4978. for($i=1;$i<=12;$i++){
  4979. if($month==$i)
  4980. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4981. else
  4982. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4983. }
  4984. $data['year']=$year;
  4985. $data['mothHtml']=$mothHtml;
  4986. $data['memu']="receipt";
  4987. $data['staff']=$this->staff;
  4988. $data['receiptMemu']='approval';
  4989. $data['verifyId']=$this->verifyId;
  4990. $data['executeId']=$this->executeId;
  4991. $this->render ( "/admin/saeaReportListPay", $data );
  4992. }
  4993. function revocationAdjustment(){
  4994. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  4995. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  4996. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4997. //echo $price;die;
  4998. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  4999. Doo::loadModel('receipt');
  5000. $receipt=new receipt();
  5001. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5002. if (empty($receiptDetail['reviseDetail']))
  5003. return "/approval";
  5004. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5005. $RD=array();
  5006. foreach ($reviseDetail as $key=>$value){
  5007. if ($value['price']==$price&&$value['sid']==$sid)
  5008. continue;
  5009. array_push($RD, $value);
  5010. }
  5011. $reviseDetailString=json_encode($RD);
  5012. $receipt->reviseDetail=$reviseDetailString;
  5013. $receipt->sum=$receiptDetail['sum']-$price;
  5014. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  5015. $receipt->update(array('where'=>'rid='.$rid));
  5016. }
  5017. //approvalEdi/37
  5018. return "/approvalEdi/".$rid;
  5019. }
  5020. function updateApprovalReceipt(){
  5021. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5022. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  5023. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5024. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  5025. if(!empty($rid)){
  5026. Doo::loadModel("verify");
  5027. $verify=new verify();
  5028. Doo::loadModel("receiptDetail");
  5029. $receiptDetailObj=new receiptDetail();
  5030. Doo::loadModel("itemStatistics");
  5031. Doo::loadModel("statistics");
  5032. $statistics=new statistics();
  5033. $itemStatistics=new itemStatistics();
  5034. Doo::loadModel("receipt");
  5035. $receipt=new receipt();
  5036. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5037. if (empty($receiptDetail))
  5038. return "/approval";
  5039. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  5040. $verifyString=$verifyDetail['staff'];
  5041. $verifyDetail=json_decode($verifyDetail['staff'],true);
  5042. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  5043. if(empty($opinion)){
  5044. if ($status==3)
  5045. $opinion="终止";
  5046. else
  5047. $opinion="同意支付";
  5048. }
  5049. $nowStaff=0;$nowStaffList=array();
  5050. if(empty($verifyStaff)){
  5051. //还需加入是否已经进入角色审批
  5052. if ($verifyDetail[0][1]=='ROLE'){
  5053. $vStaffString=json_decode($verifyDetail[0][3]);
  5054. foreach ($vStaffString as $key=>$value){
  5055. $staffK=explode("_", $value);
  5056. if ($staffK[0]!=$this->staff[0]['sid'])
  5057. array_push($nowStaffList, $staffK[0]);
  5058. }
  5059. //print_r($verifyDetail);
  5060. //die;
  5061. if (!empty($nowStaffList)){
  5062. $nowStaff=implode(',', $nowStaffList);
  5063. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5064. }else{
  5065. $nowStaff=$verifyDetail[1][0];
  5066. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5067. }
  5068. }else{
  5069. if ($verifyDetail[1][1]=='ROLE'){
  5070. $vStaffString=json_decode($verifyDetail[1][3]);
  5071. //echo "dd";
  5072. foreach ($vStaffString as $key=>$value){
  5073. $staffK=explode("_", $value);
  5074. array_push($nowStaffList, $staffK[0]);
  5075. }
  5076. $nowStaff=implode(',', $nowStaffList);
  5077. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5078. }else{
  5079. $nowStaff=$verifyDetail[1][0];
  5080. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5081. }
  5082. }
  5083. if($status==3)
  5084. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5085. $vStaffString=json_encode($verifyStaff);
  5086. $receipt->nowStaff=$nowStaff;
  5087. $receipt->verifyStaff=$vStaffString;
  5088. }else{
  5089. $VS=end($verifyStaff);
  5090. //非角色审批
  5091. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5092. $nextStaff=0;$roleSTF=false;
  5093. foreach ($verifyDetail as $key=>$value){
  5094. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5095. if (isset($verifyDetail[$key+1])){
  5096. $nextStaff=$verifyDetail[$key+1][0];
  5097. if ($verifyDetail[$key+1][1]=='ROLE')
  5098. $roleSTF=true;
  5099. }
  5100. break;
  5101. }
  5102. }
  5103. if (!$roleSTF){
  5104. $nowStaff=$nextStaff;
  5105. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5106. }else{
  5107. //获取角色下的所有用户ID
  5108. $nowStaffList=array();
  5109. foreach ($verifyDetail as $vfk){
  5110. if ($vfk[1]=='ROLE'){
  5111. $vStaffString=json_decode($vfk[3]);
  5112. foreach ($vStaffString as $key=>$value){
  5113. $staffK=explode("_", $value);
  5114. array_push($nowStaffList, $staffK[0]);
  5115. }
  5116. }
  5117. }
  5118. $nowStaff=implode(',', $nowStaffList);
  5119. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5120. }
  5121. if($status==3){
  5122. $verifyStaff['final']=$status;
  5123. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5124. }
  5125. $vStaffString=json_encode($verifyStaff);
  5126. $receipt->nowStaff=$nowStaff;
  5127. $receipt->verifyStaff=$vStaffString;
  5128. }
  5129. //角色审批
  5130. if (isset($VS['ROLE'])){
  5131. //找出角色人 当前审批角色组
  5132. $verifyJSStaff=array();$nowStaffList2=array();
  5133. foreach ($verifyDetail as $key=>$value){
  5134. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5135. $verifyJSStaff=json_decode($value[3]);
  5136. foreach ($verifyJSStaff as $m){
  5137. $staffK=explode("_", $m);
  5138. array_push($nowStaffList2, $staffK[0]);
  5139. }
  5140. // print_r($nowStaffList2);
  5141. }
  5142. }
  5143. $RoleVerifyStaff=array();
  5144. foreach ($verifyStaff as $key=>$value){
  5145. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5146. foreach ($nowStaffList2 as $m) {
  5147. if ($key==$m."_R")
  5148. $RoleVerifyStaff[$key]=$value;
  5149. }
  5150. }
  5151. }
  5152. // print_r($verifyStaff);
  5153. // print_r($nowStaffList2);
  5154. // print_r($RoleVerifyStaff);
  5155. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5156. //print_r($verifyJSStaff);
  5157. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5158. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5159. //下一个审批人ID
  5160. $nextStaff=0;$falg=false;
  5161. foreach ($verifyDetail as $key=>$value){
  5162. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5163. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5164. $falg=true;
  5165. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5166. foreach ($vStaffString as $v){
  5167. $staffK=explode("_", $v);
  5168. array_push($nowStaffList, $staffK[0]);
  5169. }
  5170. $nowStaff=implode(',', $nowStaffList);
  5171. $nextStaff=$verifyDetail[$key+1][0];
  5172. }elseif(isset($verifyDetail[$key+1])){
  5173. $nextStaff=$verifyDetail[$key+1][0];
  5174. $nowStaff=$nextStaff;
  5175. }else
  5176. $nowStaff='';
  5177. break;
  5178. }
  5179. }
  5180. if ($falg)
  5181. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5182. else
  5183. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5184. // print_r($verifyStaff);
  5185. // echo $nowStaff;die;
  5186. }else{ //进入下一个角色或者审批人
  5187. /*
  5188. */
  5189. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5190. //
  5191. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5192. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5193. // print_r($verifyStaff);
  5194. // die;
  5195. }
  5196. if($status==3){
  5197. $verifyStaff['final']=$status;
  5198. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5199. }
  5200. $vStaffString=json_encode($verifyStaff);
  5201. $receipt->verifyStaff=$vStaffString;
  5202. $receipt->nowStaff=$nowStaff;
  5203. //die;
  5204. //}
  5205. // print_r($verifyStaff);
  5206. // die;
  5207. }
  5208. //print_r($verifyStaff);die;
  5209. }
  5210. //print_r($verifyDetail);
  5211. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5212. foreach ($verifyDetail as $k=>$v){
  5213. if ($v[1]=='ROLE'){
  5214. $roleId=$v[0];
  5215. $roleVerify=json_decode($v[3],true);
  5216. $roleKey=$k;$roleArray=array();
  5217. foreach ($roleVerify as $o=>$p){
  5218. $staffID=explode ('_',$p);
  5219. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5220. array_push($roleArray, $exp);
  5221. }
  5222. $verifyDetailCopy[$v[0]]=$roleArray;
  5223. }
  5224. }
  5225. //print_r($verifyDetail);
  5226. foreach ($verifyDetailCopy as $k=>$v){
  5227. foreach ($verifyDetail as $m=>$n){
  5228. if ($n[0]==$k){
  5229. array_splice($verifyDetail,$m,1,$v);
  5230. }
  5231. }
  5232. }
  5233. // die;
  5234. // if (!empty($roleArray))
  5235. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5236. // echo $roleId;
  5237. // print_r($verifyStaff);
  5238. // print_r($verifyDetail);
  5239. // die;
  5240. Doo::loadModel("receiptLog");
  5241. $receiptLog=new receiptLog();
  5242. //审批日志
  5243. if (!isset($verifyStaff['final'])){
  5244. if (!empty($roleId)){
  5245. Doo::loadModel("role");
  5246. $role=new role();
  5247. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5248. $receiptLog->rolename=$roleInfo['name'];
  5249. }
  5250. $receiptLog->username=$this->staff[0]['username'];
  5251. $receiptLog->uid=$this->staff[0]['sid'];
  5252. $receiptLog->date=date("Y-m-d");
  5253. $receiptLog->opinion=$opinion;
  5254. $receiptLog->img=$this->staff[0]['avatar'];
  5255. $receiptLog->status=1;
  5256. $receiptLog->rid=$rid;
  5257. $receiptLog->insert();
  5258. }
  5259. if (isset($verifyStaff['final'])){//rDetail
  5260. $receipt->verifyBreakup=$verifyString;
  5261. $receipt->status=3;
  5262. $receiptDetailObj->status=3;
  5263. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5264. if (!empty($roleId)){
  5265. Doo::loadModel("role");
  5266. $role=new role();
  5267. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5268. $receiptLog->rolename=$roleInfo['name'];
  5269. }
  5270. $receiptLog->username=$this->staff[0]['username'];
  5271. $receiptLog->uid=$this->staff[0]['sid'];
  5272. $receiptLog->date=date("Y-m-d");
  5273. $receiptLog->opinion=$opinion;
  5274. $receiptLog->img=$this->staff[0]['avatar'];
  5275. $receiptLog->status=3;
  5276. $receiptLog->rid=$rid;
  5277. $receiptLog->insert();
  5278. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5279. $receipt->status=1;$reviseSum=0;
  5280. $receipt->verifyBreakup=$verifyString;
  5281. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5282. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5283. foreach ($reviseDetail as $key=>$value){
  5284. $receiptDetailObj=new receiptDetail();
  5285. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5286. $receiptDetailObj->item=$value['description'];
  5287. $receiptDetailObj->itemCategory="报销金额调整";
  5288. $receiptDetailObj->price=$value['price'];
  5289. $receiptDetailObj->date=$receiptDetail['date'];
  5290. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5291. $receiptDetailObj->rid=$rid;
  5292. $receiptDetailObj->status=1;
  5293. $receiptDetailObj->insert();
  5294. $reviseSum+=$value['price'];
  5295. }
  5296. $itemStatistics=new itemStatistics();
  5297. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5298. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5299. $itemStatistics->price=$reviseSum;
  5300. $itemStatistics->itemCategory="报销金额调整";
  5301. $itemStatistics->date=$receiptDetail['date'];
  5302. $itemStatistics->insert();
  5303. }
  5304. $receiptDetailObj=new receiptDetail();
  5305. $receiptDetailObj->status=1;
  5306. $receiptDetailObj->pastDate=date("Y-m-d");
  5307. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5308. $dateArray=explode("-", $receiptDetail['date']);
  5309. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5310. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5311. if(empty($stat)){
  5312. $statistics->date=$receiptDetail['date'];
  5313. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5314. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5315. $statistics->agPrice=$receiptDetail['sum'];
  5316. $statistics->rePrice=$reviseSum;
  5317. $statistics->insert();
  5318. }else{
  5319. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5320. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5321. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5322. }
  5323. $dateArray=explode("-", $receiptDetail['date']);
  5324. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5325. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5326. foreach ($accountItem['cSum'] as $key=>$value){
  5327. if($key=="agencySum"){
  5328. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5329. if(empty($iStatistics)){
  5330. $itemStatistics->cid=$receiptDetail['cid'];;
  5331. $itemStatistics->staff=$receiptDetail['staff'];
  5332. $itemStatistics->price=$value;
  5333. $itemStatistics->itemCategory=$this->AGENCY;
  5334. $itemStatistics->date=$receiptDetail['date'];
  5335. $itemStatistics->insert();
  5336. }else{
  5337. if (!empty($value)){
  5338. $itemStatistics->price=$value+$iStatistics['price'];
  5339. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5340. }
  5341. }
  5342. }elseif($key=="travelSum"){
  5343. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5344. if(empty($iStatistics)){
  5345. $itemStatistics->cid=$receiptDetail['cid'];
  5346. $itemStatistics->staff=$receiptDetail['staff'];
  5347. $itemStatistics->price=$value;
  5348. $itemStatistics->itemCategory=$this->TRAVEL;
  5349. $itemStatistics->date=$receiptDetail['date'];
  5350. $itemStatistics->insert();
  5351. }else{
  5352. if (!empty($value)){
  5353. $itemStatistics->price=$value+$iStatistics['price'];
  5354. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5355. }
  5356. }
  5357. }elseif($key=="trainSum"){
  5358. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5359. if(empty($iStatistics)){
  5360. $itemStatistics->cid=$receiptDetail['cid'];
  5361. $itemStatistics->staff=$receiptDetail['staff'];
  5362. $itemStatistics->price=$value;
  5363. $itemStatistics->itemCategory=$this->TRAIN;
  5364. $itemStatistics->date=$receiptDetail['date'];
  5365. $itemStatistics->insert();
  5366. }else{
  5367. if (!empty($value)){
  5368. $itemStatistics->price=$value+$iStatistics['price'];
  5369. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5370. }
  5371. }
  5372. }elseif($key=="otherSum"){
  5373. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5374. if(empty($iStatistics)){
  5375. $itemStatistics->cid=$receiptDetail['cid'];
  5376. $itemStatistics->staff=$receiptDetail['staff'];
  5377. $itemStatistics->price=$value;
  5378. $itemStatistics->itemCategory=$this->OTHER;
  5379. $itemStatistics->date=$receiptDetail['date'];
  5380. $itemStatistics->insert();
  5381. }else{
  5382. if (!empty($value)){
  5383. $itemStatistics->price=$value+$iStatistics['price'];
  5384. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5385. }
  5386. }
  5387. }
  5388. }
  5389. $receipt->pastDate=date("Y-m-d");
  5390. }
  5391. $receipt->update(array('where'=>' rid = '.$rid));
  5392. return "/approvalExpenses/2";
  5393. }
  5394. }
  5395. function expensesRetreats(){
  5396. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5397. if (!empty($rid)){
  5398. //操作记录
  5399. Doo::loadModel("receipt");
  5400. $receipt=new receipt();
  5401. Doo::loadModel("receiptLog");
  5402. $receiptLog=new receiptLog();
  5403. Doo::loadModel("verify");
  5404. $verify=new verify();
  5405. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5406. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5407. $jd=json_decode($vr['staff']);$roleId=0;
  5408. foreach ($jd as $key=>$value){
  5409. if ($value[1]=='ROLE'){
  5410. $pos = strpos($value[3], $this->staff[0]['sid']);
  5411. if ($pos !== false) {
  5412. $roleId=$value[0];
  5413. }
  5414. }
  5415. }
  5416. //审批日志
  5417. //echo $roleId;die;
  5418. if (!empty($roleId)){
  5419. Doo::loadModel("role");
  5420. $role=new role();
  5421. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5422. $receiptLog->rolename=$roleInfo['name'];
  5423. }
  5424. $receiptLog->username=$this->staff[0]['username'];
  5425. $receiptLog->uid=$this->staff[0]['sid'];
  5426. $receiptLog->date=date("Y-m-d");
  5427. $receiptLog->opinion='撤回';
  5428. $receiptLog->img=$this->staff[0]['avatar'];
  5429. $receiptLog->status=4;
  5430. $receiptLog->rid=$rid;
  5431. $receiptLog->insert();
  5432. $receipt->status=4;
  5433. $receipt->update(array('where'=>'rid='.$rid));
  5434. }
  5435. //echo "ddd";
  5436. return '/approvalExpenses';
  5437. }
  5438. function updateCheReceipt(){
  5439. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5440. if (!empty($rid)){
  5441. //操作记录
  5442. Doo::loadModel("receipt");
  5443. $receipt=new receipt();
  5444. Doo::loadModel("receiptLog");
  5445. $receiptLog=new receiptLog();
  5446. Doo::loadModel("verify");
  5447. $verify=new verify();
  5448. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5449. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5450. $jd=json_decode($vr['staff']);$roleId=0;
  5451. foreach ($jd as $key=>$value){
  5452. if ($value[1]=='ROLE'){
  5453. $pos = strpos($value[3], $this->staff[0]['sid']);
  5454. if ($pos !== false) {
  5455. $roleId=$value[0];
  5456. }
  5457. }
  5458. }
  5459. //审批日志
  5460. //echo $roleId;die;
  5461. if (!empty($roleId)){
  5462. Doo::loadModel("role");
  5463. $role=new role();
  5464. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5465. $receiptLog->rolename=$roleInfo['name'];
  5466. }
  5467. $receiptLog->username=$this->staff[0]['username'];
  5468. $receiptLog->uid=$this->staff[0]['sid'];
  5469. $receiptLog->date=date("Y-m-d");
  5470. $receiptLog->opinion='撤回';
  5471. $receiptLog->img=$this->staff[0]['avatar'];
  5472. $receiptLog->status=4;
  5473. $receiptLog->rid=$rid;
  5474. $receiptLog->insert();
  5475. $receipt->status=4;
  5476. $receipt->update(array('where'=>'rid='.$rid));
  5477. }
  5478. //echo "ddd";
  5479. return '/saeaBorad';
  5480. }
  5481. function revisePrice(){
  5482. $description=$this->get_args('description')?$this->get_args('description'):"";
  5483. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5484. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5485. //echo $price;die;
  5486. if (!empty($rid)){
  5487. Doo::loadModel("receipt");
  5488. $receipt=new receipt();
  5489. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5490. if (empty($receiptDetail))
  5491. return "/approval";
  5492. $reviseDetail=array();
  5493. if (empty($receiptDetail['reviseDetail'])){
  5494. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5495. $reviseDetailString=json_encode($reviseDetail);
  5496. $receipt->reviseDetail=$reviseDetailString;
  5497. $receipt->revisePrice=$price;
  5498. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5499. }else{
  5500. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5501. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5502. $reviseDetailString=json_encode($reviseDetail);
  5503. $receipt->reviseDetail=$reviseDetailString;
  5504. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5505. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5506. }
  5507. $receipt->update(array('where'=>'rid='.$rid));
  5508. }
  5509. return '/approvalEdi/'.$rid;
  5510. }
  5511. function personalCollect(){
  5512. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5513. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5514. $this->showCache($path);
  5515. Doo::loadModel("receiptDetail");
  5516. Doo::loadModel("itemStatistics");
  5517. Doo::loadModel('statistics');
  5518. $statistics=new statistics();
  5519. $itemStatistics=new itemStatistics();
  5520. $receiptDetail=new receiptDetail();
  5521. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5522. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5523. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5524. //create collect html
  5525. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5526. $adjustment=array();
  5527. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5528. array_push($collectArray['日常相关费用'], $collectHtml);
  5529. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5530. array_push($collectArray['差旅相关费用'], $collectHtml);
  5531. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5532. array_push($collectArray['培训班费用'], $collectHtml);
  5533. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5534. array_push($collectArray['其他'], $collectHtml);
  5535. $data['collectArray']=$collectArray;
  5536. //statistics html
  5537. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5538. if(empty($stList))
  5539. $stList=array('rePrice'=>0,'agPrice'=>0);
  5540. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5541. //Adjustment price html
  5542. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5543. array_push($adjustment, $collectHtml);
  5544. $data['adjustment']=$adjustment;
  5545. //total price html
  5546. $collectHtml="";$total=0;
  5547. for ($i=1;$i<=12;$i++){
  5548. $sumPrice=0;
  5549. foreach ($receiptCollectList as $key=>$value){
  5550. if($value['month']==$i){
  5551. $sumPrice+=$value['price'];
  5552. }
  5553. }
  5554. if ($sumPrice==0)
  5555. $collectHtml.='<td class="taR">-</td>';
  5556. else
  5557. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5558. $total+=$sumPrice;
  5559. }
  5560. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5561. $data['totalPrice']=$collectHtml;
  5562. $data['year']=$year;
  5563. $data['totalYear']=$total;
  5564. $data['memu']="receipt";
  5565. $data['staff']=$this->staff;
  5566. $data['receiptMemu']='personalCollect';
  5567. $data['verifyId']=$this->verifyId;
  5568. $data['executeId']=$this->executeId;
  5569. //year staff status 2,4
  5570. if($year<date("Y")){
  5571. Doo::loadModel('receipt');
  5572. $receipt=new receipt();
  5573. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5574. if(empty($receiptList)){
  5575. ob_start();
  5576. $this->render ( "/admin/saea_slist_collect", $data );
  5577. $this->cacheFile($path);die;
  5578. }
  5579. }
  5580. $this->render ( "/admin/saea_slist_collect", $data );
  5581. }
  5582. function personalCollectDetail(){
  5583. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5584. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5585. $this->showCache($path);
  5586. Doo::loadModel("receiptDetail");
  5587. Doo::loadModel("itemStatistics");
  5588. Doo::loadModel('statistics');
  5589. Doo::loadModel('accountItem');
  5590. $accountItem=new accountItem();
  5591. $statistics=new statistics();
  5592. $itemStatistics=new itemStatistics();
  5593. $receiptDetail=new receiptDetail();
  5594. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5595. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5596. $accountList=$accountItem->find(array('asArray'=>true));
  5597. //create CollectDetail HTML
  5598. $collectHtml=array();
  5599. foreach ($accountList as $key=>$value){
  5600. $html="";$asum=0;
  5601. for ($i=1;$i<=12;$i++){
  5602. $falg=true;
  5603. foreach ($receiptCollectList as $v) {
  5604. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5605. $asum+=$v['price'];
  5606. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5607. }
  5608. }
  5609. if($falg)
  5610. $html.='<td class="taR">-</td>';
  5611. }
  5612. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5613. $collectHtml[$value['category']][$value['name']]=$html;
  5614. }
  5615. $data['collectHtml']=$collectHtml;
  5616. //create Adjustment price html
  5617. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5618. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5619. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5620. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5621. array_push($collectArray['日常相关费用'], $collectHtml);
  5622. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5623. array_push($collectArray['差旅相关费用'], $collectHtml);
  5624. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5625. array_push($collectArray['培训班费用'], $collectHtml);
  5626. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5627. array_push($collectArray['其他'], $collectHtml);
  5628. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5629. array_push($adjustment, $collectHtml);
  5630. //total price html
  5631. $collectHtml="";$total=0;
  5632. for ($i=1;$i<=12;$i++){
  5633. $sumPrice=0;
  5634. foreach ($receiptCollectList as $key=>$value){
  5635. if($value['month']==$i){
  5636. $sumPrice+=$value['price'];
  5637. }
  5638. }
  5639. if ($sumPrice==0)
  5640. $collectHtml.='<td class="taR">-</td>';
  5641. else
  5642. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5643. $total+=$sumPrice;
  5644. }
  5645. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5646. //statistics html
  5647. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5648. if(empty($stList))
  5649. $stList=array('rePrice'=>0,'agPrice'=>0);
  5650. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5651. $data['collectArray']=$collectArray;
  5652. $data['adjustment']=$adjustment;
  5653. $data['totalPrice']=$collectHtml;
  5654. $data['totalYear']=$total;
  5655. $data['year']=$year;
  5656. $data['memu']="receipt";
  5657. $data['staff']=$this->staff;
  5658. $data['receiptMemu']='personalCollect';
  5659. $data['verifyId']=$this->verifyId;
  5660. $data['executeId']=$this->executeId;
  5661. //year staff status 2,4
  5662. if($year<date("Y")){
  5663. Doo::loadModel('receipt');
  5664. $receipt=new receipt();
  5665. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5666. if(empty($receiptList)){
  5667. ob_start();
  5668. $this->render ( "/admin/saeaCollectArticles", $data );
  5669. $this->cacheFile($path);die;
  5670. }
  5671. }
  5672. $this->render ( "/admin/saeaCollectArticles", $data );
  5673. }
  5674. function companyCategoryCollect(){
  5675. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5676. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5677. $this->showCache($path);
  5678. Doo::loadModel('L_category');
  5679. Doo::loadModel('itemStatistics');
  5680. Doo::loadModel('statistics');
  5681. $statistics=new statistics();
  5682. $Lcategory=new L_category();
  5683. $itemStatistics=new itemStatistics();
  5684. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5685. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5686. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5687. //ceatre companyCollectHtml
  5688. foreach ($LcategoryList as $value){
  5689. $html="";$asum=0;
  5690. for ($i=1;$i<=12;$i++){
  5691. $falg=true;
  5692. foreach ($itemStatisticsList as $v){
  5693. if($value['cid']==$v['cid']&&$i==$v['month']){
  5694. $asum+=$v['price'];
  5695. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5696. }
  5697. }
  5698. if($falg)
  5699. $html.='<td class="taR">-</td>';
  5700. }
  5701. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5702. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5703. }
  5704. $data['companyHtml']=$collectHtml;
  5705. //total price html
  5706. $collectHtml="";$total=0;
  5707. for ($i=1;$i<=12;$i++){
  5708. $sumPrice=0;
  5709. foreach ($itemStatisticsList as $key=>$value){
  5710. if($value['month']==$i){
  5711. $sumPrice+=$value['price'];
  5712. }
  5713. }
  5714. if ($sumPrice==0)
  5715. $collectHtml.='<td class="taR">-</td>';
  5716. else
  5717. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5718. $total+=$sumPrice;
  5719. }
  5720. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5721. $data['companyTotalHtml']=$collectHtml;
  5722. $data['total']=$total;
  5723. //statistics html
  5724. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5725. if(empty($stList))
  5726. $stList=array('rePrice'=>0,'agPrice'=>0);
  5727. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5728. $data['year']=$year;
  5729. $data['memu']="receipt";
  5730. $data['staff']=$this->staff;
  5731. $data['receiptMemu']='companyCategoryCollect';
  5732. $data['verifyId']=$this->verifyId;
  5733. $data['executeId']=$this->executeId;
  5734. //year staff status 2,4
  5735. if($year<date("Y")){
  5736. Doo::loadModel('receipt');
  5737. $receipt=new receipt();
  5738. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5739. if(empty($receiptList)){
  5740. ob_start();
  5741. $this->render ( "/admin/saeaCompanyCollect", $data );
  5742. $this->cacheFile($path);die;
  5743. }
  5744. }
  5745. $this->render ( "/admin/saeaCompanyCollect", $data );
  5746. }
  5747. function categoryCollectDetail(){
  5748. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5749. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5750. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".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. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5761. if ($cid==0){
  5762. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5763. if ($cid==0)
  5764. $cid=$LcategoryList[0]['cid'];
  5765. }
  5766. $data['LcategoryList']=$LcategoryList;
  5767. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5768. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5769. $accountList=$accountItem->find(array('asArray'=>true));
  5770. //create CollectDetail HTML
  5771. $collectHtml=array();
  5772. foreach ($accountList as $key=>$value){
  5773. $html="";$asum=0;
  5774. for ($i=1;$i<=12;$i++){
  5775. $falg=true;
  5776. foreach ($receiptCollectList as $v) {
  5777. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5778. $asum+=$v['price'];
  5779. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5780. }
  5781. }
  5782. if($falg)
  5783. $html.='<td class="taR">-</td>';
  5784. }
  5785. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5786. $collectHtml[$value['category']][$value['name']]=$html;
  5787. }
  5788. $data['collectHtml']=$collectHtml;
  5789. //create Adjustment price html
  5790. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5791. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5792. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5793. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5794. array_push($collectArray['日常相关费用'], $collectHtml);
  5795. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5796. array_push($collectArray['差旅相关费用'], $collectHtml);
  5797. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5798. array_push($collectArray['培训班费用'], $collectHtml);
  5799. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5800. array_push($collectArray['其他'], $collectHtml);
  5801. $data['collectArray']=$collectArray;
  5802. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5803. array_push($adjustment, $collectHtml);
  5804. $data['adjustment']=$adjustment;
  5805. //total price html
  5806. $collectHtml="";$total=0;
  5807. for ($i=1;$i<=12;$i++){
  5808. $sumPrice=0;
  5809. foreach ($receiptCollectList as $key=>$value){
  5810. if($value['month']==$i){
  5811. $sumPrice+=$value['price'];
  5812. }
  5813. }
  5814. if ($sumPrice==0)
  5815. $collectHtml.='<td class="taR">-</td>';
  5816. else
  5817. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5818. $total+=$sumPrice;
  5819. }
  5820. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5821. //statistics html
  5822. $stList=$statistics->statisticsByCid($year,$cid);
  5823. if(empty($stList))
  5824. $stList=array('rePrice'=>0,'agPrice'=>0);
  5825. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5826. $data['totalYear']=$total;
  5827. $data['year']=$year;
  5828. $data['cid']=$cid;
  5829. $data['memu']="receipt";
  5830. $data['staff']=$this->staff;
  5831. $data['receiptMemu']='companyCategoryCollect';
  5832. $data['verifyId']=$this->verifyId;
  5833. $data['executeId']=$this->executeId;
  5834. //year staff status 2,4
  5835. if($year<date("Y")){
  5836. Doo::loadModel('receipt');
  5837. $receipt=new receipt();
  5838. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5839. if(empty($receiptList)){
  5840. ob_start();
  5841. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5842. $this->cacheFile($path);die;
  5843. }
  5844. }
  5845. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5846. }
  5847. function staffCollect(){
  5848. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5849. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5850. //$this->showCache($path);
  5851. Doo::loadModel('statistics');
  5852. $statistics=new statistics();
  5853. Doo::loadModel("receiptDetail");
  5854. $receiptDetail=new receiptDetail();
  5855. Doo::loadModel('L_category');
  5856. $Lcategory=new L_category();
  5857. Doo::loadModel('accountItem');
  5858. $accountItem=new accountItem();
  5859. Doo::loadModel('staff');
  5860. $staff=new staff();
  5861. Doo::loadModel('itemStatistics');
  5862. $itemStatistics=new itemStatistics();
  5863. /*
  5864. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5865. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5866. if(empty($stList))
  5867. $stList=array('rePrice'=>0,'agPrice'=>0);
  5868. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5869. */
  5870. //statistics html
  5871. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5872. if(empty($stList))
  5873. $stList=array('rePrice'=>0,'agPrice'=>0);
  5874. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5875. //---
  5876. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5877. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5878. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5879. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5880. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5881. //print_r($itemStatisticsList);die;
  5882. //ceatre companyCollectHtml
  5883. foreach ($categoryList as $vlu){
  5884. $count=$vlu['count']+1;
  5885. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5886. $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;
  5887. foreach ($staffList as $value){
  5888. if ($vlu['cid']==$value['cid']){
  5889. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5890. $asum=0;
  5891. for ($i=1;$i<=12;$i++){
  5892. $falg=true;
  5893. foreach ($itemStatisticsList as $v){
  5894. if($value['sid']==$v['staff']&&$i==$v['month']){
  5895. if ($v['month']==1)
  5896. $m1+=$v['price'];
  5897. if ($v['month']==2)
  5898. $m2+=$v['price'];
  5899. if ($v['month']==3)
  5900. $m3+=$v['price'];
  5901. if ($v['month']==4)
  5902. $m4+=$v['price'];
  5903. if ($v['month']==5)
  5904. $m5+=$v['price'];
  5905. if ($v['month']==6)
  5906. $m6+=$v['price'];
  5907. if ($v['month']==7)
  5908. $m7+=$v['price'];
  5909. if ($v['month']==8)
  5910. $m8+=$v['price'];
  5911. if ($v['month']==9)
  5912. $m9+=$v['price'];
  5913. if ($v['month']==10)
  5914. $m10+=$v['price'];
  5915. if ($v['month']==11)
  5916. $m11+=$v['price'];
  5917. if ($v['month']==12)
  5918. $m12+=$v['price'];
  5919. $asum+=$v['price'];
  5920. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5921. }
  5922. }
  5923. if($falg)
  5924. $html.='<td class="taR">-</td>';
  5925. }
  5926. $m13+=$asum;
  5927. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5928. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5929. $html="";
  5930. }
  5931. }
  5932. $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>
  5933. <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>
  5934. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5935. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5936. }
  5937. $data['companyHtml']=$collectHtml;
  5938. //total price html
  5939. $collectHtml="";$total=0;
  5940. for ($i=1;$i<=12;$i++){
  5941. $sumPrice=0;
  5942. foreach ($itemStatisticsList as $key=>$value){
  5943. if($value['month']==$i){
  5944. $sumPrice+=$value['price'];
  5945. }
  5946. }
  5947. if ($sumPrice==0)
  5948. $collectHtml.='<td class="taR">-</td>';
  5949. else
  5950. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5951. $total+=$sumPrice;
  5952. }
  5953. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5954. $data['companyTotalHtml']=$collectHtml;
  5955. $data['total']=$total;
  5956. $data['year']=$year;
  5957. $data['memu']="receipt";
  5958. $data['staff']=$this->staff;
  5959. $data['receiptMemu']='companyCategoryCollect';
  5960. $data['verifyId']=$this->verifyId;
  5961. $data['executeId']=$this->executeId;
  5962. if ($year<=date("Y")){
  5963. Doo::loadModel('receipt');
  5964. $receipt=new receipt();
  5965. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5966. if(empty($receiptList)){ //generated files
  5967. ob_start();
  5968. $this->render ( "/admin/saeaStaffCollectB", $data );
  5969. $this->cacheFile($path);die;
  5970. }
  5971. }
  5972. $this->render ( "/admin/saeaStaffCollectB", $data );
  5973. }
  5974. function staffCollectBak(){
  5975. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5976. $month=$this->get_args('month')?$this->get_args('month'):1;
  5977. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  5978. $this->showCache($path);
  5979. Doo::loadModel('statistics');
  5980. $statistics=new statistics();
  5981. Doo::loadModel("receiptDetail");
  5982. $receiptDetail=new receiptDetail();
  5983. Doo::loadModel('L_category');
  5984. $Lcategory=new L_category();
  5985. Doo::loadModel('accountItem');
  5986. $accountItem=new accountItem();
  5987. Doo::loadModel('staff');
  5988. $staff=new staff();
  5989. Doo::loadModel('itemStatistics');
  5990. $itemStatistics=new itemStatistics();
  5991. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5992. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  5993. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5994. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  5995. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5996. $staffList=$staff->find(array('asArray'=>true));
  5997. $htmlArray=array();
  5998. foreach ($LcategoryList as $value){
  5999. $htmlArray[$value['title']]=array();
  6000. foreach ($staffList as $v){
  6001. if($value['cid']==$v['cid']){
  6002. $html="";$falg=true;$staffSumPrice=0;
  6003. foreach ($itemStatisticsList as $a){
  6004. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  6005. if(empty($a['price'])){
  6006. $html.='<td class="taR">-</td>';$falg=false;break;
  6007. }else{
  6008. $staffSumPrice+=$a['price'];
  6009. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6010. }
  6011. }
  6012. }
  6013. if ($falg){
  6014. $html.='<td class="taR">-</td>';$falg=true;
  6015. }
  6016. $falg=true;
  6017. foreach ($itemStatisticsList as $a){
  6018. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  6019. if(empty($a['price'])){
  6020. $html.='<td class="taR">-</td>';$falg=false;break;
  6021. }else{
  6022. $staffSumPrice+=$a['price'];
  6023. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6024. }
  6025. }
  6026. }
  6027. if ($falg){
  6028. $html.='<td class="taR">-</td>';$falg=true;
  6029. }
  6030. $falg=true;
  6031. foreach ($itemStatisticsList as $a){
  6032. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  6033. if(empty($a['price'])){
  6034. $html.='<td class="taR">-</td>';$falg=false;break;
  6035. }else{
  6036. $staffSumPrice+=$a['price'];
  6037. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6038. }
  6039. }
  6040. }
  6041. if ($falg){
  6042. $html.='<td class="taR">-</td>';$falg=true;
  6043. }
  6044. $falg=true;
  6045. foreach ($itemStatisticsList as $a){
  6046. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6047. if(!empty($a['price'])){
  6048. $staffSumPrice+=$a['price'];
  6049. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6050. }else{
  6051. $html.='<td class="taR">-</td>';$falg=false;break;
  6052. }
  6053. }
  6054. }
  6055. if ($falg){
  6056. $html.='<td class="taR">-</td>';$falg=true;
  6057. }
  6058. $falg=true;
  6059. foreach ($itemStatisticsList as $a){
  6060. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6061. if(!empty($a['price'])){
  6062. $staffSumPrice+=$a['price'];
  6063. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6064. }else{
  6065. $html.='<td class="taR">-</td>';$falg=false;break;
  6066. }
  6067. }
  6068. }
  6069. if ($falg){
  6070. $html.='<td class="taR">-</td>';$falg=true;
  6071. }
  6072. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6073. $htmlArray[$value['title']][$v['username']]=$html;
  6074. }
  6075. }
  6076. /*-- ---*/
  6077. //合计费用
  6078. $cateHtml="";$catePrice=0;$cateFalg=true;
  6079. foreach ($itemCategoryList as $l){
  6080. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6081. if(empty($l['price'])){
  6082. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6083. }else{
  6084. $catePrice+=$l['price'];
  6085. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6086. }
  6087. }
  6088. }
  6089. if ($cateFalg){
  6090. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6091. }
  6092. $cateFalg=true;
  6093. foreach ($itemCategoryList as $l){
  6094. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6095. if(empty($l['price'])){
  6096. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6097. }else{
  6098. $catePrice+=$l['price'];
  6099. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6100. }
  6101. }
  6102. }
  6103. if ($cateFalg){
  6104. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6105. }
  6106. $cateFalg=true;
  6107. foreach ($itemCategoryList as $l){
  6108. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6109. if(empty($l['price'])){
  6110. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6111. }else{
  6112. $catePrice+=$l['price'];
  6113. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6114. }
  6115. }
  6116. }
  6117. if ($cateFalg){
  6118. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6119. }
  6120. $cateFalg=true;
  6121. foreach ($itemCategoryList as $l){
  6122. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6123. if(empty($l['price'])){
  6124. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6125. }else{
  6126. $catePrice+=$l['price'];
  6127. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6128. }
  6129. }
  6130. }
  6131. if ($cateFalg){
  6132. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6133. }
  6134. $cateFalg=true;
  6135. foreach ($itemCategoryList as $l){
  6136. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6137. if(empty($l['price'])){
  6138. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6139. }else{
  6140. $catePrice+=$l['price'];
  6141. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6142. }
  6143. }
  6144. }
  6145. if ($cateFalg){
  6146. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6147. }
  6148. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6149. $htmlArray[$value['title']]['合计']=$cateHtml;
  6150. /*-- ---*/
  6151. }
  6152. //print_r($htmlArray);die;
  6153. $data['htmlArray']=$htmlArray;
  6154. //statistics html
  6155. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6156. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6157. if(empty($stList))
  6158. $stList=array('rePrice'=>0,'agPrice'=>0);
  6159. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6160. $monthHtml="";
  6161. for ($i=1;$i<=12;$i++){
  6162. if ($i==$month)
  6163. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6164. else
  6165. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6166. }
  6167. $data['monthHtml']=$monthHtml;
  6168. $data['year']=$year;
  6169. $data['month']=$month;
  6170. $data['memu']="receipt";
  6171. $data['staff']=$this->staff;
  6172. $data['receiptMemu']='companyCategoryCollect';
  6173. $data['verifyId']=$this->verifyId;
  6174. $data['executeId']=$this->executeId;
  6175. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6176. Doo::loadModel('receipt');
  6177. $receipt=new receipt();
  6178. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6179. if(empty($receiptList)){ //generated files
  6180. ob_start();
  6181. $this->render ( "/admin/saeaStaffCollect", $data );
  6182. $this->cacheFile($path);die;
  6183. }
  6184. }
  6185. $this->render ( "/admin/saeaStaffCollect", $data );
  6186. }
  6187. function lyt(){
  6188. Doo::loadModel("receiptDetail");
  6189. $receiptDetail=new receiptDetail();
  6190. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6191. foreach ($receiptCollectList as $key=>$value){
  6192. $receiptDetail=new receiptDetail();
  6193. $receiptDetail->pastDate=$value['date'];
  6194. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6195. }
  6196. }
  6197. function staffCollectMonthDetail(){
  6198. $year=$this->get_args('year')?$this->get_args('year'):"";
  6199. $month=$this->get_args('month')?$this->get_args('month'):"";
  6200. if(!$year)
  6201. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6202. if(!$month)
  6203. $month=isset($this->params['month'])?$this->params['month']:1;
  6204. Doo::loadModel('staff');
  6205. $staff=new staff();
  6206. Doo::loadModel("receiptDetail");
  6207. $receiptDetail=new receiptDetail();
  6208. Doo::loadModel('accountItem');
  6209. $accountItem=new accountItem();
  6210. Doo::loadModel('statistics');
  6211. $statistics=new statistics();
  6212. Doo::loadModel('L_category');
  6213. $lCategory=new L_category();
  6214. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6215. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6216. $list=array();
  6217. foreach ($categoryList as $vlu){
  6218. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6219. $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;
  6220. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6221. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6222. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6223. $s1=0;
  6224. $m1=0;
  6225. foreach ($staffList as $value){
  6226. if ($vlu['cid']==$value['cid']){
  6227. //pastDate
  6228. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6229. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6230. // if ($value['sid']==42){
  6231. // print_r($receiptCollectList);die;
  6232. // }
  6233. if(!empty($receiptCollectList)){
  6234. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6235. $html="";
  6236. $psum=0;
  6237. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6238. foreach ($item as $va){
  6239. $falg=true;
  6240. foreach ($receiptCollectList as $v){
  6241. if($v['itemCategory']=='日常相关费用'){
  6242. if($v['item']==$va){
  6243. if ($va=='市内交通费')
  6244. $r1+=$v['price'];
  6245. if ($va=='市内出租费')
  6246. $r2+=$v['price'];
  6247. if ($va=='办事处房租')
  6248. $r3+=$v['price'];
  6249. if ($va=='电话费')
  6250. $r4+=$v['price'];
  6251. if ($va=='水费')
  6252. $r5+=$v['price'];
  6253. if ($va=='电费')
  6254. $r6+=$v['price'];
  6255. if ($va=='办公费用')
  6256. $r7+=$v['price'];
  6257. if ($va=='邮寄费')
  6258. $r8+=$v['price'];
  6259. if ($va=='其他费用')
  6260. $r9+=$v['price'];
  6261. if ($va=='车辆费用')
  6262. $r10+=$v['price'];
  6263. if ($va=='广告费')
  6264. $r11+=$v['price'];
  6265. if ($va=='团队建设费')
  6266. $r13+=$v['price'];
  6267. if ($va=='物业管理费')
  6268. $r14+=$v['price'];
  6269. if ($va=='宽带费')
  6270. $r15+=$v['price'];
  6271. $psum+=$v['price'];
  6272. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6273. }
  6274. }
  6275. }
  6276. if($falg)
  6277. $html.='<td class="taR">-</td>';
  6278. }
  6279. $r12+=$psum;
  6280. if(!empty($psum))
  6281. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6282. else
  6283. $psum='<td class="colGreen taR">-</td>';
  6284. $receiptL['日常相关费用']=$psum.$html;
  6285. /*-----------------------------------*/
  6286. $html="";
  6287. $psum=0;
  6288. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6289. foreach ($item as $va){
  6290. $falg=true;
  6291. foreach ($receiptCollectList as $v){
  6292. if($v['itemCategory']=='差旅相关费用'){
  6293. if($v['item']==$va){
  6294. if ($va=='往来交通费')
  6295. $c1+=$v['price'];
  6296. if ($va=='市内交通费')
  6297. $c2+=$v['price'];
  6298. if ($va=='出差住宿费')
  6299. $c3+=$v['price'];
  6300. if ($va=='出差补助')
  6301. $c4+=$v['price'];
  6302. if ($va=='其他费用')
  6303. $c5+=$v['price'];
  6304. $psum+=$v['price'];
  6305. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6306. }
  6307. }
  6308. }
  6309. if($falg)
  6310. $html.='<td class="taR">-</td>';
  6311. }
  6312. $c6+=$psum;
  6313. if(!empty($psum))
  6314. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6315. else
  6316. $psum='<td class="colGreen taR">-</td>';
  6317. $receiptL['差旅相关费用']=$psum.$html;
  6318. /*-------------------------------------*/
  6319. $html="";
  6320. $psum=0;
  6321. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6322. foreach ($item as $va){
  6323. $falg=true;
  6324. foreach ($receiptCollectList as $v){
  6325. if($v['itemCategory']=='培训班费用'){
  6326. if($v['item']==$va){
  6327. if ($va=='场租费')
  6328. $p1+=$v['price'];
  6329. if ($va=='薪酬')
  6330. $p2+=$v['price'];
  6331. if ($va=='住宿费')
  6332. $p3+=$v['price'];
  6333. if ($va=='交通费')
  6334. $p4+=$v['price'];
  6335. if ($va=='餐饮费')
  6336. $p5+=$v['price'];
  6337. if ($va=='办公费')
  6338. $p6+=$v['price'];
  6339. if ($va=='公关费')
  6340. $p7+=$v['price'];
  6341. if ($va=='其他')
  6342. $p8+=$v['price'];
  6343. $psum+=$v['price'];
  6344. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6345. }
  6346. }
  6347. }
  6348. if($falg)
  6349. $html.='<td class="taR">-</td>';
  6350. }
  6351. $p9+=$psum;
  6352. if(!empty($psum))
  6353. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6354. else
  6355. $psum='<td class="colGreen taR">-</td>';
  6356. $receiptL['培训班费用']=$psum.$html;
  6357. /*-------------------------------------*/
  6358. $html="";
  6359. $psum=0;
  6360. $item=array('公关费','广告费','借款','可自加费用');
  6361. foreach ($item as $va){
  6362. $falg=true;
  6363. foreach ($receiptCollectList as $v){
  6364. if($v['itemCategory']=='其他'){
  6365. // if ($value['sid']==42){
  6366. //
  6367. // echo var_dump($v['item']);
  6368. // echo var_dump($va);
  6369. // echo var_dump($v['item']==" ".$va);
  6370. // echo $v['item']."==".$va."/<br/>";
  6371. // //print_r( $receiptCollectList);//echo $va;
  6372. // }
  6373. if(trim($v['item'])==$va){
  6374. if ($va=='公关费')
  6375. $t1+=$v['price'];
  6376. if ($va=='广告费'){
  6377. $t2+=$v['price'];
  6378. }
  6379. if ($va=='借款')
  6380. $t3+=$v['price'];
  6381. if ($va=='可自加费用')
  6382. $t4+=$v['price'];
  6383. $psum+=$v['price'];
  6384. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6385. }
  6386. }
  6387. }
  6388. if($falg)
  6389. $html.='<td class="taR">-</td>';
  6390. }
  6391. $t5+=$psum;
  6392. if(!empty($psum))
  6393. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6394. else
  6395. $psum='<td class="colGreen taR">-</td>';
  6396. $receiptL['其他']=$psum.$html;
  6397. /*-------------------------------------*/
  6398. $html="";
  6399. $psum=0;
  6400. foreach ($receiptCollectList as $v){
  6401. if($v['itemCategory']=='报销金额调整'){
  6402. if (!empty($v['price'])){
  6403. $psum+=$v['price'];
  6404. }
  6405. }
  6406. }
  6407. $s1+=$psum;
  6408. if(!empty($psum))
  6409. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6410. else
  6411. $psum='<td class="taR colOrange">-</td>';
  6412. $receiptL['报销金额调整']=$psum.$html;
  6413. }else{
  6414. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6415. <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>
  6416. <td class="taR">-</td><td class="taR">-</td>';
  6417. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6418. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6419. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6420. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6421. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6422. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6423. }
  6424. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6425. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6426. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6427. if(!empty($monthStaffPrice[0]['price'])){
  6428. $m1+=$monthStaffPrice[0]['price'];
  6429. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6430. }else
  6431. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6432. $list[$value['username']]=$receiptL;
  6433. }
  6434. }
  6435. $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>
  6436. <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>
  6437. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6438. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6439. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6440. $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>
  6441. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6442. $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>';
  6443. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6444. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6445. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6446. }
  6447. $data['list']=$list;
  6448. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6449. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6450. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6451. //statistics html
  6452. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6453. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6454. if(empty($stList))
  6455. $stList=array('rePrice'=>0,'agPrice'=>0);
  6456. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6457. $monthHtml="";
  6458. for ($i=1;$i<=12;$i++){
  6459. if ($i==$month)
  6460. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6461. else
  6462. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6463. }
  6464. $data['monthHtml']=$monthHtml;
  6465. $data['year']=$year;
  6466. $data['month']=$month;
  6467. $data['memu']="receipt";
  6468. $data['staff']=$this->staff;
  6469. $data['receiptMemu']='companyCategoryCollect';
  6470. $data['verifyId']=$this->verifyId;
  6471. $data['executeId']=$this->executeId;
  6472. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6473. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6474. }
  6475. function staffCollectMonthDetail2(){
  6476. $year=$this->get_args('year')?$this->get_args('year'):"";
  6477. $month=$this->get_args('month')?$this->get_args('month'):"";
  6478. if(!$year)
  6479. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6480. if(!$month)
  6481. $month=isset($this->params['month'])?$this->params['month']:1;
  6482. Doo::loadModel('staff');
  6483. $staff=new staff();
  6484. Doo::loadModel("receiptDetail");
  6485. $receiptDetail=new receiptDetail();
  6486. Doo::loadModel('accountItem');
  6487. $accountItem=new accountItem();
  6488. Doo::loadModel('statistics');
  6489. $statistics=new statistics();
  6490. Doo::loadModel('L_category');
  6491. $lCategory=new L_category();
  6492. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6493. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6494. $list=array();
  6495. foreach ($categoryList as $vlu){
  6496. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6497. $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;
  6498. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6499. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6500. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6501. $s1=0;
  6502. $m1=0;
  6503. foreach ($staffList as $value){
  6504. if ($vlu['cid']==$value['cid']){
  6505. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6506. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6507. if(!empty($receiptCollectList)){
  6508. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6509. $html="";
  6510. $psum=0;
  6511. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6512. foreach ($item as $va){
  6513. $falg=true;
  6514. foreach ($receiptCollectList as $v){
  6515. if($v['itemCategory']=='日常相关费用'){
  6516. if($v['item']==$va){
  6517. if ($va=='市内交通费')
  6518. $r1+=$v['price'];
  6519. if ($va=='市内出租费')
  6520. $r2+=$v['price'];
  6521. if ($va=='办事处房租')
  6522. $r3+=$v['price'];
  6523. if ($va=='电话费')
  6524. $r4+=$v['price'];
  6525. if ($va=='水费')
  6526. $r5+=$v['price'];
  6527. if ($va=='电费')
  6528. $r6+=$v['price'];
  6529. if ($va=='办公费用')
  6530. $r7+=$v['price'];
  6531. if ($va=='邮寄费')
  6532. $r8+=$v['price'];
  6533. if ($va=='其他费用')
  6534. $r9+=$v['price'];
  6535. if ($va=='车辆费用')
  6536. $r10+=$v['price'];
  6537. if ($va=='广告费')
  6538. $r11+=$v['price'];
  6539. if ($va=='团队建设费')
  6540. $r13+=$v['price'];
  6541. if ($va=='物业管理费')
  6542. $r14+=$v['price'];
  6543. if ($va=='宽带费')
  6544. $r15+=$v['price'];
  6545. $psum+=$v['price'];
  6546. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6547. }
  6548. }
  6549. }
  6550. if($falg)
  6551. $html.='<td class="taR">-</td>';
  6552. }
  6553. $r12+=$psum;
  6554. if(!empty($psum))
  6555. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6556. else
  6557. $psum='<td class="colGreen taR">-</td>';
  6558. $receiptL['日常相关费用']=$psum.$html;
  6559. /*-----------------------------------*/
  6560. $html="";
  6561. $psum=0;
  6562. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6563. foreach ($item as $va){
  6564. $falg=true;
  6565. foreach ($receiptCollectList as $v){
  6566. if($v['itemCategory']=='差旅相关费用'){
  6567. if($v['item']==$va){
  6568. if ($va=='往来交通费')
  6569. $c1+=$v['price'];
  6570. if ($va=='市内交通费')
  6571. $c2+=$v['price'];
  6572. if ($va=='出差住宿费')
  6573. $c3+=$v['price'];
  6574. if ($va=='出差补助')
  6575. $c4+=$v['price'];
  6576. if ($va=='其他费用')
  6577. $c5+=$v['price'];
  6578. $psum+=$v['price'];
  6579. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6580. }
  6581. }
  6582. }
  6583. if($falg)
  6584. $html.='<td class="taR">-</td>';
  6585. }
  6586. $c6+=$psum;
  6587. if(!empty($psum))
  6588. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6589. else
  6590. $psum='<td class="colGreen taR">-</td>';
  6591. $receiptL['差旅相关费用']=$psum.$html;
  6592. /*-------------------------------------*/
  6593. $html="";
  6594. $psum=0;
  6595. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6596. foreach ($item as $va){
  6597. $falg=true;
  6598. foreach ($receiptCollectList as $v){
  6599. if($v['itemCategory']=='培训班费用'){
  6600. if($v['item']==$va){
  6601. if ($va=='场租费')
  6602. $p1+=$v['price'];
  6603. if ($va=='薪酬')
  6604. $p2+=$v['price'];
  6605. if ($va=='住宿费')
  6606. $p3+=$v['price'];
  6607. if ($va=='交通费')
  6608. $p4+=$v['price'];
  6609. if ($va=='餐饮费')
  6610. $p5+=$v['price'];
  6611. if ($va=='办公费')
  6612. $p6+=$v['price'];
  6613. if ($va=='公关费')
  6614. $p7+=$v['price'];
  6615. if ($va=='其他')
  6616. $p8+=$v['price'];
  6617. $psum+=$v['price'];
  6618. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6619. }
  6620. }
  6621. }
  6622. if($falg)
  6623. $html.='<td class="taR">-</td>';
  6624. }
  6625. $p9+=$psum;
  6626. if(!empty($psum))
  6627. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6628. else
  6629. $psum='<td class="colGreen taR">-</td>';
  6630. $receiptL['培训班费用']=$psum.$html;
  6631. /*-------------------------------------*/
  6632. $html="";
  6633. $psum=0;
  6634. $item=array('公关费','广告费','借款','可自加费用');
  6635. foreach ($item as $va){
  6636. $falg=true;
  6637. foreach ($receiptCollectList as $v){
  6638. if($v['itemCategory']=='其他'){
  6639. if($v['item']==$va){
  6640. if ($va=='公关费')
  6641. $t1+=$v['price'];
  6642. if ($va=='广告费')
  6643. $t2+=$v['price'];
  6644. if ($va=='借款')
  6645. $t3+=$v['price'];
  6646. if ($va=='可自加费用')
  6647. $t4+=$v['price'];
  6648. $psum+=$v['price'];
  6649. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6650. }
  6651. }
  6652. }
  6653. if($falg)
  6654. $html.='<td class="taR">-</td>';
  6655. }
  6656. $t5+=$psum;
  6657. if(!empty($psum))
  6658. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6659. else
  6660. $psum='<td class="colGreen taR">-</td>';
  6661. $receiptL['其他']=$psum.$html;
  6662. /*-------------------------------------*/
  6663. $html="";
  6664. $psum=0;
  6665. foreach ($receiptCollectList as $v){
  6666. if($v['itemCategory']=='报销金额调整'){
  6667. if (!empty($v['price'])){
  6668. $psum+=$v['price'];
  6669. }
  6670. }
  6671. }
  6672. $s1+=$psum;
  6673. if(!empty($psum))
  6674. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6675. else
  6676. $psum='<td class="taR colOrange">-</td>';
  6677. $receiptL['报销金额调整']=$psum.$html;
  6678. }else{
  6679. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6680. <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>';
  6681. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6682. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6683. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6684. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6685. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6686. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6687. }
  6688. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6689. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6690. if(!empty($monthStaffPrice[0]['price'])){
  6691. $m1+=$monthStaffPrice[0]['price'];
  6692. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6693. }else
  6694. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6695. $list[$value['username']]=$receiptL;
  6696. }
  6697. }
  6698. $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>
  6699. <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>
  6700. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6701. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6702. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6703. $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>
  6704. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6705. $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>';
  6706. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6707. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6708. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6709. }
  6710. $data['list']=$list;
  6711. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6712. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6713. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6714. //statistics html
  6715. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6716. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6717. if(empty($stList))
  6718. $stList=array('rePrice'=>0,'agPrice'=>0);
  6719. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6720. $monthHtml="";
  6721. for ($i=1;$i<=12;$i++){
  6722. if ($i==$month)
  6723. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6724. else
  6725. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6726. }
  6727. $data['monthHtml']=$monthHtml;
  6728. $data['year']=$year;
  6729. $data['month']=$month;
  6730. $data['memu']="receipt";
  6731. $data['staff']=$this->staff;
  6732. $data['receiptMemu']='companyCategoryCollect';
  6733. $data['verifyId']=$this->verifyId;
  6734. $data['executeId']=$this->executeId;
  6735. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6736. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6737. }
  6738. function companyMonthCollectDetail(){
  6739. $year=$this->get_args('year')?$this->get_args('year'):"";
  6740. $month=$this->get_args('month')?$this->get_args('month'):"";
  6741. if(!$year)
  6742. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6743. if(!$month)
  6744. $month=isset($this->params['month'])?$this->params['month']:1;
  6745. Doo::loadModel('staff');
  6746. $staff=new staff();
  6747. Doo::loadModel("receiptDetail");
  6748. $receiptDetail=new receiptDetail();
  6749. Doo::loadModel('accountItem');
  6750. $accountItem=new accountItem();
  6751. Doo::loadModel('statistics');
  6752. $statistics=new statistics();
  6753. Doo::loadModel('L_category');
  6754. $lCategory=new L_category();
  6755. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6756. $categoryList=$lCategory->find(array('asArray'=>true));
  6757. $list=array();
  6758. foreach ($categoryList as $value){
  6759. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6760. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6761. if(!empty($receiptCollectList)){
  6762. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6763. $html="";
  6764. $psum=0;
  6765. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6766. foreach ($item as $va){
  6767. $falg=true;
  6768. foreach ($receiptCollectList as $v){
  6769. if($v['itemCategory']=='日常相关费用'){
  6770. if($v['item']==$va){
  6771. $psum+=$v['price'];
  6772. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6773. }
  6774. }
  6775. }
  6776. if($falg)
  6777. $html.='<td class="taR">-</td>';
  6778. }
  6779. if(!empty($psum))
  6780. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6781. else
  6782. $psum='<td class="colGreen taR">-</td>';
  6783. $receiptL['日常相关费用']=$psum.$html;
  6784. /*-----------------------------------*/
  6785. $html="";
  6786. $psum=0;
  6787. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6788. foreach ($item as $va){
  6789. $falg=true;
  6790. foreach ($receiptCollectList as $v){
  6791. if($v['itemCategory']=='差旅相关费用'){
  6792. if($v['item']==$va){
  6793. $psum+=$v['price'];
  6794. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6795. }
  6796. }
  6797. }
  6798. if($falg)
  6799. $html.='<td class="taR">-</td>';
  6800. }
  6801. if(!empty($psum))
  6802. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6803. else
  6804. $psum='<td class="colGreen taR">-</td>';
  6805. $receiptL['差旅相关费用']=$psum.$html;
  6806. /*-------------------------------------*/
  6807. $html="";
  6808. $psum=0;
  6809. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6810. foreach ($item as $va){
  6811. $falg=true;
  6812. foreach ($receiptCollectList as $v){
  6813. if($v['itemCategory']=='培训班费用'){
  6814. if($v['item']==$va){
  6815. $psum+=$v['price'];
  6816. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6817. }
  6818. }
  6819. }
  6820. if($falg)
  6821. $html.='<td class="taR">-</td>';
  6822. }
  6823. if(!empty($psum))
  6824. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6825. else
  6826. $psum='<td class="colGreen taR">-</td>';
  6827. $receiptL['培训班费用']=$psum.$html;
  6828. /*-------------------------------------*/
  6829. $html="";
  6830. $psum=0;
  6831. $item=array('公关费','广告费','借款','可自加费用');
  6832. foreach ($item as $va){
  6833. $falg=true;
  6834. foreach ($receiptCollectList as $v){
  6835. if($v['itemCategory']=='其他'){
  6836. if($v['item']==$va){
  6837. $psum+=$v['price'];
  6838. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6839. }
  6840. }
  6841. }
  6842. if($falg)
  6843. $html.='<td class="taR">-</td>';
  6844. }
  6845. if(!empty($psum))
  6846. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6847. else
  6848. $psum='<td class="colGreen taR">-</td>';
  6849. $receiptL['其他']=$psum.$html;
  6850. /*-------------------------------------*/
  6851. $html="";
  6852. $psum=0;
  6853. foreach ($receiptCollectList as $v){
  6854. if($v['itemCategory']=='报销金额调整'){
  6855. if (!empty($v['price']))
  6856. $psum+=$v['price'];
  6857. }
  6858. }
  6859. if(!empty($psum))
  6860. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6861. else
  6862. $psum='<td class="taR colOrange">-</td>';
  6863. $receiptL['报销金额调整']=$psum.$html;
  6864. }else{
  6865. $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>
  6866. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6867. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6868. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6869. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6870. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6871. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6872. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6873. }
  6874. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6875. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6876. if(!empty($monthStaffPrice[0]['price']))
  6877. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6878. else
  6879. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6880. $list[$value['title']]=$receiptL;
  6881. }
  6882. $data['list']=$list;
  6883. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6884. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6885. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6886. //print_r($data['monthPriceHtml']);
  6887. // foreach ($data['monthPriceHtml'] as $value){
  6888. // echo $value;
  6889. // }
  6890. // die;
  6891. //statistics html
  6892. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6893. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6894. if(empty($stList))
  6895. $stList=array('rePrice'=>0,'agPrice'=>0);
  6896. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6897. $monthHtml="";
  6898. for ($i=1;$i<=12;$i++){
  6899. if ($i==$month)
  6900. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6901. else
  6902. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6903. }
  6904. $data['monthHtml']=$monthHtml;
  6905. $data['year']=$year;
  6906. $data['month']=$month;
  6907. $data['memu']="receipt";
  6908. $data['staff']=$this->staff;
  6909. $data['receiptMemu']='companyCategoryCollect';
  6910. $data['verifyId']=$this->verifyId;
  6911. $data['executeId']=$this->executeId;
  6912. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6913. }
  6914. function staffCollectDetail(){
  6915. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6916. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6917. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6918. if(!$staffname){
  6919. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6920. $staffname= urldecode($staffname);
  6921. }
  6922. Doo::loadModel('staff');
  6923. $staff=new staff();
  6924. Doo::loadModel("receiptDetail");
  6925. $receiptDetail=new receiptDetail();
  6926. Doo::loadModel('accountItem');
  6927. $accountItem=new accountItem();
  6928. Doo::loadModel('statistics');
  6929. $statistics=new statistics();
  6930. Doo::loadModel('L_category');
  6931. $lCategory=new L_category();
  6932. $staffList=$staff->find(array('asArray'=>true));
  6933. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6934. foreach ($staffList as $value){
  6935. if ($value['username']==$staffname&&$value['username']!='admin'){
  6936. $stTitle=$value['category'].'-'.$value['username'];
  6937. $staffId=$value['sid'];
  6938. $cid=$value['cid'];
  6939. $ocid=$value['cid'];
  6940. if (!empty($value['othercid']))
  6941. $cid=$value['cid'].','.$value['othercid'];
  6942. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6943. }elseif ($value['username']!='admin')
  6944. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6945. }
  6946. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6947. if(empty($pcid))
  6948. $pcid=$ocid;
  6949. $data['ocid']=$pcid;
  6950. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6951. $this->showCache($path);
  6952. //
  6953. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6954. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6955. $accountList=$accountItem->find(array('asArray'=>true));
  6956. //create CollectDetail HTML
  6957. $collectHtml=array();
  6958. foreach ($accountList as $key=>$value){
  6959. $html="";$asum=0;
  6960. for ($i=1;$i<=12;$i++){
  6961. $falg=true;
  6962. foreach ($receiptCollectList as $v) {
  6963. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  6964. $asum+=$v['price'];
  6965. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  6966. }
  6967. }
  6968. if($falg)
  6969. $html.='<td class="taR">-</td>';
  6970. }
  6971. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  6972. $collectHtml[$value['category']][$value['name']]=$html;
  6973. }
  6974. $data['collectHtml']=$collectHtml;
  6975. //create Adjustment price html
  6976. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  6977. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  6978. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6979. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  6980. array_push($collectArray['日常相关费用'], $collectHtml);
  6981. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  6982. array_push($collectArray['差旅相关费用'], $collectHtml);
  6983. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  6984. array_push($collectArray['培训班费用'], $collectHtml);
  6985. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  6986. array_push($collectArray['其他'], $collectHtml);
  6987. $data['collectArray']=$collectArray;
  6988. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  6989. array_push($adjustment, $collectHtml);
  6990. $data['adjustment']=$adjustment;
  6991. //total price html
  6992. $collectHtml="";$total=0;
  6993. for ($i=1;$i<=12;$i++){
  6994. $sumPrice=0;
  6995. foreach ($receiptCollectList as $key=>$value){
  6996. if($value['month']==$i){
  6997. $sumPrice+=$value['price'];
  6998. }
  6999. }
  7000. if ($sumPrice==0)
  7001. $collectHtml.='<td class="taR">-</td>';
  7002. else
  7003. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  7004. $total+=$sumPrice;
  7005. }
  7006. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  7007. //statistics html
  7008. $stList=$statistics->statisticsByYear($year,$staffId);
  7009. if(empty($stList))
  7010. $stList=array('rePrice'=>0,'agPrice'=>0);
  7011. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  7012. $data['totalPrice']=$collectHtml;
  7013. $data['totalYear']=$total;
  7014. $data['stHtml']=$stHtml;
  7015. $data['year']=$year;
  7016. $data['stTitle']=$stTitle;
  7017. $data['memu']="receipt";
  7018. $data['staff']=$this->staff;
  7019. $data['receiptMemu']='companyCategoryCollect';
  7020. $data['verifyId']=$this->verifyId;
  7021. $data['executeId']=$this->executeId;
  7022. if ($year<date("Y")){
  7023. Doo::loadModel('receipt');
  7024. $receipt=new receipt();
  7025. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  7026. if(empty($receiptList)){ //generated files
  7027. ob_start();
  7028. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7029. $this->cacheFile($path);die;
  7030. }
  7031. }
  7032. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7033. }
  7034. function BUGFLAG(){
  7035. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  7036. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  7037. $month=$this->get_args('month')?$this->get_args('month'):"";
  7038. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  7039. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  7040. if (empty($status))
  7041. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  7042. $page_size=12;
  7043. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7044. $vidList=array();
  7045. $button=0;
  7046. Doo::loadModel('verify');
  7047. $verify=new verify();
  7048. Doo::loadModel('receipt');
  7049. $receipt=new receipt();
  7050. Doo::loadModel('staff');
  7051. $staff=new staff();
  7052. Doo::loadModel('L_category');
  7053. $Lcategory=new L_category();
  7054. $dateCondition=" and Year(date) =".$year;
  7055. if(!empty($month))
  7056. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  7057. $categoryList=$Lcategory->find(array('asArray'=>true));
  7058. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7059. $cateCondition="";$staffCondition="";$approvalCondition="";
  7060. if (!empty($cid))
  7061. $cateCondition=' and cid='.$cid;
  7062. if(!empty($sid)){
  7063. $staffCondition=' and staff='.$sid;
  7064. $cateCondition="";
  7065. }
  7066. $approvalCondition=" and status=".$status;
  7067. if($status==2){
  7068. //查找角色审批人
  7069. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7070. }
  7071. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7072. $approvalCondition=' and status=2 ';
  7073. }
  7074. if($status==1){
  7075. $approvalCondition=' and (status='.$status.' or status=6) ';
  7076. }
  7077. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7078. $pageinfo['page']=array('previous'=>'');
  7079. if ($status==0){
  7080. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7081. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7082. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7083. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7084. }else
  7085. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7086. ,'desc'=>'rid','asArray'=>true));
  7087. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )'.$cateCondition.$staffCondition
  7088. ,'desc'=>'rid','asArray'=>true));
  7089. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7090. //print_r($pageinfo);
  7091. $Locate=0;
  7092. foreach ($receiptList as $key=>$value){
  7093. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7094. $receiptList[$key]['reviseDetail']=array();
  7095. if (!empty($value['reviseDetail']))
  7096. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7097. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7098. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7099. $receiptList[$key]['category']=$categoryDetil['title'];
  7100. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7101. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7102. $verifyStaff=json_decode($value['verifyStaff'],true);
  7103. foreach ($verifyList as $k=>$v){
  7104. //init verifyStaff
  7105. $verifyList[$k]['date']="";
  7106. $verifyList[$k]['opinion']="";
  7107. $verifyList[$k]['status']="";
  7108. if (empty($verifyStaff)){
  7109. $verifyList[$k]['date']="";
  7110. $verifyList[$k]['opinion']="";
  7111. if ($v[0]==$this->staff[0]['sid']){
  7112. $verifyList[$k]['status']=4;
  7113. $button=4;
  7114. }
  7115. }else{
  7116. $flag=true;
  7117. foreach ($verifyStaff as $m=>$u){
  7118. if ($v[0]==$m){
  7119. $verifyList[$k]['date']=$u['date'];
  7120. $verifyList[$k]['opinion']=$u['opinion'];
  7121. $verifyList[$k]['status']=$u['status'];
  7122. $flag=false;
  7123. break;
  7124. }
  7125. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7126. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7127. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7128. }
  7129. if($flag){//检测可编辑
  7130. if($v[0]==$this->staff[0]['sid']){
  7131. $verifyList[$k]['status']=4;$button=4;
  7132. }
  7133. }
  7134. }
  7135. }
  7136. $receiptList[$key]['verifyList']=$verifyList;
  7137. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7138. $receiptList[$key]['button']=$button;
  7139. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7140. }
  7141. //print_r($receiptList);die;
  7142. //$data['verifyDetail']=$verifyDetail;
  7143. $mothHtml="";
  7144. for($i=1;$i<=12;$i++){
  7145. if($month==$i)
  7146. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7147. else
  7148. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7149. }
  7150. $data['mothHtml']=$mothHtml;
  7151. $data['page']=$pageinfo;
  7152. $data['receiptList']=$receiptList;
  7153. $data['receiptApprovalCount']=count($rLRes);
  7154. $data['status']=$status;
  7155. $data['year']=$year;
  7156. $data['categoryList']=$categoryList;
  7157. $data['staffList']=$staffList;
  7158. $data['cid']=$cid;
  7159. $data['sid']=$sid;
  7160. //print_r($receiptList);
  7161. $data['memu']="receipt";
  7162. $data['staff']=$this->staff;
  7163. $data['receiptMemu']='approvalExpenses';
  7164. $data['verifyId']=$this->verifyId;
  7165. $data['executeId']=$this->executeId;
  7166. $this->render ( "/admin/FALG", $data );
  7167. }
  7168. function ajaxGetReceiptOrder(){
  7169. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7170. if (!empty($receiptOrder)){
  7171. Doo::loadModel('receipt');
  7172. $receipt=new receipt();
  7173. Doo::loadModel ( 'staff' );
  7174. $staff = new staff ();
  7175. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7176. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7177. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7178. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7179. </tbody></table><table class="table table table-bordered"><tbody>';
  7180. foreach ($verifyStaff as $key=>$value){
  7181. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7182. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7183. }
  7184. $html.='</tbody></table></div></div>';
  7185. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7186. }
  7187. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7188. }
  7189. function _getMonthCollectDetail($receiptCollectList){
  7190. if(!empty($receiptCollectList)){
  7191. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7192. $html="";
  7193. $psum=0;
  7194. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7195. foreach ($item as $value){
  7196. $falg=true;
  7197. foreach ($receiptCollectList as $v){
  7198. if($v['itemCategory']=='日常相关费用'){
  7199. if($v['item']==$value){
  7200. $psum+=$v['price'];
  7201. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7202. }
  7203. }
  7204. }
  7205. if($falg)
  7206. $html.='<td class="taR">-</td>';
  7207. }
  7208. if(!empty($psum))
  7209. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7210. else
  7211. $psum='<td class="colGreen taR">-</td>';
  7212. $receiptL['日常相关费用']=$psum.$html;
  7213. /*-----------------------------------*/
  7214. $html="";
  7215. $psum=0;
  7216. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7217. foreach ($item as $value){
  7218. $falg=true;
  7219. foreach ($receiptCollectList as $v){
  7220. if($v['itemCategory']=='差旅相关费用'){
  7221. if($v['item']==$value){
  7222. $psum+=$v['price'];
  7223. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7224. }
  7225. }
  7226. }
  7227. if($falg)
  7228. $html.='<td class="taR">-</td>';
  7229. }
  7230. if(!empty($psum))
  7231. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7232. else
  7233. $psum='<td class="colGreen taR">-</td>';
  7234. $receiptL['差旅相关费用']=$psum.$html;
  7235. /*-------------------------------------*/
  7236. $html="";
  7237. $psum=0;
  7238. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7239. foreach ($item as $value){
  7240. $falg=true;
  7241. foreach ($receiptCollectList as $v){
  7242. if($v['itemCategory']=='培训班费用'){
  7243. if($v['item']==$value){
  7244. $psum+=$v['price'];
  7245. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7246. }
  7247. }
  7248. }
  7249. if($falg)
  7250. $html.='<td class="taR">-</td>';
  7251. }
  7252. if(!empty($psum))
  7253. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7254. else
  7255. $psum='<td class="colGreen taR">-</td>';
  7256. $receiptL['培训班费用']=$psum.$html;
  7257. /*-------------------------------------*/
  7258. $html="";
  7259. $psum=0;
  7260. $item=array('公关费','广告费','借款','可自加费用');
  7261. foreach ($item as $value){
  7262. $falg=true;
  7263. foreach ($receiptCollectList as $v){
  7264. if($v['itemCategory']=='其他'){
  7265. if($v['item']==$value){
  7266. $psum+=$v['price'];
  7267. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7268. }
  7269. }
  7270. }
  7271. if($falg)
  7272. $html.='<td class="taR">-</td>';
  7273. }
  7274. if(!empty($psum))
  7275. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7276. else
  7277. $psum='<td class="colGreen taR">-</td>';
  7278. $receiptL['其他']=$psum.$html;
  7279. /*-------------------------------------*/
  7280. $html="";
  7281. $psum=0;
  7282. foreach ($receiptCollectList as $v){
  7283. if($v['itemCategory']=='报销金额调整'){
  7284. if (!empty($v['price']))
  7285. $psum+=$v['price'];
  7286. }
  7287. }
  7288. if(!empty($psum))
  7289. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7290. else
  7291. $psum='<td class="taR colOrange">-</td>';
  7292. $receiptL['报销金额调整']=$psum.$html;
  7293. }else{
  7294. $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>
  7295. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7296. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7297. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7298. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7299. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7300. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7301. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7302. }
  7303. return $receiptL;
  7304. }
  7305. function eMail(){
  7306. Doo::loadModel('staff');
  7307. $staff=new staff();
  7308. Doo::loadModel('receipt');
  7309. $receipt=new receipt();
  7310. Doo::loadModel('L_category');
  7311. $Lcategory=new L_category();
  7312. Doo::loadModel("verify");
  7313. $verify=new verify();
  7314. $staffList=$staff->find(array('asArray'=>true));
  7315. foreach ($staffList as $key=>$value){
  7316. if($value['username']!='admin'){
  7317. //提交人
  7318. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7319. if(!empty($receiptList)){
  7320. $html='<br><div><style></style>
  7321. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7322. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7323. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7324. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7325. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7326. <tbody><tr>
  7327. <td style="padding: 0 40px;" align="left">
  7328. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7329. </td></tr><tr>
  7330. <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>
  7331. </tr>
  7332. </tbody> </table></td> </tr> <tr><td>
  7333. <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">
  7334. <tbody> <tr><td>
  7335. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7336. 以下报销单完成了审批,等着收款吧:</p>
  7337. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7338. foreach ($receiptList as $k=>$v){
  7339. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7340. $html.='
  7341. <tr>
  7342. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7343. <td align="left">
  7344. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7345. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7346. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7347. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7348. </tr>';
  7349. }
  7350. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7351. <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>
  7352. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7353. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7354. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7355. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7356. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7357. $receipt=new receipt();
  7358. $receipt->notice=1;
  7359. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7360. }
  7361. }
  7362. //审批人
  7363. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7364. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7365. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7366. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7367. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7368. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7369. <tbody><tr><td style="padding: 0 40px;" align="left">
  7370. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7371. </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>
  7372. </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">
  7373. <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>
  7374. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7375. foreach ($verifyList as $k=>$v){
  7376. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7377. foreach ($receiptList as $r=>$l){
  7378. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7379. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7380. $html.='
  7381. <tr>
  7382. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7383. <td align="left">
  7384. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7385. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7386. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7387. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7388. </tr>';
  7389. }
  7390. }
  7391. $html.='
  7392. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7393. <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>
  7394. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7395. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7396. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7397. // $receipt=new receipt();
  7398. // $receipt->notice=1;
  7399. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7400. }
  7401. }
  7402. }
  7403. }
  7404. // Email发送函数
  7405. function SMail($toemail, $subject, $contents) {
  7406. Doo::loadClass('class.phpmailer');
  7407. $mail = new PHPMailer();
  7408. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7409. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7410. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7411. $mail->Password = "cDO1GjtY1seH"; //密码
  7412. $mail->CharSet = "UTF8";
  7413. $mail->SMTPAuth = true;
  7414. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7415. $mail->Mailer = "smtp";
  7416. $mail->Port = 25;
  7417. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7418. $mail->MsgHTML($contents);
  7419. $mail->AddAddress($toemail);
  7420. $mail->CharSet = "UTF-8";
  7421. return $mail->Send();
  7422. }
  7423. function swfupload(){
  7424. $POST_MAX_SIZE = ini_get('post_max_size');
  7425. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7426. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7427. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7428. header("HTTP/1.1 500 Internal Server Error");
  7429. echo "POST exceeded maximum allowed size.";
  7430. exit(0);
  7431. }
  7432. // Settings
  7433. $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)
  7434. $upload_name = "Filedata";
  7435. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7436. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7437. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7438. // Other variables
  7439. $MAX_FILENAME_LENGTH = 260;
  7440. $file_name = "";
  7441. $file_extension = "";
  7442. $uploadErrors = array(
  7443. 0=>"文件上传成功",
  7444. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7445. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7446. 3=>"上传的文件仅为部分文件",
  7447. 4=>"没有文件上传",
  7448. 6=>"缺少临时文件夹"
  7449. );
  7450. $nk= time();
  7451. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7452. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7453. echo "文件无法保存.";
  7454. exit(0);
  7455. }
  7456. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7457. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7458. exit(0);
  7459. }
  7460. function _GetFileEXT($filename) {
  7461. $pics = explode ( '.', $filename );
  7462. $num = count ( $pics );
  7463. return $pics [$num - 1];
  7464. }
  7465. /**
  7466. * 获取get或者POST值
  7467. * @param string $name 属性名称
  7468. * @return fixed 值
  7469. */
  7470. function get_args($name) {
  7471. if (isset ( $_GET [$name] )) {
  7472. if (is_array ( $_GET [$name] ))
  7473. return $_GET [$name];
  7474. else
  7475. return addslashes ( $_GET [$name] );
  7476. } elseif (isset ( $_POST [$name] )) {
  7477. if (is_array ( $_POST [$name] ))
  7478. return $_POST [$name];
  7479. else
  7480. return addslashes ( $_POST [$name] );
  7481. } else
  7482. return false;
  7483. }
  7484. function num_to_rmb($num){
  7485. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7486. $c2 = "分角元拾佰仟万拾佰仟亿";
  7487. //精确到分后面就不要了,所以只留两个小数位
  7488. $num = round($num, 2);
  7489. //将数字转化为整数
  7490. $num = $num * 100;
  7491. if (strlen($num) > 10) {
  7492. return "金额太大,请检查";
  7493. }
  7494. $i = 0;
  7495. $c = "";
  7496. while (1) {
  7497. if ($i == 0) {
  7498. //获取最后一位数字
  7499. $n = substr($num, strlen($num)-1, 1);
  7500. } else {
  7501. $n = $num % 10;
  7502. }
  7503. //每次将最后一位数字转化为中文
  7504. $p1 = substr($c1, 3 * $n, 3);
  7505. $p2 = substr($c2, 3 * $i, 3);
  7506. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7507. $c = $p1 . $p2 . $c;
  7508. } else {
  7509. $c = $p1 . $c;
  7510. }
  7511. $i = $i + 1;
  7512. //去掉数字最后一位了
  7513. $num = $num / 10;
  7514. $num = (int)$num;
  7515. //结束循环
  7516. if ($num == 0) {
  7517. break;
  7518. }
  7519. }
  7520. $j = 0;
  7521. $slen = strlen($c);
  7522. while ($j < $slen) {
  7523. //utf8一个汉字相当3个字符
  7524. $m = substr($c, $j, 6);
  7525. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7526. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7527. $left = substr($c, 0, $j);
  7528. $right = substr($c, $j + 3);
  7529. $c = $left . $right;
  7530. $j = $j-3;
  7531. $slen = $slen-3;
  7532. }
  7533. $j = $j + 3;
  7534. }
  7535. //这个是为了去掉类似23.0中最后一个“零”字
  7536. if (substr($c, strlen($c)-3, 3) == '零') {
  7537. $c = substr($c, 0, strlen($c)-3);
  7538. }
  7539. //将处理的汉字加上“整”
  7540. if (empty($c)) {
  7541. return "零元整";
  7542. }else{
  7543. return $c . "整";
  7544. }
  7545. }
  7546. /**
  7547. * 获得分页数据
  7548. * @param unknown_type $table
  7549. * @param unknown_type $condition
  7550. * @param unknown_type $on_page
  7551. * @param unknown_type $page_size
  7552. */
  7553. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7554. $page_c = "";
  7555. $page ['previous'] = $this->get_previous ( $on_page );
  7556. $page ['on_page'] = $on_page;
  7557. $total_count = $this->get_table_count ( $table, $condition );
  7558. $total = intval ( $total_count / $page_size );
  7559. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7560. $page ['total_data'] = $total_count;
  7561. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7562. $i = 1;
  7563. $page_max = 1;
  7564. $page_width=3;
  7565. if ($on_page >= $page_width) {
  7566. $page_max = intval ( $on_page / $page_width ) + 1;
  7567. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7568. }
  7569. for(; $i <= $page ['total_page']; $i ++) {
  7570. if ($i == $on_page)
  7571. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7572. else
  7573. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7574. if ($i == ($page_width * $page_max))
  7575. break;
  7576. }
  7577. $page ['page'] = $page_c;
  7578. $page ['lower'] = (-- $on_page) * $page_size;
  7579. return $page;
  7580. }
  7581. /**
  7582. * 获取总页数
  7583. * @param unknown_type $table
  7584. * @param unknown_type $condition
  7585. */
  7586. public function get_table_count($table = "", $condition = "") {
  7587. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7588. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7589. //echo $sql;die;
  7590. $query = Doo::db ()->query ( $sql );
  7591. $result = $query->fetch ();
  7592. return $result ['count'];
  7593. }
  7594. /**
  7595. * 获取上一页
  7596. * @param unknown_type $on_page
  7597. */
  7598. function get_previous($on_page = 1) {
  7599. return $on_page != 0 ? $on_page - 1 : $on_page;
  7600. }
  7601. }
  7602. ?>