ReceiptController.php 301 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. public static $NEW = 0;
  10. public static $NEW2 = 0;
  11. public $AGENCY="日常相关费用";
  12. public $TRAVEL="差旅相关费用";
  13. public $TRAIN="培训班费用";
  14. public $OTHER="其他";
  15. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  16. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  17. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  18. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  19. private function showCache($path){
  20. if(file_exists($path)){
  21. echo "<!DOCTYPE html>";
  22. include $path;die;
  23. }
  24. }
  25. private function cacheFile($path){
  26. $content = ob_get_contents();
  27. $fp = fopen($path, "w");
  28. fwrite($fp, $content);
  29. fclose($fp);
  30. }
  31. private function getExeCount(){
  32. Doo::loadModel('receipt');
  33. $receipt=new receipt();
  34. $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  35. return count($receiptList);
  36. }
  37. private function getReceiptCount(){
  38. $status=2;
  39. $year=date('Y');
  40. Doo::loadModel('receipt');
  41. $receipt=new receipt();
  42. $dateCondition=" and Year(date) =".$year;
  43. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  44. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  45. return count($receiptList);
  46. }
  47. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  48. $collectHtml="";$sumPrice=0.00;
  49. for ($i=1;$i<=12;$i++){
  50. $falg=true;
  51. foreach ($receiptCollectList as $key=>$value){
  52. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  53. $sumPrice+=$value['price'];
  54. if ($classType=="b"){
  55. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  56. }else{
  57. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  58. }
  59. }
  60. }
  61. if ($falg)
  62. $collectHtml.='<td class="taR">-</td>';
  63. }
  64. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  65. return $collectHtml;
  66. }
  67. function __construct() {
  68. if(isset($_COOKIE["staff"])){
  69. if(!empty($_COOKIE["staff"])){
  70. Doo::loadModel ( 'staff' );
  71. Doo::loadModel('verify');
  72. $verify=new verify();
  73. $staff = new staff ();
  74. Doo::loadModel("execute");
  75. $execute=new execute();
  76. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  77. $list=array();
  78. //判断角色的审批权限
  79. foreach ($verifyList as $key=>$value){
  80. $ver=json_decode($value['staff']);
  81. foreach ($ver as $k=>$v){
  82. if ($v[1]=='ROLE'){
  83. $roleList=json_decode($v[3]);
  84. foreach ($roleList as $t=>$g){
  85. $gList=explode("_", $g);
  86. array_push($list, $gList[0]);
  87. //print_r($list);
  88. }
  89. }else
  90. array_push($list, $v[0]);
  91. }
  92. }
  93. //判断执行人的审批权限
  94. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  95. $list2=array();
  96. foreach ($executeList as $key=>$value){
  97. $ver=json_decode($value['staff']);
  98. foreach ($ver as $k=>$v){
  99. array_push($list2, $v[0]);
  100. }
  101. }
  102. $eidList=file_get_contents("protected/config/execute/execute.ini");
  103. $eidList=array_filter(explode(",", $eidList));
  104. $this->executeId= array_merge($list2,$eidList);
  105. $this->verifyId=$list;
  106. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  107. self::$NEW= $this->getReceiptCount();
  108. self::$NEW2= $this->getExeCount();
  109. return "/";
  110. }
  111. }
  112. Doo::loadCore ( 'uri/DooUriRouter' );
  113. $router = new DooUriRouter ();
  114. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  115. if($routeRs['1']!="login"){
  116. header ( 'Content-Type:text/html;charset=utf-8' );
  117. @header ( "Location: /login" );
  118. }
  119. }
  120. function saeaBorad(){
  121. Doo::loadModel('receipt');
  122. Doo::loadModel('verify');
  123. $verify=new verify();
  124. $receipt=new receipt();
  125. Doo::loadModel('L_category');
  126. $lCategory=new L_category();
  127. Doo::loadModel("role");
  128. $role=new role();
  129. Doo::loadModel("receiptLog");
  130. $receiptLog=new receiptLog();
  131. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  132. $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));
  133. foreach ($receiptDetail as $key=>$value){
  134. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  135. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  136. $v=json_decode($veList['staff']);
  137. array_push($v[0], $veList['description']);
  138. foreach ($v as $n=>$m){
  139. if ($m['1']=='ROLE'){
  140. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  141. $v[$n][1]=$roleInfo['name'];
  142. }
  143. }
  144. $receiptDetail[$key]['staff']=$v;
  145. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  146. $receiptDetail[$key]['category']=$category['title'];
  147. }
  148. //print_r($receiptLogList);
  149. $data['receiptLogList']=$receiptLogList;
  150. $data['receiptDetail']=$receiptDetail;
  151. $data['memu']="receipt";
  152. $data['staff']=$this->staff;
  153. $data['receiptMemu']='saeaBorad';
  154. $data['verifyId']=$this->verifyId;
  155. $data['executeId']=$this->executeId;
  156. $this->render ( "/admin/saeaBorad", $data );
  157. }
  158. function remitAdd(){
  159. Doo::loadModel('accountItem');
  160. Doo::loadModel('verify');
  161. Doo::loadModel('receipt');
  162. Doo::loadModel('L_category');
  163. $lCategory=new L_category();
  164. $receipt=new receipt();
  165. $verify=new verify();
  166. $accountItem=new accountItem();
  167. Doo::loadModel("role");
  168. $role=new role();
  169. $acItem=$accountItem->find(array('asArray'=>true));
  170. $veList=$verify->find(array('asArray'=>true));
  171. foreach ($veList as $key=>$value){
  172. $v=json_decode($value['staff']);
  173. $list=array();
  174. foreach ($v as $n=>$m){
  175. if ($m['1']=='ROLE'){
  176. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  177. $v[$n][1]=$roleInfo['name'];
  178. array_push($list, $roleInfo['name']);
  179. }else{
  180. array_push($list, $v[$n][1]);
  181. }
  182. }
  183. $veList[$key]['staff']=implode('>', $list);
  184. }
  185. $data['category']=$lCategory->find(array('asArray'=>true));
  186. $data['veList']=$veList;
  187. $data['acItem']=$acItem;
  188. $data['memu']="receipt";
  189. $data['staff']=$this->staff;
  190. $data['receiptMemu']='saeaBorad';
  191. $data['verifyId']=$this->verifyId;
  192. $data['executeId']=$this->executeId;
  193. $this->render ( "/admin/remitAdd", $data );
  194. }
  195. function remitAddDo(){
  196. $agency=$this->get_args('agency');
  197. $travel=$this->get_args('travel');
  198. $train=$this->get_args('train');
  199. $other=$this->get_args('other');
  200. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  201. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  202. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  203. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  204. //print_r($agency);die;
  205. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  206. Doo::loadModel('receipt');
  207. Doo::loadModel('receiptDetail');
  208. Doo::loadModel('accountItem');
  209. $accountItem=new accountItem();
  210. $receipt=new receipt();
  211. Doo::loadModel('enclosur');
  212. Doo::loadModel('execute');
  213. $execute=new execute();
  214. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  215. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  216. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  217. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  218. $ag=$tr=$ta=$ot=0;
  219. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  220. foreach ($aItem as $key=>$value){
  221. if ($value['category']==$this->AGENCY){
  222. if (isset($agency[$ag])){
  223. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  224. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  225. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  226. }
  227. }
  228. $ag++;
  229. }
  230. }
  231. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  232. //报销单
  233. $receipt->accountItem=json_encode($accountJson);
  234. $receipt->staff=$this->staff[0]['sid'];
  235. $receipt->sum=number_format($sum, 2, '.', '');
  236. $receipt->date=date("Y-m-d");
  237. $receipt->cid=$cid;
  238. $receipt->status=5;
  239. $receipt->Rtype=2;
  240. //修改审批流程加入角色
  241. $receipt->verify=$verify;
  242. $receipt->executeCopy=$executeDetail['staff'];
  243. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  244. $receipt->explanation=$explanation;
  245. $rid=$receipt->insert();
  246. //附件
  247. if (!empty($enclosurName)){
  248. $enclosurArray=explode('-', $enclosurName);
  249. foreach ($enclosurArray as $value){
  250. $enclosur=new enclosur();
  251. $enclosur->name=$value;
  252. $enclosur->rid=$rid;
  253. $enclosur->insert();
  254. }
  255. //print_r($enclosurArray);die;
  256. }
  257. //报销详情
  258. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  259. $receiptDetail=new receiptDetail();
  260. $receiptDetail->staff=$this->staff[0]['sid'];
  261. $receiptDetail->item=$value['name'];
  262. $receiptDetail->itemCategory=$this->AGENCY;
  263. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  264. $receiptDetail->date=date("Y-m-d");
  265. $receiptDetail->cid=$cid;
  266. $receiptDetail->rid=$rid;
  267. $receiptDetail->status=4;
  268. $receiptDetail->insert();
  269. }
  270. }
  271. return "/saeaBorad";
  272. }
  273. function remitEdit(){
  274. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  275. //echo $rid;
  276. Doo::loadModel('accountItem');
  277. Doo::loadModel('verify');
  278. Doo::loadModel('receipt');
  279. $receipt=new receipt();
  280. $verify=new verify();
  281. $accountItem=new accountItem();
  282. Doo::loadModel('L_category');
  283. $lCategory=new L_category();
  284. Doo::loadModel("role");
  285. $role=new role();
  286. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  287. if(empty($receiptDetail))
  288. return "/saeaCreate";
  289. $acItem=$accountItem->find(array('asArray'=>true));
  290. $veList=$verify->find(array('asArray'=>true));
  291. foreach ($veList as $key=>$value){
  292. $v=json_decode($value['staff']);
  293. $list=array();
  294. foreach ($v as $n=>$m){
  295. if ($m['1']=='ROLE'){
  296. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  297. $v[$n][1]=$roleInfo['name'];
  298. array_push($list, $roleInfo['name']);
  299. }else{
  300. array_push($list, $v[$n][1]);
  301. }
  302. }
  303. $veList[$key]['staff']=implode('>', $list);
  304. }
  305. //配置编辑信息
  306. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  307. foreach ($acItem as $key=>$value){
  308. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  309. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  310. $acItem[$key]['price']=$v['price'];
  311. }
  312. }
  313. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  314. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  315. $acItem[$key]['price']=$v['price'];
  316. }
  317. }
  318. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  319. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  320. $acItem[$key]['price']=$v['price'];
  321. }
  322. }
  323. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  324. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  325. $acItem[$key]['price']=$v['price'];
  326. }
  327. }
  328. }
  329. $data['category']=$lCategory->find(array('asArray'=>true));
  330. $data['cSum']=$accountItemList['cSum'];
  331. $data['sum']=$receiptDetail['sum'];
  332. $data['receiptDetail']=$receiptDetail;
  333. $data['veList']=$veList;
  334. $data['acItem']=$acItem;
  335. $data['memu']="receipt";
  336. $data['staff']=$this->staff;
  337. $data['receiptMemu']='saeaBorad';
  338. $data['verify']=$receiptDetail['verify'];
  339. $data['verifyId']=$this->verifyId;
  340. $data['executeId']=$this->executeId;
  341. $data['rid']=$rid;
  342. $this->render ( "/admin/remitEdit", $data );
  343. }
  344. function remitEdiDo(){
  345. $agency=$this->get_args('agency');
  346. $travel=$this->get_args('travel');
  347. $train=$this->get_args('train');
  348. $other=$this->get_args('other');
  349. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  350. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  351. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  352. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  353. if(!empty($verify)&&!empty($explanation)){
  354. Doo::loadModel('receipt');
  355. Doo::loadModel('receiptDetail');
  356. Doo::loadModel('accountItem');
  357. $accountItem=new accountItem();
  358. $receipt=new receipt();
  359. Doo::loadModel('execute');
  360. $execute=new execute();
  361. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  362. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  363. if(empty($receiptDetail))
  364. return "/saeaBorad";
  365. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  366. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  367. $ag=$tr=$ta=$ot=0;
  368. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  369. foreach ($aItem as $key=>$value){
  370. if ($value['category']==$this->AGENCY){
  371. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  372. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  373. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  374. }
  375. $ag++;
  376. }
  377. }
  378. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  379. //报销单
  380. $rid=$receipt->rid=$receiptDetail['rid'];
  381. $receipt->accountItem=json_encode($accountJson);
  382. $receipt->staff=$this->staff[0]['sid'];
  383. $receipt->sum=number_format($sum, 2, '.', '');
  384. $receipt->date=date("Y-m-d");
  385. $receipt->cid=$cid;
  386. if ($receiptDetail['Rtype']==1)
  387. $receipt->status=7;
  388. else
  389. $receipt->status=5;
  390. $receipt->verify=$verify;
  391. $receipt->executeCopy=$executeDetail['staff'];
  392. $receipt->explanation=$explanation;
  393. $receipt->update();
  394. $receiptDetail=new receiptDetail();
  395. $receiptDetail->delete(array('where'=>'rid='.$rid));
  396. //报销详情
  397. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  398. $receiptDetail=new receiptDetail();
  399. $receiptDetail->staff=$this->staff[0]['sid'];
  400. $receiptDetail->item=$value['name'];
  401. $receiptDetail->itemCategory=$this->AGENCY;
  402. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  403. $receiptDetail->date=date("Y-m-d");
  404. $receiptDetail->cid=$cid;
  405. $receiptDetail->rid=$rid;
  406. $receiptDetail->status=4;
  407. $receiptDetail->insert();
  408. }
  409. //return "/referReceipt/".$rid;
  410. }
  411. return "/saeaBorad";
  412. }
  413. function remitApproval(){
  414. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  415. $status=isset($this->params['status'])?$this->params['status']:'';
  416. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  417. $month=$this->get_args('month')?$this->get_args('month'):"";
  418. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  419. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  420. if (empty($status))
  421. $status=$this->get_args('status')?$this->get_args('status'):2;
  422. $vidList=array();
  423. $button=0;
  424. Doo::loadModel('verify');
  425. Doo::loadModel('receipt');
  426. Doo::loadModel('staff');
  427. $staff=new staff();
  428. $receipt=new receipt();
  429. $verify=new verify();
  430. Doo::loadModel('L_category');
  431. $Lcategory=new L_category();
  432. Doo::loadModel('enclosur');
  433. $enclosur=new enclosur();
  434. //user verify ID
  435. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  436. foreach ($verifyDetail as $key=>$value){
  437. array_push($vidList, $value['vid']);
  438. }
  439. $vid=implode(",", $vidList);
  440. if(empty($verifyDetail))
  441. $vid=0;
  442. $categoryList=$Lcategory->find(array('asArray'=>true));
  443. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  444. $ap="";
  445. if($status==4){
  446. $ap=4;$status=2;
  447. }
  448. //get Receipt By verifyID status 2
  449. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  450. $Locate=0;$roleId=0;
  451. if($ap==4)
  452. $status=4;
  453. foreach ($receiptList as $key=>$value){
  454. $receiptList[$key]['Locate']=$Locate;$Locate++;
  455. $receiptList[$key]['reviseDetail']=array();
  456. if (!empty($value['reviseDetail']))
  457. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  458. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  459. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  460. $receiptList[$key]['category']=$categoryDetil['title'];
  461. //检测编辑状态
  462. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  463. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  464. $verifyStaff=json_decode($value['verifyStaff'],true);
  465. Doo::loadModel('role');
  466. $role=new role();
  467. //print_r($verifyList);
  468. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  469. foreach ($verifyList as $k=>$v){
  470. //init verifyStaff
  471. if ($v[1]=='ROLE'){
  472. if (!empty($verifyStaff)){
  473. $endStaffArray=end($verifyStaff);
  474. if ($v[0]==$endStaffArray['nextStaff']){
  475. $roleId=$v[0];
  476. }
  477. }
  478. $roleVerify=json_decode($v[3],true);
  479. $roleKey=$k;$roleArray=array();
  480. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  481. foreach ($roleVerify as $o=>$p){
  482. $staffID=explode ('_',$p);
  483. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  484. //print_r($staffID);
  485. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  486. array_push($roleArray, $exp);
  487. }
  488. $roleArrayCopy[$v[0]]=$roleArray;
  489. //$verifyList[$k]['roleArray']=$roleArray;
  490. }
  491. //print_r($roleArray);
  492. $verifyList[$k]['date']="";
  493. $verifyList[$k]['opinion']="";
  494. $verifyList[$k]['status']="";
  495. if (empty($verifyStaff)){
  496. $verifyList[$k]['date']="";
  497. $verifyList[$k]['opinion']="";
  498. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  499. $verifyList[$k]['status']=4;
  500. $button=4;$flag=false;
  501. }
  502. }else{
  503. foreach ($verifyStaff as $m=>$u){
  504. if ($v[0]==$m){
  505. $verifyList[$k]['date']=$u['date'];
  506. $verifyList[$k]['opinion']=$u['opinion'];
  507. $verifyList[$k]['status']=$u['status'];
  508. $flag=false;
  509. break;
  510. }
  511. }
  512. $endStaffArray=end($verifyStaff);
  513. if (isset($endStaffArray['ROLE'])){
  514. }else{
  515. $endKey=key($verifyStaff);
  516. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  517. $button=4;
  518. $verifyList[$k]['status']=4;
  519. }
  520. }
  521. }
  522. }
  523. $rolename['name']='';
  524. if (!empty($roleId)){
  525. Doo::loadModel('role');
  526. $role=new role();
  527. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  528. }
  529. if (!empty($verifyStaff))
  530. $endStaffArray=end($verifyStaff);
  531. $KOP=false;
  532. foreach ($roleArrayCopy as $P=>$A){
  533. foreach ( $A as $MKI=>$AVL){
  534. if (!empty($verifyStaff)){
  535. //&&$rolename['rid']==$endStaffArray['nextStaff']
  536. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  537. $button=4;
  538. $roleArrayCopy[$P][$MKI]['status']=4;
  539. }
  540. foreach ($verifyStaff as $m=>$u){
  541. $AVLFK=$AVL[0].'_R';
  542. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  543. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  544. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  545. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  546. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  547. break;
  548. }
  549. }
  550. }else{
  551. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  552. $button=4;
  553. $roleArrayCopy[$P][$MKI]['status']=4;
  554. }
  555. }
  556. //$roleArray[$MKI]['rolename']=$rolename['name'];
  557. $KOP=true;
  558. }
  559. }
  560. foreach ($roleArrayCopy as $k=>$v){
  561. foreach ($verifyList as $m=>$n){
  562. if ($n[0]==$k){
  563. array_splice($verifyList,$m,1,$v);
  564. }
  565. }
  566. }
  567. $receiptList[$key]['verifyList']= $verifyList;
  568. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  569. $receiptList[$key]['button']=$button;
  570. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  571. }
  572. $mothHtml="";
  573. for($i=1;$i<=12;$i++){
  574. if($month==$i)
  575. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  576. else
  577. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  578. }
  579. //获取审批日志
  580. Doo::loadModel('receiptLog');
  581. $receiptLog=new receiptLog();
  582. $rlList=array();
  583. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  584. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  585. if (!empty($rlInfo)){
  586. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  587. }
  588. $receiptList[0]['rlList']=$rlList;
  589. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  590. $enclosurHtml='';
  591. foreach ($enclosurList as $value){
  592. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  593. }
  594. //print_r($receiptList);
  595. $data['enclosurHtml']=$enclosurHtml;
  596. $data['rolename']=$rolename['name'];
  597. $data['datetij']=$tijdate['date'];
  598. $data['mothHtml']=$mothHtml;
  599. $data['rid']=$rid;
  600. $data['receiptList']=$receiptList;
  601. $data['receiptApprovalCount']=count($receiptList);
  602. $data['status']=$status;
  603. $data['year']=$year;
  604. $data['categoryList']=$categoryList;
  605. $data['staffList']=$staffList;
  606. $data['cid']=$cid;
  607. $data['sid']=$sid;
  608. $data['ap']=$ap;
  609. $data['memu']="receipt";
  610. $data['staff']=$this->staff;
  611. $data['receiptMemu']='approvalExpenses';
  612. $data['verifyId']=$this->verifyId;
  613. $data['executeId']=$this->executeId;
  614. $this->render ( "/admin/remitApproval", $data );
  615. }
  616. function saeaLoanAdd(){
  617. Doo::loadModel('verify');
  618. $verify=new verify();
  619. Doo::loadModel("role");
  620. $role=new role();
  621. Doo::loadModel('L_category');
  622. $lCategory=new L_category();
  623. $veList=$verify->find(array('asArray'=>true));
  624. foreach ($veList as $key=>$value){
  625. $v=json_decode($value['staff']);
  626. $list=array();
  627. foreach ($v as $n=>$m){
  628. if ($m['1']=='ROLE'){
  629. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  630. $v[$n][1]=$roleInfo['name'];
  631. array_push($list, $roleInfo['name']);
  632. }else{
  633. array_push($list, $v[$n][1]);
  634. }
  635. }
  636. $veList[$key]['staff']=implode('>', $list);
  637. }
  638. $data['category']=$lCategory->find(array('asArray'=>true));
  639. $data['veList']=$veList;
  640. $data['memu']="receipt";
  641. $data['staff']=$this->staff;
  642. $data['receiptMemu']='saeaBorad';
  643. $data['verifyId']=$this->verifyId;
  644. $data['executeId']=$this->executeId;
  645. $this->render ( "/admin/saeaLoanAdd", $data );
  646. }
  647. function saeaLoanAddDo(){
  648. $agency=$this->get_args('agency');
  649. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  650. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  651. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  652. //die;
  653. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  654. Doo::loadModel('receipt');
  655. Doo::loadModel('receiptDetail');
  656. Doo::loadModel('accountItem');
  657. $accountItem=new accountItem();
  658. $receipt=new receipt();
  659. Doo::loadModel('loanReceipt');
  660. $loanReceipt=new loanReceipt();
  661. Doo::loadModel('execute');
  662. $execute=new execute();
  663. Doo::loadModel('enclosur');
  664. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  665. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  666. // if(!empty($receiptDetail))
  667. // return "/referReceipt/".$receiptDetail['rid'];
  668. $aItem=$accountItem->find(array('asArray'=>true));
  669. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  670. $ag=$tr=$ta=$ot=0;
  671. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  672. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  673. $sum+=$agency;$agencySum+=$agency;
  674. $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, '.', ''));
  675. //借款数据备份
  676. $loanReceipt->loanItem=json_encode($accountJson);
  677. $loanReceipt->staff=$this->staff[0]['sid'];
  678. $loanReceipt->sum=number_format($sum, 2, '.', '');
  679. $loanReceipt->date=date("Y-m-d");
  680. $loanReceipt->cid=$cid;
  681. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  682. $loanReceipt->status=5;
  683. $loanReceipt->Rtype=1;
  684. $loanReceipt->verify=$verify;
  685. $receipt->receiptOrder=$receipt->receiptOrder;
  686. $loanReceipt->explanation=$explanation;
  687. $loanRid=$loanReceipt->insert();
  688. //报销单
  689. $receipt->loanItem=json_encode($accountJson);
  690. $receipt->staff=$this->staff[0]['sid'];
  691. $receipt->sum=number_format($sum, 2, '.', '');
  692. $receipt->date=date("Y-m-d");
  693. $receipt->cid=$cid;
  694. //特殊状态
  695. $receipt->status=5;
  696. $receipt->Rtype=1;
  697. $receipt->loanRid=$loanRid;
  698. //修改审批流程加入角色
  699. $receipt->verify=$verify;
  700. $receipt->executeCopy=$executeDetail['staff'];
  701. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  702. $receipt->explanation=$explanation;
  703. $rid=$receipt->insert();
  704. //执行数据备份
  705. // $executeCopy->rid=$rid;
  706. // $executeCopy->staff=$executeDetail['staff'];
  707. // $executeCopy->eid=$executeDetail['eid'];
  708. // $ecid=$executeCopy->insert();
  709. }
  710. return "/saeaBorad";
  711. }
  712. function saeaLoanEdi(){
  713. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  714. Doo::loadModel('verify');
  715. $verify=new verify();
  716. Doo::loadModel("role");
  717. $role=new role();
  718. Doo::loadModel('L_category');
  719. $lCategory=new L_category();
  720. Doo::loadModel('receipt');
  721. $receipt=new receipt();
  722. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  723. $veList=$verify->find(array('asArray'=>true));
  724. foreach ($veList as $key=>$value){
  725. $v=json_decode($value['staff']);
  726. $list=array();
  727. foreach ($v as $n=>$m){
  728. if ($m['1']=='ROLE'){
  729. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  730. $v[$n][1]=$roleInfo['name'];
  731. array_push($list, $roleInfo['name']);
  732. }else{
  733. array_push($list, $v[$n][1]);
  734. }
  735. }
  736. $veList[$key]['staff']=implode('>', $list);
  737. }
  738. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  739. $data['receiptInfo']=$receiptInfo;
  740. $data['category']=$lCategory->find(array('asArray'=>true));
  741. $data['veList']=$veList;
  742. $data['memu']="receipt";
  743. $data['staff']=$this->staff;
  744. $data['receiptMemu']='saeaBorad';
  745. $data['verifyId']=$this->verifyId;
  746. $data['executeId']=$this->executeId;
  747. $this->render ( "/admin/saeaLoanEdi", $data );
  748. }
  749. function saeaLoanEdiDo(){
  750. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  751. $agency=$this->get_args('agency');
  752. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  753. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  754. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  755. //die;
  756. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  757. Doo::loadModel('receipt');
  758. Doo::loadModel('receiptDetail');
  759. Doo::loadModel('accountItem');
  760. $accountItem=new accountItem();
  761. $receipt=new receipt();
  762. Doo::loadModel('loanReceipt');
  763. $loanReceipt=new loanReceipt();
  764. Doo::loadModel('enclosur');
  765. Doo::loadModel('execute');
  766. $execute=new execute();
  767. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  768. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 and rid='.$rid,'asArray'=>true));
  769. if(empty($receiptDetail))
  770. die('参数错误');
  771. $aItem=$accountItem->find(array('asArray'=>true));
  772. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  773. $ag=$tr=$ta=$ot=0;
  774. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  775. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  776. $sum+=$agency;$agencySum+=$agency;
  777. $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, '.', ''));
  778. //报销单
  779. $receipt->loanItem=json_encode($accountJson);
  780. $receipt->sum=number_format($sum, 2, '.', '');
  781. $receipt->cid=$cid;
  782. //特殊状态
  783. //修改审批流程加入角色
  784. $receipt->verify=$verify;
  785. $receipt->explanation=$explanation;
  786. $receipt->update(array('where'=>'rid='.$rid));
  787. //借款数据更新
  788. $loanReceipt->loanItem=json_encode($accountJson);
  789. $loanReceipt->sum=number_format($sum, 2, '.', '');
  790. $loanReceipt->cid=$cid;
  791. $loanReceipt->verify=$verify;
  792. $loanReceipt->explanation=$explanation;
  793. $receipt->executeCopy=$executeDetail['staff'];
  794. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  795. }
  796. return "/saeaBorad";
  797. }
  798. function saeaLoanReceiptAdd(){
  799. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  800. Doo::loadModel('receipt');
  801. $receipt=new receipt();
  802. Doo::loadModel('loanReceipt');
  803. $loanReceipt=new loanReceipt();
  804. Doo::loadModel('L_category');
  805. $Lcategory=new L_category();
  806. Doo::loadModel('verify');
  807. Doo::loadModel('statistics');
  808. $statistics=new statistics();
  809. $verify=new verify();
  810. Doo::loadModel('staff');
  811. $staff=new staff();
  812. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  813. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  814. $Locate=0;$roleId=0;$button=0;
  815. foreach ($receiptList as $key=>$value){
  816. $receiptList[$key]['Locate']=$Locate;$Locate++;
  817. $receiptList[$key]['reviseDetail']=array();
  818. if (!empty($value['reviseDetail']))
  819. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  820. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  821. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  822. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  823. $receiptList[$key]['category']=$categoryDetil['title'];
  824. //检测编辑状态
  825. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  826. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  827. $verifyStaff=json_decode($value['verifyStaff'],true);
  828. Doo::loadModel('role');
  829. $role=new role();
  830. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  831. foreach ($verifyList as $k=>$v){
  832. //init verifyStaff
  833. if ($v[1]=='ROLE'){
  834. if (!empty($verifyStaff)){
  835. $endStaffArray=end($verifyStaff);
  836. // if ($v[0]==$endStaffArray['nextStaff']){
  837. // $roleId=$v[0];
  838. // }
  839. }
  840. $roleVerify=json_decode($v[3],true);
  841. $roleKey=$k;$roleArray=array();
  842. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  843. foreach ($roleVerify as $o=>$p){
  844. $staffID=explode ('_',$p);
  845. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  846. //print_r($staffID);
  847. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  848. array_push($roleArray, $exp);
  849. }
  850. $roleArrayCopy[$v[0]]=$roleArray;
  851. //$verifyList[$k]['roleArray']=$roleArray;
  852. }
  853. $verifyList[$k]['date']="";
  854. $verifyList[$k]['opinion']="";
  855. $verifyList[$k]['status']="";
  856. if (empty($verifyStaff)){
  857. $verifyList[$k]['date']="";
  858. $verifyList[$k]['opinion']="";
  859. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  860. $verifyList[$k]['status']=4;
  861. $flag=false;
  862. }
  863. }else{
  864. foreach ($verifyStaff as $m=>$u){
  865. if ($v[0]==$m){
  866. $verifyList[$k]['date']=$u['date'];
  867. $verifyList[$k]['opinion']=$u['opinion'];
  868. $verifyList[$k]['status']=$u['status'];
  869. $flag=false;
  870. break;
  871. }
  872. }
  873. $endStaffArray=end($verifyStaff);
  874. if (isset($endStaffArray['ROLE'])){
  875. }else{
  876. // $endKey=key($verifyStaff);
  877. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  878. // $button=4;
  879. // $verifyList[$k]['status']=4;
  880. // }
  881. }
  882. }
  883. }
  884. $rolename['name']='';
  885. if (!empty($roleId)){
  886. Doo::loadModel('role');
  887. $role=new role();
  888. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  889. }
  890. if (!empty($verifyStaff))
  891. $endStaffArray=end($verifyStaff);
  892. $KOP=false;
  893. foreach ($roleArrayCopy as $P=>$A){
  894. foreach ( $A as $MKI=>$AVL){
  895. if (!empty($verifyStaff)){
  896. //&&$rolename['rid']==$endStaffArray['nextStaff']
  897. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  898. $button=4;
  899. $roleArrayCopy[$P][$MKI]['status']=4;
  900. }
  901. foreach ($verifyStaff as $m=>$u){
  902. $AVLFK=$AVL[0].'_R';
  903. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  904. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  905. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  906. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  907. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  908. break;
  909. }
  910. }
  911. }else{
  912. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  913. $button=4;
  914. $roleArrayCopy[$P][$MKI]['status']=4;
  915. }
  916. }
  917. //$roleArray[$MKI]['rolename']=$rolename['name'];
  918. $KOP=true;
  919. }
  920. }
  921. foreach ($roleArrayCopy as $k=>$v){
  922. foreach ($verifyList as $m=>$n){
  923. if ($n[0]==$k){
  924. array_splice($verifyList,$m,1,$v);
  925. }
  926. }
  927. }
  928. $receiptList[$key]['verifyList']=$verifyList;
  929. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  930. $receiptList[$key]['button']=$button;
  931. //
  932. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  933. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  934. }
  935. $data['receiptList']=$receiptList;
  936. Doo::loadModel('L_category');
  937. $lCategory=new L_category();
  938. Doo::loadModel('accountItem');
  939. $accountItem=new accountItem();
  940. $acItem=$accountItem->find(array('asArray'=>true));
  941. $veList=$verify->find(array('asArray'=>true));
  942. foreach ($veList as $key=>$value){
  943. $v=json_decode($value['staff']);
  944. $list=array();
  945. foreach ($v as $n=>$m){
  946. if ($m['1']=='ROLE'){
  947. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  948. $v[$n][1]=$roleInfo['name'];
  949. array_push($list, $roleInfo['name']);
  950. }else{
  951. array_push($list, $v[$n][1]);
  952. }
  953. }
  954. $veList[$key]['staff']=implode('>', $list);
  955. }
  956. $data['rid']=$rid;
  957. $data['category']=$lCategory->find(array('asArray'=>true));
  958. $data['veList']=$veList;
  959. $data['acItem']=$acItem;
  960. $data['memu']="receipt";
  961. $data['staff']=$this->staff;
  962. $data['receiptMemu']='saeaBorad';
  963. $data['verifyId']=$this->verifyId;
  964. $data['executeId']=$this->executeId;
  965. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  966. }
  967. function saeaLoanReceiptAddDo(){
  968. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  969. $agency=$this->get_args('agency');
  970. $travel=$this->get_args('travel');
  971. $train=$this->get_args('train');
  972. $other=$this->get_args('other');
  973. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  974. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  975. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  976. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  977. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  978. Doo::loadModel('receipt');
  979. Doo::loadModel('receiptDetail');
  980. Doo::loadModel('accountItem');
  981. $accountItem=new accountItem();
  982. $receipt=new receipt();
  983. Doo::loadModel('enclosur');
  984. Doo::loadModel('execute');
  985. $execute=new execute();
  986. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  987. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  988. // if(!empty($receiptDetail))
  989. // return "/referReceipt/".$receiptDetail['rid'];
  990. $aItem=$accountItem->find(array('asArray'=>true));
  991. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  992. $ag=$tr=$ta=$ot=0;
  993. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  994. foreach ($aItem as $key=>$value){
  995. if ($value['category']==$this->AGENCY){
  996. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  997. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  998. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  999. }
  1000. $ag++;
  1001. }
  1002. if($value['category']==$this->TRAVEL){
  1003. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1004. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1005. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1006. }
  1007. $tr++;
  1008. }
  1009. if($value['category']==$this->TRAIN){
  1010. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1011. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1012. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1013. }
  1014. $ta++;
  1015. }
  1016. if($value['category']==$this->OTHER){
  1017. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1018. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1019. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1020. }
  1021. $ot++;
  1022. }
  1023. }
  1024. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1025. //报销单
  1026. $receipt->accountItem=json_encode($accountJson);
  1027. $receipt->staff=$this->staff[0]['sid'];
  1028. $receipt->loanSum=$receiptDet['sum'];
  1029. $receipt->sum=number_format($sum, 2, '.', '');
  1030. $receipt->date=date("Y-m-d");
  1031. $receipt->pastDate='';
  1032. $receipt->cid=$cid;
  1033. $receipt->status=7;
  1034. //修改审批流程加入角色
  1035. $receipt->verify=$verify;
  1036. $receipt->verifyStaff='';
  1037. $receipt->executeStaff='';
  1038. $receipt->executeCopy=$executeDetail['staff'];
  1039. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1040. $receipt->explanation=$explanation;
  1041. $receipt->update(array('where'=>'rid='.$rid));
  1042. //附件
  1043. if (!empty($enclosurName)){
  1044. $enclosurArray=explode('-', $enclosurName);
  1045. foreach ($enclosurArray as $value){
  1046. $enclosur=new enclosur();
  1047. $enclosur->name=$value;
  1048. $enclosur->rid=$rid;
  1049. $enclosur->insert();
  1050. }
  1051. //print_r($enclosurArray);die;
  1052. }
  1053. //报销详情
  1054. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1055. $receiptDetail=new receiptDetail();
  1056. $receiptDetail->staff=$this->staff[0]['sid'];
  1057. $receiptDetail->item=$value['name'];
  1058. $receiptDetail->itemCategory=$this->AGENCY;
  1059. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1060. $receiptDetail->date=date("Y-m-d");
  1061. $receiptDetail->cid=$cid;
  1062. $receiptDetail->rid=$rid;
  1063. $receiptDetail->status=4;
  1064. $receiptDetail->insert();
  1065. }
  1066. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1067. $receiptDetail=new receiptDetail();
  1068. $receiptDetail->staff=$this->staff[0]['sid'];
  1069. $receiptDetail->item=$value['name'];
  1070. $receiptDetail->itemCategory=$this->TRAVEL;
  1071. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1072. $receiptDetail->date=date("Y-m-d");
  1073. $receiptDetail->cid=$cid;
  1074. $receiptDetail->rid=$rid;
  1075. $receiptDetail->status=4;
  1076. $receiptDetail->insert();
  1077. }
  1078. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1079. $receiptDetail=new receiptDetail();
  1080. $receiptDetail->staff=$this->staff[0]['sid'];
  1081. $receiptDetail->item=$value['name'];
  1082. $receiptDetail->itemCategory=$this->TRAIN;
  1083. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1084. $receiptDetail->date=date("Y-m-d");
  1085. $receiptDetail->cid=$cid;
  1086. $receiptDetail->rid=$rid;
  1087. $receiptDetail->status=4;
  1088. $receiptDetail->insert();
  1089. }
  1090. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1091. $receiptDetail=new receiptDetail();
  1092. $receiptDetail->staff=$this->staff[0]['sid'];
  1093. $receiptDetail->item=$value['name'];
  1094. $receiptDetail->itemCategory=$this->OTHER;
  1095. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1096. $receiptDetail->date=date("Y-m-d");
  1097. $receiptDetail->cid=$cid;
  1098. $receiptDetail->rid=$rid;
  1099. $receiptDetail->status=4;
  1100. $receiptDetail->insert();
  1101. }
  1102. return "/saeaBorad";
  1103. }
  1104. return "/saeaLoanReceiptAdd/".$rid;
  1105. }
  1106. function saeaLoanReceiptEdi(){
  1107. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1108. //echo $rid;
  1109. Doo::loadModel('accountItem');
  1110. Doo::loadModel('verify');
  1111. Doo::loadModel('receipt');
  1112. $receipt=new receipt();
  1113. $verify=new verify();
  1114. $accountItem=new accountItem();
  1115. Doo::loadModel('L_category');
  1116. $Lcategory=new L_category();
  1117. Doo::loadModel("role");
  1118. $role=new role();
  1119. Doo::loadModel('loanReceipt');
  1120. $loanReceipt=new loanReceipt();
  1121. Doo::loadModel('staff');
  1122. $staff=new staff();
  1123. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1124. if(empty($receiptDetail))
  1125. return "/saeaBorad";
  1126. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1127. $Locate=0;$roleId=0;$button=0;
  1128. foreach ($receiptList as $key=>$value){
  1129. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1130. $receiptList[$key]['reviseDetail']=array();
  1131. if (!empty($value['reviseDetail']))
  1132. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1133. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1134. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1135. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1136. $receiptList[$key]['category']=$categoryDetil['title'];
  1137. //检测编辑状态
  1138. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1139. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1140. $verifyStaff=json_decode($value['verifyStaff'],true);
  1141. Doo::loadModel('role');
  1142. $role=new role();
  1143. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1144. foreach ($verifyList as $k=>$v){
  1145. //init verifyStaff
  1146. if ($v[1]=='ROLE'){
  1147. if (!empty($verifyStaff)){
  1148. $endStaffArray=end($verifyStaff);
  1149. // if ($v[0]==$endStaffArray['nextStaff']){
  1150. // $roleId=$v[0];
  1151. // }
  1152. }
  1153. $roleVerify=json_decode($v[3],true);
  1154. $roleKey=$k;$roleArray=array();
  1155. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1156. foreach ($roleVerify as $o=>$p){
  1157. $staffID=explode ('_',$p);
  1158. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1159. //print_r($staffID);
  1160. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1161. array_push($roleArray, $exp);
  1162. }
  1163. $roleArrayCopy[$v[0]]=$roleArray;
  1164. //$verifyList[$k]['roleArray']=$roleArray;
  1165. }
  1166. $verifyList[$k]['date']="";
  1167. $verifyList[$k]['opinion']="";
  1168. $verifyList[$k]['status']="";
  1169. if (empty($verifyStaff)){
  1170. $verifyList[$k]['date']="";
  1171. $verifyList[$k]['opinion']="";
  1172. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1173. $verifyList[$k]['status']=4;
  1174. $flag=false;
  1175. }
  1176. }else{
  1177. foreach ($verifyStaff as $m=>$u){
  1178. if ($v[0]==$m){
  1179. $verifyList[$k]['date']=$u['date'];
  1180. $verifyList[$k]['opinion']=$u['opinion'];
  1181. $verifyList[$k]['status']=$u['status'];
  1182. $flag=false;
  1183. break;
  1184. }
  1185. }
  1186. $endStaffArray=end($verifyStaff);
  1187. if (isset($endStaffArray['ROLE'])){
  1188. }else{
  1189. // $endKey=key($verifyStaff);
  1190. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1191. // $button=4;
  1192. // $verifyList[$k]['status']=4;
  1193. // }
  1194. }
  1195. }
  1196. }
  1197. $rolename['name']='';
  1198. if (!empty($roleId)){
  1199. Doo::loadModel('role');
  1200. $role=new role();
  1201. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1202. }
  1203. if (!empty($verifyStaff))
  1204. $endStaffArray=end($verifyStaff);
  1205. $KOP=false;
  1206. foreach ($roleArrayCopy as $P=>$A){
  1207. foreach ( $A as $MKI=>$AVL){
  1208. if (!empty($verifyStaff)){
  1209. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1210. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1211. $button=4;
  1212. $roleArrayCopy[$P][$MKI]['status']=4;
  1213. }
  1214. foreach ($verifyStaff as $m=>$u){
  1215. $AVLFK=$AVL[0].'_R';
  1216. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1217. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1218. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1219. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1220. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1221. break;
  1222. }
  1223. }
  1224. }else{
  1225. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1226. $button=4;
  1227. $roleArrayCopy[$P][$MKI]['status']=4;
  1228. }
  1229. }
  1230. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1231. $KOP=true;
  1232. }
  1233. }
  1234. foreach ($roleArrayCopy as $k=>$v){
  1235. foreach ($verifyList as $m=>$n){
  1236. if ($n[0]==$k){
  1237. array_splice($verifyList,$m,1,$v);
  1238. }
  1239. }
  1240. }
  1241. $receiptList[$key]['verifyList']=$verifyList;
  1242. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1243. $receiptList[$key]['button']=$button;
  1244. //
  1245. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1246. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1247. }
  1248. $data['receiptList']=$receiptList;
  1249. $acItem=$accountItem->find(array('asArray'=>true));
  1250. $veList=$verify->find(array('asArray'=>true));
  1251. foreach ($veList as $key=>$value){
  1252. $v=json_decode($value['staff']);
  1253. $list=array();
  1254. foreach ($v as $n=>$m){
  1255. if ($m['1']=='ROLE'){
  1256. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1257. $v[$n][1]=$roleInfo['name'];
  1258. array_push($list, $roleInfo['name']);
  1259. }else{
  1260. array_push($list, $v[$n][1]);
  1261. }
  1262. }
  1263. $veList[$key]['staff']=implode('>', $list);
  1264. }
  1265. //配置编辑信息
  1266. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1267. foreach ($acItem as $key=>$value){
  1268. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1269. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1270. $acItem[$key]['price']=$v['price'];
  1271. }
  1272. }
  1273. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1274. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1275. $acItem[$key]['price']=$v['price'];
  1276. }
  1277. }
  1278. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1279. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1280. $acItem[$key]['price']=$v['price'];
  1281. }
  1282. }
  1283. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1284. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1285. $acItem[$key]['price']=$v['price'];
  1286. }
  1287. }
  1288. }
  1289. $data['category']=$Lcategory->find(array('asArray'=>true));
  1290. $data['cSum']=$accountItemList['cSum'];
  1291. $data['sum']=$receiptDetail['sum'];
  1292. $data['receiptDetail']=$receiptDetail;
  1293. $data['veList']=$veList;
  1294. $data['acItem']=$acItem;
  1295. $data['memu']="receipt";
  1296. $data['staff']=$this->staff;
  1297. $data['receiptMemu']='saeaBorad';
  1298. $data['verify']=$receiptDetail['verify'];
  1299. $data['verifyId']=$this->verifyId;
  1300. $data['executeId']=$this->executeId;
  1301. $data['rid']=$rid;
  1302. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1303. }
  1304. function confirmation(){
  1305. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1306. Doo::loadModel('receipt');
  1307. Doo::loadModel('receiptDetail');
  1308. $receipt=new receipt();
  1309. $receiptDetail=new receiptDetail();
  1310. Doo::loadModel('statistics');
  1311. Doo::loadModel('itemStatistics');
  1312. $statistics=new statistics();
  1313. $itemStatistics=new itemStatistics();
  1314. Doo::loadModel("verify");
  1315. $verify=new verify();
  1316. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1317. if(empty($receiptDetailList))
  1318. return "/saeaBorad";
  1319. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1320. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1321. if (empty($receiptDetailList['nowStaff'])){
  1322. $nowStaff="";$nowStaffList=array();
  1323. if ($verifyDetail[0][1]=='ROLE'){
  1324. $vStaffString=json_decode($verifyDetail[0][3]);
  1325. foreach ($vStaffString as $key=>$value){
  1326. $staffK=explode("_", $value);
  1327. array_push($nowStaffList, $staffK[0]);
  1328. }
  1329. $nowStaff=implode(',', $nowStaffList);
  1330. }else{
  1331. $nowStaff=$verifyDetail[0][0];
  1332. }
  1333. $receipt->nowStaff=$nowStaff;
  1334. }
  1335. // echo $nowStaff;
  1336. // print_r($verifyDetail);die;
  1337. $receipt->rid=$receiptDetailList['rid'];
  1338. $receipt->status=2;
  1339. $receipt->update();
  1340. //操作日志
  1341. Doo::loadModel("receiptLog");
  1342. $receiptLog=new receiptLog();
  1343. $verify=new verify();
  1344. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1345. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1346. $jd=json_decode($vr['staff']);$roleId=0;
  1347. foreach ($jd as $key=>$value){
  1348. if ($value[1]=='ROLE'){
  1349. $pos = strpos($value[3], $this->staff[0]['sid']);
  1350. if ($pos !== false) {
  1351. $roleId=$value[0];
  1352. }
  1353. }
  1354. }
  1355. //审批日志
  1356. //echo $roleId;die;
  1357. if (!empty($roleId)){
  1358. Doo::loadModel("role");
  1359. $role=new role();
  1360. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1361. $receiptLog->rolename=$roleInfo['name'];
  1362. }
  1363. $receiptLog->username=$this->staff[0]['username'];
  1364. $receiptLog->uid=$this->staff[0]['sid'];
  1365. $receiptLog->date=date("Y-m-d");
  1366. $receiptLog->opinion='提交审批';
  1367. $receiptLog->img=$this->staff[0]['avatar'];
  1368. $receiptLog->status=2;
  1369. $receiptLog->rid=$rid;
  1370. $receiptLog->insert();
  1371. return "/expenses";
  1372. }
  1373. function expenses(){
  1374. $item=isset($this->params['item'])?$this->params['item']:"";
  1375. if(empty($item))
  1376. $item=$this->get_args('item')?$this->get_args('item'):"";
  1377. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1378. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1379. Doo::loadModel('receipt');
  1380. $receipt=new receipt();
  1381. Doo::loadModel('L_category');
  1382. $Lcategory=new L_category();
  1383. Doo::loadModel('verify');
  1384. Doo::loadModel('statistics');
  1385. $statistics=new statistics();
  1386. $verify=new verify();
  1387. Doo::loadModel('staff');
  1388. $staff=new staff();
  1389. $condition="";
  1390. if($item=="expenses")
  1391. $condition=" and Rtype=1 ";
  1392. elseif ($item=="receipts")
  1393. $condition=" and Rtype=0 ";
  1394. elseif ($item=="remits")
  1395. $condition=" and Rtype=2 ";
  1396. $dateCondition=" and Year(date) =".$year;
  1397. if(!empty($moth)){
  1398. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1399. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1400. }else
  1401. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1402. if(empty($stList))
  1403. $stList=array('rePrice'=>0,'agPrice'=>0);
  1404. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  1405. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  1406. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1407. $Locate=0;$roleId=0;$button=0;
  1408. foreach ($receiptList as $key=>$value){
  1409. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1410. $receiptList[$key]['reviseDetail']=array();
  1411. if (!empty($value['reviseDetail']))
  1412. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1413. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1414. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1415. $receiptList[$key]['category']=$categoryDetil['title'];
  1416. //检测编辑状态
  1417. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1418. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1419. $verifyStaff=json_decode($value['verifyStaff'],true);
  1420. Doo::loadModel('role');
  1421. $role=new role();
  1422. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1423. foreach ($verifyList as $k=>$v){
  1424. //init verifyStaff
  1425. if ($v[1]=='ROLE'){
  1426. if (!empty($verifyStaff)){
  1427. $endStaffArray=end($verifyStaff);
  1428. // if ($v[0]==$endStaffArray['nextStaff']){
  1429. // $roleId=$v[0];
  1430. // }
  1431. }
  1432. $roleVerify=json_decode($v[3],true);
  1433. $roleKey=$k;$roleArray=array();
  1434. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1435. foreach ($roleVerify as $o=>$p){
  1436. $staffID=explode ('_',$p);
  1437. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1438. //print_r($staffID);
  1439. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1440. array_push($roleArray, $exp);
  1441. }
  1442. $roleArrayCopy[$v[0]]=$roleArray;
  1443. //$verifyList[$k]['roleArray']=$roleArray;
  1444. }
  1445. $verifyList[$k]['date']="";
  1446. $verifyList[$k]['opinion']="";
  1447. $verifyList[$k]['status']="";
  1448. if (empty($verifyStaff)){
  1449. $verifyList[$k]['date']="";
  1450. $verifyList[$k]['opinion']="";
  1451. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1452. $verifyList[$k]['status']=4;
  1453. $flag=false;
  1454. }
  1455. }else{
  1456. foreach ($verifyStaff as $m=>$u){
  1457. if ($v[0]==$m){
  1458. $verifyList[$k]['date']=$u['date'];
  1459. $verifyList[$k]['opinion']=$u['opinion'];
  1460. $verifyList[$k]['status']=$u['status'];
  1461. $flag=false;
  1462. break;
  1463. }
  1464. }
  1465. $endStaffArray=end($verifyStaff);
  1466. if (isset($endStaffArray['ROLE'])){
  1467. }else{
  1468. // $endKey=key($verifyStaff);
  1469. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1470. // $button=4;
  1471. // $verifyList[$k]['status']=4;
  1472. // }
  1473. }
  1474. }
  1475. }
  1476. $rolename['name']='';
  1477. if (!empty($roleId)){
  1478. Doo::loadModel('role');
  1479. $role=new role();
  1480. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1481. }
  1482. if (!empty($verifyStaff))
  1483. $endStaffArray=end($verifyStaff);
  1484. $KOP=false;
  1485. foreach ($roleArrayCopy as $P=>$A){
  1486. foreach ( $A as $MKI=>$AVL){
  1487. if (!empty($verifyStaff)){
  1488. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1489. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1490. $button=4;
  1491. $roleArrayCopy[$P][$MKI]['status']=4;
  1492. }
  1493. foreach ($verifyStaff as $m=>$u){
  1494. $AVLFK=$AVL[0].'_R';
  1495. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1496. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1497. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1498. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1499. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1500. break;
  1501. }
  1502. }
  1503. }else{
  1504. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1505. $button=4;
  1506. $roleArrayCopy[$P][$MKI]['status']=4;
  1507. }
  1508. }
  1509. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1510. $KOP=true;
  1511. }
  1512. }
  1513. foreach ($roleArrayCopy as $k=>$v){
  1514. foreach ($verifyList as $m=>$n){
  1515. if ($n[0]==$k){
  1516. array_splice($verifyList,$m,1,$v);
  1517. }
  1518. }
  1519. }
  1520. $receiptList[$key]['verifyList']=$verifyList;
  1521. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1522. $receiptList[$key]['button']=$button;
  1523. }
  1524. //print_r($receiptList);die;
  1525. $mothHtml="";
  1526. for($i=1;$i<=12;$i++){
  1527. if($moth==$i)
  1528. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1529. else
  1530. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1531. }
  1532. $data['mothHtml']=$mothHtml;
  1533. $data['receiptList']=$receiptList;
  1534. $data['memu']="receipt";
  1535. $data['staff']=$this->staff;
  1536. $data['receiptMemu']='expenses';
  1537. $data['verifyId']=$this->verifyId;
  1538. $data['executeId']=$this->executeId;
  1539. $data['item']=$item;
  1540. $data['year']=$year;
  1541. $this->render ( "/admin/expenses", $data );
  1542. }
  1543. function expensesCollect(){
  1544. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1545. Doo::loadModel('receipt');
  1546. $receipt=new receipt();
  1547. Doo::loadModel('L_category');
  1548. $Lcategory=new L_category();
  1549. Doo::loadModel('verify');
  1550. Doo::loadModel('statistics');
  1551. $statistics=new statistics();
  1552. $verify=new verify();
  1553. Doo::loadModel('staff');
  1554. $staff=new staff();
  1555. Doo::loadModel('loanReceipt');
  1556. $loanReceipt=new loanReceipt();
  1557. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1558. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1559. $Locate=0;$roleId=0;$button=0;
  1560. foreach ($loanList as $key=>$value){
  1561. $loanList[$key]['Locate']=$Locate;$Locate++;
  1562. $loanList[$key]['reviseDetail']=array();
  1563. if (!empty($value['reviseDetail']))
  1564. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1565. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1566. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1567. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1568. $loanList[$key]['category']=$categoryDetil['title'];
  1569. //检测编辑状态
  1570. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1571. $verifyList['staff']=$value['verifyBreakup'];
  1572. else
  1573. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1574. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1575. $verifyStaff=json_decode($value['verifyStaff'],true);
  1576. Doo::loadModel('role');
  1577. $role=new role();
  1578. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1579. foreach ($verifyList as $k=>$v){
  1580. //init verifyStaff
  1581. if ($v[1]=='ROLE'){
  1582. if (!empty($verifyStaff)){
  1583. $endStaffArray=end($verifyStaff);
  1584. // if ($v[0]==$endStaffArray['nextStaff']){
  1585. // $roleId=$v[0];
  1586. // }
  1587. }
  1588. $roleVerify=json_decode($v[3],true);
  1589. $roleKey=$k;$roleArray=array();
  1590. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1591. foreach ($roleVerify as $o=>$p){
  1592. $staffID=explode ('_',$p);
  1593. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1594. //print_r($staffID);
  1595. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1596. array_push($roleArray, $exp);
  1597. }
  1598. $roleArrayCopy[$v[0]]=$roleArray;
  1599. //$verifyList[$k]['roleArray']=$roleArray;
  1600. }
  1601. $verifyList[$k]['date']="";
  1602. $verifyList[$k]['opinion']="";
  1603. $verifyList[$k]['status']="";
  1604. if (empty($verifyStaff)){
  1605. $verifyList[$k]['date']="";
  1606. $verifyList[$k]['opinion']="";
  1607. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1608. $verifyList[$k]['status']=4;
  1609. $flag=false;
  1610. }
  1611. }else{
  1612. foreach ($verifyStaff as $m=>$u){
  1613. if ($v[0]==$m){
  1614. $verifyList[$k]['date']=$u['date'];
  1615. $verifyList[$k]['opinion']=$u['opinion'];
  1616. $verifyList[$k]['status']=$u['status'];
  1617. $flag=false;
  1618. break;
  1619. }
  1620. }
  1621. $endStaffArray=end($verifyStaff);
  1622. if (isset($endStaffArray['ROLE'])){
  1623. }else{
  1624. // $endKey=key($verifyStaff);
  1625. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1626. // $button=4;
  1627. // $verifyList[$k]['status']=4;
  1628. // }
  1629. }
  1630. }
  1631. }
  1632. $rolename['name']='';
  1633. if (!empty($roleId)){
  1634. Doo::loadModel('role');
  1635. $role=new role();
  1636. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1637. }
  1638. if (!empty($verifyStaff))
  1639. $endStaffArray=end($verifyStaff);
  1640. $KOP=false;
  1641. foreach ($roleArrayCopy as $P=>$A){
  1642. foreach ( $A as $MKI=>$AVL){
  1643. if (!empty($verifyStaff)){
  1644. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1645. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1646. $button=4;
  1647. $roleArrayCopy[$P][$MKI]['status']=4;
  1648. }
  1649. foreach ($verifyStaff as $m=>$u){
  1650. $AVLFK=$AVL[0].'_R';
  1651. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1652. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1653. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1654. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1655. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1656. break;
  1657. }
  1658. }
  1659. }else{
  1660. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1661. $button=4;
  1662. $roleArrayCopy[$P][$MKI]['status']=4;
  1663. }
  1664. }
  1665. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1666. $KOP=true;
  1667. }
  1668. }
  1669. foreach ($roleArrayCopy as $k=>$v){
  1670. foreach ($verifyList as $m=>$n){
  1671. if ($n[0]==$k){
  1672. array_splice($verifyList,$m,1,$v);
  1673. }
  1674. }
  1675. }
  1676. $loanList[$key]['verifyList']=$verifyList;
  1677. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1678. $loanList[$key]['button']=$button;
  1679. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1680. }
  1681. $data['loanList']=$loanList;
  1682. $Locate=0;$roleId=0;$button=0;
  1683. foreach ($receiptList as $key=>$value){
  1684. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1685. $receiptList[$key]['reviseDetail']=array();
  1686. if (!empty($value['reviseDetail']))
  1687. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1688. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1689. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1690. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1691. $receiptList[$key]['category']=$categoryDetil['title'];
  1692. //检测编辑状态
  1693. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1694. if($value['status']==8&&$value['Rtype']==1)
  1695. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1696. else
  1697. $verifyList['staff']=$value['verifyBreakup'];
  1698. }else
  1699. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1700. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1701. $verifyStaff=json_decode($value['verifyStaff'],true);
  1702. Doo::loadModel('role');
  1703. $role=new role();
  1704. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1705. foreach ($verifyList as $k=>$v){
  1706. //init verifyStaff
  1707. if ($v[1]=='ROLE'){
  1708. if (!empty($verifyStaff)){
  1709. $endStaffArray=end($verifyStaff);
  1710. // if ($v[0]==$endStaffArray['nextStaff']){
  1711. // $roleId=$v[0];
  1712. // }
  1713. }
  1714. $roleVerify=json_decode($v[3],true);
  1715. $roleKey=$k;$roleArray=array();
  1716. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1717. foreach ($roleVerify as $o=>$p){
  1718. $staffID=explode ('_',$p);
  1719. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1720. //print_r($staffID);
  1721. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1722. array_push($roleArray, $exp);
  1723. }
  1724. $roleArrayCopy[$v[0]]=$roleArray;
  1725. //$verifyList[$k]['roleArray']=$roleArray;
  1726. }
  1727. $verifyList[$k]['date']="";
  1728. $verifyList[$k]['opinion']="";
  1729. $verifyList[$k]['status']="";
  1730. if (empty($verifyStaff)){
  1731. $verifyList[$k]['date']="";
  1732. $verifyList[$k]['opinion']="";
  1733. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1734. $verifyList[$k]['status']=4;
  1735. $flag=false;
  1736. }
  1737. }else{
  1738. foreach ($verifyStaff as $m=>$u){
  1739. if ($v[0]==$m){
  1740. $verifyList[$k]['date']=$u['date'];
  1741. $verifyList[$k]['opinion']=$u['opinion'];
  1742. $verifyList[$k]['status']=$u['status'];
  1743. $flag=false;
  1744. break;
  1745. }
  1746. }
  1747. $endStaffArray=end($verifyStaff);
  1748. if (isset($endStaffArray['ROLE'])){
  1749. }else{
  1750. // $endKey=key($verifyStaff);
  1751. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1752. // $button=4;
  1753. // $verifyList[$k]['status']=4;
  1754. // }
  1755. }
  1756. }
  1757. }
  1758. $rolename['name']='';
  1759. if (!empty($roleId)){
  1760. Doo::loadModel('role');
  1761. $role=new role();
  1762. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1763. }
  1764. if (!empty($verifyStaff))
  1765. $endStaffArray=end($verifyStaff);
  1766. $KOP=false;
  1767. foreach ($roleArrayCopy as $P=>$A){
  1768. foreach ( $A as $MKI=>$AVL){
  1769. if (!empty($verifyStaff)){
  1770. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1771. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1772. $button=4;
  1773. $roleArrayCopy[$P][$MKI]['status']=4;
  1774. }
  1775. foreach ($verifyStaff as $m=>$u){
  1776. $AVLFK=$AVL[0].'_R';
  1777. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1778. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1779. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1780. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1781. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1782. break;
  1783. }
  1784. }
  1785. }else{
  1786. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1787. $button=4;
  1788. $roleArrayCopy[$P][$MKI]['status']=4;
  1789. }
  1790. }
  1791. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1792. $KOP=true;
  1793. }
  1794. }
  1795. foreach ($roleArrayCopy as $k=>$v){
  1796. foreach ($verifyList as $m=>$n){
  1797. if ($n[0]==$k){
  1798. array_splice($verifyList,$m,1,$v);
  1799. }
  1800. }
  1801. }
  1802. $receiptList[$key]['verifyList']=$verifyList;
  1803. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1804. $receiptList[$key]['button']=$button;
  1805. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1806. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1807. $relust=$value['sum']-$value['loanSum'];
  1808. $receiptList[$key]['relust']=$relust;
  1809. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1810. }
  1811. $data['receiptList']=$receiptList;
  1812. $data['memu']="receipt";
  1813. $data['staff']=$this->staff;
  1814. $data['receiptMemu']='expenses';
  1815. $data['verifyId']=$this->verifyId;
  1816. $data['executeId']=$this->executeId;
  1817. $this->render ( "/admin/expensesCollect", $data );
  1818. }
  1819. function approvalExpenses(){
  1820. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1821. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1822. $month=$this->get_args('month')?$this->get_args('month'):"";
  1823. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1824. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1825. if (empty($status))
  1826. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1827. $page_size=12;
  1828. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1829. $vidList=array();
  1830. $button=0;
  1831. Doo::loadModel('verify');
  1832. $verify=new verify();
  1833. Doo::loadModel('receipt');
  1834. $receipt=new receipt();
  1835. Doo::loadModel('staff');
  1836. $staff=new staff();
  1837. Doo::loadModel('L_category');
  1838. $Lcategory=new L_category();
  1839. //user verify ID
  1840. $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));
  1841. foreach ($verifyDetail as $key=>$value){
  1842. array_push($vidList, $value['vid']);
  1843. }
  1844. $vid=implode(",", $vidList);
  1845. if(empty($verifyDetail))
  1846. $vid=0;
  1847. // if ($status==0)
  1848. // $dateCondition="";
  1849. // else
  1850. $dateCondition=" and Year(date) =".$year;
  1851. if(!empty($month))
  1852. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1853. $categoryList=$Lcategory->find(array('asArray'=>true));
  1854. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1855. $cateCondition="";$staffCondition="";$approvalCondition="";
  1856. if (!empty($cid))
  1857. $cateCondition=' and cid='.$cid;
  1858. if(!empty($sid)){
  1859. $staffCondition=' and staff='.$sid;
  1860. $cateCondition="";
  1861. }
  1862. $approvalCondition=" and status=".$status;
  1863. if($status==2){
  1864. //查找角色审批人
  1865. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1866. }
  1867. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1868. $approvalCondition=' and status=2 ';
  1869. }
  1870. if($status==1){
  1871. $approvalCondition=' and (status='.$status.' or status=6) ';
  1872. }
  1873. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1874. $pageinfo['page']=array('previous'=>'');
  1875. if ($status==0){
  1876. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1877. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1878. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1879. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1880. }else
  1881. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1882. ,'desc'=>'rid','asArray'=>true));
  1883. $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
  1884. ,'desc'=>'rid','asArray'=>true));
  1885. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1886. //print_r($pageinfo);
  1887. $Locate=0;
  1888. foreach ($receiptList as $key=>$value){
  1889. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1890. $receiptList[$key]['reviseDetail']=array();
  1891. if (!empty($value['reviseDetail']))
  1892. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1893. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1894. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1895. $receiptList[$key]['category']=$categoryDetil['title'];
  1896. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1897. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1898. $verifyStaff=json_decode($value['verifyStaff'],true);
  1899. foreach ($verifyList as $k=>$v){
  1900. //init verifyStaff
  1901. $verifyList[$k]['date']="";
  1902. $verifyList[$k]['opinion']="";
  1903. $verifyList[$k]['status']="";
  1904. if (empty($verifyStaff)){
  1905. $verifyList[$k]['date']="";
  1906. $verifyList[$k]['opinion']="";
  1907. if ($v[0]==$this->staff[0]['sid']){
  1908. $verifyList[$k]['status']=4;
  1909. $button=4;
  1910. }
  1911. }else{
  1912. $flag=true;
  1913. foreach ($verifyStaff as $m=>$u){
  1914. if ($v[0]==$m){
  1915. $verifyList[$k]['date']=$u['date'];
  1916. $verifyList[$k]['opinion']=$u['opinion'];
  1917. $verifyList[$k]['status']=$u['status'];
  1918. $flag=false;
  1919. break;
  1920. }
  1921. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1922. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1923. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1924. }
  1925. if($flag){//检测可编辑
  1926. if($v[0]==$this->staff[0]['sid']){
  1927. $verifyList[$k]['status']=4;$button=4;
  1928. }
  1929. }
  1930. }
  1931. }
  1932. $receiptList[$key]['verifyList']=$verifyList;
  1933. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1934. $receiptList[$key]['button']=$button;
  1935. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1936. }
  1937. //print_r($receiptList);die;
  1938. //$data['verifyDetail']=$verifyDetail;
  1939. $mothHtml="";
  1940. for($i=1;$i<=12;$i++){
  1941. if($month==$i)
  1942. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1943. else
  1944. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1945. }
  1946. $data['mothHtml']=$mothHtml;
  1947. $data['page']=$pageinfo;
  1948. $data['receiptList']=$receiptList;
  1949. $data['receiptApprovalCount']=count($rLRes);
  1950. $data['status']=$status;
  1951. $data['year']=$year;
  1952. $data['categoryList']=$categoryList;
  1953. $data['staffList']=$staffList;
  1954. $data['cid']=$cid;
  1955. $data['sid']=$sid;
  1956. //print_r($receiptList);
  1957. $data['memu']="receipt";
  1958. $data['staff']=$this->staff;
  1959. $data['receiptMemu']='approvalExpenses';
  1960. $data['verifyId']=$this->verifyId;
  1961. $data['executeId']=$this->executeId;
  1962. $this->render ( "/admin/approvalExpenses", $data );
  1963. }
  1964. function expensesDoc(){
  1965. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1966. Doo::loadModel('receipt');
  1967. $receipt=new receipt();
  1968. Doo::loadModel('L_category');
  1969. $Lcategory=new L_category();
  1970. Doo::loadModel('verify');
  1971. Doo::loadModel('statistics');
  1972. $statistics=new statistics();
  1973. $verify=new verify();
  1974. Doo::loadModel('staff');
  1975. $staff=new staff();
  1976. Doo::loadModel('loanReceipt');
  1977. $loanReceipt=new loanReceipt();
  1978. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  1979. $loanList=array();
  1980. if (!empty($receiptList))
  1981. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1982. $Locate=0;$roleId=0;$button=0;
  1983. foreach ($loanList as $key=>$value){
  1984. $loanList[$key]['Locate']=$Locate;$Locate++;
  1985. $loanList[$key]['reviseDetail']=array();
  1986. if (!empty($value['reviseDetail']))
  1987. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1988. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1989. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1990. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1991. $loanList[$key]['category']=$categoryDetil['title'];
  1992. //检测编辑状态
  1993. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1994. $verifyList['staff']=$value['verifyBreakup'];
  1995. else
  1996. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1997. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1998. $verifyStaff=json_decode($value['verifyStaff'],true);
  1999. Doo::loadModel('role');
  2000. $role=new role();
  2001. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2002. foreach ($verifyList as $k=>$v){
  2003. //init verifyStaff
  2004. if ($v[1]=='ROLE'){
  2005. if (!empty($verifyStaff)){
  2006. $endStaffArray=end($verifyStaff);
  2007. // if ($v[0]==$endStaffArray['nextStaff']){
  2008. // $roleId=$v[0];
  2009. // }
  2010. }
  2011. $roleVerify=json_decode($v[3],true);
  2012. $roleKey=$k;$roleArray=array();
  2013. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2014. foreach ($roleVerify as $o=>$p){
  2015. $staffID=explode ('_',$p);
  2016. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2017. //print_r($staffID);
  2018. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2019. array_push($roleArray, $exp);
  2020. }
  2021. $roleArrayCopy[$v[0]]=$roleArray;
  2022. //$verifyList[$k]['roleArray']=$roleArray;
  2023. }
  2024. $verifyList[$k]['date']="";
  2025. $verifyList[$k]['opinion']="";
  2026. $verifyList[$k]['status']="";
  2027. if (empty($verifyStaff)){
  2028. $verifyList[$k]['date']="";
  2029. $verifyList[$k]['opinion']="";
  2030. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2031. $verifyList[$k]['status']=4;
  2032. $flag=false;
  2033. }
  2034. }else{
  2035. foreach ($verifyStaff as $m=>$u){
  2036. if ($v[0]==$m){
  2037. $verifyList[$k]['date']=$u['date'];
  2038. $verifyList[$k]['opinion']=$u['opinion'];
  2039. $verifyList[$k]['status']=$u['status'];
  2040. $flag=false;
  2041. break;
  2042. }
  2043. }
  2044. $endStaffArray=end($verifyStaff);
  2045. if (isset($endStaffArray['ROLE'])){
  2046. }else{
  2047. // $endKey=key($verifyStaff);
  2048. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2049. // $button=4;
  2050. // $verifyList[$k]['status']=4;
  2051. // }
  2052. }
  2053. }
  2054. }
  2055. $rolename['name']='';
  2056. if (!empty($roleId)){
  2057. Doo::loadModel('role');
  2058. $role=new role();
  2059. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2060. }
  2061. if (!empty($verifyStaff))
  2062. $endStaffArray=end($verifyStaff);
  2063. $KOP=false;
  2064. foreach ($roleArrayCopy as $P=>$A){
  2065. foreach ( $A as $MKI=>$AVL){
  2066. if (!empty($verifyStaff)){
  2067. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2068. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2069. $button=4;
  2070. $roleArrayCopy[$P][$MKI]['status']=4;
  2071. }
  2072. foreach ($verifyStaff as $m=>$u){
  2073. $AVLFK=$AVL[0].'_R';
  2074. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2075. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2076. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2077. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2078. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2079. break;
  2080. }
  2081. }
  2082. }else{
  2083. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2084. $button=4;
  2085. $roleArrayCopy[$P][$MKI]['status']=4;
  2086. }
  2087. }
  2088. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2089. $KOP=true;
  2090. }
  2091. }
  2092. foreach ($roleArrayCopy as $k=>$v){
  2093. foreach ($verifyList as $m=>$n){
  2094. if ($n[0]==$k){
  2095. array_splice($verifyList,$m,1,$v);
  2096. }
  2097. }
  2098. }
  2099. $loanList[$key]['verifyList']=$verifyList;
  2100. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2101. $loanList[$key]['button']=$button;
  2102. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2103. }
  2104. $data['loanList']=$loanList;
  2105. //print_r($loanList);
  2106. $Locate=0;$roleId=0;$button=0;
  2107. foreach ($receiptList as $key=>$value){
  2108. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2109. $receiptList[$key]['reviseDetail']=array();
  2110. if (!empty($value['reviseDetail']))
  2111. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2112. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2113. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2114. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2115. $receiptList[$key]['category']=$categoryDetil['title'];
  2116. //检测编辑状态
  2117. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2118. $verifyList['staff']=$value['verifyBreakup'];
  2119. }else
  2120. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2121. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2122. $verifyStaff=json_decode($value['verifyStaff'],true);
  2123. Doo::loadModel('role');
  2124. $role=new role();
  2125. if ($verifyList==NULL)
  2126. $verifyList=array();
  2127. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2128. foreach ($verifyList as $k=>$v){
  2129. //init verifyStaff
  2130. if ($v[1]=='ROLE'){
  2131. if (!empty($verifyStaff)){
  2132. $endStaffArray=end($verifyStaff);
  2133. // if ($v[0]==$endStaffArray['nextStaff']){
  2134. // $roleId=$v[0];
  2135. // }
  2136. }
  2137. $roleVerify=json_decode($v[3],true);
  2138. $roleKey=$k;$roleArray=array();
  2139. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2140. foreach ($roleVerify as $o=>$p){
  2141. $staffID=explode ('_',$p);
  2142. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2143. //print_r($staffID);
  2144. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2145. array_push($roleArray, $exp);
  2146. }
  2147. $roleArrayCopy[$v[0]]=$roleArray;
  2148. //$verifyList[$k]['roleArray']=$roleArray;
  2149. }
  2150. $verifyList[$k]['date']="";
  2151. $verifyList[$k]['opinion']="";
  2152. $verifyList[$k]['status']="";
  2153. if (empty($verifyStaff)){
  2154. $verifyList[$k]['date']="";
  2155. $verifyList[$k]['opinion']="";
  2156. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2157. $verifyList[$k]['status']=4;
  2158. $flag=false;
  2159. }
  2160. }else{
  2161. foreach ($verifyStaff as $m=>$u){
  2162. if ($v[0]==$m){
  2163. $verifyList[$k]['date']=$u['date'];
  2164. $verifyList[$k]['opinion']=$u['opinion'];
  2165. $verifyList[$k]['status']=$u['status'];
  2166. $flag=false;
  2167. break;
  2168. }
  2169. }
  2170. $endStaffArray=end($verifyStaff);
  2171. if (isset($endStaffArray['ROLE'])){
  2172. }else{
  2173. // $endKey=key($verifyStaff);
  2174. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2175. // $button=4;
  2176. // $verifyList[$k]['status']=4;
  2177. // }
  2178. }
  2179. }
  2180. }
  2181. $rolename['name']='';
  2182. if (!empty($roleId)){
  2183. Doo::loadModel('role');
  2184. $role=new role();
  2185. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2186. }
  2187. if (!empty($verifyStaff))
  2188. $endStaffArray=end($verifyStaff);
  2189. $KOP=false;
  2190. foreach ($roleArrayCopy as $P=>$A){
  2191. foreach ( $A as $MKI=>$AVL){
  2192. if (!empty($verifyStaff)){
  2193. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2194. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2195. $button=4;
  2196. $roleArrayCopy[$P][$MKI]['status']=4;
  2197. }
  2198. foreach ($verifyStaff as $m=>$u){
  2199. $AVLFK=$AVL[0].'_R';
  2200. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2201. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2202. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2203. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2204. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2205. break;
  2206. }
  2207. }
  2208. }else{
  2209. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2210. $button=4;
  2211. $roleArrayCopy[$P][$MKI]['status']=4;
  2212. }
  2213. }
  2214. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2215. $KOP=true;
  2216. }
  2217. }
  2218. foreach ($roleArrayCopy as $k=>$v){
  2219. foreach ($verifyList as $m=>$n){
  2220. if ($n[0]==$k){
  2221. array_splice($verifyList,$m,1,$v);
  2222. }
  2223. }
  2224. }
  2225. $receiptList[$key]['verifyList']=$verifyList;
  2226. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2227. $receiptList[$key]['button']=$button;
  2228. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2229. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2230. }
  2231. //获取审批日志
  2232. Doo::loadModel('receiptLog');
  2233. $receiptLog=new receiptLog();
  2234. $rlList=array();
  2235. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2236. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2237. if (!empty($rlInfo)){
  2238. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2239. }
  2240. $receiptList[0]['rlList']=$rlList;
  2241. $data['receiptList']=$receiptList;
  2242. $data['memu']="receipt";
  2243. $data['staff']=$this->staff;
  2244. $data['receiptMemu']='approvalExpenses';
  2245. $data['verifyId']=$this->verifyId;
  2246. $data['executeId']=$this->executeId;
  2247. $this->render ( "/admin/expensesDoc", $data );
  2248. }
  2249. function expensesEdi(){
  2250. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2251. $status=isset($this->params['status'])?$this->params['status']:'';
  2252. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2253. $month=$this->get_args('month')?$this->get_args('month'):"";
  2254. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2255. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2256. if (empty($status))
  2257. $status=$this->get_args('status')?$this->get_args('status'):2;
  2258. $vidList=array();
  2259. $button=0;
  2260. Doo::loadModel('verify');
  2261. Doo::loadModel('receipt');
  2262. Doo::loadModel('staff');
  2263. $staff=new staff();
  2264. $receipt=new receipt();
  2265. $verify=new verify();
  2266. Doo::loadModel('L_category');
  2267. $Lcategory=new L_category();
  2268. Doo::loadModel('enclosur');
  2269. $enclosur=new enclosur();
  2270. //user verify ID
  2271. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2272. foreach ($verifyDetail as $key=>$value){
  2273. array_push($vidList, $value['vid']);
  2274. }
  2275. $vid=implode(",", $vidList);
  2276. if(empty($verifyDetail))
  2277. $vid=0;
  2278. $categoryList=$Lcategory->find(array('asArray'=>true));
  2279. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2280. $ap="";
  2281. if($status==4){
  2282. $ap=4;$status=2;
  2283. }
  2284. //get Receipt By verifyID status 2
  2285. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2286. $Locate=0;$roleId=0;
  2287. if($ap==4)
  2288. $status=4;
  2289. foreach ($receiptList as $key=>$value){
  2290. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2291. $receiptList[$key]['reviseDetail']=array();
  2292. if (!empty($value['reviseDetail']))
  2293. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2294. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2295. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2296. $receiptList[$key]['category']=$categoryDetil['title'];
  2297. //检测编辑状态
  2298. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2299. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2300. $verifyStaff=json_decode($value['verifyStaff'],true);
  2301. Doo::loadModel('role');
  2302. $role=new role();
  2303. //print_r($verifyList);
  2304. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2305. foreach ($verifyList as $k=>$v){
  2306. //init verifyStaff
  2307. if ($v[1]=='ROLE'){
  2308. if (!empty($verifyStaff)){
  2309. $endStaffArray=end($verifyStaff);
  2310. if ($v[0]==$endStaffArray['nextStaff']){
  2311. $roleId=$v[0];
  2312. }
  2313. }
  2314. $roleVerify=json_decode($v[3],true);
  2315. $roleKey=$k;$roleArray=array();
  2316. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2317. foreach ($roleVerify as $o=>$p){
  2318. $staffID=explode ('_',$p);
  2319. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2320. //print_r($staffID);
  2321. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2322. array_push($roleArray, $exp);
  2323. }
  2324. $roleArrayCopy[$v[0]]=$roleArray;
  2325. //$verifyList[$k]['roleArray']=$roleArray;
  2326. }
  2327. //print_r($roleArray);
  2328. $verifyList[$k]['date']="";
  2329. $verifyList[$k]['opinion']="";
  2330. $verifyList[$k]['status']="";
  2331. if (empty($verifyStaff)){
  2332. $verifyList[$k]['date']="";
  2333. $verifyList[$k]['opinion']="";
  2334. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2335. $verifyList[$k]['status']=4;
  2336. $button=4;$flag=false;
  2337. }
  2338. }else{
  2339. foreach ($verifyStaff as $m=>$u){
  2340. if ($v[0]==$m){
  2341. $verifyList[$k]['date']=$u['date'];
  2342. $verifyList[$k]['opinion']=$u['opinion'];
  2343. $verifyList[$k]['status']=$u['status'];
  2344. $flag=false;
  2345. break;
  2346. }
  2347. }
  2348. $endStaffArray=end($verifyStaff);
  2349. if (isset($endStaffArray['ROLE'])){
  2350. }else{
  2351. $endKey=key($verifyStaff);
  2352. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2353. $button=4;
  2354. $verifyList[$k]['status']=4;
  2355. }
  2356. }
  2357. }
  2358. }
  2359. $rolename['name']='';
  2360. if (!empty($roleId)){
  2361. Doo::loadModel('role');
  2362. $role=new role();
  2363. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2364. }
  2365. if (!empty($verifyStaff))
  2366. $endStaffArray=end($verifyStaff);
  2367. $KOP=false;
  2368. foreach ($roleArrayCopy as $P=>$A){
  2369. foreach ( $A as $MKI=>$AVL){
  2370. if (!empty($verifyStaff)){
  2371. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2372. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2373. $button=4;
  2374. $roleArrayCopy[$P][$MKI]['status']=4;
  2375. }
  2376. foreach ($verifyStaff as $m=>$u){
  2377. $AVLFK=$AVL[0].'_R';
  2378. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2379. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2380. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2381. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2382. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2383. break;
  2384. }
  2385. }
  2386. }else{
  2387. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2388. $button=4;
  2389. $roleArrayCopy[$P][$MKI]['status']=4;
  2390. }
  2391. }
  2392. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2393. $KOP=true;
  2394. }
  2395. }
  2396. // print_r($roleArrayCopy);
  2397. // echo $roleKey;
  2398. foreach ($roleArrayCopy as $k=>$v){
  2399. foreach ($verifyList as $m=>$n){
  2400. if ($n[0]==$k){
  2401. array_splice($verifyList,$m,1,$v);
  2402. }
  2403. }
  2404. }
  2405. $receiptList[$key]['verifyList']=$verifyList;
  2406. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2407. $receiptList[$key]['button']=$button;
  2408. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2409. }
  2410. //$data['verifyDetail']=$verifyDetail;
  2411. $mothHtml="";
  2412. for($i=1;$i<=12;$i++){
  2413. if($month==$i)
  2414. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2415. else
  2416. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2417. }
  2418. //获取审批日志
  2419. Doo::loadModel('receiptLog');
  2420. $receiptLog=new receiptLog();
  2421. $rlList=array();
  2422. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2423. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2424. if (!empty($rlInfo)){
  2425. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2426. }
  2427. $receiptList[0]['rlList']=$rlList;
  2428. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2429. $enclosurHtml='';
  2430. foreach ($enclosurList as $value){
  2431. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2432. }
  2433. //print_r($receiptList);
  2434. $data['rid']=$rid;
  2435. $data['enclosurHtml']=$enclosurHtml;
  2436. $data['rolename']=$rolename['name'];
  2437. $data['datetij']=$tijdate['date'];
  2438. $data['mothHtml']=$mothHtml;
  2439. $data['receiptList']=$receiptList;
  2440. $data['receiptApprovalCount']=count($receiptList);
  2441. $data['status']=$status;
  2442. $data['year']=$year;
  2443. $data['categoryList']=$categoryList;
  2444. $data['staffList']=$staffList;
  2445. $data['cid']=$cid;
  2446. $data['sid']=$sid;
  2447. $data['ap']=$ap;
  2448. $data['memu']="receipt";
  2449. $data['staff']=$this->staff;
  2450. $data['receiptMemu']='approvalExpenses';
  2451. $data['verifyId']=$this->verifyId;
  2452. $data['executeId']=$this->executeId;
  2453. $this->render ( "/admin/expensesEdi", $data );
  2454. }
  2455. function expensesDefray(){
  2456. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2457. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2458. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2459. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2460. if(!empty($rid)){
  2461. Doo::loadModel("verify");
  2462. $verify=new verify();
  2463. Doo::loadModel("receiptDetail");
  2464. $receiptDetailObj=new receiptDetail();
  2465. Doo::loadModel("itemStatistics");
  2466. Doo::loadModel("statistics");
  2467. $statistics=new statistics();
  2468. $itemStatistics=new itemStatistics();
  2469. Doo::loadModel("receipt");
  2470. $receipt=new receipt();
  2471. Doo::loadModel("loanReceipt");
  2472. $loanReceipt=new loanReceipt();
  2473. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2474. if (empty($receiptDetail))
  2475. return "/approval";
  2476. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2477. $verifyString=$verifyDetail['staff'];
  2478. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2479. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2480. if(empty($opinion)){
  2481. if ($status==3)
  2482. $opinion="终止";
  2483. else
  2484. $opinion="同意支付";
  2485. }
  2486. $nowStaff=0;$nowStaffList=array();
  2487. if(empty($verifyStaff)){
  2488. //还需加入是否已经进入角色审批
  2489. if ($verifyDetail[0][1]=='ROLE'){
  2490. //print_r($verifyDetail);echo "ddd";
  2491. $vStaffString=json_decode($verifyDetail[0][3]);
  2492. foreach ($vStaffString as $key=>$value){
  2493. $staffK=explode("_", $value);
  2494. if ($staffK[0]!=$this->staff[0]['sid'])
  2495. array_push($nowStaffList, $staffK[0]);
  2496. }
  2497. //print_r($verifyDetail);
  2498. //die;
  2499. $nowStaff=implode(',', $nowStaffList);
  2500. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2501. }else{
  2502. if ($verifyDetail[1][1]=='ROLE'){
  2503. $vStaffString=json_decode($verifyDetail[1][3]);
  2504. //echo "dd";
  2505. foreach ($vStaffString as $key=>$value){
  2506. $staffK=explode("_", $value);
  2507. array_push($nowStaffList, $staffK[0]);
  2508. }
  2509. $nowStaff=implode(',', $nowStaffList);
  2510. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2511. }else{
  2512. $nowStaff=$verifyDetail[1][0];
  2513. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2514. }
  2515. }
  2516. if($status==3)
  2517. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2518. $vStaffString=json_encode($verifyStaff);
  2519. $receipt->nowStaff=$nowStaff;
  2520. $receipt->verifyStaff=$vStaffString;
  2521. $loanReceipt->nowStaff=$nowStaff;
  2522. $loanReceipt->verifyStaff=$vStaffString;
  2523. }else{
  2524. $VS=end($verifyStaff);
  2525. //非角色审批
  2526. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2527. $nextStaff=0;$roleSTF=false;
  2528. foreach ($verifyDetail as $key=>$value){
  2529. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2530. if (isset($verifyDetail[$key+1])){
  2531. $nextStaff=$verifyDetail[$key+1][0];
  2532. if ($verifyDetail[$key+1][1]=='ROLE')
  2533. $roleSTF=true;
  2534. }
  2535. break;
  2536. }
  2537. }
  2538. if (!$roleSTF){
  2539. $nowStaff=$nextStaff;
  2540. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2541. }else{
  2542. //获取角色下的所有用户ID
  2543. $nowStaffList=array();
  2544. foreach ($verifyDetail as $vfk){
  2545. if ($vfk[1]=='ROLE'){
  2546. $vStaffString=json_decode($vfk[3]);
  2547. foreach ($vStaffString as $key=>$value){
  2548. $staffK=explode("_", $value);
  2549. array_push($nowStaffList, $staffK[0]);
  2550. }
  2551. }
  2552. }
  2553. $nowStaff=implode(',', $nowStaffList);
  2554. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2555. }
  2556. if($status==3){
  2557. $verifyStaff['final']=$status;
  2558. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2559. }
  2560. $vStaffString=json_encode($verifyStaff);
  2561. $receipt->nowStaff=$nowStaff;
  2562. $receipt->verifyStaff=$vStaffString;
  2563. $loanReceipt->nowStaff=$nowStaff;
  2564. $loanReceipt->verifyStaff=$vStaffString;
  2565. }
  2566. //角色审批
  2567. if (isset($VS['ROLE'])){
  2568. //找出角色人 当前审批角色组
  2569. $verifyJSStaff=array();$nowStaffList2=array();
  2570. foreach ($verifyDetail as $key=>$value){
  2571. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2572. $verifyJSStaff=json_decode($value[3]);
  2573. foreach ($verifyJSStaff as $m){
  2574. $staffK=explode("_", $m);
  2575. array_push($nowStaffList2, $staffK[0]);
  2576. }
  2577. // print_r($nowStaffList2);
  2578. }
  2579. }
  2580. $RoleVerifyStaff=array();
  2581. foreach ($verifyStaff as $key=>$value){
  2582. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2583. foreach ($nowStaffList2 as $m) {
  2584. if ($key==$m."_R")
  2585. $RoleVerifyStaff[$key]=$value;
  2586. }
  2587. }
  2588. }
  2589. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2590. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2591. //下一个审批人ID
  2592. $nextStaff=0;$falg=false;
  2593. foreach ($verifyDetail as $key=>$value){
  2594. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2595. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2596. $falg=true;
  2597. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2598. foreach ($vStaffString as $v){
  2599. $staffK=explode("_", $v);
  2600. array_push($nowStaffList, $staffK[0]);
  2601. }
  2602. $nowStaff=implode(',', $nowStaffList);
  2603. $nextStaff=$verifyDetail[$key+1][0];
  2604. }elseif(isset($verifyDetail[$key+1])){
  2605. $nextStaff=$verifyDetail[$key+1][0];
  2606. $nowStaff=$nextStaff;
  2607. }else
  2608. $nowStaff='';
  2609. break;
  2610. }
  2611. }
  2612. if ($falg)
  2613. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2614. else
  2615. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2616. // print_r($verifyStaff);
  2617. // echo $nowStaff;die;
  2618. }else{ //进入下一个角色或者审批人
  2619. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2620. //
  2621. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2622. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2623. // print_r($verifyStaff);
  2624. // die;
  2625. }
  2626. if($status==3){
  2627. $verifyStaff['final']=$status;
  2628. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2629. }
  2630. $vStaffString=json_encode($verifyStaff);
  2631. $receipt->verifyStaff=$vStaffString;
  2632. $receipt->nowStaff=$nowStaff;
  2633. $loanReceipt->nowStaff=$nowStaff;
  2634. $loanReceipt->verifyStaff=$vStaffString;
  2635. //die;
  2636. //}
  2637. // print_r($verifyStaff);
  2638. // die;
  2639. }
  2640. //print_r($verifyStaff);die;
  2641. }
  2642. //print_r($verifyDetail);
  2643. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2644. foreach ($verifyDetail as $k=>$v){
  2645. if ($v[1]=='ROLE'){
  2646. $roleId=$v[0];
  2647. $roleVerify=json_decode($v[3],true);
  2648. $roleKey=$k;$roleArray=array();
  2649. foreach ($roleVerify as $o=>$p){
  2650. $staffID=explode ('_',$p);
  2651. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2652. array_push($roleArray, $exp);
  2653. }
  2654. $verifyDetailCopy[$v[0]]=$roleArray;
  2655. }
  2656. }
  2657. //print_r($verifyDetail);
  2658. foreach ($verifyDetailCopy as $k=>$v){
  2659. foreach ($verifyDetail as $m=>$n){
  2660. if ($n[0]==$k){
  2661. array_splice($verifyDetail,$m,1,$v);
  2662. }
  2663. }
  2664. }
  2665. //审批日志
  2666. if (!isset($verifyStaff['final'])){
  2667. Doo::loadModel("receiptLog");
  2668. $receiptLog=new receiptLog();
  2669. if (!empty($roleId)){
  2670. Doo::loadModel("role");
  2671. $role=new role();
  2672. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2673. $receiptLog->rolename=$roleInfo['name'];
  2674. }
  2675. $receiptLog->username=$this->staff[0]['username'];
  2676. $receiptLog->uid=$this->staff[0]['sid'];
  2677. $receiptLog->date=date("Y-m-d");
  2678. $receiptLog->opinion=$opinion;
  2679. $receiptLog->img=$this->staff[0]['avatar'];
  2680. $receiptLog->status=1;
  2681. $receiptLog->rid=$rid;
  2682. $receiptLog->insert();
  2683. }
  2684. if (isset($verifyStaff['final'])){//rDetail
  2685. $receipt->status=3;
  2686. $receipt->verifyBreakup=$verifyString;
  2687. $receiptDetailObj->status=3;
  2688. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2689. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2690. $receipt->status=6;
  2691. $receipt->pastDate=date("Y-m-d");
  2692. $receipt->isBK=1;
  2693. $loanReceipt->verifyBreakup=$verifyString;
  2694. $loanReceipt->status=1;
  2695. $loanReceipt->pastDate=date("Y-m-d");
  2696. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2697. }
  2698. $receipt->update(array('where'=>' rid = '.$rid));
  2699. return "/approvalExpenses/2";
  2700. }
  2701. }
  2702. function implement(){
  2703. Doo::loadModel('receipt');
  2704. $receipt=new receipt();
  2705. Doo::loadModel('L_category');
  2706. $Lcategory=new L_category();
  2707. Doo::loadModel('verify');
  2708. $verify=new verify();
  2709. Doo::loadModel('staff');
  2710. $staff=new staff();
  2711. Doo::loadModel("execute");
  2712. $execute=new execute();
  2713. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2714. Doo::loadModel('loanReceipt');
  2715. $loanReceipt=new loanReceipt();
  2716. //print_r($receiptList);
  2717. $loanList=array();
  2718. if (!isset($receiptList))
  2719. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2720. $Locate=0;$roleId=0;$button=0;
  2721. foreach ($loanList as $key=>$value){
  2722. $loanList[$key]['Locate']=$Locate;$Locate++;
  2723. $loanList[$key]['reviseDetail']=array();
  2724. if (!empty($value['reviseDetail']))
  2725. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2726. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2727. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2728. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2729. $loanList[$key]['category']=$categoryDetil['title'];
  2730. //检测编辑状态
  2731. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2732. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2733. $verifyStaff=json_decode($value['verifyStaff'],true);
  2734. Doo::loadModel('role');
  2735. $role=new role();
  2736. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2737. foreach ($verifyList as $k=>$v){
  2738. //init verifyStaff
  2739. if ($v[1]=='ROLE'){
  2740. if (!empty($verifyStaff)){
  2741. $endStaffArray=end($verifyStaff);
  2742. // if ($v[0]==$endStaffArray['nextStaff']){
  2743. // $roleId=$v[0];
  2744. // }
  2745. }
  2746. $roleVerify=json_decode($v[3],true);
  2747. $roleKey=$k;$roleArray=array();
  2748. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2749. foreach ($roleVerify as $o=>$p){
  2750. $staffID=explode ('_',$p);
  2751. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2752. //print_r($staffID);
  2753. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2754. array_push($roleArray, $exp);
  2755. }
  2756. $roleArrayCopy[$v[0]]=$roleArray;
  2757. //$verifyList[$k]['roleArray']=$roleArray;
  2758. }
  2759. $verifyList[$k]['date']="";
  2760. $verifyList[$k]['opinion']="";
  2761. $verifyList[$k]['status']="";
  2762. if (empty($verifyStaff)){
  2763. $verifyList[$k]['date']="";
  2764. $verifyList[$k]['opinion']="";
  2765. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2766. $verifyList[$k]['status']=4;
  2767. $flag=false;
  2768. }
  2769. }else{
  2770. foreach ($verifyStaff as $m=>$u){
  2771. if ($v[0]==$m){
  2772. $verifyList[$k]['date']=$u['date'];
  2773. $verifyList[$k]['opinion']=$u['opinion'];
  2774. $verifyList[$k]['status']=$u['status'];
  2775. $flag=false;
  2776. break;
  2777. }
  2778. }
  2779. $endStaffArray=end($verifyStaff);
  2780. if (isset($endStaffArray['ROLE'])){
  2781. }else{
  2782. // $endKey=key($verifyStaff);
  2783. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2784. // $button=4;
  2785. // $verifyList[$k]['status']=4;
  2786. // }
  2787. }
  2788. }
  2789. }
  2790. $rolename['name']='';
  2791. if (!empty($roleId)){
  2792. Doo::loadModel('role');
  2793. $role=new role();
  2794. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2795. }
  2796. if (!empty($verifyStaff))
  2797. $endStaffArray=end($verifyStaff);
  2798. $KOP=false;
  2799. foreach ($roleArrayCopy as $P=>$A){
  2800. foreach ( $A as $MKI=>$AVL){
  2801. if (!empty($verifyStaff)){
  2802. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2803. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2804. $button=4;
  2805. $roleArrayCopy[$P][$MKI]['status']=4;
  2806. }
  2807. foreach ($verifyStaff as $m=>$u){
  2808. $AVLFK=$AVL[0].'_R';
  2809. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2810. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2811. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2812. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2813. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2814. break;
  2815. }
  2816. }
  2817. }else{
  2818. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2819. $button=4;
  2820. $roleArrayCopy[$P][$MKI]['status']=4;
  2821. }
  2822. }
  2823. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2824. $KOP=true;
  2825. }
  2826. }
  2827. foreach ($roleArrayCopy as $k=>$v){
  2828. foreach ($verifyList as $m=>$n){
  2829. if ($n[0]==$k){
  2830. array_splice($verifyList,$m,1,$v);
  2831. }
  2832. }
  2833. }
  2834. $loanList[$key]['verifyList']=$verifyList;
  2835. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2836. }
  2837. $data['loanList']=$loanList;
  2838. $Locate=0;$roleId=0;$button=0;
  2839. foreach ($receiptList as $key=>$value){
  2840. $button2=0;
  2841. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2842. $receiptList[$key]['reviseDetail']=array();
  2843. if (!empty($value['reviseDetail']))
  2844. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2845. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2846. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2847. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2848. $receiptList[$key]['category']=$categoryDetil['title'];
  2849. $executeList=json_decode($value['executeCopy'],true);
  2850. $executeStaff=array();
  2851. if (!empty($value['executeStaff'] ))
  2852. $executeStaff=json_decode($value['executeStaff'],true);
  2853. if (isset($executeList)){
  2854. foreach ($executeList as $op=>$lo){
  2855. $executeList[$op]['date']="";
  2856. $executeList[$op]['opinion']="";
  2857. $executeList[$op]['status']="";
  2858. foreach ($executeStaff as $m=>$u){
  2859. if ($lo[0]==$m){
  2860. $executeList[$op]['date']=$u['date'];
  2861. $executeList[$op]['opinion']=$u['opinion'];
  2862. $executeList[$op]['status']=$u['status'];
  2863. break;
  2864. }
  2865. }
  2866. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2867. $button2=1;
  2868. $executeList[$op]['status']=4;
  2869. }
  2870. }
  2871. }
  2872. //检测编辑状态
  2873. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2874. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2875. $verifyStaff=json_decode($value['verifyStaff'],true);
  2876. Doo::loadModel('role');
  2877. $role=new role();
  2878. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2879. foreach ($verifyList as $k=>$v){
  2880. //init verifyStaff
  2881. if ($v[1]=='ROLE'){
  2882. if (!empty($verifyStaff)){
  2883. $endStaffArray=end($verifyStaff);
  2884. // if ($v[0]==$endStaffArray['nextStaff']){
  2885. // $roleId=$v[0];
  2886. // }
  2887. }
  2888. $roleVerify=json_decode($v[3],true);
  2889. $roleKey=$k;$roleArray=array();
  2890. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2891. foreach ($roleVerify as $o=>$p){
  2892. $staffID=explode ('_',$p);
  2893. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2894. //print_r($staffID);
  2895. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2896. array_push($roleArray, $exp);
  2897. }
  2898. $roleArrayCopy[$v[0]]=$roleArray;
  2899. //$verifyList[$k]['roleArray']=$roleArray;
  2900. }
  2901. $verifyList[$k]['date']="";
  2902. $verifyList[$k]['opinion']="";
  2903. $verifyList[$k]['status']="";
  2904. if (empty($verifyStaff)){
  2905. $verifyList[$k]['date']="";
  2906. $verifyList[$k]['opinion']="";
  2907. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2908. $verifyList[$k]['status']=4;
  2909. $flag=false;
  2910. }
  2911. }else{
  2912. foreach ($verifyStaff as $m=>$u){
  2913. if ($v[0]==$m){
  2914. $verifyList[$k]['date']=$u['date'];
  2915. $verifyList[$k]['opinion']=$u['opinion'];
  2916. $verifyList[$k]['status']=$u['status'];
  2917. $flag=false;
  2918. break;
  2919. }
  2920. }
  2921. $endStaffArray=end($verifyStaff);
  2922. if (isset($endStaffArray['ROLE'])){
  2923. }else{
  2924. }
  2925. }
  2926. }
  2927. $rolename['name']='';
  2928. if (!empty($roleId)){
  2929. Doo::loadModel('role');
  2930. $role=new role();
  2931. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2932. }
  2933. if (!empty($verifyStaff))
  2934. $endStaffArray=end($verifyStaff);
  2935. $KOP=false;
  2936. foreach ($roleArrayCopy as $P=>$A){
  2937. foreach ( $A as $MKI=>$AVL){
  2938. if (!empty($verifyStaff)){
  2939. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2940. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2941. $button=4;
  2942. $roleArrayCopy[$P][$MKI]['status']=4;
  2943. }
  2944. foreach ($verifyStaff as $m=>$u){
  2945. $AVLFK=$AVL[0].'_R';
  2946. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2947. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2948. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2949. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2950. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2951. break;
  2952. }
  2953. }
  2954. }else{
  2955. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2956. $button=4;
  2957. $roleArrayCopy[$P][$MKI]['status']=4;
  2958. }
  2959. }
  2960. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2961. $KOP=true;
  2962. }
  2963. }
  2964. foreach ($roleArrayCopy as $k=>$v){
  2965. foreach ($verifyList as $m=>$n){
  2966. if ($n[0]==$k){
  2967. array_splice($verifyList,$m,1,$v);
  2968. }
  2969. }
  2970. }
  2971. $receiptList[$key]['executeList']=$executeList;
  2972. $receiptList[$key]['verifyList']=$verifyList;
  2973. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2974. $receiptList[$key]['button2']=$button2;
  2975. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2976. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2977. $relust=$value['sum']-$value['loanSum'];
  2978. $receiptList[$key]['relust']=$relust;
  2979. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  2980. }
  2981. //print_r($receiptList[$key]['executeList']);
  2982. $data['receiptList']=$receiptList;
  2983. $data['memu']="receipt";
  2984. $data['staff']=$this->staff;
  2985. $data['receiptMemu']='implement';
  2986. $data['verifyId']=$this->verifyId;
  2987. $data['executeId']=$this->executeId;
  2988. $this->render ( "/admin/implement", $data );
  2989. }
  2990. function implementDo(){
  2991. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2992. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2993. if (!empty($rid)){
  2994. Doo::loadModel('receipt');
  2995. $receipt=new receipt();
  2996. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  2997. $executeCopy=json_decode($rinfo['executeCopy'],true);
  2998. $executeStaff=json_decode($rinfo['executeStaff'],true);
  2999. if(empty($executeStaff)){
  3000. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3001. }else{
  3002. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3003. }
  3004. if (count($executeStaff)==count($executeCopy)){
  3005. $receipt->executeStaff=json_encode($executeStaff);
  3006. $receipt->status=8;
  3007. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3008. $receipt->status=9;
  3009. $receipt->executeDate= date("Y-m-d");
  3010. }else{
  3011. $receipt->executeStaff=json_encode($executeStaff);
  3012. }
  3013. $receipt->update(array('where'=>'rid='.$rid));
  3014. }
  3015. return "/implement";
  3016. }
  3017. function receiptburEdi(){
  3018. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3019. $status=isset($this->params['status'])?$this->params['status']:'';
  3020. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3021. $month=$this->get_args('month')?$this->get_args('month'):"";
  3022. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3023. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3024. if (empty($status))
  3025. $status=$this->get_args('status')?$this->get_args('status'):2;
  3026. $vidList=array();
  3027. $button=0;
  3028. Doo::loadModel('verify');
  3029. Doo::loadModel('receipt');
  3030. Doo::loadModel('staff');
  3031. $staff=new staff();
  3032. $receipt=new receipt();
  3033. $verify=new verify();
  3034. Doo::loadModel('L_category');
  3035. $Lcategory=new L_category();
  3036. Doo::loadModel('enclosur');
  3037. $enclosur=new enclosur();
  3038. Doo::loadModel('loanReceipt');
  3039. $loanReceipt=new loanReceipt();
  3040. //user verify ID
  3041. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3042. foreach ($verifyDetail as $key=>$value){
  3043. array_push($vidList, $value['vid']);
  3044. }
  3045. $vid=implode(",", $vidList);
  3046. if(empty($verifyDetail))
  3047. $vid=0;
  3048. $categoryList=$Lcategory->find(array('asArray'=>true));
  3049. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3050. $ap="";
  3051. if($status==4){
  3052. $ap=4;$status=2;
  3053. }
  3054. //get Receipt By verifyID status 2
  3055. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3056. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3057. $Locate=0;$roleId=0;$button=0;
  3058. foreach ($loanList as $key=>$value){
  3059. $loanList[$key]['Locate']=$Locate;$Locate++;
  3060. $loanList[$key]['reviseDetail']=array();
  3061. if (!empty($value['reviseDetail']))
  3062. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3063. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3064. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3065. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3066. $loanList[$key]['category']=$categoryDetil['title'];
  3067. //检测编辑状态
  3068. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3069. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3070. $verifyStaff=json_decode($value['verifyStaff'],true);
  3071. Doo::loadModel('role');
  3072. $role=new role();
  3073. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3074. foreach ($verifyList as $k=>$v){
  3075. //init verifyStaff
  3076. if ($v[1]=='ROLE'){
  3077. if (!empty($verifyStaff)){
  3078. $endStaffArray=end($verifyStaff);
  3079. }
  3080. $roleVerify=json_decode($v[3],true);
  3081. $roleKey=$k;$roleArray=array();
  3082. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3083. foreach ($roleVerify as $o=>$p){
  3084. $staffID=explode ('_',$p);
  3085. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3086. //print_r($staffID);
  3087. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3088. array_push($roleArray, $exp);
  3089. }
  3090. $roleArrayCopy[$v[0]]=$roleArray;
  3091. //$verifyList[$k]['roleArray']=$roleArray;
  3092. }
  3093. $verifyList[$k]['date']="";
  3094. $verifyList[$k]['opinion']="";
  3095. $verifyList[$k]['status']="";
  3096. if (empty($verifyStaff)){
  3097. $verifyList[$k]['date']="";
  3098. $verifyList[$k]['opinion']="";
  3099. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3100. $verifyList[$k]['status']=4;
  3101. $flag=false;
  3102. }
  3103. }else{
  3104. foreach ($verifyStaff as $m=>$u){
  3105. if ($v[0]==$m){
  3106. $verifyList[$k]['date']=$u['date'];
  3107. $verifyList[$k]['opinion']=$u['opinion'];
  3108. $verifyList[$k]['status']=$u['status'];
  3109. $flag=false;
  3110. break;
  3111. }
  3112. }
  3113. $endStaffArray=end($verifyStaff);
  3114. if (isset($endStaffArray['ROLE'])){
  3115. }else{
  3116. }
  3117. }
  3118. }
  3119. $rolename['name']='';
  3120. if (!empty($roleId)){
  3121. Doo::loadModel('role');
  3122. $role=new role();
  3123. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3124. }
  3125. if (!empty($verifyStaff))
  3126. $endStaffArray=end($verifyStaff);
  3127. $KOP=false;
  3128. foreach ($roleArrayCopy as $P=>$A){
  3129. foreach ( $A as $MKI=>$AVL){
  3130. if (!empty($verifyStaff)){
  3131. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3132. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3133. $button=4;
  3134. $roleArrayCopy[$P][$MKI]['status']=4;
  3135. }
  3136. foreach ($verifyStaff as $m=>$u){
  3137. $AVLFK=$AVL[0].'_R';
  3138. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3139. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3140. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3141. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3142. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3143. break;
  3144. }
  3145. }
  3146. }else{
  3147. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3148. $button=4;
  3149. $roleArrayCopy[$P][$MKI]['status']=4;
  3150. }
  3151. }
  3152. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3153. $KOP=true;
  3154. }
  3155. }
  3156. foreach ($roleArrayCopy as $k=>$v){
  3157. foreach ($verifyList as $m=>$n){
  3158. if ($n[0]==$k){
  3159. array_splice($verifyList,$m,1,$v);
  3160. }
  3161. }
  3162. }
  3163. $loanList[$key]['verifyList']=$verifyList;
  3164. }
  3165. $htmlLoan='';
  3166. if (isset($loanList[0])){
  3167. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3168. if ($value['status']==1)
  3169. $htmlLoan.='<li class="done" >';
  3170. elseif ($value['status']==3)
  3171. $htmlLoan.='<li class="undone" >';
  3172. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3173. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3174. if (isset($value['rolename']))
  3175. $htmlLoan.=$value['rolename'];
  3176. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3177. }
  3178. $data['loanDate']=$loanList[0]['date'];
  3179. }
  3180. $data['htmlLoan']=$htmlLoan;
  3181. /*
  3182. <!-- loop loanList.0.verifyList -->
  3183. <li <!-- if {{loanList' value.status}}==1 --> class="done" <!-- elseif {{loanList' value.status}}==3 --> class="undone" <!-- endif -->>
  3184. <div class="avtra"><img src="{{loanList' value.2}}_2.jpg"></div>
  3185. <div class="comment">
  3186. <p class="colGray"><span class="fR">{{loanList' value.date}}</span>{{loanList' value.1}}<!-- if isset({{loanList' value.rolename}}) --> ({{loanList' value.rolename}}) <!-- endif --></p>
  3187. <p>{{loanList' value.opinion}}</p>
  3188. </div>
  3189. </li>
  3190. <!-- endloop -->
  3191. */
  3192. //print_r($loanList);
  3193. $Locate=0;$roleId=0;
  3194. if($ap==4)
  3195. $status=4;
  3196. foreach ($receiptList as $key=>$value){
  3197. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3198. $receiptList[$key]['reviseDetail']=array();
  3199. if (!empty($value['reviseDetail']))
  3200. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3201. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3202. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3203. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3204. $receiptList[$key]['category']=$categoryDetil['title'];
  3205. //检测编辑状态
  3206. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3207. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3208. $verifyStaff=json_decode($value['verifyStaff'],true);
  3209. Doo::loadModel('role');
  3210. $role=new role();
  3211. //print_r($verifyList);
  3212. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3213. foreach ($verifyList as $k=>$v){
  3214. //init verifyStaff
  3215. if ($v[1]=='ROLE'){
  3216. if (!empty($verifyStaff)){
  3217. $endStaffArray=end($verifyStaff);
  3218. if ($v[0]==$endStaffArray['nextStaff']){
  3219. $roleId=$v[0];
  3220. }
  3221. }
  3222. $roleVerify=json_decode($v[3],true);
  3223. $roleKey=$k;$roleArray=array();
  3224. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3225. foreach ($roleVerify as $o=>$p){
  3226. $staffID=explode ('_',$p);
  3227. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3228. //print_r($staffID);
  3229. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3230. array_push($roleArray, $exp);
  3231. }
  3232. $roleArrayCopy[$v[0]]=$roleArray;
  3233. //$verifyList[$k]['roleArray']=$roleArray;
  3234. }
  3235. //print_r($roleArray);
  3236. $verifyList[$k]['date']="";
  3237. $verifyList[$k]['opinion']="";
  3238. $verifyList[$k]['status']="";
  3239. if (empty($verifyStaff)){
  3240. $verifyList[$k]['date']="";
  3241. $verifyList[$k]['opinion']="";
  3242. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3243. $verifyList[$k]['status']=4;
  3244. $button=4;$flag=false;
  3245. }
  3246. }else{
  3247. foreach ($verifyStaff as $m=>$u){
  3248. if ($v[0]==$m){
  3249. $verifyList[$k]['date']=$u['date'];
  3250. $verifyList[$k]['opinion']=$u['opinion'];
  3251. $verifyList[$k]['status']=$u['status'];
  3252. $flag=false;
  3253. break;
  3254. }
  3255. }
  3256. $endStaffArray=end($verifyStaff);
  3257. if (isset($endStaffArray['ROLE'])){
  3258. }else{
  3259. $endKey=key($verifyStaff);
  3260. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3261. $button=4;
  3262. $verifyList[$k]['status']=4;
  3263. }
  3264. }
  3265. }
  3266. }
  3267. $rolename['name']='';
  3268. if (!empty($roleId)){
  3269. Doo::loadModel('role');
  3270. $role=new role();
  3271. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3272. }
  3273. if (!empty($verifyStaff))
  3274. $endStaffArray=end($verifyStaff);
  3275. $KOP=false;
  3276. foreach ($roleArrayCopy as $P=>$A){
  3277. foreach ( $A as $MKI=>$AVL){
  3278. if (!empty($verifyStaff)){
  3279. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3280. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3281. $button=4;
  3282. $roleArrayCopy[$P][$MKI]['status']=4;
  3283. }
  3284. foreach ($verifyStaff as $m=>$u){
  3285. $AVLFK=$AVL[0].'_R';
  3286. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3287. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3288. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3289. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3290. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3291. break;
  3292. }
  3293. }
  3294. }else{
  3295. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3296. $button=4;
  3297. $roleArrayCopy[$P][$MKI]['status']=4;
  3298. }
  3299. }
  3300. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3301. $KOP=true;
  3302. }
  3303. }
  3304. foreach ($roleArrayCopy as $k=>$v){
  3305. foreach ($verifyList as $m=>$n){
  3306. if ($n[0]==$k){
  3307. array_splice($verifyList,$m,1,$v);
  3308. }
  3309. }
  3310. }
  3311. //print_r($verifyList);
  3312. $receiptList[$key]['verifyList']=$verifyList;
  3313. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3314. $receiptList[$key]['button']=$button;
  3315. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3316. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3317. $relust=$value['sum']-$value['loanSum'];
  3318. $receiptList[$key]['relust']=$relust;
  3319. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3320. }
  3321. //$data['verifyDetail']=$verifyDetail;
  3322. $mothHtml="";
  3323. for($i=1;$i<=12;$i++){
  3324. if($month==$i)
  3325. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3326. else
  3327. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3328. }
  3329. //获取审批日志
  3330. Doo::loadModel('receiptLog');
  3331. $receiptLog=new receiptLog();
  3332. $rlList=array();
  3333. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3334. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3335. if (!empty($rlInfo)){
  3336. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3337. }
  3338. //echo $rid;
  3339. //print_r($receiptList);
  3340. $receiptList[0]['rlList']=$rlList;
  3341. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3342. $enclosurHtml='';
  3343. foreach ($enclosurList as $value){
  3344. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3345. }
  3346. $data['enclosurHtml']=$enclosurHtml;
  3347. $data['rolename']=$rolename['name'];
  3348. // $data['datetij']=$tijdate['date'];
  3349. $data['mothHtml']=$mothHtml;
  3350. //print_r($receiptList);
  3351. $data['rid']=$rid;
  3352. $data['tijdate']=$tijdate['date'];
  3353. $data['receiptList']=$receiptList;
  3354. $data['receiptApprovalCount']=count($receiptList);
  3355. $data['status']=$status;
  3356. $data['year']=$year;
  3357. $data['categoryList']=$categoryList;
  3358. $data['staffList']=$staffList;
  3359. $data['cid']=$cid;
  3360. $data['sid']=$sid;
  3361. $data['ap']=$ap;
  3362. $data['memu']="receipt";
  3363. $data['staff']=$this->staff;
  3364. $data['receiptMemu']='approvalExpenses';
  3365. $data['verifyId']=$this->verifyId;
  3366. $data['executeId']=$this->executeId;
  3367. $this->render ( "/admin/receiptburEdi", $data );
  3368. }
  3369. function hisImplement(){
  3370. $item=isset($this->params['item'])?$this->params['item']:"";
  3371. if(empty($item))
  3372. $item=$this->get_args('item')?$this->get_args('item'):"";
  3373. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3374. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3375. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3376. Doo::loadModel('receipt');
  3377. $receipt=new receipt();
  3378. Doo::loadModel('L_category');
  3379. $Lcategory=new L_category();
  3380. Doo::loadModel('verify');
  3381. Doo::loadModel('statistics');
  3382. $statistics=new statistics();
  3383. $verify=new verify();
  3384. Doo::loadModel('staff');
  3385. $staff=new staff();
  3386. $condition="";
  3387. if($item=="expenses")
  3388. $condition=" and Rtype=1 ";
  3389. elseif ($item=="receipts")
  3390. $condition=" and Rtype=0 ";
  3391. elseif ($item=="remits")
  3392. $condition=" and Rtype=2 ";
  3393. $dateCondition=" and Year(executeDate) =".$year;
  3394. if($moth!='MONTH'){
  3395. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3396. }
  3397. if($day!='DAY')
  3398. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3399. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3400. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3401. $Locate=0;$roleId=0;$button=0;
  3402. foreach ($receiptList as $key=>$value){
  3403. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3404. $receiptList[$key]['reviseDetail']=array();
  3405. if (!empty($value['reviseDetail']))
  3406. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3407. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3408. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3409. $receiptList[$key]['category']=$categoryDetil['title'];
  3410. //检测编辑状态
  3411. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3412. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3413. $verifyStaff=json_decode($value['verifyStaff'],true);
  3414. Doo::loadModel('role');
  3415. $role=new role();
  3416. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3417. foreach ($verifyList as $k=>$v){
  3418. //init verifyStaff
  3419. if ($v[1]=='ROLE'){
  3420. if (!empty($verifyStaff)){
  3421. $endStaffArray=end($verifyStaff);
  3422. }
  3423. $roleVerify=json_decode($v[3],true);
  3424. $roleKey=$k;$roleArray=array();
  3425. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3426. foreach ($roleVerify as $o=>$p){
  3427. $staffID=explode ('_',$p);
  3428. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3429. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3430. array_push($roleArray, $exp);
  3431. }
  3432. $roleArrayCopy[$v[0]]=$roleArray;
  3433. }
  3434. $verifyList[$k]['date']="";
  3435. $verifyList[$k]['opinion']="";
  3436. $verifyList[$k]['status']="";
  3437. if (empty($verifyStaff)){
  3438. $verifyList[$k]['date']="";
  3439. $verifyList[$k]['opinion']="";
  3440. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3441. $verifyList[$k]['status']=4;
  3442. $flag=false;
  3443. }
  3444. }else{
  3445. foreach ($verifyStaff as $m=>$u){
  3446. if ($v[0]==$m){
  3447. $verifyList[$k]['date']=$u['date'];
  3448. $verifyList[$k]['opinion']=$u['opinion'];
  3449. $verifyList[$k]['status']=$u['status'];
  3450. $flag=false;
  3451. break;
  3452. }
  3453. }
  3454. $endStaffArray=end($verifyStaff);
  3455. }
  3456. }
  3457. $rolename['name']='';
  3458. if (!empty($roleId)){
  3459. Doo::loadModel('role');
  3460. $role=new role();
  3461. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3462. }
  3463. if (!empty($verifyStaff))
  3464. $endStaffArray=end($verifyStaff);
  3465. $KOP=false;
  3466. foreach ($roleArrayCopy as $P=>$A){
  3467. foreach ( $A as $MKI=>$AVL){
  3468. if (!empty($verifyStaff)){
  3469. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3470. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3471. $button=4;
  3472. $roleArrayCopy[$P][$MKI]['status']=4;
  3473. }
  3474. foreach ($verifyStaff as $m=>$u){
  3475. $AVLFK=$AVL[0].'_R';
  3476. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3477. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3478. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3479. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3480. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3481. break;
  3482. }
  3483. }
  3484. }else{
  3485. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3486. $button=4;
  3487. $roleArrayCopy[$P][$MKI]['status']=4;
  3488. }
  3489. }
  3490. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3491. $KOP=true;
  3492. }
  3493. }
  3494. foreach ($roleArrayCopy as $k=>$v){
  3495. foreach ($verifyList as $m=>$n){
  3496. if ($n[0]==$k){
  3497. array_splice($verifyList,$m,1,$v);
  3498. }
  3499. }
  3500. }
  3501. $receiptList[$key]['verifyList']=$verifyList;
  3502. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3503. $receiptList[$key]['button']=$button;
  3504. }
  3505. //print_r($receiptList);die;
  3506. $mothHtml="";
  3507. for($i=1;$i<=12;$i++){
  3508. if($moth==$i)
  3509. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3510. else
  3511. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3512. }
  3513. $dayHtml="";
  3514. if ($day!="DAY"||$moth!="MONTH"){
  3515. for($i = 1; $i <= 31; $i ++) {
  3516. if($day==$i)
  3517. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3518. else
  3519. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3520. }
  3521. }
  3522. $data['dayHtml']=$dayHtml;
  3523. $data['mothHtml']=$mothHtml;
  3524. $data['receiptList']=$receiptList;
  3525. $data['memu']="receipt";
  3526. $data['staff']=$this->staff;
  3527. $data['receiptMemu']='implement';
  3528. $data['verifyId']=$this->verifyId;
  3529. $data['executeId']=$this->executeId;
  3530. $data['item']=$item;
  3531. $data['year']=$year;
  3532. $data['moth']=$moth;
  3533. $data['day']=$day;
  3534. $this->render ( "/admin/hisImplement", $data );
  3535. }
  3536. function ajaxExamine(){
  3537. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3538. Doo::loadModel('receipt');
  3539. $receipt=new receipt();
  3540. if (!empty($rid)){
  3541. $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
  3542. ,'asArray'=>true));
  3543. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3544. }
  3545. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3546. }
  3547. function myReceipt(){
  3548. //all approval past withdraw
  3549. $item=isset($this->params['item'])?$this->params['item']:"";
  3550. if(empty($item))
  3551. $item=$this->get_args('item')?$this->get_args('item'):"";
  3552. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3553. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3554. Doo::loadModel('receipt');
  3555. $receipt=new receipt();
  3556. //pre-loaded
  3557. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3558. //have cache
  3559. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3560. if(!empty($moth))//yearPage
  3561. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3562. $this->showCache($path);
  3563. }
  3564. Doo::loadModel('L_category');
  3565. $Lcategory=new L_category();
  3566. Doo::loadModel('verify');
  3567. Doo::loadModel('statistics');
  3568. $statistics=new statistics();
  3569. $verify=new verify();
  3570. Doo::loadModel('staff');
  3571. $staff=new staff();
  3572. $condition=" and status!=0 ";
  3573. if($item=="approval")
  3574. $condition=" and status=2 ";
  3575. elseif ($item=="withdraw")
  3576. $condition=" and status=3 ";
  3577. elseif ($item=="past")
  3578. $condition=" and status=1 ";
  3579. elseif ($item=="whdw")
  3580. $condition=" and status=4 ";
  3581. $dateCondition=" and Year(date) =".$year;
  3582. if(!empty($moth)){
  3583. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3584. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3585. }else
  3586. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3587. if(empty($stList))
  3588. $stList=array('rePrice'=>0,'agPrice'=>0);
  3589. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3590. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3591. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3592. $Locate=0;$roleId=0;$button=0;
  3593. foreach ($receiptList as $key=>$value){
  3594. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3595. $receiptList[$key]['reviseDetail']=array();
  3596. if (!empty($value['reviseDetail']))
  3597. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3598. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3599. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3600. $receiptList[$key]['category']=$categoryDetil['title'];
  3601. //检测编辑状态
  3602. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3603. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3604. $verifyStaff=json_decode($value['verifyStaff'],true);
  3605. Doo::loadModel('role');
  3606. $role=new role();
  3607. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3608. foreach ($verifyList as $k=>$v){
  3609. //init verifyStaff
  3610. if ($v[1]=='ROLE'){
  3611. if (!empty($verifyStaff)){
  3612. $endStaffArray=end($verifyStaff);
  3613. // if ($v[0]==$endStaffArray['nextStaff']){
  3614. // $roleId=$v[0];
  3615. // }
  3616. }
  3617. $roleVerify=json_decode($v[3],true);
  3618. $roleKey=$k;$roleArray=array();
  3619. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3620. foreach ($roleVerify as $o=>$p){
  3621. $staffID=explode ('_',$p);
  3622. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3623. //print_r($staffID);
  3624. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3625. array_push($roleArray, $exp);
  3626. }
  3627. $roleArrayCopy[$v[0]]=$roleArray;
  3628. //$verifyList[$k]['roleArray']=$roleArray;
  3629. }
  3630. $verifyList[$k]['date']="";
  3631. $verifyList[$k]['opinion']="";
  3632. $verifyList[$k]['status']="";
  3633. if (empty($verifyStaff)){
  3634. $verifyList[$k]['date']="";
  3635. $verifyList[$k]['opinion']="";
  3636. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3637. $verifyList[$k]['status']=4;
  3638. $flag=false;
  3639. }
  3640. }else{
  3641. foreach ($verifyStaff as $m=>$u){
  3642. if ($v[0]==$m){
  3643. $verifyList[$k]['date']=$u['date'];
  3644. $verifyList[$k]['opinion']=$u['opinion'];
  3645. $verifyList[$k]['status']=$u['status'];
  3646. $flag=false;
  3647. break;
  3648. }
  3649. }
  3650. $endStaffArray=end($verifyStaff);
  3651. if (isset($endStaffArray['ROLE'])){
  3652. }else{
  3653. // $endKey=key($verifyStaff);
  3654. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3655. // $button=4;
  3656. // $verifyList[$k]['status']=4;
  3657. // }
  3658. }
  3659. }
  3660. }
  3661. $rolename['name']='';
  3662. if (!empty($roleId)){
  3663. Doo::loadModel('role');
  3664. $role=new role();
  3665. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3666. }
  3667. if (!empty($verifyStaff))
  3668. $endStaffArray=end($verifyStaff);
  3669. $KOP=false;
  3670. foreach ($roleArrayCopy as $P=>$A){
  3671. foreach ( $A as $MKI=>$AVL){
  3672. if (!empty($verifyStaff)){
  3673. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3674. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3675. $button=4;
  3676. $roleArrayCopy[$P][$MKI]['status']=4;
  3677. }
  3678. foreach ($verifyStaff as $m=>$u){
  3679. $AVLFK=$AVL[0].'_R';
  3680. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3681. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3682. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3683. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3684. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3685. break;
  3686. }
  3687. }
  3688. }else{
  3689. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3690. $button=4;
  3691. $roleArrayCopy[$P][$MKI]['status']=4;
  3692. }
  3693. }
  3694. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3695. $KOP=true;
  3696. }
  3697. }
  3698. foreach ($roleArrayCopy as $k=>$v){
  3699. foreach ($verifyList as $m=>$n){
  3700. if ($n[0]==$k){
  3701. array_splice($verifyList,$m,1,$v);
  3702. }
  3703. }
  3704. }
  3705. $receiptList[$key]['verifyList']=$verifyList;
  3706. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3707. $receiptList[$key]['button']=$button;
  3708. }
  3709. //print_r($receiptList);die;
  3710. $mothHtml="";
  3711. for($i=1;$i<=12;$i++){
  3712. if($moth==$i)
  3713. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3714. else
  3715. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3716. }
  3717. $data['mothHtml']=$mothHtml;
  3718. $data['receiptList']=$receiptList;
  3719. $data['memu']="receipt";
  3720. $data['staff']=$this->staff;
  3721. $data['receiptMemu']='receipt';
  3722. $data['verifyId']=$this->verifyId;
  3723. $data['executeId']=$this->executeId;
  3724. $data['item']=$item;
  3725. $data['year']=$year;
  3726. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3727. //sufficient condition to generate cache
  3728. if(empty($moth)&&($year<date("Y"))){
  3729. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3730. if(empty($receiptList)){ //generated files
  3731. ob_start();
  3732. $this->render ( "/admin/saea_myList", $data );
  3733. $this->cacheFile($path);die;
  3734. // $content = ob_get_contents();
  3735. // $fp = fopen($path, "w");
  3736. // fwrite($fp, $content);
  3737. // fclose($fp);
  3738. }
  3739. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3740. $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));
  3741. if(empty($receiptList)){ //generated files
  3742. ob_start();
  3743. $this->render ( "/admin/saea_myList", $data );
  3744. $this->cacheFile($path);die;
  3745. }
  3746. }
  3747. }
  3748. $this->render ( "/admin/saea_myList", $data );
  3749. }
  3750. function saeaCreate(){
  3751. Doo::loadModel('accountItem');
  3752. Doo::loadModel('verify');
  3753. Doo::loadModel('receipt');
  3754. Doo::loadModel('L_category');
  3755. $lCategory=new L_category();
  3756. $receipt=new receipt();
  3757. $verify=new verify();
  3758. $accountItem=new accountItem();
  3759. Doo::loadModel("role");
  3760. $role=new role();
  3761. $acItem=$accountItem->find(array('asArray'=>true));
  3762. $veList=$verify->find(array('asArray'=>true));
  3763. foreach ($veList as $key=>$value){
  3764. $v=json_decode($value['staff']);
  3765. $list=array();
  3766. foreach ($v as $n=>$m){
  3767. if ($m['1']=='ROLE'){
  3768. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3769. $v[$n][1]=$roleInfo['name'];
  3770. array_push($list, $roleInfo['name']);
  3771. }else{
  3772. array_push($list, $v[$n][1]);
  3773. }
  3774. }
  3775. $veList[$key]['staff']=implode('>', $list);
  3776. }
  3777. $data['category']=$lCategory->find(array('asArray'=>true));
  3778. $data['veList']=$veList;
  3779. $data['acItem']=$acItem;
  3780. $data['memu']="receipt";
  3781. $data['staff']=$this->staff;
  3782. $data['receiptMemu']='saeaBorad';
  3783. $data['verifyId']=$this->verifyId;
  3784. $data['executeId']=$this->executeId;
  3785. $this->render ( "/admin/saea_create", $data );
  3786. }
  3787. function addReceipt(){
  3788. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3789. $agency=$this->get_args('agency');
  3790. $travel=$this->get_args('travel');
  3791. $train=$this->get_args('train');
  3792. $other=$this->get_args('other');
  3793. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3794. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3795. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3796. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3797. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3798. Doo::loadModel('receipt');
  3799. Doo::loadModel('receiptDetail');
  3800. Doo::loadModel('accountItem');
  3801. $accountItem=new accountItem();
  3802. $receipt=new receipt();
  3803. Doo::loadModel('enclosur');
  3804. Doo::loadModel('execute');
  3805. $execute=new execute();
  3806. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3807. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3808. // if(!empty($receiptDetail))
  3809. // return "/referReceipt/".$receiptDetail['rid'];
  3810. $aItem=$accountItem->find(array('asArray'=>true));
  3811. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3812. $ag=$tr=$ta=$ot=0;
  3813. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3814. foreach ($aItem as $key=>$value){
  3815. if ($value['category']==$this->AGENCY){
  3816. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3817. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3818. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3819. }
  3820. $ag++;
  3821. }
  3822. if($value['category']==$this->TRAVEL){
  3823. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3824. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3825. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3826. }
  3827. $tr++;
  3828. }
  3829. if($value['category']==$this->TRAIN){
  3830. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3831. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3832. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3833. }
  3834. $ta++;
  3835. }
  3836. if($value['category']==$this->OTHER){
  3837. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3838. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3839. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3840. }
  3841. $ot++;
  3842. }
  3843. }
  3844. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3845. //报销单
  3846. $receipt->accountItem=json_encode($accountJson);
  3847. $receipt->staff=$this->staff[0]['sid'];
  3848. $receipt->sum=number_format($sum, 2, '.', '');
  3849. $receipt->date=date("Y-m-d");
  3850. $receipt->cid=$cid;
  3851. $receipt->status=5;
  3852. //修改审批流程加入角色
  3853. $receipt->verify=$verify;
  3854. $receipt->executeCopy=$executeDetail['staff'];
  3855. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3856. $receipt->explanation=$explanation;
  3857. $rid=$receipt->insert();
  3858. //附件
  3859. if (!empty($enclosurName)){
  3860. $enclosurArray=explode('-', $enclosurName);
  3861. foreach ($enclosurArray as $value){
  3862. $enclosur=new enclosur();
  3863. $enclosur->name=$value;
  3864. $enclosur->rid=$rid;
  3865. $enclosur->insert();
  3866. }
  3867. //print_r($enclosurArray);die;
  3868. }
  3869. //报销详情
  3870. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3871. $receiptDetail=new receiptDetail();
  3872. $receiptDetail->staff=$this->staff[0]['sid'];
  3873. $receiptDetail->item=$value['name'];
  3874. $receiptDetail->itemCategory=$this->AGENCY;
  3875. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3876. $receiptDetail->date=date("Y-m-d");
  3877. $receiptDetail->cid=$cid;
  3878. $receiptDetail->rid=$rid;
  3879. $receiptDetail->status=4;
  3880. $receiptDetail->insert();
  3881. }
  3882. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3883. $receiptDetail=new receiptDetail();
  3884. $receiptDetail->staff=$this->staff[0]['sid'];
  3885. $receiptDetail->item=$value['name'];
  3886. $receiptDetail->itemCategory=$this->TRAVEL;
  3887. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3888. $receiptDetail->date=date("Y-m-d");
  3889. $receiptDetail->cid=$cid;
  3890. $receiptDetail->rid=$rid;
  3891. $receiptDetail->status=4;
  3892. $receiptDetail->insert();
  3893. }
  3894. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3895. $receiptDetail=new receiptDetail();
  3896. $receiptDetail->staff=$this->staff[0]['sid'];
  3897. $receiptDetail->item=$value['name'];
  3898. $receiptDetail->itemCategory=$this->TRAIN;
  3899. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3900. $receiptDetail->date=date("Y-m-d");
  3901. $receiptDetail->cid=$cid;
  3902. $receiptDetail->rid=$rid;
  3903. $receiptDetail->status=4;
  3904. $receiptDetail->insert();
  3905. }
  3906. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3907. $receiptDetail=new receiptDetail();
  3908. $receiptDetail->staff=$this->staff[0]['sid'];
  3909. $receiptDetail->item=$value['name'];
  3910. $receiptDetail->itemCategory=$this->OTHER;
  3911. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3912. $receiptDetail->date=date("Y-m-d");
  3913. $receiptDetail->cid=$cid;
  3914. $receiptDetail->rid=$rid;
  3915. $receiptDetail->status=4;
  3916. $receiptDetail->insert();
  3917. }
  3918. //return "/referReceipt/".$rid;
  3919. }
  3920. return "/saeaBorad";
  3921. }
  3922. function referReceipt(){
  3923. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3924. Doo::loadModel('receipt');
  3925. Doo::loadModel('verify');
  3926. $verify=new verify();
  3927. $receipt=new receipt();
  3928. Doo::loadModel('L_category');
  3929. $lCategory=new L_category();
  3930. Doo::loadModel("role");
  3931. $role=new role();
  3932. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  3933. if(empty($receiptDetail))
  3934. return "/addReceipt";
  3935. foreach ($receiptDetail as $key=>$value){
  3936. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  3937. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3938. $v=json_decode($veList['staff']);
  3939. array_push($v[0], $veList['description']);
  3940. foreach ($v as $n=>$m){
  3941. if ($m['1']=='ROLE'){
  3942. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3943. $v[$n][1]=$roleInfo['name'];
  3944. }
  3945. }
  3946. $receiptDetail[$key]['staff']=$v;
  3947. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3948. $receiptDetail[$key]['category']=$category['title'];
  3949. }
  3950. //print_r($receiptDetail);
  3951. $data['receiptDetail']=$receiptDetail;
  3952. $data['memu']="receipt";
  3953. $data['staff']=$this->staff;
  3954. $data['receiptMemu']='saeaCreate';
  3955. $data['verifyId']=$this->verifyId;
  3956. $data['executeId']=$this->executeId;
  3957. $this->render ( "/admin/saea_confirm", $data );
  3958. }
  3959. function editReceipt(){
  3960. //edit status 4
  3961. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3962. //echo $rid;
  3963. Doo::loadModel('accountItem');
  3964. Doo::loadModel('verify');
  3965. Doo::loadModel('receipt');
  3966. $receipt=new receipt();
  3967. $verify=new verify();
  3968. $accountItem=new accountItem();
  3969. Doo::loadModel('L_category');
  3970. $lCategory=new L_category();
  3971. Doo::loadModel("role");
  3972. $role=new role();
  3973. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  3974. if(empty($receiptDetail))
  3975. return "/saeaCreate";
  3976. $acItem=$accountItem->find(array('asArray'=>true));
  3977. $veList=$verify->find(array('asArray'=>true));
  3978. foreach ($veList as $key=>$value){
  3979. $v=json_decode($value['staff']);
  3980. $list=array();
  3981. foreach ($v as $n=>$m){
  3982. if ($m['1']=='ROLE'){
  3983. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3984. $v[$n][1]=$roleInfo['name'];
  3985. array_push($list, $roleInfo['name']);
  3986. }else{
  3987. array_push($list, $v[$n][1]);
  3988. }
  3989. }
  3990. $veList[$key]['staff']=implode('>', $list);
  3991. }
  3992. //配置编辑信息
  3993. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  3994. foreach ($acItem as $key=>$value){
  3995. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  3996. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  3997. $acItem[$key]['price']=$v['price'];
  3998. }
  3999. }
  4000. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4001. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4002. $acItem[$key]['price']=$v['price'];
  4003. }
  4004. }
  4005. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4006. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4007. $acItem[$key]['price']=$v['price'];
  4008. }
  4009. }
  4010. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4011. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4012. $acItem[$key]['price']=$v['price'];
  4013. }
  4014. }
  4015. }
  4016. $data['category']=$lCategory->find(array('asArray'=>true));
  4017. $data['cSum']=$accountItemList['cSum'];
  4018. $data['sum']=$receiptDetail['sum'];
  4019. $data['receiptDetail']=$receiptDetail;
  4020. $data['veList']=$veList;
  4021. $data['acItem']=$acItem;
  4022. $data['memu']="receipt";
  4023. $data['staff']=$this->staff;
  4024. $data['receiptMemu']='saeaBorad';
  4025. $data['verify']=$receiptDetail['verify'];
  4026. $data['verifyId']=$this->verifyId;
  4027. $data['executeId']=$this->executeId;
  4028. $data['rid']=$rid;
  4029. $this->render ( "/admin/saea_edit", $data );
  4030. }
  4031. function updateReceipt(){
  4032. $agency=$this->get_args('agency');
  4033. $travel=$this->get_args('travel');
  4034. $train=$this->get_args('train');
  4035. $other=$this->get_args('other');
  4036. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4037. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4038. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4039. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4040. if(!empty($verify)&&!empty($explanation)){
  4041. Doo::loadModel('receipt');
  4042. Doo::loadModel('receiptDetail');
  4043. Doo::loadModel('accountItem');
  4044. $accountItem=new accountItem();
  4045. $receipt=new receipt();
  4046. Doo::loadModel('execute');
  4047. $execute=new execute();
  4048. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4049. if(empty($receiptDetail))
  4050. return "/saeaBorad";
  4051. if ($receiptDetail['Rtype']==1)
  4052. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4053. else
  4054. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4055. $aItem=$accountItem->find(array('asArray'=>true));
  4056. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4057. $ag=$tr=$ta=$ot=0;
  4058. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4059. foreach ($aItem as $key=>$value){
  4060. if ($value['category']==$this->AGENCY){
  4061. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4062. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4063. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4064. }
  4065. $ag++;
  4066. }
  4067. if($value['category']==$this->TRAVEL){
  4068. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4069. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4070. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4071. }
  4072. $tr++;
  4073. }
  4074. if($value['category']==$this->TRAIN){
  4075. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4076. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4077. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4078. }
  4079. $ta++;
  4080. }
  4081. if($value['category']==$this->OTHER){
  4082. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4083. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4084. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4085. }
  4086. $ot++;
  4087. }
  4088. }
  4089. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4090. //报销单
  4091. $rid=$receipt->rid=$receiptDetail['rid'];
  4092. $receipt->accountItem=json_encode($accountJson);
  4093. $receipt->staff=$this->staff[0]['sid'];
  4094. $receipt->sum=number_format($sum, 2, '.', '');
  4095. $receipt->date=date("Y-m-d");
  4096. $receipt->cid=$cid;
  4097. if (($receiptDetail['status']!=4)){
  4098. if ($receiptDetail['Rtype']==1)
  4099. $receipt->status=7;
  4100. else
  4101. $receipt->status=5;
  4102. }
  4103. $receipt->verify=$verify;
  4104. $receipt->executeCopy=$executeDetail['staff'];
  4105. $receipt->explanation=$explanation;
  4106. $receipt->update();
  4107. $receiptDetail=new receiptDetail();
  4108. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4109. //报销详情
  4110. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4111. $receiptDetail=new receiptDetail();
  4112. $receiptDetail->staff=$this->staff[0]['sid'];
  4113. $receiptDetail->item=$value['name'];
  4114. $receiptDetail->itemCategory=$this->AGENCY;
  4115. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4116. $receiptDetail->date=date("Y-m-d");
  4117. $receiptDetail->cid=$cid;
  4118. $receiptDetail->rid=$rid;
  4119. $receiptDetail->status=4;
  4120. $receiptDetail->insert();
  4121. }
  4122. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4123. $receiptDetail=new receiptDetail();
  4124. $receiptDetail->staff=$this->staff[0]['sid'];
  4125. $receiptDetail->item=$value['name'];
  4126. $receiptDetail->itemCategory=$this->TRAVEL;
  4127. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4128. $receiptDetail->date=date("Y-m-d");
  4129. $receiptDetail->cid=$cid;
  4130. $receiptDetail->rid=$rid;
  4131. $receiptDetail->status=4;
  4132. $receiptDetail->insert();
  4133. }
  4134. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4135. $receiptDetail=new receiptDetail();
  4136. $receiptDetail->staff=$this->staff[0]['sid'];
  4137. $receiptDetail->item=$value['name'];
  4138. $receiptDetail->itemCategory=$this->TRAIN;
  4139. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4140. $receiptDetail->date=date("Y-m-d");
  4141. $receiptDetail->cid=$cid;
  4142. $receiptDetail->rid=$rid;
  4143. $receiptDetail->status=4;
  4144. $receiptDetail->insert();
  4145. }
  4146. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4147. $receiptDetail=new receiptDetail();
  4148. $receiptDetail->staff=$this->staff[0]['sid'];
  4149. $receiptDetail->item=$value['name'];
  4150. $receiptDetail->itemCategory=$this->OTHER;
  4151. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4152. $receiptDetail->date=date("Y-m-d");
  4153. $receiptDetail->cid=$cid;
  4154. $receiptDetail->rid=$rid;
  4155. $receiptDetail->status=4;
  4156. $receiptDetail->insert();
  4157. }
  4158. //return "/referReceipt/".$rid;
  4159. }
  4160. return "/saeaBorad";
  4161. }
  4162. function approvedReceipt(){
  4163. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4164. Doo::loadModel('receipt');
  4165. Doo::loadModel('receiptDetail');
  4166. $receipt=new receipt();
  4167. $receiptDetail=new receiptDetail();
  4168. Doo::loadModel('statistics');
  4169. Doo::loadModel('itemStatistics');
  4170. $statistics=new statistics();
  4171. $itemStatistics=new itemStatistics();
  4172. Doo::loadModel("verify");
  4173. $verify=new verify();
  4174. //审批状态的判定
  4175. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4176. if(empty($receiptDetailList))
  4177. return "/saeaBorad";
  4178. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4179. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4180. if (empty($receiptDetailList['nowStaff'])){
  4181. $nowStaff="";$nowStaffList=array();
  4182. if ($verifyDetail[0][1]=='ROLE'){
  4183. $vStaffString=json_decode($verifyDetail[0][3]);
  4184. foreach ($vStaffString as $key=>$value){
  4185. $staffK=explode("_", $value);
  4186. array_push($nowStaffList, $staffK[0]);
  4187. }
  4188. $nowStaff=implode(',', $nowStaffList);
  4189. }else{
  4190. $nowStaff=$verifyDetail[0][0];
  4191. }
  4192. $receipt->nowStaff=$nowStaff;
  4193. }
  4194. // echo $nowStaff;
  4195. // print_r($verifyDetail);die;
  4196. $receipt->rid=$receiptDetailList['rid'];
  4197. $receipt->date=date("Y-m-d");
  4198. $receipt->status=2;
  4199. $receipt->update();
  4200. $receiptDetail->status=2;
  4201. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4202. Doo::loadModel("receiptLog");
  4203. $receiptLog=new receiptLog();
  4204. Doo::loadModel("verify");
  4205. $verify=new verify();
  4206. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4207. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4208. $jd=json_decode($vr['staff']);$roleId=0;
  4209. foreach ($jd as $key=>$value){
  4210. if ($value[1]=='ROLE'){
  4211. $pos = strpos($value[3], $this->staff[0]['sid']);
  4212. if ($pos !== false) {
  4213. $roleId=$value[0];
  4214. }
  4215. }
  4216. }
  4217. //审批日志
  4218. //echo $roleId;die;
  4219. if (!empty($roleId)){
  4220. Doo::loadModel("role");
  4221. $role=new role();
  4222. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4223. $receiptLog->rolename=$roleInfo['name'];
  4224. }
  4225. $receiptLog->username=$this->staff[0]['username'];
  4226. $receiptLog->uid=$this->staff[0]['sid'];
  4227. $receiptLog->date=date("Y-m-d");
  4228. $receiptLog->opinion='提交审批';
  4229. $receiptLog->img=$this->staff[0]['avatar'];
  4230. $receiptLog->status=2;
  4231. $receiptLog->rid=$rid;
  4232. $receiptLog->insert();
  4233. //statistics item
  4234. $dateArray=explode("-", $receiptDetailList['date']);
  4235. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4236. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4237. //print_r($accountItem['cSum']['agencySum']);die;
  4238. // foreach ($accountItem['cSum'] as $key=>$value){
  4239. // if($key=="agencySum"){
  4240. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4241. // if(empty($iStatistics)){
  4242. // $itemStatistics->cid=$this->staff[0]['cid'];
  4243. // $itemStatistics->staff=$this->staff[0]['sid'];
  4244. // $itemStatistics->price=$value;
  4245. // $itemStatistics->itemCategory=$this->AGENCY;
  4246. // $itemStatistics->date=date("Y-m-d");
  4247. // $itemStatistics->insert();
  4248. // }else{
  4249. // if (!empty($value)){
  4250. // $itemStatistics->price=$value+$iStatistics['price'];
  4251. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4252. // }
  4253. // }
  4254. // }elseif($key=="travelSum"){
  4255. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4256. // if(empty($iStatistics)){
  4257. // $itemStatistics->cid=$this->staff[0]['cid'];
  4258. // $itemStatistics->staff=$this->staff[0]['sid'];
  4259. // $itemStatistics->price=$value;
  4260. // $itemStatistics->itemCategory=$this->TRAVEL;
  4261. // $itemStatistics->date=date("Y-m-d");
  4262. // $itemStatistics->insert();
  4263. // }else{
  4264. // if (!empty($value)){
  4265. // $itemStatistics->price=$value+$iStatistics['price'];
  4266. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4267. // }
  4268. // }
  4269. // }elseif($key=="trainSum"){
  4270. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4271. // if(empty($iStatistics)){
  4272. // $itemStatistics->cid=$this->staff[0]['cid'];
  4273. // $itemStatistics->staff=$this->staff[0]['sid'];
  4274. // $itemStatistics->price=$value;
  4275. // $itemStatistics->itemCategory=$this->TRAIN;
  4276. // $itemStatistics->date=date("Y-m-d");
  4277. // $itemStatistics->insert();
  4278. // }else{
  4279. // if (!empty($value)){
  4280. // $itemStatistics->price=$value+$iStatistics['price'];
  4281. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4282. // }
  4283. // }
  4284. // }elseif($key=="otherSum"){
  4285. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4286. // if(empty($iStatistics)){
  4287. // $itemStatistics->cid=$this->staff[0]['cid'];
  4288. // $itemStatistics->staff=$this->staff[0]['sid'];
  4289. // $itemStatistics->price=$value;
  4290. // $itemStatistics->itemCategory=$this->OTHER;
  4291. // $itemStatistics->date=date("Y-m-d");
  4292. // $itemStatistics->insert();
  4293. // }else{
  4294. // if (!empty($value)){
  4295. // $itemStatistics->price=$value+$iStatistics['price'];
  4296. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4297. // }
  4298. // }
  4299. // }
  4300. // }
  4301. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4302. if(empty($stat)){
  4303. $statistics->date=date("Y-m-d");
  4304. $statistics->cid=$this->staff[0]['cid'];
  4305. $statistics->staff=$this->staff[0]['sid'];
  4306. $statistics->agPrice=0;
  4307. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4308. $statistics->insert();
  4309. }else{
  4310. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4311. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4312. }
  4313. return "/expenses";
  4314. }
  4315. function approval(){
  4316. $status=isset($this->params['status'])?$this->params['status']:'';
  4317. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4318. $month=$this->get_args('month')?$this->get_args('month'):"";
  4319. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4320. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4321. if (empty($status))
  4322. $status=$this->get_args('status')?$this->get_args('status'):2;
  4323. $vidList=array();
  4324. $button=0;
  4325. Doo::loadModel('verify');
  4326. $verify=new verify();
  4327. Doo::loadModel('receipt');
  4328. $receipt=new receipt();
  4329. Doo::loadModel('staff');
  4330. $staff=new staff();
  4331. Doo::loadModel('L_category');
  4332. $Lcategory=new L_category();
  4333. //user verify ID
  4334. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4335. foreach ($verifyDetail as $key=>$value){
  4336. array_push($vidList, $value['vid']);
  4337. }
  4338. $vid=implode(",", $vidList);
  4339. if(empty($verifyDetail))
  4340. $vid=0;
  4341. /*
  4342. */
  4343. $dateCondition=" and Year(date) =".$year;
  4344. if(!empty($month))
  4345. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4346. $categoryList=$Lcategory->find(array('asArray'=>true));
  4347. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4348. $cateCondition="";$staffCondition="";$approvalCondition="";
  4349. if (!empty($cid))
  4350. $cateCondition=' and cid='.$cid;
  4351. if(!empty($sid)){
  4352. $staffCondition=' and staff='.$sid;
  4353. $cateCondition="";
  4354. }
  4355. // elseif($status==1){
  4356. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4357. // }
  4358. if($status==2){
  4359. //查找角色审批人
  4360. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4361. }
  4362. $ap="";
  4363. if($status==4){
  4364. $ap=4;$status=2;
  4365. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4366. }
  4367. if($status==5){
  4368. $status=4;$ap=5;
  4369. }
  4370. //echo $vid;
  4371. //get Receipt By verifyID status 2 .$approvalCondition
  4372. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4373. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4374. ,'desc'=>'rid','asArray'=>true));
  4375. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4376. $Locate=0;
  4377. if($ap==4)
  4378. $status=4;
  4379. elseif ($ap==5)
  4380. $status=5;
  4381. foreach ($receiptList as $key=>$value){
  4382. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4383. $receiptList[$key]['reviseDetail']=array();
  4384. if (!empty($value['reviseDetail']))
  4385. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4386. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4387. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4388. $receiptList[$key]['category']=$categoryDetil['title'];
  4389. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4390. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4391. $verifyStaff=json_decode($value['verifyStaff'],true);
  4392. foreach ($verifyList as $k=>$v){
  4393. //init verifyStaff
  4394. $verifyList[$k]['date']="";
  4395. $verifyList[$k]['opinion']="";
  4396. $verifyList[$k]['status']="";
  4397. if (empty($verifyStaff)){
  4398. $verifyList[$k]['date']="";
  4399. $verifyList[$k]['opinion']="";
  4400. if ($v[0]==$this->staff[0]['sid']){
  4401. $verifyList[$k]['status']=4;
  4402. $button=4;
  4403. }
  4404. }else{
  4405. $flag=true;
  4406. foreach ($verifyStaff as $m=>$u){
  4407. if ($v[0]==$m){
  4408. $verifyList[$k]['date']=$u['date'];
  4409. $verifyList[$k]['opinion']=$u['opinion'];
  4410. $verifyList[$k]['status']=$u['status'];
  4411. $flag=false;
  4412. break;
  4413. }
  4414. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4415. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4416. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4417. }
  4418. if($flag){//检测可编辑
  4419. if($v[0]==$this->staff[0]['sid']){
  4420. $verifyList[$k]['status']=4;$button=4;
  4421. }
  4422. }
  4423. }
  4424. }
  4425. $receiptList[$key]['verifyList']=$verifyList;
  4426. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4427. $receiptList[$key]['button']=$button;
  4428. }
  4429. //print_r($receiptList);die;
  4430. //$data['verifyDetail']=$verifyDetail;
  4431. $mothHtml="";
  4432. for($i=1;$i<=12;$i++){
  4433. if($month==$i)
  4434. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4435. else
  4436. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4437. }
  4438. $data['mothHtml']=$mothHtml;
  4439. $data['receiptList']=$receiptList;
  4440. $data['receiptApprovalCount']=count($receiptList);
  4441. $data['status']=$status;
  4442. $data['year']=$year;
  4443. $data['categoryList']=$categoryList;
  4444. $data['staffList']=$staffList;
  4445. $data['cid']=$cid;
  4446. $data['sid']=$sid;
  4447. $data['ap']=$ap;
  4448. $data['memu']="receipt";
  4449. $data['staff']=$this->staff;
  4450. $data['receiptMemu']='approval';
  4451. $data['verifyId']=$this->verifyId;
  4452. $data['executeId']=$this->executeId;
  4453. $this->render ( "/admin/saea_reportList", $data );
  4454. }
  4455. function approvalDetails(){
  4456. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4457. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4458. $month=$this->get_args('month')?$this->get_args('month'):"";
  4459. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4460. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4461. Doo::loadModel('verify');
  4462. $verify=new verify();
  4463. Doo::loadModel('receipt');
  4464. $receipt=new receipt();
  4465. Doo::loadModel('staff');
  4466. $staff=new staff();
  4467. Doo::loadModel('L_category');
  4468. $Lcategory=new L_category();
  4469. Doo::loadModel('enclosur');
  4470. $enclosur=new enclosur();
  4471. $vidList=array();
  4472. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4473. foreach ($verifyDetail as $key=>$value){
  4474. array_push($vidList, $value['vid']);
  4475. }
  4476. $vid=implode(",", $vidList);
  4477. if(empty($verifyDetail))
  4478. $vid=0;
  4479. $categoryList=$Lcategory->find(array('asArray'=>true));
  4480. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4481. $ap=0;
  4482. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4483. $Locate=0;$roleId=0;$button=0;
  4484. foreach ($receiptList as $key=>$value){
  4485. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4486. $receiptList[$key]['reviseDetail']=array();
  4487. if (!empty($value['reviseDetail']))
  4488. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4489. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4490. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4491. $receiptList[$key]['category']=$categoryDetil['title'];
  4492. //检测编辑状态
  4493. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4494. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4495. $verifyStaff=json_decode($value['verifyStaff'],true);
  4496. Doo::loadModel('role');
  4497. $role=new role();
  4498. //print_r($verifyList);
  4499. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4500. foreach ($verifyList as $k=>$v){
  4501. //init verifyStaff
  4502. if ($v[1]=='ROLE'){
  4503. if (!empty($verifyStaff)){
  4504. $endStaffArray=end($verifyStaff);
  4505. if ($v[0]==$endStaffArray['nextStaff']){
  4506. $roleId=$v[0];
  4507. }
  4508. }
  4509. $roleVerify=json_decode($v[3],true);
  4510. $roleKey=$k;$roleArray=array();
  4511. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4512. foreach ($roleVerify as $o=>$p){
  4513. $staffID=explode ('_',$p);
  4514. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4515. //print_r($staffID);
  4516. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4517. array_push($roleArray, $exp);
  4518. }
  4519. $roleArrayCopy[$v[0]]=$roleArray;
  4520. //$verifyList[$k]['roleArray']=$roleArray;
  4521. }
  4522. //print_r($roleArray);
  4523. $verifyList[$k]['date']="";
  4524. $verifyList[$k]['opinion']="";
  4525. $verifyList[$k]['status']="";
  4526. if (empty($verifyStaff)){
  4527. $verifyList[$k]['date']="";
  4528. $verifyList[$k]['opinion']="";
  4529. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4530. $verifyList[$k]['status']=4;
  4531. $button=4;$flag=false;
  4532. }
  4533. }else{
  4534. foreach ($verifyStaff as $m=>$u){
  4535. if ($v[0]==$m){
  4536. $verifyList[$k]['date']=$u['date'];
  4537. $verifyList[$k]['opinion']=$u['opinion'];
  4538. $verifyList[$k]['status']=$u['status'];
  4539. $flag=false;
  4540. break;
  4541. }
  4542. }
  4543. $endStaffArray=end($verifyStaff);
  4544. if (isset($endStaffArray['ROLE'])){
  4545. }else{
  4546. $endKey=key($verifyStaff);
  4547. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4548. $button=4;
  4549. $verifyList[$k]['status']=4;
  4550. }
  4551. }
  4552. }
  4553. }
  4554. $rolename['name']='';
  4555. if (!empty($roleId)){
  4556. Doo::loadModel('role');
  4557. $role=new role();
  4558. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4559. }
  4560. if (!empty($verifyStaff))
  4561. $endStaffArray=end($verifyStaff);
  4562. $KOP=false;
  4563. foreach ($roleArrayCopy as $P=>$A){
  4564. foreach ( $A as $MKI=>$AVL){
  4565. if (!empty($verifyStaff)){
  4566. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4567. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4568. $button=4;
  4569. $roleArrayCopy[$P][$MKI]['status']=4;
  4570. }
  4571. foreach ($verifyStaff as $m=>$u){
  4572. $AVLFK=$AVL[0].'_R';
  4573. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4574. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4575. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4576. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4577. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4578. break;
  4579. }
  4580. }
  4581. }else{
  4582. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4583. $button=4;
  4584. $roleArrayCopy[$P][$MKI]['status']=4;
  4585. }
  4586. }
  4587. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4588. $KOP=true;
  4589. }
  4590. }
  4591. foreach ($roleArrayCopy as $k=>$v){
  4592. foreach ($verifyList as $m=>$n){
  4593. if ($n[0]==$k){
  4594. array_splice($verifyList,$m,1,$v);
  4595. }
  4596. }
  4597. }
  4598. $receiptList[$key]['verifyList']=$verifyList;
  4599. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4600. $receiptList[$key]['button']=$button;
  4601. }
  4602. $mothHtml="";
  4603. for($i=1;$i<=12;$i++){
  4604. if($month==$i)
  4605. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4606. else
  4607. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4608. }
  4609. //获取审批日志
  4610. Doo::loadModel('receiptLog');
  4611. $receiptLog=new receiptLog();
  4612. $rlList=array();
  4613. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4614. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4615. if (!empty($rlInfo)){
  4616. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4617. }
  4618. $receiptList[0]['rlList']=$rlList;
  4619. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4620. $enclosurHtml='';
  4621. foreach ($enclosurList as $value){
  4622. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4623. }
  4624. $data['enclosurHtml']=$enclosurHtml;
  4625. $data['rolename']=$rolename['name'];
  4626. $data['datetij']=$tijdate['date'];
  4627. $data['mothHtml']=$mothHtml;
  4628. $data['receiptList']=$receiptList;
  4629. $data['receiptApprovalCount']=count($receiptList);
  4630. $data['year']=$year;
  4631. $data['categoryList']=$categoryList;
  4632. $data['staffList']=$staffList;
  4633. $data['cid']=$cid;
  4634. $data['sid']=$sid;
  4635. $data['status']=0;
  4636. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4637. $ap=4;
  4638. }else
  4639. $data['status']=$receiptList[0]['status'];
  4640. if ($receiptList[0]['status']==4){
  4641. $data['status']=5;
  4642. $ap=0;
  4643. }
  4644. $data['ap']=$ap;
  4645. $data['memu']="receipt";
  4646. $data['staff']=$this->staff;
  4647. $data['receiptMemu']='approval';
  4648. $data['verifyId']=$this->verifyId;
  4649. $data['executeId']=$this->executeId;
  4650. $this->render ( "/admin/saeaReportListReport", $data );
  4651. }
  4652. function approvalEdi(){
  4653. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4654. $status=isset($this->params['status'])?$this->params['status']:'';
  4655. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4656. $month=$this->get_args('month')?$this->get_args('month'):"";
  4657. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4658. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4659. if (empty($status))
  4660. $status=$this->get_args('status')?$this->get_args('status'):2;
  4661. $vidList=array();
  4662. $button=0;
  4663. Doo::loadModel('verify');
  4664. Doo::loadModel('receipt');
  4665. Doo::loadModel('staff');
  4666. $staff=new staff();
  4667. $receipt=new receipt();
  4668. $verify=new verify();
  4669. Doo::loadModel('L_category');
  4670. $Lcategory=new L_category();
  4671. Doo::loadModel('enclosur');
  4672. $enclosur=new enclosur();
  4673. //user verify ID
  4674. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4675. foreach ($verifyDetail as $key=>$value){
  4676. array_push($vidList, $value['vid']);
  4677. }
  4678. $vid=implode(",", $vidList);
  4679. if(empty($verifyDetail))
  4680. $vid=0;
  4681. $categoryList=$Lcategory->find(array('asArray'=>true));
  4682. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4683. $ap="";
  4684. if($status==4){
  4685. $ap=4;$status=2;
  4686. }
  4687. //get Receipt By verifyID status 2
  4688. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4689. $Locate=0;$roleId=0;
  4690. if($ap==4)
  4691. $status=4;
  4692. foreach ($receiptList as $key=>$value){
  4693. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4694. $receiptList[$key]['reviseDetail']=array();
  4695. if (!empty($value['reviseDetail']))
  4696. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4697. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4698. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4699. $receiptList[$key]['category']=$categoryDetil['title'];
  4700. //检测编辑状态
  4701. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4702. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4703. $verifyStaff=json_decode($value['verifyStaff'],true);
  4704. // print_r($verifyList);
  4705. //
  4706. // if (empty($verifyStaff)){
  4707. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4708. // $verifyList[0]['status']=4;$button=4;
  4709. // }
  4710. //
  4711. // }else{
  4712. //
  4713. // }
  4714. // die;
  4715. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4716. // echo array_search("green",$a);
  4717. //
  4718. Doo::loadModel('role');
  4719. $role=new role();
  4720. //print_r($verifyList);
  4721. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4722. foreach ($verifyList as $k=>$v){
  4723. //init verifyStaff
  4724. if ($v[1]=='ROLE'){
  4725. if (!empty($verifyStaff)){
  4726. $endStaffArray=end($verifyStaff);
  4727. if ($v[0]==$endStaffArray['nextStaff']){
  4728. $roleId=$v[0];
  4729. }
  4730. }
  4731. $roleVerify=json_decode($v[3],true);
  4732. $roleKey=$k;$roleArray=array();
  4733. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4734. foreach ($roleVerify as $o=>$p){
  4735. $staffID=explode ('_',$p);
  4736. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4737. //print_r($staffID);
  4738. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4739. array_push($roleArray, $exp);
  4740. }
  4741. $roleArrayCopy[$v[0]]=$roleArray;
  4742. //$verifyList[$k]['roleArray']=$roleArray;
  4743. }
  4744. //print_r($roleArray);
  4745. $verifyList[$k]['date']="";
  4746. $verifyList[$k]['opinion']="";
  4747. $verifyList[$k]['status']="";
  4748. if (empty($verifyStaff)){
  4749. $verifyList[$k]['date']="";
  4750. $verifyList[$k]['opinion']="";
  4751. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4752. $verifyList[$k]['status']=4;
  4753. $button=4;$flag=false;
  4754. }
  4755. }else{
  4756. foreach ($verifyStaff as $m=>$u){
  4757. if ($v[0]==$m){
  4758. $verifyList[$k]['date']=$u['date'];
  4759. $verifyList[$k]['opinion']=$u['opinion'];
  4760. $verifyList[$k]['status']=$u['status'];
  4761. $flag=false;
  4762. break;
  4763. }
  4764. }
  4765. $endStaffArray=end($verifyStaff);
  4766. if (isset($endStaffArray['ROLE'])){
  4767. }else{
  4768. $endKey=key($verifyStaff);
  4769. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4770. $button=4;
  4771. $verifyList[$k]['status']=4;
  4772. }
  4773. }
  4774. //print_r($endStaffArray);die;
  4775. // if (empty($verifyStaff)){
  4776. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4777. // $verifyList[$k]['status']=4;$button=4;
  4778. // }
  4779. //
  4780. // }else{
  4781. //
  4782. // }
  4783. // if($flag){//检测可编辑
  4784. // if($v[0]==$this->staff[0]['sid']){
  4785. // $verifyList[$k]['status']=4;$button=4;
  4786. // }
  4787. // }
  4788. }
  4789. }
  4790. $rolename['name']='';
  4791. if (!empty($roleId)){
  4792. Doo::loadModel('role');
  4793. $role=new role();
  4794. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4795. }
  4796. if (!empty($verifyStaff))
  4797. $endStaffArray=end($verifyStaff);
  4798. $KOP=false;
  4799. foreach ($roleArrayCopy as $P=>$A){
  4800. foreach ( $A as $MKI=>$AVL){
  4801. if (!empty($verifyStaff)){
  4802. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4803. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4804. $button=4;
  4805. $roleArrayCopy[$P][$MKI]['status']=4;
  4806. }
  4807. foreach ($verifyStaff as $m=>$u){
  4808. $AVLFK=$AVL[0].'_R';
  4809. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4810. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4811. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4812. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4813. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4814. break;
  4815. }
  4816. }
  4817. }else{
  4818. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4819. $button=4;
  4820. $roleArrayCopy[$P][$MKI]['status']=4;
  4821. }
  4822. }
  4823. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4824. $KOP=true;
  4825. }
  4826. }
  4827. // print_r($roleArrayCopy);
  4828. // echo $roleKey;
  4829. foreach ($roleArrayCopy as $k=>$v){
  4830. foreach ($verifyList as $m=>$n){
  4831. if ($n[0]==$k){
  4832. array_splice($verifyList,$m,1,$v);
  4833. }
  4834. }
  4835. }
  4836. // if ($KOP)
  4837. // array_splice($verifyList,$roleKey,1,$roleArray);
  4838. //print_r($verifyList);
  4839. $receiptList[$key]['verifyList']=$verifyList;
  4840. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4841. $receiptList[$key]['button']=$button;
  4842. }
  4843. //$data['verifyDetail']=$verifyDetail;
  4844. $mothHtml="";
  4845. for($i=1;$i<=12;$i++){
  4846. if($month==$i)
  4847. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4848. else
  4849. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4850. }
  4851. //获取审批日志
  4852. Doo::loadModel('receiptLog');
  4853. $receiptLog=new receiptLog();
  4854. $rlList=array();
  4855. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4856. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4857. if (!empty($rlInfo)){
  4858. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4859. }
  4860. $receiptList[0]['rlList']=$rlList;
  4861. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4862. $enclosurHtml='';
  4863. foreach ($enclosurList as $value){
  4864. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4865. }
  4866. $data['enclosurHtml']=$enclosurHtml;
  4867. $data['rolename']=$rolename['name'];
  4868. $data['datetij']=$tijdate['date'];
  4869. $data['mothHtml']=$mothHtml;
  4870. $data['receiptList']=$receiptList;
  4871. $data['receiptApprovalCount']=count($receiptList);
  4872. $data['status']=$status;
  4873. $data['year']=$year;
  4874. $data['categoryList']=$categoryList;
  4875. $data['staffList']=$staffList;
  4876. $data['cid']=$cid;
  4877. $data['sid']=$sid;
  4878. $data['ap']=$ap;
  4879. $data['memu']="receipt";
  4880. $data['staff']=$this->staff;
  4881. $data['receiptMemu']='approval';
  4882. $data['verifyId']=$this->verifyId;
  4883. $data['executeId']=$this->executeId;
  4884. $this->render ( "/admin/saeaReportListReport", $data );
  4885. }
  4886. function remittance(){
  4887. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4888. $month=$this->get_args('month')?$this->get_args('month'):"";
  4889. Doo::loadModel('receipt');
  4890. $receipt=new receipt();
  4891. Doo::loadModel('staff');
  4892. $staff=new staff();
  4893. $dateCondition=" and Year(pastDate) =".$year;
  4894. if(!empty($month))
  4895. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4896. //get Receipt By verifyID status 1
  4897. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4898. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4899. $dataList=array();
  4900. foreach ($dateList as $d=>$a){
  4901. $dataList[$a['pastDate']]=array();$daySum=0;
  4902. foreach ($receiptList as $key=>$value){
  4903. if($a['pastDate']==$value['pastDate']){
  4904. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4905. $list=array();$html="";
  4906. foreach ($oderList as $v){
  4907. array_push($list, $v['receiptOrder']);
  4908. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4909. }
  4910. $receiptList[$key]['receiptOrder']=$html;
  4911. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4912. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4913. $receiptList[$key]['username']=$sinfo['username'];
  4914. $daySum+=$value['sum'];
  4915. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4916. }
  4917. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4918. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4919. }
  4920. }
  4921. //print_r($dataList);
  4922. $data['dataList']=$dataList;
  4923. $mothHtml="";
  4924. for($i=1;$i<=12;$i++){
  4925. if($month==$i)
  4926. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4927. else
  4928. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4929. }
  4930. $data['year']=$year;
  4931. $data['mothHtml']=$mothHtml;
  4932. $data['memu']="receipt";
  4933. $data['staff']=$this->staff;
  4934. $data['receiptMemu']='approval';
  4935. $data['verifyId']=$this->verifyId;
  4936. $data['executeId']=$this->executeId;
  4937. $this->render ( "/admin/saeaReportListPay", $data );
  4938. }
  4939. function revocationAdjustment(){
  4940. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  4941. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  4942. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4943. //echo $price;die;
  4944. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  4945. Doo::loadModel('receipt');
  4946. $receipt=new receipt();
  4947. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4948. if (empty($receiptDetail['reviseDetail']))
  4949. return "/approval";
  4950. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  4951. $RD=array();
  4952. foreach ($reviseDetail as $key=>$value){
  4953. if ($value['price']==$price&&$value['sid']==$sid)
  4954. continue;
  4955. array_push($RD, $value);
  4956. }
  4957. $reviseDetailString=json_encode($RD);
  4958. $receipt->reviseDetail=$reviseDetailString;
  4959. $receipt->sum=$receiptDetail['sum']-$price;
  4960. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  4961. $receipt->update(array('where'=>'rid='.$rid));
  4962. }
  4963. //approvalEdi/37
  4964. return "/approvalEdi/".$rid;
  4965. }
  4966. function updateApprovalReceipt(){
  4967. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  4968. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  4969. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4970. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  4971. if(!empty($rid)){
  4972. Doo::loadModel("verify");
  4973. $verify=new verify();
  4974. Doo::loadModel("receiptDetail");
  4975. $receiptDetailObj=new receiptDetail();
  4976. Doo::loadModel("itemStatistics");
  4977. Doo::loadModel("statistics");
  4978. $statistics=new statistics();
  4979. $itemStatistics=new itemStatistics();
  4980. Doo::loadModel("receipt");
  4981. $receipt=new receipt();
  4982. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  4983. if (empty($receiptDetail))
  4984. return "/approval";
  4985. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  4986. $verifyString=$verifyDetail['staff'];
  4987. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4988. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  4989. if(empty($opinion)){
  4990. if ($status==3)
  4991. $opinion="终止";
  4992. else
  4993. $opinion="同意支付";
  4994. }
  4995. $nowStaff=0;$nowStaffList=array();
  4996. if(empty($verifyStaff)){
  4997. //还需加入是否已经进入角色审批
  4998. if ($verifyDetail[0][1]=='ROLE'){
  4999. //print_r($verifyDetail);echo "ddd";
  5000. $vStaffString=json_decode($verifyDetail[0][3]);
  5001. foreach ($vStaffString as $key=>$value){
  5002. $staffK=explode("_", $value);
  5003. if ($staffK[0]!=$this->staff[0]['sid'])
  5004. array_push($nowStaffList, $staffK[0]);
  5005. }
  5006. //print_r($verifyDetail);
  5007. //die;
  5008. $nowStaff=implode(',', $nowStaffList);
  5009. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5010. }else{
  5011. if ($verifyDetail[1][1]=='ROLE'){
  5012. $vStaffString=json_decode($verifyDetail[1][3]);
  5013. //echo "dd";
  5014. foreach ($vStaffString as $key=>$value){
  5015. $staffK=explode("_", $value);
  5016. array_push($nowStaffList, $staffK[0]);
  5017. }
  5018. $nowStaff=implode(',', $nowStaffList);
  5019. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5020. }else{
  5021. $nowStaff=$verifyDetail[1][0];
  5022. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5023. }
  5024. }
  5025. if($status==3)
  5026. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5027. $vStaffString=json_encode($verifyStaff);
  5028. $receipt->nowStaff=$nowStaff;
  5029. $receipt->verifyStaff=$vStaffString;
  5030. }else{
  5031. $VS=end($verifyStaff);
  5032. //非角色审批
  5033. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5034. $nextStaff=0;$roleSTF=false;
  5035. foreach ($verifyDetail as $key=>$value){
  5036. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5037. if (isset($verifyDetail[$key+1])){
  5038. $nextStaff=$verifyDetail[$key+1][0];
  5039. if ($verifyDetail[$key+1][1]=='ROLE')
  5040. $roleSTF=true;
  5041. }
  5042. break;
  5043. }
  5044. }
  5045. if (!$roleSTF){
  5046. $nowStaff=$nextStaff;
  5047. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5048. }else{
  5049. //获取角色下的所有用户ID
  5050. $nowStaffList=array();
  5051. foreach ($verifyDetail as $vfk){
  5052. if ($vfk[1]=='ROLE'){
  5053. $vStaffString=json_decode($vfk[3]);
  5054. foreach ($vStaffString as $key=>$value){
  5055. $staffK=explode("_", $value);
  5056. array_push($nowStaffList, $staffK[0]);
  5057. }
  5058. }
  5059. }
  5060. $nowStaff=implode(',', $nowStaffList);
  5061. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5062. }
  5063. if($status==3){
  5064. $verifyStaff['final']=$status;
  5065. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5066. }
  5067. $vStaffString=json_encode($verifyStaff);
  5068. $receipt->nowStaff=$nowStaff;
  5069. $receipt->verifyStaff=$vStaffString;
  5070. }
  5071. //角色审批
  5072. if (isset($VS['ROLE'])){
  5073. //找出角色人 当前审批角色组
  5074. $verifyJSStaff=array();$nowStaffList2=array();
  5075. foreach ($verifyDetail as $key=>$value){
  5076. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5077. $verifyJSStaff=json_decode($value[3]);
  5078. foreach ($verifyJSStaff as $m){
  5079. $staffK=explode("_", $m);
  5080. array_push($nowStaffList2, $staffK[0]);
  5081. }
  5082. // print_r($nowStaffList2);
  5083. }
  5084. }
  5085. $RoleVerifyStaff=array();
  5086. foreach ($verifyStaff as $key=>$value){
  5087. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5088. foreach ($nowStaffList2 as $m) {
  5089. if ($key==$m."_R")
  5090. $RoleVerifyStaff[$key]=$value;
  5091. }
  5092. }
  5093. }
  5094. // print_r($verifyStaff);
  5095. // print_r($nowStaffList2);
  5096. // print_r($RoleVerifyStaff);
  5097. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5098. //print_r($verifyJSStaff);
  5099. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5100. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5101. //下一个审批人ID
  5102. $nextStaff=0;$falg=false;
  5103. foreach ($verifyDetail as $key=>$value){
  5104. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5105. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5106. $falg=true;
  5107. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5108. foreach ($vStaffString as $v){
  5109. $staffK=explode("_", $v);
  5110. array_push($nowStaffList, $staffK[0]);
  5111. }
  5112. $nowStaff=implode(',', $nowStaffList);
  5113. $nextStaff=$verifyDetail[$key+1][0];
  5114. }elseif(isset($verifyDetail[$key+1])){
  5115. $nextStaff=$verifyDetail[$key+1][0];
  5116. $nowStaff=$nextStaff;
  5117. }else
  5118. $nowStaff='';
  5119. break;
  5120. }
  5121. }
  5122. if ($falg)
  5123. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5124. else
  5125. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5126. // print_r($verifyStaff);
  5127. // echo $nowStaff;die;
  5128. }else{ //进入下一个角色或者审批人
  5129. /*
  5130. */
  5131. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5132. //
  5133. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5134. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5135. // print_r($verifyStaff);
  5136. // die;
  5137. }
  5138. if($status==3){
  5139. $verifyStaff['final']=$status;
  5140. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5141. }
  5142. $vStaffString=json_encode($verifyStaff);
  5143. $receipt->verifyStaff=$vStaffString;
  5144. $receipt->nowStaff=$nowStaff;
  5145. //die;
  5146. //}
  5147. // print_r($verifyStaff);
  5148. // die;
  5149. }
  5150. //print_r($verifyStaff);die;
  5151. }
  5152. //print_r($verifyDetail);
  5153. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5154. foreach ($verifyDetail as $k=>$v){
  5155. if ($v[1]=='ROLE'){
  5156. $roleId=$v[0];
  5157. $roleVerify=json_decode($v[3],true);
  5158. $roleKey=$k;$roleArray=array();
  5159. foreach ($roleVerify as $o=>$p){
  5160. $staffID=explode ('_',$p);
  5161. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5162. array_push($roleArray, $exp);
  5163. }
  5164. $verifyDetailCopy[$v[0]]=$roleArray;
  5165. }
  5166. }
  5167. //print_r($verifyDetail);
  5168. foreach ($verifyDetailCopy as $k=>$v){
  5169. foreach ($verifyDetail as $m=>$n){
  5170. if ($n[0]==$k){
  5171. array_splice($verifyDetail,$m,1,$v);
  5172. }
  5173. }
  5174. }
  5175. // die;
  5176. // if (!empty($roleArray))
  5177. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5178. // echo $roleId;
  5179. // print_r($verifyStaff);
  5180. // print_r($verifyDetail);
  5181. // die;
  5182. Doo::loadModel("receiptLog");
  5183. $receiptLog=new receiptLog();
  5184. //审批日志
  5185. if (!isset($verifyStaff['final'])){
  5186. if (!empty($roleId)){
  5187. Doo::loadModel("role");
  5188. $role=new role();
  5189. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5190. $receiptLog->rolename=$roleInfo['name'];
  5191. }
  5192. $receiptLog->username=$this->staff[0]['username'];
  5193. $receiptLog->uid=$this->staff[0]['sid'];
  5194. $receiptLog->date=date("Y-m-d");
  5195. $receiptLog->opinion=$opinion;
  5196. $receiptLog->img=$this->staff[0]['avatar'];
  5197. $receiptLog->status=1;
  5198. $receiptLog->rid=$rid;
  5199. $receiptLog->insert();
  5200. }
  5201. if (isset($verifyStaff['final'])){//rDetail
  5202. $receipt->verifyBreakup=$verifyString;
  5203. $receipt->status=3;
  5204. $receiptDetailObj->status=3;
  5205. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5206. if (!empty($roleId)){
  5207. Doo::loadModel("role");
  5208. $role=new role();
  5209. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5210. $receiptLog->rolename=$roleInfo['name'];
  5211. }
  5212. $receiptLog->username=$this->staff[0]['username'];
  5213. $receiptLog->uid=$this->staff[0]['sid'];
  5214. $receiptLog->date=date("Y-m-d");
  5215. $receiptLog->opinion=$opinion;
  5216. $receiptLog->img=$this->staff[0]['avatar'];
  5217. $receiptLog->status=3;
  5218. $receiptLog->rid=$rid;
  5219. $receiptLog->insert();
  5220. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5221. $receipt->status=1;$reviseSum=0;
  5222. $receipt->verifyBreakup=$verifyString;
  5223. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5224. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5225. foreach ($reviseDetail as $key=>$value){
  5226. $receiptDetailObj=new receiptDetail();
  5227. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5228. $receiptDetailObj->item=$value['description'];
  5229. $receiptDetailObj->itemCategory="报销金额调整";
  5230. $receiptDetailObj->price=$value['price'];
  5231. $receiptDetailObj->date=$receiptDetail['date'];
  5232. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5233. $receiptDetailObj->rid=$rid;
  5234. $receiptDetailObj->status=1;
  5235. $receiptDetailObj->insert();
  5236. $reviseSum+=$value['price'];
  5237. }
  5238. $itemStatistics=new itemStatistics();
  5239. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5240. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5241. $itemStatistics->price=$reviseSum;
  5242. $itemStatistics->itemCategory="报销金额调整";
  5243. $itemStatistics->date=$receiptDetail['date'];
  5244. $itemStatistics->insert();
  5245. }
  5246. $receiptDetailObj=new receiptDetail();
  5247. $receiptDetailObj->status=1;
  5248. $receiptDetailObj->pastDate=date("Y-m-d");
  5249. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5250. $dateArray=explode("-", $receiptDetail['date']);
  5251. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5252. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5253. if(empty($stat)){
  5254. $statistics->date=$receiptDetail['date'];
  5255. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5256. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5257. $statistics->agPrice=$receiptDetail['sum'];
  5258. $statistics->rePrice=$reviseSum;
  5259. $statistics->insert();
  5260. }else{
  5261. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5262. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5263. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5264. }
  5265. $dateArray=explode("-", $receiptDetail['date']);
  5266. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5267. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5268. foreach ($accountItem['cSum'] as $key=>$value){
  5269. if($key=="agencySum"){
  5270. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5271. if(empty($iStatistics)){
  5272. $itemStatistics->cid=$receiptDetail['cid'];;
  5273. $itemStatistics->staff=$receiptDetail['staff'];
  5274. $itemStatistics->price=$value;
  5275. $itemStatistics->itemCategory=$this->AGENCY;
  5276. $itemStatistics->date=$receiptDetail['date'];
  5277. $itemStatistics->insert();
  5278. }else{
  5279. if (!empty($value)){
  5280. $itemStatistics->price=$value+$iStatistics['price'];
  5281. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5282. }
  5283. }
  5284. }elseif($key=="travelSum"){
  5285. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5286. if(empty($iStatistics)){
  5287. $itemStatistics->cid=$receiptDetail['cid'];
  5288. $itemStatistics->staff=$receiptDetail['staff'];
  5289. $itemStatistics->price=$value;
  5290. $itemStatistics->itemCategory=$this->TRAVEL;
  5291. $itemStatistics->date=$receiptDetail['date'];
  5292. $itemStatistics->insert();
  5293. }else{
  5294. if (!empty($value)){
  5295. $itemStatistics->price=$value+$iStatistics['price'];
  5296. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5297. }
  5298. }
  5299. }elseif($key=="trainSum"){
  5300. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5301. if(empty($iStatistics)){
  5302. $itemStatistics->cid=$receiptDetail['cid'];
  5303. $itemStatistics->staff=$receiptDetail['staff'];
  5304. $itemStatistics->price=$value;
  5305. $itemStatistics->itemCategory=$this->TRAIN;
  5306. $itemStatistics->date=$receiptDetail['date'];
  5307. $itemStatistics->insert();
  5308. }else{
  5309. if (!empty($value)){
  5310. $itemStatistics->price=$value+$iStatistics['price'];
  5311. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5312. }
  5313. }
  5314. }elseif($key=="otherSum"){
  5315. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5316. if(empty($iStatistics)){
  5317. $itemStatistics->cid=$receiptDetail['cid'];
  5318. $itemStatistics->staff=$receiptDetail['staff'];
  5319. $itemStatistics->price=$value;
  5320. $itemStatistics->itemCategory=$this->OTHER;
  5321. $itemStatistics->date=$receiptDetail['date'];
  5322. $itemStatistics->insert();
  5323. }else{
  5324. if (!empty($value)){
  5325. $itemStatistics->price=$value+$iStatistics['price'];
  5326. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5327. }
  5328. }
  5329. }
  5330. }
  5331. $receipt->pastDate=date("Y-m-d");
  5332. }
  5333. $receipt->update(array('where'=>' rid = '.$rid));
  5334. return "/approvalExpenses/2";
  5335. }
  5336. }
  5337. function expensesRetreats(){
  5338. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5339. if (!empty($rid)){
  5340. //操作记录
  5341. Doo::loadModel("receipt");
  5342. $receipt=new receipt();
  5343. Doo::loadModel("receiptLog");
  5344. $receiptLog=new receiptLog();
  5345. Doo::loadModel("verify");
  5346. $verify=new verify();
  5347. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5348. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5349. $jd=json_decode($vr['staff']);$roleId=0;
  5350. foreach ($jd as $key=>$value){
  5351. if ($value[1]=='ROLE'){
  5352. $pos = strpos($value[3], $this->staff[0]['sid']);
  5353. if ($pos !== false) {
  5354. $roleId=$value[0];
  5355. }
  5356. }
  5357. }
  5358. //审批日志
  5359. //echo $roleId;die;
  5360. if (!empty($roleId)){
  5361. Doo::loadModel("role");
  5362. $role=new role();
  5363. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5364. $receiptLog->rolename=$roleInfo['name'];
  5365. }
  5366. $receiptLog->username=$this->staff[0]['username'];
  5367. $receiptLog->uid=$this->staff[0]['sid'];
  5368. $receiptLog->date=date("Y-m-d");
  5369. $receiptLog->opinion='撤回';
  5370. $receiptLog->img=$this->staff[0]['avatar'];
  5371. $receiptLog->status=4;
  5372. $receiptLog->rid=$rid;
  5373. $receiptLog->insert();
  5374. $receipt->status=4;
  5375. $receipt->update(array('where'=>'rid='.$rid));
  5376. }
  5377. //echo "ddd";
  5378. return '/approvalExpenses';
  5379. }
  5380. function updateCheReceipt(){
  5381. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5382. if (!empty($rid)){
  5383. //操作记录
  5384. Doo::loadModel("receipt");
  5385. $receipt=new receipt();
  5386. Doo::loadModel("receiptLog");
  5387. $receiptLog=new receiptLog();
  5388. Doo::loadModel("verify");
  5389. $verify=new verify();
  5390. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5391. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5392. $jd=json_decode($vr['staff']);$roleId=0;
  5393. foreach ($jd as $key=>$value){
  5394. if ($value[1]=='ROLE'){
  5395. $pos = strpos($value[3], $this->staff[0]['sid']);
  5396. if ($pos !== false) {
  5397. $roleId=$value[0];
  5398. }
  5399. }
  5400. }
  5401. //审批日志
  5402. //echo $roleId;die;
  5403. if (!empty($roleId)){
  5404. Doo::loadModel("role");
  5405. $role=new role();
  5406. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5407. $receiptLog->rolename=$roleInfo['name'];
  5408. }
  5409. $receiptLog->username=$this->staff[0]['username'];
  5410. $receiptLog->uid=$this->staff[0]['sid'];
  5411. $receiptLog->date=date("Y-m-d");
  5412. $receiptLog->opinion='撤回';
  5413. $receiptLog->img=$this->staff[0]['avatar'];
  5414. $receiptLog->status=4;
  5415. $receiptLog->rid=$rid;
  5416. $receiptLog->insert();
  5417. $receipt->status=4;
  5418. $receipt->update(array('where'=>'rid='.$rid));
  5419. }
  5420. //echo "ddd";
  5421. return '/saeaBorad';
  5422. }
  5423. function revisePrice(){
  5424. $description=$this->get_args('description')?$this->get_args('description'):"";
  5425. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5426. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5427. //echo $price;die;
  5428. if (!empty($rid)){
  5429. Doo::loadModel("receipt");
  5430. $receipt=new receipt();
  5431. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5432. if (empty($receiptDetail))
  5433. return "/approval";
  5434. $reviseDetail=array();
  5435. if (empty($receiptDetail['reviseDetail'])){
  5436. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5437. $reviseDetailString=json_encode($reviseDetail);
  5438. $receipt->reviseDetail=$reviseDetailString;
  5439. $receipt->revisePrice=$price;
  5440. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5441. }else{
  5442. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5443. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5444. $reviseDetailString=json_encode($reviseDetail);
  5445. $receipt->reviseDetail=$reviseDetailString;
  5446. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5447. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5448. }
  5449. $receipt->update(array('where'=>'rid='.$rid));
  5450. }
  5451. return '/approvalEdi/'.$rid;
  5452. }
  5453. function personalCollect(){
  5454. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5455. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5456. $this->showCache($path);
  5457. Doo::loadModel("receiptDetail");
  5458. Doo::loadModel("itemStatistics");
  5459. Doo::loadModel('statistics');
  5460. $statistics=new statistics();
  5461. $itemStatistics=new itemStatistics();
  5462. $receiptDetail=new receiptDetail();
  5463. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5464. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5465. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5466. //create collect html
  5467. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5468. $adjustment=array();
  5469. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5470. array_push($collectArray['日常相关费用'], $collectHtml);
  5471. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5472. array_push($collectArray['差旅相关费用'], $collectHtml);
  5473. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5474. array_push($collectArray['培训班费用'], $collectHtml);
  5475. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5476. array_push($collectArray['其他'], $collectHtml);
  5477. $data['collectArray']=$collectArray;
  5478. //statistics html
  5479. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5480. if(empty($stList))
  5481. $stList=array('rePrice'=>0,'agPrice'=>0);
  5482. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5483. //Adjustment price html
  5484. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5485. array_push($adjustment, $collectHtml);
  5486. $data['adjustment']=$adjustment;
  5487. //total price html
  5488. $collectHtml="";$total=0;
  5489. for ($i=1;$i<=12;$i++){
  5490. $sumPrice=0;
  5491. foreach ($receiptCollectList as $key=>$value){
  5492. if($value['month']==$i){
  5493. $sumPrice+=$value['price'];
  5494. }
  5495. }
  5496. if ($sumPrice==0)
  5497. $collectHtml.='<td class="taR">-</td>';
  5498. else
  5499. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5500. $total+=$sumPrice;
  5501. }
  5502. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5503. $data['totalPrice']=$collectHtml;
  5504. $data['year']=$year;
  5505. $data['totalYear']=$total;
  5506. $data['memu']="receipt";
  5507. $data['staff']=$this->staff;
  5508. $data['receiptMemu']='personalCollect';
  5509. $data['verifyId']=$this->verifyId;
  5510. $data['executeId']=$this->executeId;
  5511. //year staff status 2,4
  5512. if($year<date("Y")){
  5513. Doo::loadModel('receipt');
  5514. $receipt=new receipt();
  5515. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5516. if(empty($receiptList)){
  5517. ob_start();
  5518. $this->render ( "/admin/saea_slist_collect", $data );
  5519. $this->cacheFile($path);die;
  5520. }
  5521. }
  5522. $this->render ( "/admin/saea_slist_collect", $data );
  5523. }
  5524. function personalCollectDetail(){
  5525. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5526. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5527. $this->showCache($path);
  5528. Doo::loadModel("receiptDetail");
  5529. Doo::loadModel("itemStatistics");
  5530. Doo::loadModel('statistics');
  5531. Doo::loadModel('accountItem');
  5532. $accountItem=new accountItem();
  5533. $statistics=new statistics();
  5534. $itemStatistics=new itemStatistics();
  5535. $receiptDetail=new receiptDetail();
  5536. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5537. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5538. $accountList=$accountItem->find(array('asArray'=>true));
  5539. //create CollectDetail HTML
  5540. $collectHtml=array();
  5541. foreach ($accountList as $key=>$value){
  5542. $html="";$asum=0;
  5543. for ($i=1;$i<=12;$i++){
  5544. $falg=true;
  5545. foreach ($receiptCollectList as $v) {
  5546. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5547. $asum+=$v['price'];
  5548. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5549. }
  5550. }
  5551. if($falg)
  5552. $html.='<td class="taR">-</td>';
  5553. }
  5554. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5555. $collectHtml[$value['category']][$value['name']]=$html;
  5556. }
  5557. $data['collectHtml']=$collectHtml;
  5558. //create Adjustment price html
  5559. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5560. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5561. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5562. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5563. array_push($collectArray['日常相关费用'], $collectHtml);
  5564. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5565. array_push($collectArray['差旅相关费用'], $collectHtml);
  5566. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5567. array_push($collectArray['培训班费用'], $collectHtml);
  5568. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5569. array_push($collectArray['其他'], $collectHtml);
  5570. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5571. array_push($adjustment, $collectHtml);
  5572. //total price html
  5573. $collectHtml="";$total=0;
  5574. for ($i=1;$i<=12;$i++){
  5575. $sumPrice=0;
  5576. foreach ($receiptCollectList as $key=>$value){
  5577. if($value['month']==$i){
  5578. $sumPrice+=$value['price'];
  5579. }
  5580. }
  5581. if ($sumPrice==0)
  5582. $collectHtml.='<td class="taR">-</td>';
  5583. else
  5584. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5585. $total+=$sumPrice;
  5586. }
  5587. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5588. //statistics html
  5589. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5590. if(empty($stList))
  5591. $stList=array('rePrice'=>0,'agPrice'=>0);
  5592. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5593. $data['collectArray']=$collectArray;
  5594. $data['adjustment']=$adjustment;
  5595. $data['totalPrice']=$collectHtml;
  5596. $data['totalYear']=$total;
  5597. $data['year']=$year;
  5598. $data['memu']="receipt";
  5599. $data['staff']=$this->staff;
  5600. $data['receiptMemu']='personalCollect';
  5601. $data['verifyId']=$this->verifyId;
  5602. $data['executeId']=$this->executeId;
  5603. //year staff status 2,4
  5604. if($year<date("Y")){
  5605. Doo::loadModel('receipt');
  5606. $receipt=new receipt();
  5607. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5608. if(empty($receiptList)){
  5609. ob_start();
  5610. $this->render ( "/admin/saeaCollectArticles", $data );
  5611. $this->cacheFile($path);die;
  5612. }
  5613. }
  5614. $this->render ( "/admin/saeaCollectArticles", $data );
  5615. }
  5616. function companyCategoryCollect(){
  5617. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5618. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5619. $this->showCache($path);
  5620. Doo::loadModel('L_category');
  5621. Doo::loadModel('itemStatistics');
  5622. Doo::loadModel('statistics');
  5623. $statistics=new statistics();
  5624. $Lcategory=new L_category();
  5625. $itemStatistics=new itemStatistics();
  5626. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5627. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5628. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5629. //ceatre companyCollectHtml
  5630. foreach ($LcategoryList as $value){
  5631. $html="";$asum=0;
  5632. for ($i=1;$i<=12;$i++){
  5633. $falg=true;
  5634. foreach ($itemStatisticsList as $v){
  5635. if($value['cid']==$v['cid']&&$i==$v['month']){
  5636. $asum+=$v['price'];
  5637. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5638. }
  5639. }
  5640. if($falg)
  5641. $html.='<td class="taR">-</td>';
  5642. }
  5643. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5644. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5645. }
  5646. $data['companyHtml']=$collectHtml;
  5647. //total price html
  5648. $collectHtml="";$total=0;
  5649. for ($i=1;$i<=12;$i++){
  5650. $sumPrice=0;
  5651. foreach ($itemStatisticsList as $key=>$value){
  5652. if($value['month']==$i){
  5653. $sumPrice+=$value['price'];
  5654. }
  5655. }
  5656. if ($sumPrice==0)
  5657. $collectHtml.='<td class="taR">-</td>';
  5658. else
  5659. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5660. $total+=$sumPrice;
  5661. }
  5662. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5663. $data['companyTotalHtml']=$collectHtml;
  5664. $data['total']=$total;
  5665. //statistics html
  5666. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5667. if(empty($stList))
  5668. $stList=array('rePrice'=>0,'agPrice'=>0);
  5669. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5670. $data['year']=$year;
  5671. $data['memu']="receipt";
  5672. $data['staff']=$this->staff;
  5673. $data['receiptMemu']='companyCategoryCollect';
  5674. $data['verifyId']=$this->verifyId;
  5675. $data['executeId']=$this->executeId;
  5676. //year staff status 2,4
  5677. if($year<date("Y")){
  5678. Doo::loadModel('receipt');
  5679. $receipt=new receipt();
  5680. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5681. if(empty($receiptList)){
  5682. ob_start();
  5683. $this->render ( "/admin/saeaCompanyCollect", $data );
  5684. $this->cacheFile($path);die;
  5685. }
  5686. }
  5687. $this->render ( "/admin/saeaCompanyCollect", $data );
  5688. }
  5689. function categoryCollectDetail(){
  5690. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5691. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5692. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5693. $this->showCache($path);
  5694. Doo::loadModel('statistics');
  5695. $statistics=new statistics();
  5696. Doo::loadModel("receiptDetail");
  5697. $receiptDetail=new receiptDetail();
  5698. Doo::loadModel('L_category');
  5699. $Lcategory=new L_category();
  5700. Doo::loadModel('accountItem');
  5701. $accountItem=new accountItem();
  5702. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5703. if ($cid==0){
  5704. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5705. if ($cid==0)
  5706. $cid=$LcategoryList[0]['cid'];
  5707. }
  5708. $data['LcategoryList']=$LcategoryList;
  5709. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5710. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5711. $accountList=$accountItem->find(array('asArray'=>true));
  5712. //create CollectDetail HTML
  5713. $collectHtml=array();
  5714. foreach ($accountList as $key=>$value){
  5715. $html="";$asum=0;
  5716. for ($i=1;$i<=12;$i++){
  5717. $falg=true;
  5718. foreach ($receiptCollectList as $v) {
  5719. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5720. $asum+=$v['price'];
  5721. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5722. }
  5723. }
  5724. if($falg)
  5725. $html.='<td class="taR">-</td>';
  5726. }
  5727. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5728. $collectHtml[$value['category']][$value['name']]=$html;
  5729. }
  5730. $data['collectHtml']=$collectHtml;
  5731. //create Adjustment price html
  5732. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5733. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5734. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5735. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5736. array_push($collectArray['日常相关费用'], $collectHtml);
  5737. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5738. array_push($collectArray['差旅相关费用'], $collectHtml);
  5739. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5740. array_push($collectArray['培训班费用'], $collectHtml);
  5741. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5742. array_push($collectArray['其他'], $collectHtml);
  5743. $data['collectArray']=$collectArray;
  5744. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5745. array_push($adjustment, $collectHtml);
  5746. $data['adjustment']=$adjustment;
  5747. //total price html
  5748. $collectHtml="";$total=0;
  5749. for ($i=1;$i<=12;$i++){
  5750. $sumPrice=0;
  5751. foreach ($receiptCollectList as $key=>$value){
  5752. if($value['month']==$i){
  5753. $sumPrice+=$value['price'];
  5754. }
  5755. }
  5756. if ($sumPrice==0)
  5757. $collectHtml.='<td class="taR">-</td>';
  5758. else
  5759. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5760. $total+=$sumPrice;
  5761. }
  5762. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5763. //statistics html
  5764. $stList=$statistics->statisticsByCid($year,$cid);
  5765. if(empty($stList))
  5766. $stList=array('rePrice'=>0,'agPrice'=>0);
  5767. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5768. $data['totalYear']=$total;
  5769. $data['year']=$year;
  5770. $data['cid']=$cid;
  5771. $data['memu']="receipt";
  5772. $data['staff']=$this->staff;
  5773. $data['receiptMemu']='companyCategoryCollect';
  5774. $data['verifyId']=$this->verifyId;
  5775. $data['executeId']=$this->executeId;
  5776. //year staff status 2,4
  5777. if($year<date("Y")){
  5778. Doo::loadModel('receipt');
  5779. $receipt=new receipt();
  5780. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5781. if(empty($receiptList)){
  5782. ob_start();
  5783. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5784. $this->cacheFile($path);die;
  5785. }
  5786. }
  5787. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5788. }
  5789. function staffCollect(){
  5790. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5791. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5792. //$this->showCache($path);
  5793. Doo::loadModel('statistics');
  5794. $statistics=new statistics();
  5795. Doo::loadModel("receiptDetail");
  5796. $receiptDetail=new receiptDetail();
  5797. Doo::loadModel('L_category');
  5798. $Lcategory=new L_category();
  5799. Doo::loadModel('accountItem');
  5800. $accountItem=new accountItem();
  5801. Doo::loadModel('staff');
  5802. $staff=new staff();
  5803. Doo::loadModel('itemStatistics');
  5804. $itemStatistics=new itemStatistics();
  5805. /*
  5806. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5807. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5808. if(empty($stList))
  5809. $stList=array('rePrice'=>0,'agPrice'=>0);
  5810. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5811. */
  5812. //statistics html
  5813. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5814. if(empty($stList))
  5815. $stList=array('rePrice'=>0,'agPrice'=>0);
  5816. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5817. //---
  5818. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5819. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5820. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5821. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5822. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5823. //print_r($itemStatisticsList);die;
  5824. //ceatre companyCollectHtml
  5825. foreach ($categoryList as $vlu){
  5826. $count=$vlu['count']+1;
  5827. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5828. $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;
  5829. foreach ($staffList as $value){
  5830. if ($vlu['cid']==$value['cid']){
  5831. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5832. $asum=0;
  5833. for ($i=1;$i<=12;$i++){
  5834. $falg=true;
  5835. foreach ($itemStatisticsList as $v){
  5836. if($value['sid']==$v['staff']&&$i==$v['month']){
  5837. if ($v['month']==1)
  5838. $m1+=$v['price'];
  5839. if ($v['month']==2)
  5840. $m2+=$v['price'];
  5841. if ($v['month']==3)
  5842. $m3+=$v['price'];
  5843. if ($v['month']==4)
  5844. $m4+=$v['price'];
  5845. if ($v['month']==5)
  5846. $m5+=$v['price'];
  5847. if ($v['month']==6)
  5848. $m6+=$v['price'];
  5849. if ($v['month']==7)
  5850. $m7+=$v['price'];
  5851. if ($v['month']==8)
  5852. $m8+=$v['price'];
  5853. if ($v['month']==9)
  5854. $m9+=$v['price'];
  5855. if ($v['month']==10)
  5856. $m10+=$v['price'];
  5857. if ($v['month']==11)
  5858. $m11+=$v['price'];
  5859. if ($v['month']==12)
  5860. $m12+=$v['price'];
  5861. $asum+=$v['price'];
  5862. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5863. }
  5864. }
  5865. if($falg)
  5866. $html.='<td class="taR">-</td>';
  5867. }
  5868. $m13+=$asum;
  5869. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5870. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5871. $html="";
  5872. }
  5873. }
  5874. $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>
  5875. <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>
  5876. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5877. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5878. }
  5879. $data['companyHtml']=$collectHtml;
  5880. //total price html
  5881. $collectHtml="";$total=0;
  5882. for ($i=1;$i<=12;$i++){
  5883. $sumPrice=0;
  5884. foreach ($itemStatisticsList as $key=>$value){
  5885. if($value['month']==$i){
  5886. $sumPrice+=$value['price'];
  5887. }
  5888. }
  5889. if ($sumPrice==0)
  5890. $collectHtml.='<td class="taR">-</td>';
  5891. else
  5892. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5893. $total+=$sumPrice;
  5894. }
  5895. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5896. $data['companyTotalHtml']=$collectHtml;
  5897. $data['total']=$total;
  5898. $data['year']=$year;
  5899. $data['memu']="receipt";
  5900. $data['staff']=$this->staff;
  5901. $data['receiptMemu']='companyCategoryCollect';
  5902. $data['verifyId']=$this->verifyId;
  5903. $data['executeId']=$this->executeId;
  5904. if ($year<=date("Y")){
  5905. Doo::loadModel('receipt');
  5906. $receipt=new receipt();
  5907. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5908. if(empty($receiptList)){ //generated files
  5909. ob_start();
  5910. $this->render ( "/admin/saeaStaffCollectB", $data );
  5911. $this->cacheFile($path);die;
  5912. }
  5913. }
  5914. $this->render ( "/admin/saeaStaffCollectB", $data );
  5915. }
  5916. function staffCollectBak(){
  5917. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5918. $month=$this->get_args('month')?$this->get_args('month'):1;
  5919. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  5920. $this->showCache($path);
  5921. Doo::loadModel('statistics');
  5922. $statistics=new statistics();
  5923. Doo::loadModel("receiptDetail");
  5924. $receiptDetail=new receiptDetail();
  5925. Doo::loadModel('L_category');
  5926. $Lcategory=new L_category();
  5927. Doo::loadModel('accountItem');
  5928. $accountItem=new accountItem();
  5929. Doo::loadModel('staff');
  5930. $staff=new staff();
  5931. Doo::loadModel('itemStatistics');
  5932. $itemStatistics=new itemStatistics();
  5933. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5934. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  5935. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5936. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  5937. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5938. $staffList=$staff->find(array('asArray'=>true));
  5939. $htmlArray=array();
  5940. foreach ($LcategoryList as $value){
  5941. $htmlArray[$value['title']]=array();
  5942. foreach ($staffList as $v){
  5943. if($value['cid']==$v['cid']){
  5944. $html="";$falg=true;$staffSumPrice=0;
  5945. foreach ($itemStatisticsList as $a){
  5946. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  5947. if(empty($a['price'])){
  5948. $html.='<td class="taR">-</td>';$falg=false;break;
  5949. }else{
  5950. $staffSumPrice+=$a['price'];
  5951. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5952. }
  5953. }
  5954. }
  5955. if ($falg){
  5956. $html.='<td class="taR">-</td>';$falg=true;
  5957. }
  5958. $falg=true;
  5959. foreach ($itemStatisticsList as $a){
  5960. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  5961. if(empty($a['price'])){
  5962. $html.='<td class="taR">-</td>';$falg=false;break;
  5963. }else{
  5964. $staffSumPrice+=$a['price'];
  5965. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5966. }
  5967. }
  5968. }
  5969. if ($falg){
  5970. $html.='<td class="taR">-</td>';$falg=true;
  5971. }
  5972. $falg=true;
  5973. foreach ($itemStatisticsList as $a){
  5974. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  5975. if(empty($a['price'])){
  5976. $html.='<td class="taR">-</td>';$falg=false;break;
  5977. }else{
  5978. $staffSumPrice+=$a['price'];
  5979. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5980. }
  5981. }
  5982. }
  5983. if ($falg){
  5984. $html.='<td class="taR">-</td>';$falg=true;
  5985. }
  5986. $falg=true;
  5987. foreach ($itemStatisticsList as $a){
  5988. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  5989. if(!empty($a['price'])){
  5990. $staffSumPrice+=$a['price'];
  5991. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5992. }else{
  5993. $html.='<td class="taR">-</td>';$falg=false;break;
  5994. }
  5995. }
  5996. }
  5997. if ($falg){
  5998. $html.='<td class="taR">-</td>';$falg=true;
  5999. }
  6000. $falg=true;
  6001. foreach ($itemStatisticsList as $a){
  6002. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6003. if(!empty($a['price'])){
  6004. $staffSumPrice+=$a['price'];
  6005. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6006. }else{
  6007. $html.='<td class="taR">-</td>';$falg=false;break;
  6008. }
  6009. }
  6010. }
  6011. if ($falg){
  6012. $html.='<td class="taR">-</td>';$falg=true;
  6013. }
  6014. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6015. $htmlArray[$value['title']][$v['username']]=$html;
  6016. }
  6017. }
  6018. /*-- ---*/
  6019. //合计费用
  6020. $cateHtml="";$catePrice=0;$cateFalg=true;
  6021. foreach ($itemCategoryList as $l){
  6022. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6023. if(empty($l['price'])){
  6024. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6025. }else{
  6026. $catePrice+=$l['price'];
  6027. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6028. }
  6029. }
  6030. }
  6031. if ($cateFalg){
  6032. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6033. }
  6034. $cateFalg=true;
  6035. foreach ($itemCategoryList as $l){
  6036. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6037. if(empty($l['price'])){
  6038. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6039. }else{
  6040. $catePrice+=$l['price'];
  6041. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6042. }
  6043. }
  6044. }
  6045. if ($cateFalg){
  6046. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6047. }
  6048. $cateFalg=true;
  6049. foreach ($itemCategoryList as $l){
  6050. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6051. if(empty($l['price'])){
  6052. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6053. }else{
  6054. $catePrice+=$l['price'];
  6055. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6056. }
  6057. }
  6058. }
  6059. if ($cateFalg){
  6060. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6061. }
  6062. $cateFalg=true;
  6063. foreach ($itemCategoryList as $l){
  6064. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6065. if(empty($l['price'])){
  6066. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6067. }else{
  6068. $catePrice+=$l['price'];
  6069. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6070. }
  6071. }
  6072. }
  6073. if ($cateFalg){
  6074. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6075. }
  6076. $cateFalg=true;
  6077. foreach ($itemCategoryList as $l){
  6078. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6079. if(empty($l['price'])){
  6080. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6081. }else{
  6082. $catePrice+=$l['price'];
  6083. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6084. }
  6085. }
  6086. }
  6087. if ($cateFalg){
  6088. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6089. }
  6090. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6091. $htmlArray[$value['title']]['合计']=$cateHtml;
  6092. /*-- ---*/
  6093. }
  6094. //print_r($htmlArray);die;
  6095. $data['htmlArray']=$htmlArray;
  6096. //statistics html
  6097. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6098. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6099. if(empty($stList))
  6100. $stList=array('rePrice'=>0,'agPrice'=>0);
  6101. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6102. $monthHtml="";
  6103. for ($i=1;$i<=12;$i++){
  6104. if ($i==$month)
  6105. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6106. else
  6107. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6108. }
  6109. $data['monthHtml']=$monthHtml;
  6110. $data['year']=$year;
  6111. $data['month']=$month;
  6112. $data['memu']="receipt";
  6113. $data['staff']=$this->staff;
  6114. $data['receiptMemu']='companyCategoryCollect';
  6115. $data['verifyId']=$this->verifyId;
  6116. $data['executeId']=$this->executeId;
  6117. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6118. Doo::loadModel('receipt');
  6119. $receipt=new receipt();
  6120. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6121. if(empty($receiptList)){ //generated files
  6122. ob_start();
  6123. $this->render ( "/admin/saeaStaffCollect", $data );
  6124. $this->cacheFile($path);die;
  6125. }
  6126. }
  6127. $this->render ( "/admin/saeaStaffCollect", $data );
  6128. }
  6129. function lyt(){
  6130. Doo::loadModel("receiptDetail");
  6131. $receiptDetail=new receiptDetail();
  6132. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6133. foreach ($receiptCollectList as $key=>$value){
  6134. $receiptDetail=new receiptDetail();
  6135. $receiptDetail->pastDate=$value['date'];
  6136. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6137. }
  6138. }
  6139. function staffCollectMonthDetail(){
  6140. $year=$this->get_args('year')?$this->get_args('year'):"";
  6141. $month=$this->get_args('month')?$this->get_args('month'):"";
  6142. if(!$year)
  6143. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6144. if(!$month)
  6145. $month=isset($this->params['month'])?$this->params['month']:1;
  6146. Doo::loadModel('staff');
  6147. $staff=new staff();
  6148. Doo::loadModel("receiptDetail");
  6149. $receiptDetail=new receiptDetail();
  6150. Doo::loadModel('accountItem');
  6151. $accountItem=new accountItem();
  6152. Doo::loadModel('statistics');
  6153. $statistics=new statistics();
  6154. Doo::loadModel('L_category');
  6155. $lCategory=new L_category();
  6156. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6157. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6158. $list=array();
  6159. foreach ($categoryList as $vlu){
  6160. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6161. $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;
  6162. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6163. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6164. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6165. $s1=0;
  6166. $m1=0;
  6167. foreach ($staffList as $value){
  6168. if ($vlu['cid']==$value['cid']){
  6169. //pastDate
  6170. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6171. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6172. // if ($value['sid']==42){
  6173. // print_r($receiptCollectList);die;
  6174. // }
  6175. if(!empty($receiptCollectList)){
  6176. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6177. $html="";
  6178. $psum=0;
  6179. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6180. foreach ($item as $va){
  6181. $falg=true;
  6182. foreach ($receiptCollectList as $v){
  6183. if($v['itemCategory']=='日常相关费用'){
  6184. if($v['item']==$va){
  6185. if ($va=='市内交通费')
  6186. $r1+=$v['price'];
  6187. if ($va=='市内出租费')
  6188. $r2+=$v['price'];
  6189. if ($va=='办事处房租')
  6190. $r3+=$v['price'];
  6191. if ($va=='电话费')
  6192. $r4+=$v['price'];
  6193. if ($va=='水费')
  6194. $r5+=$v['price'];
  6195. if ($va=='电费')
  6196. $r6+=$v['price'];
  6197. if ($va=='办公费用')
  6198. $r7+=$v['price'];
  6199. if ($va=='邮寄费')
  6200. $r8+=$v['price'];
  6201. if ($va=='其他费用')
  6202. $r9+=$v['price'];
  6203. if ($va=='车辆费用')
  6204. $r10+=$v['price'];
  6205. if ($va=='广告费')
  6206. $r11+=$v['price'];
  6207. if ($va=='团队建设费')
  6208. $r13+=$v['price'];
  6209. if ($va=='物业管理费')
  6210. $r14+=$v['price'];
  6211. if ($va=='宽带费')
  6212. $r15+=$v['price'];
  6213. $psum+=$v['price'];
  6214. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6215. }
  6216. }
  6217. }
  6218. if($falg)
  6219. $html.='<td class="taR">-</td>';
  6220. }
  6221. $r12+=$psum;
  6222. if(!empty($psum))
  6223. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6224. else
  6225. $psum='<td class="colGreen taR">-</td>';
  6226. $receiptL['日常相关费用']=$psum.$html;
  6227. /*-----------------------------------*/
  6228. $html="";
  6229. $psum=0;
  6230. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6231. foreach ($item as $va){
  6232. $falg=true;
  6233. foreach ($receiptCollectList as $v){
  6234. if($v['itemCategory']=='差旅相关费用'){
  6235. if($v['item']==$va){
  6236. if ($va=='往来交通费')
  6237. $c1+=$v['price'];
  6238. if ($va=='市内交通费')
  6239. $c2+=$v['price'];
  6240. if ($va=='出差住宿费')
  6241. $c3+=$v['price'];
  6242. if ($va=='出差补助')
  6243. $c4+=$v['price'];
  6244. if ($va=='其他费用')
  6245. $c5+=$v['price'];
  6246. $psum+=$v['price'];
  6247. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6248. }
  6249. }
  6250. }
  6251. if($falg)
  6252. $html.='<td class="taR">-</td>';
  6253. }
  6254. $c6+=$psum;
  6255. if(!empty($psum))
  6256. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6257. else
  6258. $psum='<td class="colGreen taR">-</td>';
  6259. $receiptL['差旅相关费用']=$psum.$html;
  6260. /*-------------------------------------*/
  6261. $html="";
  6262. $psum=0;
  6263. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6264. foreach ($item as $va){
  6265. $falg=true;
  6266. foreach ($receiptCollectList as $v){
  6267. if($v['itemCategory']=='培训班费用'){
  6268. if($v['item']==$va){
  6269. if ($va=='场租费')
  6270. $p1+=$v['price'];
  6271. if ($va=='薪酬')
  6272. $p2+=$v['price'];
  6273. if ($va=='住宿费')
  6274. $p3+=$v['price'];
  6275. if ($va=='交通费')
  6276. $p4+=$v['price'];
  6277. if ($va=='餐饮费')
  6278. $p5+=$v['price'];
  6279. if ($va=='办公费')
  6280. $p6+=$v['price'];
  6281. if ($va=='公关费')
  6282. $p7+=$v['price'];
  6283. if ($va=='其他')
  6284. $p8+=$v['price'];
  6285. $psum+=$v['price'];
  6286. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6287. }
  6288. }
  6289. }
  6290. if($falg)
  6291. $html.='<td class="taR">-</td>';
  6292. }
  6293. $p9+=$psum;
  6294. if(!empty($psum))
  6295. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6296. else
  6297. $psum='<td class="colGreen taR">-</td>';
  6298. $receiptL['培训班费用']=$psum.$html;
  6299. /*-------------------------------------*/
  6300. $html="";
  6301. $psum=0;
  6302. $item=array('公关费','广告费','借款','可自加费用');
  6303. foreach ($item as $va){
  6304. $falg=true;
  6305. foreach ($receiptCollectList as $v){
  6306. if($v['itemCategory']=='其他'){
  6307. // if ($value['sid']==42){
  6308. //
  6309. // echo var_dump($v['item']);
  6310. // echo var_dump($va);
  6311. // echo var_dump($v['item']==" ".$va);
  6312. // echo $v['item']."==".$va."/<br/>";
  6313. // //print_r( $receiptCollectList);//echo $va;
  6314. // }
  6315. if(trim($v['item'])==$va){
  6316. if ($va=='公关费')
  6317. $t1+=$v['price'];
  6318. if ($va=='广告费'){
  6319. $t2+=$v['price'];
  6320. }
  6321. if ($va=='借款')
  6322. $t3+=$v['price'];
  6323. if ($va=='可自加费用')
  6324. $t4+=$v['price'];
  6325. $psum+=$v['price'];
  6326. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6327. }
  6328. }
  6329. }
  6330. if($falg)
  6331. $html.='<td class="taR">-</td>';
  6332. }
  6333. $t5+=$psum;
  6334. if(!empty($psum))
  6335. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6336. else
  6337. $psum='<td class="colGreen taR">-</td>';
  6338. $receiptL['其他']=$psum.$html;
  6339. /*-------------------------------------*/
  6340. $html="";
  6341. $psum=0;
  6342. foreach ($receiptCollectList as $v){
  6343. if($v['itemCategory']=='报销金额调整'){
  6344. if (!empty($v['price'])){
  6345. $psum+=$v['price'];
  6346. }
  6347. }
  6348. }
  6349. $s1+=$psum;
  6350. if(!empty($psum))
  6351. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6352. else
  6353. $psum='<td class="taR colOrange">-</td>';
  6354. $receiptL['报销金额调整']=$psum.$html;
  6355. }else{
  6356. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6357. <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>
  6358. <td class="taR">-</td><td class="taR">-</td>';
  6359. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6360. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6361. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6362. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6363. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6364. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6365. }
  6366. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6367. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6368. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6369. if(!empty($monthStaffPrice[0]['price'])){
  6370. $m1+=$monthStaffPrice[0]['price'];
  6371. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6372. }else
  6373. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6374. $list[$value['username']]=$receiptL;
  6375. }
  6376. }
  6377. $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>
  6378. <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>
  6379. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6380. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6381. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6382. $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>
  6383. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6384. $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>';
  6385. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6386. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6387. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6388. }
  6389. $data['list']=$list;
  6390. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6391. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6392. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6393. //statistics html
  6394. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6395. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6396. if(empty($stList))
  6397. $stList=array('rePrice'=>0,'agPrice'=>0);
  6398. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6399. $monthHtml="";
  6400. for ($i=1;$i<=12;$i++){
  6401. if ($i==$month)
  6402. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6403. else
  6404. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6405. }
  6406. $data['monthHtml']=$monthHtml;
  6407. $data['year']=$year;
  6408. $data['month']=$month;
  6409. $data['memu']="receipt";
  6410. $data['staff']=$this->staff;
  6411. $data['receiptMemu']='companyCategoryCollect';
  6412. $data['verifyId']=$this->verifyId;
  6413. $data['executeId']=$this->executeId;
  6414. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6415. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6416. }
  6417. function staffCollectMonthDetail2(){
  6418. $year=$this->get_args('year')?$this->get_args('year'):"";
  6419. $month=$this->get_args('month')?$this->get_args('month'):"";
  6420. if(!$year)
  6421. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6422. if(!$month)
  6423. $month=isset($this->params['month'])?$this->params['month']:1;
  6424. Doo::loadModel('staff');
  6425. $staff=new staff();
  6426. Doo::loadModel("receiptDetail");
  6427. $receiptDetail=new receiptDetail();
  6428. Doo::loadModel('accountItem');
  6429. $accountItem=new accountItem();
  6430. Doo::loadModel('statistics');
  6431. $statistics=new statistics();
  6432. Doo::loadModel('L_category');
  6433. $lCategory=new L_category();
  6434. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6435. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6436. $list=array();
  6437. foreach ($categoryList as $vlu){
  6438. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6439. $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;
  6440. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6441. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6442. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6443. $s1=0;
  6444. $m1=0;
  6445. foreach ($staffList as $value){
  6446. if ($vlu['cid']==$value['cid']){
  6447. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6448. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6449. if(!empty($receiptCollectList)){
  6450. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6451. $html="";
  6452. $psum=0;
  6453. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6454. foreach ($item as $va){
  6455. $falg=true;
  6456. foreach ($receiptCollectList as $v){
  6457. if($v['itemCategory']=='日常相关费用'){
  6458. if($v['item']==$va){
  6459. if ($va=='市内交通费')
  6460. $r1+=$v['price'];
  6461. if ($va=='市内出租费')
  6462. $r2+=$v['price'];
  6463. if ($va=='办事处房租')
  6464. $r3+=$v['price'];
  6465. if ($va=='电话费')
  6466. $r4+=$v['price'];
  6467. if ($va=='水费')
  6468. $r5+=$v['price'];
  6469. if ($va=='电费')
  6470. $r6+=$v['price'];
  6471. if ($va=='办公费用')
  6472. $r7+=$v['price'];
  6473. if ($va=='邮寄费')
  6474. $r8+=$v['price'];
  6475. if ($va=='其他费用')
  6476. $r9+=$v['price'];
  6477. if ($va=='车辆费用')
  6478. $r10+=$v['price'];
  6479. if ($va=='广告费')
  6480. $r11+=$v['price'];
  6481. if ($va=='团队建设费')
  6482. $r13+=$v['price'];
  6483. if ($va=='物业管理费')
  6484. $r14+=$v['price'];
  6485. if ($va=='宽带费')
  6486. $r15+=$v['price'];
  6487. $psum+=$v['price'];
  6488. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6489. }
  6490. }
  6491. }
  6492. if($falg)
  6493. $html.='<td class="taR">-</td>';
  6494. }
  6495. $r12+=$psum;
  6496. if(!empty($psum))
  6497. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6498. else
  6499. $psum='<td class="colGreen taR">-</td>';
  6500. $receiptL['日常相关费用']=$psum.$html;
  6501. /*-----------------------------------*/
  6502. $html="";
  6503. $psum=0;
  6504. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6505. foreach ($item as $va){
  6506. $falg=true;
  6507. foreach ($receiptCollectList as $v){
  6508. if($v['itemCategory']=='差旅相关费用'){
  6509. if($v['item']==$va){
  6510. if ($va=='往来交通费')
  6511. $c1+=$v['price'];
  6512. if ($va=='市内交通费')
  6513. $c2+=$v['price'];
  6514. if ($va=='出差住宿费')
  6515. $c3+=$v['price'];
  6516. if ($va=='出差补助')
  6517. $c4+=$v['price'];
  6518. if ($va=='其他费用')
  6519. $c5+=$v['price'];
  6520. $psum+=$v['price'];
  6521. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6522. }
  6523. }
  6524. }
  6525. if($falg)
  6526. $html.='<td class="taR">-</td>';
  6527. }
  6528. $c6+=$psum;
  6529. if(!empty($psum))
  6530. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6531. else
  6532. $psum='<td class="colGreen taR">-</td>';
  6533. $receiptL['差旅相关费用']=$psum.$html;
  6534. /*-------------------------------------*/
  6535. $html="";
  6536. $psum=0;
  6537. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6538. foreach ($item as $va){
  6539. $falg=true;
  6540. foreach ($receiptCollectList as $v){
  6541. if($v['itemCategory']=='培训班费用'){
  6542. if($v['item']==$va){
  6543. if ($va=='场租费')
  6544. $p1+=$v['price'];
  6545. if ($va=='薪酬')
  6546. $p2+=$v['price'];
  6547. if ($va=='住宿费')
  6548. $p3+=$v['price'];
  6549. if ($va=='交通费')
  6550. $p4+=$v['price'];
  6551. if ($va=='餐饮费')
  6552. $p5+=$v['price'];
  6553. if ($va=='办公费')
  6554. $p6+=$v['price'];
  6555. if ($va=='公关费')
  6556. $p7+=$v['price'];
  6557. if ($va=='其他')
  6558. $p8+=$v['price'];
  6559. $psum+=$v['price'];
  6560. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6561. }
  6562. }
  6563. }
  6564. if($falg)
  6565. $html.='<td class="taR">-</td>';
  6566. }
  6567. $p9+=$psum;
  6568. if(!empty($psum))
  6569. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6570. else
  6571. $psum='<td class="colGreen taR">-</td>';
  6572. $receiptL['培训班费用']=$psum.$html;
  6573. /*-------------------------------------*/
  6574. $html="";
  6575. $psum=0;
  6576. $item=array('公关费','广告费','借款','可自加费用');
  6577. foreach ($item as $va){
  6578. $falg=true;
  6579. foreach ($receiptCollectList as $v){
  6580. if($v['itemCategory']=='其他'){
  6581. if($v['item']==$va){
  6582. if ($va=='公关费')
  6583. $t1+=$v['price'];
  6584. if ($va=='广告费')
  6585. $t2+=$v['price'];
  6586. if ($va=='借款')
  6587. $t3+=$v['price'];
  6588. if ($va=='可自加费用')
  6589. $t4+=$v['price'];
  6590. $psum+=$v['price'];
  6591. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6592. }
  6593. }
  6594. }
  6595. if($falg)
  6596. $html.='<td class="taR">-</td>';
  6597. }
  6598. $t5+=$psum;
  6599. if(!empty($psum))
  6600. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6601. else
  6602. $psum='<td class="colGreen taR">-</td>';
  6603. $receiptL['其他']=$psum.$html;
  6604. /*-------------------------------------*/
  6605. $html="";
  6606. $psum=0;
  6607. foreach ($receiptCollectList as $v){
  6608. if($v['itemCategory']=='报销金额调整'){
  6609. if (!empty($v['price'])){
  6610. $psum+=$v['price'];
  6611. }
  6612. }
  6613. }
  6614. $s1+=$psum;
  6615. if(!empty($psum))
  6616. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6617. else
  6618. $psum='<td class="taR colOrange">-</td>';
  6619. $receiptL['报销金额调整']=$psum.$html;
  6620. }else{
  6621. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6622. <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>';
  6623. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6624. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6625. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6626. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6627. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6628. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6629. }
  6630. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6631. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6632. if(!empty($monthStaffPrice[0]['price'])){
  6633. $m1+=$monthStaffPrice[0]['price'];
  6634. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6635. }else
  6636. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6637. $list[$value['username']]=$receiptL;
  6638. }
  6639. }
  6640. $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>
  6641. <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>
  6642. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6643. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6644. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6645. $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>
  6646. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6647. $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>';
  6648. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6649. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6650. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6651. }
  6652. $data['list']=$list;
  6653. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6654. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6655. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6656. //statistics html
  6657. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6658. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6659. if(empty($stList))
  6660. $stList=array('rePrice'=>0,'agPrice'=>0);
  6661. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6662. $monthHtml="";
  6663. for ($i=1;$i<=12;$i++){
  6664. if ($i==$month)
  6665. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6666. else
  6667. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6668. }
  6669. $data['monthHtml']=$monthHtml;
  6670. $data['year']=$year;
  6671. $data['month']=$month;
  6672. $data['memu']="receipt";
  6673. $data['staff']=$this->staff;
  6674. $data['receiptMemu']='companyCategoryCollect';
  6675. $data['verifyId']=$this->verifyId;
  6676. $data['executeId']=$this->executeId;
  6677. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6678. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6679. }
  6680. function companyMonthCollectDetail(){
  6681. $year=$this->get_args('year')?$this->get_args('year'):"";
  6682. $month=$this->get_args('month')?$this->get_args('month'):"";
  6683. if(!$year)
  6684. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6685. if(!$month)
  6686. $month=isset($this->params['month'])?$this->params['month']:1;
  6687. Doo::loadModel('staff');
  6688. $staff=new staff();
  6689. Doo::loadModel("receiptDetail");
  6690. $receiptDetail=new receiptDetail();
  6691. Doo::loadModel('accountItem');
  6692. $accountItem=new accountItem();
  6693. Doo::loadModel('statistics');
  6694. $statistics=new statistics();
  6695. Doo::loadModel('L_category');
  6696. $lCategory=new L_category();
  6697. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6698. $categoryList=$lCategory->find(array('asArray'=>true));
  6699. $list=array();
  6700. foreach ($categoryList as $value){
  6701. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6702. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6703. if(!empty($receiptCollectList)){
  6704. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6705. $html="";
  6706. $psum=0;
  6707. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6708. foreach ($item as $va){
  6709. $falg=true;
  6710. foreach ($receiptCollectList as $v){
  6711. if($v['itemCategory']=='日常相关费用'){
  6712. if($v['item']==$va){
  6713. $psum+=$v['price'];
  6714. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6715. }
  6716. }
  6717. }
  6718. if($falg)
  6719. $html.='<td class="taR">-</td>';
  6720. }
  6721. if(!empty($psum))
  6722. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6723. else
  6724. $psum='<td class="colGreen taR">-</td>';
  6725. $receiptL['日常相关费用']=$psum.$html;
  6726. /*-----------------------------------*/
  6727. $html="";
  6728. $psum=0;
  6729. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6730. foreach ($item as $va){
  6731. $falg=true;
  6732. foreach ($receiptCollectList as $v){
  6733. if($v['itemCategory']=='差旅相关费用'){
  6734. if($v['item']==$va){
  6735. $psum+=$v['price'];
  6736. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6737. }
  6738. }
  6739. }
  6740. if($falg)
  6741. $html.='<td class="taR">-</td>';
  6742. }
  6743. if(!empty($psum))
  6744. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6745. else
  6746. $psum='<td class="colGreen taR">-</td>';
  6747. $receiptL['差旅相关费用']=$psum.$html;
  6748. /*-------------------------------------*/
  6749. $html="";
  6750. $psum=0;
  6751. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6752. foreach ($item as $va){
  6753. $falg=true;
  6754. foreach ($receiptCollectList as $v){
  6755. if($v['itemCategory']=='培训班费用'){
  6756. if($v['item']==$va){
  6757. $psum+=$v['price'];
  6758. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6759. }
  6760. }
  6761. }
  6762. if($falg)
  6763. $html.='<td class="taR">-</td>';
  6764. }
  6765. if(!empty($psum))
  6766. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6767. else
  6768. $psum='<td class="colGreen taR">-</td>';
  6769. $receiptL['培训班费用']=$psum.$html;
  6770. /*-------------------------------------*/
  6771. $html="";
  6772. $psum=0;
  6773. $item=array('公关费','广告费','借款','可自加费用');
  6774. foreach ($item as $va){
  6775. $falg=true;
  6776. foreach ($receiptCollectList as $v){
  6777. if($v['itemCategory']=='其他'){
  6778. if($v['item']==$va){
  6779. $psum+=$v['price'];
  6780. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6781. }
  6782. }
  6783. }
  6784. if($falg)
  6785. $html.='<td class="taR">-</td>';
  6786. }
  6787. if(!empty($psum))
  6788. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6789. else
  6790. $psum='<td class="colGreen taR">-</td>';
  6791. $receiptL['其他']=$psum.$html;
  6792. /*-------------------------------------*/
  6793. $html="";
  6794. $psum=0;
  6795. foreach ($receiptCollectList as $v){
  6796. if($v['itemCategory']=='报销金额调整'){
  6797. if (!empty($v['price']))
  6798. $psum+=$v['price'];
  6799. }
  6800. }
  6801. if(!empty($psum))
  6802. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6803. else
  6804. $psum='<td class="taR colOrange">-</td>';
  6805. $receiptL['报销金额调整']=$psum.$html;
  6806. }else{
  6807. $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>
  6808. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6809. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6810. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6811. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6812. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6813. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6814. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6815. }
  6816. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6817. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6818. if(!empty($monthStaffPrice[0]['price']))
  6819. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6820. else
  6821. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6822. $list[$value['title']]=$receiptL;
  6823. }
  6824. $data['list']=$list;
  6825. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6826. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6827. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6828. //print_r($data['monthPriceHtml']);
  6829. // foreach ($data['monthPriceHtml'] as $value){
  6830. // echo $value;
  6831. // }
  6832. // die;
  6833. //statistics html
  6834. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6835. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6836. if(empty($stList))
  6837. $stList=array('rePrice'=>0,'agPrice'=>0);
  6838. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6839. $monthHtml="";
  6840. for ($i=1;$i<=12;$i++){
  6841. if ($i==$month)
  6842. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6843. else
  6844. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6845. }
  6846. $data['monthHtml']=$monthHtml;
  6847. $data['year']=$year;
  6848. $data['month']=$month;
  6849. $data['memu']="receipt";
  6850. $data['staff']=$this->staff;
  6851. $data['receiptMemu']='companyCategoryCollect';
  6852. $data['verifyId']=$this->verifyId;
  6853. $data['executeId']=$this->executeId;
  6854. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6855. }
  6856. function staffCollectDetail(){
  6857. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6858. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6859. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6860. if(!$staffname){
  6861. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6862. $staffname= urldecode($staffname);
  6863. }
  6864. Doo::loadModel('staff');
  6865. $staff=new staff();
  6866. Doo::loadModel("receiptDetail");
  6867. $receiptDetail=new receiptDetail();
  6868. Doo::loadModel('accountItem');
  6869. $accountItem=new accountItem();
  6870. Doo::loadModel('statistics');
  6871. $statistics=new statistics();
  6872. Doo::loadModel('L_category');
  6873. $lCategory=new L_category();
  6874. $staffList=$staff->find(array('asArray'=>true));
  6875. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6876. foreach ($staffList as $value){
  6877. if ($value['username']==$staffname&&$value['username']!='admin'){
  6878. $stTitle=$value['category'].'-'.$value['username'];
  6879. $staffId=$value['sid'];
  6880. $cid=$value['cid'];
  6881. $ocid=$value['cid'];
  6882. if (!empty($value['othercid']))
  6883. $cid=$value['cid'].','.$value['othercid'];
  6884. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6885. }elseif ($value['username']!='admin')
  6886. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6887. }
  6888. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6889. if(empty($pcid))
  6890. $pcid=$ocid;
  6891. $data['ocid']=$pcid;
  6892. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6893. $this->showCache($path);
  6894. //
  6895. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6896. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6897. $accountList=$accountItem->find(array('asArray'=>true));
  6898. //create CollectDetail HTML
  6899. $collectHtml=array();
  6900. foreach ($accountList as $key=>$value){
  6901. $html="";$asum=0;
  6902. for ($i=1;$i<=12;$i++){
  6903. $falg=true;
  6904. foreach ($receiptCollectList as $v) {
  6905. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  6906. $asum+=$v['price'];
  6907. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  6908. }
  6909. }
  6910. if($falg)
  6911. $html.='<td class="taR">-</td>';
  6912. }
  6913. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  6914. $collectHtml[$value['category']][$value['name']]=$html;
  6915. }
  6916. $data['collectHtml']=$collectHtml;
  6917. //create Adjustment price html
  6918. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  6919. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  6920. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6921. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  6922. array_push($collectArray['日常相关费用'], $collectHtml);
  6923. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  6924. array_push($collectArray['差旅相关费用'], $collectHtml);
  6925. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  6926. array_push($collectArray['培训班费用'], $collectHtml);
  6927. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  6928. array_push($collectArray['其他'], $collectHtml);
  6929. $data['collectArray']=$collectArray;
  6930. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  6931. array_push($adjustment, $collectHtml);
  6932. $data['adjustment']=$adjustment;
  6933. //total price html
  6934. $collectHtml="";$total=0;
  6935. for ($i=1;$i<=12;$i++){
  6936. $sumPrice=0;
  6937. foreach ($receiptCollectList as $key=>$value){
  6938. if($value['month']==$i){
  6939. $sumPrice+=$value['price'];
  6940. }
  6941. }
  6942. if ($sumPrice==0)
  6943. $collectHtml.='<td class="taR">-</td>';
  6944. else
  6945. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  6946. $total+=$sumPrice;
  6947. }
  6948. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  6949. //statistics html
  6950. $stList=$statistics->statisticsByYear($year,$staffId);
  6951. if(empty($stList))
  6952. $stList=array('rePrice'=>0,'agPrice'=>0);
  6953. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6954. $data['totalPrice']=$collectHtml;
  6955. $data['totalYear']=$total;
  6956. $data['stHtml']=$stHtml;
  6957. $data['year']=$year;
  6958. $data['stTitle']=$stTitle;
  6959. $data['memu']="receipt";
  6960. $data['staff']=$this->staff;
  6961. $data['receiptMemu']='companyCategoryCollect';
  6962. $data['verifyId']=$this->verifyId;
  6963. $data['executeId']=$this->executeId;
  6964. if ($year<date("Y")){
  6965. Doo::loadModel('receipt');
  6966. $receipt=new receipt();
  6967. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  6968. if(empty($receiptList)){ //generated files
  6969. ob_start();
  6970. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6971. $this->cacheFile($path);die;
  6972. }
  6973. }
  6974. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6975. }
  6976. function BUGFLAG(){
  6977. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  6978. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  6979. $month=$this->get_args('month')?$this->get_args('month'):"";
  6980. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  6981. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  6982. if (empty($status))
  6983. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  6984. $page_size=12;
  6985. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  6986. $vidList=array();
  6987. $button=0;
  6988. Doo::loadModel('verify');
  6989. $verify=new verify();
  6990. Doo::loadModel('receipt');
  6991. $receipt=new receipt();
  6992. Doo::loadModel('staff');
  6993. $staff=new staff();
  6994. Doo::loadModel('L_category');
  6995. $Lcategory=new L_category();
  6996. $dateCondition=" and Year(date) =".$year;
  6997. if(!empty($month))
  6998. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  6999. $categoryList=$Lcategory->find(array('asArray'=>true));
  7000. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7001. $cateCondition="";$staffCondition="";$approvalCondition="";
  7002. if (!empty($cid))
  7003. $cateCondition=' and cid='.$cid;
  7004. if(!empty($sid)){
  7005. $staffCondition=' and staff='.$sid;
  7006. $cateCondition="";
  7007. }
  7008. $approvalCondition=" and status=".$status;
  7009. if($status==2){
  7010. //查找角色审批人
  7011. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7012. }
  7013. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7014. $approvalCondition=' and status=2 ';
  7015. }
  7016. if($status==1){
  7017. $approvalCondition=' and (status='.$status.' or status=6) ';
  7018. }
  7019. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7020. $pageinfo['page']=array('previous'=>'');
  7021. if ($status==0){
  7022. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7023. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7024. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7025. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7026. }else
  7027. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7028. ,'desc'=>'rid','asArray'=>true));
  7029. $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
  7030. ,'desc'=>'rid','asArray'=>true));
  7031. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7032. //print_r($pageinfo);
  7033. $Locate=0;
  7034. foreach ($receiptList as $key=>$value){
  7035. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7036. $receiptList[$key]['reviseDetail']=array();
  7037. if (!empty($value['reviseDetail']))
  7038. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7039. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7040. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7041. $receiptList[$key]['category']=$categoryDetil['title'];
  7042. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7043. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7044. $verifyStaff=json_decode($value['verifyStaff'],true);
  7045. foreach ($verifyList as $k=>$v){
  7046. //init verifyStaff
  7047. $verifyList[$k]['date']="";
  7048. $verifyList[$k]['opinion']="";
  7049. $verifyList[$k]['status']="";
  7050. if (empty($verifyStaff)){
  7051. $verifyList[$k]['date']="";
  7052. $verifyList[$k]['opinion']="";
  7053. if ($v[0]==$this->staff[0]['sid']){
  7054. $verifyList[$k]['status']=4;
  7055. $button=4;
  7056. }
  7057. }else{
  7058. $flag=true;
  7059. foreach ($verifyStaff as $m=>$u){
  7060. if ($v[0]==$m){
  7061. $verifyList[$k]['date']=$u['date'];
  7062. $verifyList[$k]['opinion']=$u['opinion'];
  7063. $verifyList[$k]['status']=$u['status'];
  7064. $flag=false;
  7065. break;
  7066. }
  7067. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7068. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7069. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7070. }
  7071. if($flag){//检测可编辑
  7072. if($v[0]==$this->staff[0]['sid']){
  7073. $verifyList[$k]['status']=4;$button=4;
  7074. }
  7075. }
  7076. }
  7077. }
  7078. $receiptList[$key]['verifyList']=$verifyList;
  7079. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7080. $receiptList[$key]['button']=$button;
  7081. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7082. }
  7083. //print_r($receiptList);die;
  7084. //$data['verifyDetail']=$verifyDetail;
  7085. $mothHtml="";
  7086. for($i=1;$i<=12;$i++){
  7087. if($month==$i)
  7088. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7089. else
  7090. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7091. }
  7092. $data['mothHtml']=$mothHtml;
  7093. $data['page']=$pageinfo;
  7094. $data['receiptList']=$receiptList;
  7095. $data['receiptApprovalCount']=count($rLRes);
  7096. $data['status']=$status;
  7097. $data['year']=$year;
  7098. $data['categoryList']=$categoryList;
  7099. $data['staffList']=$staffList;
  7100. $data['cid']=$cid;
  7101. $data['sid']=$sid;
  7102. //print_r($receiptList);
  7103. $data['memu']="receipt";
  7104. $data['staff']=$this->staff;
  7105. $data['receiptMemu']='approvalExpenses';
  7106. $data['verifyId']=$this->verifyId;
  7107. $data['executeId']=$this->executeId;
  7108. $this->render ( "/admin/FALG", $data );
  7109. }
  7110. function ajaxGetReceiptOrder(){
  7111. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7112. if (!empty($receiptOrder)){
  7113. Doo::loadModel('receipt');
  7114. $receipt=new receipt();
  7115. Doo::loadModel ( 'staff' );
  7116. $staff = new staff ();
  7117. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7118. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7119. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7120. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7121. </tbody></table><table class="table table table-bordered"><tbody>';
  7122. foreach ($verifyStaff as $key=>$value){
  7123. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7124. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7125. }
  7126. $html.='</tbody></table></div></div>';
  7127. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7128. }
  7129. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7130. }
  7131. function _getMonthCollectDetail($receiptCollectList){
  7132. if(!empty($receiptCollectList)){
  7133. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7134. $html="";
  7135. $psum=0;
  7136. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7137. foreach ($item as $value){
  7138. $falg=true;
  7139. foreach ($receiptCollectList as $v){
  7140. if($v['itemCategory']=='日常相关费用'){
  7141. if($v['item']==$value){
  7142. $psum+=$v['price'];
  7143. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7144. }
  7145. }
  7146. }
  7147. if($falg)
  7148. $html.='<td class="taR">-</td>';
  7149. }
  7150. if(!empty($psum))
  7151. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7152. else
  7153. $psum='<td class="colGreen taR">-</td>';
  7154. $receiptL['日常相关费用']=$psum.$html;
  7155. /*-----------------------------------*/
  7156. $html="";
  7157. $psum=0;
  7158. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7159. foreach ($item as $value){
  7160. $falg=true;
  7161. foreach ($receiptCollectList as $v){
  7162. if($v['itemCategory']=='差旅相关费用'){
  7163. if($v['item']==$value){
  7164. $psum+=$v['price'];
  7165. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7166. }
  7167. }
  7168. }
  7169. if($falg)
  7170. $html.='<td class="taR">-</td>';
  7171. }
  7172. if(!empty($psum))
  7173. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7174. else
  7175. $psum='<td class="colGreen taR">-</td>';
  7176. $receiptL['差旅相关费用']=$psum.$html;
  7177. /*-------------------------------------*/
  7178. $html="";
  7179. $psum=0;
  7180. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7181. foreach ($item as $value){
  7182. $falg=true;
  7183. foreach ($receiptCollectList as $v){
  7184. if($v['itemCategory']=='培训班费用'){
  7185. if($v['item']==$value){
  7186. $psum+=$v['price'];
  7187. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7188. }
  7189. }
  7190. }
  7191. if($falg)
  7192. $html.='<td class="taR">-</td>';
  7193. }
  7194. if(!empty($psum))
  7195. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7196. else
  7197. $psum='<td class="colGreen taR">-</td>';
  7198. $receiptL['培训班费用']=$psum.$html;
  7199. /*-------------------------------------*/
  7200. $html="";
  7201. $psum=0;
  7202. $item=array('公关费','广告费','借款','可自加费用');
  7203. foreach ($item as $value){
  7204. $falg=true;
  7205. foreach ($receiptCollectList as $v){
  7206. if($v['itemCategory']=='其他'){
  7207. if($v['item']==$value){
  7208. $psum+=$v['price'];
  7209. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7210. }
  7211. }
  7212. }
  7213. if($falg)
  7214. $html.='<td class="taR">-</td>';
  7215. }
  7216. if(!empty($psum))
  7217. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7218. else
  7219. $psum='<td class="colGreen taR">-</td>';
  7220. $receiptL['其他']=$psum.$html;
  7221. /*-------------------------------------*/
  7222. $html="";
  7223. $psum=0;
  7224. foreach ($receiptCollectList as $v){
  7225. if($v['itemCategory']=='报销金额调整'){
  7226. if (!empty($v['price']))
  7227. $psum+=$v['price'];
  7228. }
  7229. }
  7230. if(!empty($psum))
  7231. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7232. else
  7233. $psum='<td class="taR colOrange">-</td>';
  7234. $receiptL['报销金额调整']=$psum.$html;
  7235. }else{
  7236. $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>
  7237. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7238. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7239. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7240. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7241. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7242. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7243. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7244. }
  7245. return $receiptL;
  7246. }
  7247. function eMail(){
  7248. Doo::loadModel('staff');
  7249. $staff=new staff();
  7250. Doo::loadModel('receipt');
  7251. $receipt=new receipt();
  7252. Doo::loadModel('L_category');
  7253. $Lcategory=new L_category();
  7254. Doo::loadModel("verify");
  7255. $verify=new verify();
  7256. $staffList=$staff->find(array('asArray'=>true));
  7257. foreach ($staffList as $key=>$value){
  7258. if($value['username']!='admin'){
  7259. //提交人
  7260. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7261. if(!empty($receiptList)){
  7262. $html='<br><div><style></style>
  7263. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7264. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7265. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7266. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7267. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7268. <tbody><tr>
  7269. <td style="padding: 0 40px;" align="left">
  7270. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7271. </td></tr><tr>
  7272. <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>
  7273. </tr>
  7274. </tbody> </table></td> </tr> <tr><td>
  7275. <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">
  7276. <tbody> <tr><td>
  7277. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7278. 以下报销单完成了审批,等着收款吧:</p>
  7279. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7280. foreach ($receiptList as $k=>$v){
  7281. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7282. $html.='
  7283. <tr>
  7284. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7285. <td align="left">
  7286. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7287. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7288. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7289. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7290. </tr>';
  7291. }
  7292. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7293. <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>
  7294. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7295. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7296. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7297. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7298. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7299. $receipt=new receipt();
  7300. $receipt->notice=1;
  7301. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7302. }
  7303. }
  7304. //审批人
  7305. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7306. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7307. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7308. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7309. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7310. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7311. <tbody><tr><td style="padding: 0 40px;" align="left">
  7312. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7313. </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>
  7314. </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">
  7315. <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>
  7316. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7317. foreach ($verifyList as $k=>$v){
  7318. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7319. foreach ($receiptList as $r=>$l){
  7320. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7321. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7322. $html.='
  7323. <tr>
  7324. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7325. <td align="left">
  7326. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7327. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7328. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7329. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7330. </tr>';
  7331. }
  7332. }
  7333. $html.='
  7334. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7335. <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>
  7336. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7337. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7338. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7339. // $receipt=new receipt();
  7340. // $receipt->notice=1;
  7341. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7342. }
  7343. }
  7344. }
  7345. }
  7346. // Email发送函数
  7347. function SMail($toemail, $subject, $contents) {
  7348. Doo::loadClass('class.phpmailer');
  7349. $mail = new PHPMailer();
  7350. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7351. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7352. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7353. $mail->Password = "cDO1GjtY1seH"; //密码
  7354. $mail->CharSet = "UTF8";
  7355. $mail->SMTPAuth = true;
  7356. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7357. $mail->Mailer = "smtp";
  7358. $mail->Port = 25;
  7359. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7360. $mail->MsgHTML($contents);
  7361. $mail->AddAddress($toemail);
  7362. $mail->CharSet = "UTF-8";
  7363. return $mail->Send();
  7364. }
  7365. function swfupload(){
  7366. $POST_MAX_SIZE = ini_get('post_max_size');
  7367. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7368. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7369. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7370. header("HTTP/1.1 500 Internal Server Error");
  7371. echo "POST exceeded maximum allowed size.";
  7372. exit(0);
  7373. }
  7374. // Settings
  7375. $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)
  7376. $upload_name = "Filedata";
  7377. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7378. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7379. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7380. // Other variables
  7381. $MAX_FILENAME_LENGTH = 260;
  7382. $file_name = "";
  7383. $file_extension = "";
  7384. $uploadErrors = array(
  7385. 0=>"文件上传成功",
  7386. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7387. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7388. 3=>"上传的文件仅为部分文件",
  7389. 4=>"没有文件上传",
  7390. 6=>"缺少临时文件夹"
  7391. );
  7392. $nk= time();
  7393. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7394. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7395. echo "文件无法保存.";
  7396. exit(0);
  7397. }
  7398. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7399. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7400. exit(0);
  7401. }
  7402. function _GetFileEXT($filename) {
  7403. $pics = explode ( '.', $filename );
  7404. $num = count ( $pics );
  7405. return $pics [$num - 1];
  7406. }
  7407. /**
  7408. * 获取get或者POST值
  7409. * @param string $name 属性名称
  7410. * @return fixed 值
  7411. */
  7412. function get_args($name) {
  7413. if (isset ( $_GET [$name] )) {
  7414. if (is_array ( $_GET [$name] ))
  7415. return $_GET [$name];
  7416. else
  7417. return addslashes ( $_GET [$name] );
  7418. } elseif (isset ( $_POST [$name] )) {
  7419. if (is_array ( $_POST [$name] ))
  7420. return $_POST [$name];
  7421. else
  7422. return addslashes ( $_POST [$name] );
  7423. } else
  7424. return false;
  7425. }
  7426. function num_to_rmb($num){
  7427. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7428. $c2 = "分角元拾佰仟万拾佰仟亿";
  7429. //精确到分后面就不要了,所以只留两个小数位
  7430. $num = round($num, 2);
  7431. //将数字转化为整数
  7432. $num = $num * 100;
  7433. if (strlen($num) > 10) {
  7434. return "金额太大,请检查";
  7435. }
  7436. $i = 0;
  7437. $c = "";
  7438. while (1) {
  7439. if ($i == 0) {
  7440. //获取最后一位数字
  7441. $n = substr($num, strlen($num)-1, 1);
  7442. } else {
  7443. $n = $num % 10;
  7444. }
  7445. //每次将最后一位数字转化为中文
  7446. $p1 = substr($c1, 3 * $n, 3);
  7447. $p2 = substr($c2, 3 * $i, 3);
  7448. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7449. $c = $p1 . $p2 . $c;
  7450. } else {
  7451. $c = $p1 . $c;
  7452. }
  7453. $i = $i + 1;
  7454. //去掉数字最后一位了
  7455. $num = $num / 10;
  7456. $num = (int)$num;
  7457. //结束循环
  7458. if ($num == 0) {
  7459. break;
  7460. }
  7461. }
  7462. $j = 0;
  7463. $slen = strlen($c);
  7464. while ($j < $slen) {
  7465. //utf8一个汉字相当3个字符
  7466. $m = substr($c, $j, 6);
  7467. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7468. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7469. $left = substr($c, 0, $j);
  7470. $right = substr($c, $j + 3);
  7471. $c = $left . $right;
  7472. $j = $j-3;
  7473. $slen = $slen-3;
  7474. }
  7475. $j = $j + 3;
  7476. }
  7477. //这个是为了去掉类似23.0中最后一个“零”字
  7478. if (substr($c, strlen($c)-3, 3) == '零') {
  7479. $c = substr($c, 0, strlen($c)-3);
  7480. }
  7481. //将处理的汉字加上“整”
  7482. if (empty($c)) {
  7483. return "零元整";
  7484. }else{
  7485. return $c . "整";
  7486. }
  7487. }
  7488. /**
  7489. * 获得分页数据
  7490. * @param unknown_type $table
  7491. * @param unknown_type $condition
  7492. * @param unknown_type $on_page
  7493. * @param unknown_type $page_size
  7494. */
  7495. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7496. $page_c = "";
  7497. $page ['previous'] = $this->get_previous ( $on_page );
  7498. $page ['on_page'] = $on_page;
  7499. $total_count = $this->get_table_count ( $table, $condition );
  7500. $total = intval ( $total_count / $page_size );
  7501. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7502. $page ['total_data'] = $total_count;
  7503. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7504. $i = 1;
  7505. $page_max = 1;
  7506. $page_width=3;
  7507. if ($on_page >= $page_width) {
  7508. $page_max = intval ( $on_page / $page_width ) + 1;
  7509. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7510. }
  7511. for(; $i <= $page ['total_page']; $i ++) {
  7512. if ($i == $on_page)
  7513. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7514. else
  7515. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7516. if ($i == ($page_width * $page_max))
  7517. break;
  7518. }
  7519. $page ['page'] = $page_c;
  7520. $page ['lower'] = (-- $on_page) * $page_size;
  7521. return $page;
  7522. }
  7523. /**
  7524. * 获取总页数
  7525. * @param unknown_type $table
  7526. * @param unknown_type $condition
  7527. */
  7528. public function get_table_count($table = "", $condition = "") {
  7529. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7530. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7531. //echo $sql;die;
  7532. $query = Doo::db ()->query ( $sql );
  7533. $result = $query->fetch ();
  7534. return $result ['count'];
  7535. }
  7536. /**
  7537. * 获取上一页
  7538. * @param unknown_type $on_page
  7539. */
  7540. function get_previous($on_page = 1) {
  7541. return $on_page != 0 ? $on_page - 1 : $on_page;
  7542. }
  7543. }
  7544. ?>