ReceiptController.php 303 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. //public static $NEW2 = 0;
  10. public $AGENCY="日常相关费用";
  11. public $TRAVEL="差旅相关费用";
  12. public $TRAIN="培训班费用";
  13. public $OTHER="其他";
  14. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  18. private function showCache($path){
  19. if(file_exists($path)){
  20. echo "<!DOCTYPE html>";
  21. include $path;die;
  22. }
  23. }
  24. private function cacheFile($path){
  25. $content = ob_get_contents();
  26. $fp = fopen($path, "w");
  27. fwrite($fp, $content);
  28. fclose($fp);
  29. }
  30. // private function getExeCount(){
  31. // Doo::loadModel('receipt');
  32. // $receipt=new receipt();
  33. // $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  34. // return count($receiptList);
  35. // }
  36. // private function getReceiptCount(){
  37. // $status=2;
  38. // $year=date('Y');
  39. // Doo::loadModel('receipt');
  40. // $receipt=new receipt();
  41. // $dateCondition=" and Year(date) =".$year;
  42. // $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  43. // $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  44. // return count($receiptList);
  45. // }
  46. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  47. $collectHtml="";$sumPrice=0.00;
  48. for ($i=1;$i<=12;$i++){
  49. $falg=true;
  50. foreach ($receiptCollectList as $key=>$value){
  51. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  52. $sumPrice+=$value['price'];
  53. if ($classType=="b"){
  54. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  55. }else{
  56. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  57. }
  58. }
  59. }
  60. if ($falg)
  61. $collectHtml.='<td class="taR">-</td>';
  62. }
  63. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  64. return $collectHtml;
  65. }
  66. function __construct() {
  67. if(isset($_COOKIE["staff"])){
  68. if(!empty($_COOKIE["staff"])){
  69. Doo::loadModel ( 'staff' );
  70. Doo::loadModel('verify');
  71. $verify=new verify();
  72. $staff = new staff ();
  73. Doo::loadModel("execute");
  74. $execute=new execute();
  75. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  76. $list=array();
  77. //判断角色的审批权限
  78. foreach ($verifyList as $key=>$value){
  79. $ver=json_decode($value['staff']);
  80. foreach ($ver as $k=>$v){
  81. if ($v[1]=='ROLE'){
  82. $roleList=json_decode($v[3]);
  83. foreach ($roleList as $t=>$g){
  84. $gList=explode("_", $g);
  85. array_push($list, $gList[0]);
  86. //print_r($list);
  87. }
  88. }else
  89. array_push($list, $v[0]);
  90. }
  91. }
  92. //判断执行人的审批权限
  93. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  94. $list2=array();
  95. foreach ($executeList as $key=>$value){
  96. $ver=json_decode($value['staff']);
  97. foreach ($ver as $k=>$v){
  98. array_push($list2, $v[0]);
  99. }
  100. }
  101. $eidList=file_get_contents("protected/config/execute/execute.ini");
  102. $eidList=array_filter(explode(",", $eidList));
  103. $this->executeId= array_merge($list2,$eidList);
  104. $this->verifyId=$list;
  105. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  106. return "/";
  107. }
  108. }
  109. Doo::loadCore ( 'uri/DooUriRouter' );
  110. $router = new DooUriRouter ();
  111. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  112. if($routeRs['1']!="login"){
  113. header ( 'Content-Type:text/html;charset=utf-8' );
  114. @header ( "Location: /login" );
  115. }
  116. }
  117. function saeaBorad(){
  118. Doo::loadModel('receipt');
  119. Doo::loadModel('verify');
  120. $verify=new verify();
  121. $receipt=new receipt();
  122. Doo::loadModel('L_category');
  123. $lCategory=new L_category();
  124. Doo::loadModel("role");
  125. $role=new role();
  126. Doo::loadModel("receiptLog");
  127. $receiptLog=new receiptLog();
  128. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  129. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)','desc'=>'rid','asArray'=>true));
  130. foreach ($receiptDetail as $key=>$value){
  131. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  132. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  133. $v=json_decode($veList['staff']);
  134. array_push($v[0], $veList['description']);
  135. foreach ($v as $n=>$m){
  136. if ($m['1']=='ROLE'){
  137. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  138. $v[$n][1]=$roleInfo['name'];
  139. }
  140. }
  141. $receiptDetail[$key]['staff']=$v;
  142. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  143. $receiptDetail[$key]['category']=$category['title'];
  144. }
  145. //print_r($receiptLogList);
  146. $data['receiptLogList']=$receiptLogList;
  147. $data['receiptDetail']=$receiptDetail;
  148. $data['memu']="receipt";
  149. $data['staff']=$this->staff;
  150. $data['receiptMemu']='saeaBorad';
  151. $data['verifyId']=$this->verifyId;
  152. $data['executeId']=$this->executeId;
  153. $this->render ( "/admin/saeaBorad", $data );
  154. }
  155. function remitAdd(){
  156. Doo::loadModel('accountItem');
  157. Doo::loadModel('verify');
  158. Doo::loadModel('receipt');
  159. Doo::loadModel('L_category');
  160. $lCategory=new L_category();
  161. $receipt=new receipt();
  162. $verify=new verify();
  163. $accountItem=new accountItem();
  164. Doo::loadModel("role");
  165. $role=new role();
  166. $acItem=$accountItem->find(array('asArray'=>true));
  167. $veList=$verify->find(array('asArray'=>true));
  168. foreach ($veList as $key=>$value){
  169. $v=json_decode($value['staff']);
  170. $list=array();
  171. foreach ($v as $n=>$m){
  172. if ($m['1']=='ROLE'){
  173. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  174. $v[$n][1]=$roleInfo['name'];
  175. array_push($list, $roleInfo['name']);
  176. }else{
  177. array_push($list, $v[$n][1]);
  178. }
  179. }
  180. $veList[$key]['staff']=implode('>', $list);
  181. }
  182. $data['category']=$lCategory->find(array('asArray'=>true));
  183. $data['veList']=$veList;
  184. $data['acItem']=$acItem;
  185. $data['memu']="receipt";
  186. $data['staff']=$this->staff;
  187. $data['receiptMemu']='saeaBorad';
  188. $data['verifyId']=$this->verifyId;
  189. $data['executeId']=$this->executeId;
  190. $this->render ( "/admin/remitAdd", $data );
  191. }
  192. function remitAddDo(){
  193. $agency=$this->get_args('agency');
  194. $travel=$this->get_args('travel');
  195. $train=$this->get_args('train');
  196. $other=$this->get_args('other');
  197. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  198. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  199. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  200. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  201. //print_r($agency);die;
  202. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  203. Doo::loadModel('receipt');
  204. Doo::loadModel('receiptDetail');
  205. Doo::loadModel('accountItem');
  206. $accountItem=new accountItem();
  207. $receipt=new receipt();
  208. Doo::loadModel('enclosur');
  209. Doo::loadModel('execute');
  210. $execute=new execute();
  211. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  212. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  213. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  214. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  215. $ag=$tr=$ta=$ot=0;
  216. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  217. foreach ($aItem as $key=>$value){
  218. if ($value['category']==$this->AGENCY){
  219. if (isset($agency[$ag])){
  220. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  221. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  222. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  223. }
  224. }
  225. $ag++;
  226. }
  227. }
  228. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  229. //报销单
  230. $receipt->accountItem=json_encode($accountJson);
  231. $receipt->staff=$this->staff[0]['sid'];
  232. $receipt->sum=number_format($sum, 2, '.', '');
  233. $receipt->date=date("Y-m-d");
  234. $receipt->cid=$cid;
  235. $receipt->status=5;
  236. $receipt->Rtype=2;
  237. //修改审批流程加入角色
  238. $receipt->verify=$verify;
  239. $receipt->executeCopy=$executeDetail['staff'];
  240. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  241. $receipt->explanation=$explanation;
  242. $rid=$receipt->insert();
  243. //附件
  244. if (!empty($enclosurName)){
  245. $enclosurArray=explode('-', $enclosurName);
  246. foreach ($enclosurArray as $value){
  247. $enclosur=new enclosur();
  248. $enclosur->name=$value;
  249. $enclosur->rid=$rid;
  250. $enclosur->insert();
  251. }
  252. //print_r($enclosurArray);die;
  253. }
  254. //报销详情
  255. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  256. $receiptDetail=new receiptDetail();
  257. $receiptDetail->staff=$this->staff[0]['sid'];
  258. $receiptDetail->item=$value['name'];
  259. $receiptDetail->itemCategory=$this->AGENCY;
  260. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  261. $receiptDetail->date=date("Y-m-d");
  262. $receiptDetail->cid=$cid;
  263. $receiptDetail->rid=$rid;
  264. $receiptDetail->status=4;
  265. $receiptDetail->insert();
  266. }
  267. }
  268. return "/saeaBorad";
  269. }
  270. function remitEdit(){
  271. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  272. //echo $rid;
  273. Doo::loadModel('accountItem');
  274. Doo::loadModel('verify');
  275. Doo::loadModel('receipt');
  276. $receipt=new receipt();
  277. $verify=new verify();
  278. $accountItem=new accountItem();
  279. Doo::loadModel('L_category');
  280. $lCategory=new L_category();
  281. Doo::loadModel("role");
  282. $role=new role();
  283. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  284. if(empty($receiptDetail))
  285. return "/saeaCreate";
  286. $acItem=$accountItem->find(array('asArray'=>true));
  287. $veList=$verify->find(array('asArray'=>true));
  288. foreach ($veList as $key=>$value){
  289. $v=json_decode($value['staff']);
  290. $list=array();
  291. foreach ($v as $n=>$m){
  292. if ($m['1']=='ROLE'){
  293. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  294. $v[$n][1]=$roleInfo['name'];
  295. array_push($list, $roleInfo['name']);
  296. }else{
  297. array_push($list, $v[$n][1]);
  298. }
  299. }
  300. $veList[$key]['staff']=implode('>', $list);
  301. }
  302. //配置编辑信息
  303. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  304. foreach ($acItem as $key=>$value){
  305. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  306. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  307. $acItem[$key]['price']=$v['price'];
  308. }
  309. }
  310. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  311. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  312. $acItem[$key]['price']=$v['price'];
  313. }
  314. }
  315. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  316. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  317. $acItem[$key]['price']=$v['price'];
  318. }
  319. }
  320. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  321. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  322. $acItem[$key]['price']=$v['price'];
  323. }
  324. }
  325. }
  326. $data['category']=$lCategory->find(array('asArray'=>true));
  327. $data['cSum']=$accountItemList['cSum'];
  328. $data['sum']=$receiptDetail['sum'];
  329. $data['receiptDetail']=$receiptDetail;
  330. $data['veList']=$veList;
  331. $data['acItem']=$acItem;
  332. $data['memu']="receipt";
  333. $data['staff']=$this->staff;
  334. $data['receiptMemu']='saeaBorad';
  335. $data['verify']=$receiptDetail['verify'];
  336. $data['verifyId']=$this->verifyId;
  337. $data['executeId']=$this->executeId;
  338. $data['rid']=$rid;
  339. $this->render ( "/admin/remitEdit", $data );
  340. }
  341. function remitEdiDo(){
  342. $agency=$this->get_args('agency');
  343. $travel=$this->get_args('travel');
  344. $train=$this->get_args('train');
  345. $other=$this->get_args('other');
  346. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  347. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  348. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  349. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  350. if(!empty($explanation)){
  351. Doo::loadModel('receipt');
  352. Doo::loadModel('receiptDetail');
  353. Doo::loadModel('accountItem');
  354. $accountItem=new accountItem();
  355. $receipt=new receipt();
  356. Doo::loadModel('execute');
  357. $execute=new execute();
  358. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  359. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  360. if(empty($receiptDetail))
  361. return "/saeaBorad";
  362. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  363. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  364. $ag=$tr=$ta=$ot=0;
  365. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  366. foreach ($aItem as $key=>$value){
  367. if ($value['category']==$this->AGENCY){
  368. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  369. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  370. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  371. }
  372. $ag++;
  373. }
  374. }
  375. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  376. //报销单
  377. $rid=$receipt->rid=$receiptDetail['rid'];
  378. $receipt->accountItem=json_encode($accountJson);
  379. $receipt->staff=$this->staff[0]['sid'];
  380. $receipt->sum=number_format($sum, 2, '.', '');
  381. $receipt->date=date("Y-m-d");
  382. $receipt->cid=$cid;
  383. if ($receiptDetail['Rtype']==1)
  384. $receipt->status=7;
  385. else
  386. $receipt->status=5;
  387. if ($receiptDetail['status']!=4&&!empty($verify))
  388. $receipt->verify=$verify;
  389. $receipt->executeCopy=$executeDetail['staff'];
  390. $receipt->explanation=$explanation;
  391. $receipt->update();
  392. $receiptDetail=new receiptDetail();
  393. $receiptDetail->delete(array('where'=>'rid='.$rid));
  394. //报销详情
  395. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  396. $receiptDetail=new receiptDetail();
  397. $receiptDetail->staff=$this->staff[0]['sid'];
  398. $receiptDetail->item=$value['name'];
  399. $receiptDetail->itemCategory=$this->AGENCY;
  400. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  401. $receiptDetail->date=date("Y-m-d");
  402. $receiptDetail->cid=$cid;
  403. $receiptDetail->rid=$rid;
  404. $receiptDetail->status=4;
  405. $receiptDetail->insert();
  406. }
  407. //return "/referReceipt/".$rid;
  408. }
  409. return "/saeaBorad";
  410. }
  411. function remitApproval(){
  412. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  413. $status=isset($this->params['status'])?$this->params['status']:'';
  414. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  415. $month=$this->get_args('month')?$this->get_args('month'):"";
  416. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  417. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  418. if (empty($status))
  419. $status=$this->get_args('status')?$this->get_args('status'):2;
  420. $vidList=array();
  421. $button=0;
  422. Doo::loadModel('verify');
  423. Doo::loadModel('receipt');
  424. Doo::loadModel('staff');
  425. $staff=new staff();
  426. $receipt=new receipt();
  427. $verify=new verify();
  428. Doo::loadModel('L_category');
  429. $Lcategory=new L_category();
  430. Doo::loadModel('enclosur');
  431. $enclosur=new enclosur();
  432. //user verify ID
  433. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  434. foreach ($verifyDetail as $key=>$value){
  435. array_push($vidList, $value['vid']);
  436. }
  437. $vid=implode(",", $vidList);
  438. if(empty($verifyDetail))
  439. $vid=0;
  440. $categoryList=$Lcategory->find(array('asArray'=>true));
  441. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  442. $ap="";
  443. if($status==4){
  444. $ap=4;$status=2;
  445. }
  446. //get Receipt By verifyID status 2
  447. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  448. $Locate=0;$roleId=0;
  449. if($ap==4)
  450. $status=4;
  451. foreach ($receiptList as $key=>$value){
  452. $receiptList[$key]['Locate']=$Locate;$Locate++;
  453. $receiptList[$key]['reviseDetail']=array();
  454. if (!empty($value['reviseDetail']))
  455. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  456. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  457. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  458. $receiptList[$key]['category']=$categoryDetil['title'];
  459. //检测编辑状态
  460. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  461. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  462. $verifyStaff=json_decode($value['verifyStaff'],true);
  463. Doo::loadModel('role');
  464. $role=new role();
  465. //print_r($verifyList);
  466. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  467. foreach ($verifyList as $k=>$v){
  468. //init verifyStaff
  469. if ($v[1]=='ROLE'){
  470. if (!empty($verifyStaff)){
  471. $endStaffArray=end($verifyStaff);
  472. if ($v[0]==$endStaffArray['nextStaff']){
  473. $roleId=$v[0];
  474. }
  475. }
  476. $roleVerify=json_decode($v[3],true);
  477. $roleKey=$k;$roleArray=array();
  478. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  479. foreach ($roleVerify as $o=>$p){
  480. $staffID=explode ('_',$p);
  481. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  482. //print_r($staffID);
  483. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  484. array_push($roleArray, $exp);
  485. }
  486. $roleArrayCopy[$v[0]]=$roleArray;
  487. //$verifyList[$k]['roleArray']=$roleArray;
  488. }
  489. //print_r($roleArray);
  490. $verifyList[$k]['date']="";
  491. $verifyList[$k]['opinion']="";
  492. $verifyList[$k]['status']="";
  493. if (empty($verifyStaff)){
  494. $verifyList[$k]['date']="";
  495. $verifyList[$k]['opinion']="";
  496. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  497. $verifyList[$k]['status']=4;
  498. $button=4;$flag=false;
  499. }
  500. }else{
  501. foreach ($verifyStaff as $m=>$u){
  502. if ($v[0]==$m){
  503. $verifyList[$k]['date']=$u['date'];
  504. $verifyList[$k]['opinion']=$u['opinion'];
  505. $verifyList[$k]['status']=$u['status'];
  506. $flag=false;
  507. break;
  508. }
  509. }
  510. $endStaffArray=end($verifyStaff);
  511. if (isset($endStaffArray['ROLE'])){
  512. }else{
  513. $endKey=key($verifyStaff);
  514. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  515. $button=4;
  516. $verifyList[$k]['status']=4;
  517. }
  518. }
  519. }
  520. }
  521. $rolename['name']='';
  522. if (!empty($roleId)){
  523. Doo::loadModel('role');
  524. $role=new role();
  525. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  526. }
  527. if (!empty($verifyStaff))
  528. $endStaffArray=end($verifyStaff);
  529. $KOP=false;
  530. foreach ($roleArrayCopy as $P=>$A){
  531. foreach ( $A as $MKI=>$AVL){
  532. if (!empty($verifyStaff)){
  533. //&&$rolename['rid']==$endStaffArray['nextStaff']
  534. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  535. $button=4;
  536. $roleArrayCopy[$P][$MKI]['status']=4;
  537. }
  538. foreach ($verifyStaff as $m=>$u){
  539. $AVLFK=$AVL[0].'_R';
  540. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  541. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  542. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  543. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  544. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  545. break;
  546. }
  547. }
  548. }else{
  549. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  550. $button=4;
  551. $roleArrayCopy[$P][$MKI]['status']=4;
  552. }
  553. }
  554. //$roleArray[$MKI]['rolename']=$rolename['name'];
  555. $KOP=true;
  556. }
  557. }
  558. foreach ($roleArrayCopy as $k=>$v){
  559. foreach ($verifyList as $m=>$n){
  560. if ($n[0]==$k){
  561. array_splice($verifyList,$m,1,$v);
  562. }
  563. }
  564. }
  565. $receiptList[$key]['verifyList']= $verifyList;
  566. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  567. $receiptList[$key]['button']=$button;
  568. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  569. }
  570. $mothHtml="";
  571. for($i=1;$i<=12;$i++){
  572. if($month==$i)
  573. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  574. else
  575. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  576. }
  577. //获取审批日志
  578. Doo::loadModel('receiptLog');
  579. $receiptLog=new receiptLog();
  580. $rlList=array();
  581. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  582. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  583. if (!empty($rlInfo)){
  584. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  585. }
  586. $receiptList[0]['rlList']=$rlList;
  587. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  588. $enclosurHtml='';
  589. foreach ($enclosurList as $value){
  590. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  591. }
  592. //print_r($receiptList);
  593. $data['enclosurHtml']=$enclosurHtml;
  594. $data['rolename']=$rolename['name'];
  595. $data['datetij']=$tijdate['date'];
  596. $data['mothHtml']=$mothHtml;
  597. $data['rid']=$rid;
  598. $data['receiptList']=$receiptList;
  599. $data['receiptApprovalCount']=count($receiptList);
  600. $data['status']=$status;
  601. $data['year']=$year;
  602. $data['categoryList']=$categoryList;
  603. $data['staffList']=$staffList;
  604. $data['cid']=$cid;
  605. $data['sid']=$sid;
  606. $data['ap']=$ap;
  607. $data['memu']="receipt";
  608. $data['staff']=$this->staff;
  609. $data['receiptMemu']='approvalExpenses';
  610. $data['verifyId']=$this->verifyId;
  611. $data['executeId']=$this->executeId;
  612. $this->render ( "/admin/remitApproval", $data );
  613. }
  614. function saeaLoanAdd(){
  615. Doo::loadModel('verify');
  616. $verify=new verify();
  617. Doo::loadModel("role");
  618. $role=new role();
  619. Doo::loadModel('L_category');
  620. $lCategory=new L_category();
  621. $veList=$verify->find(array('asArray'=>true));
  622. foreach ($veList as $key=>$value){
  623. $v=json_decode($value['staff']);
  624. $list=array();
  625. foreach ($v as $n=>$m){
  626. if ($m['1']=='ROLE'){
  627. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  628. $v[$n][1]=$roleInfo['name'];
  629. array_push($list, $roleInfo['name']);
  630. }else{
  631. array_push($list, $v[$n][1]);
  632. }
  633. }
  634. $veList[$key]['staff']=implode('>', $list);
  635. }
  636. $data['category']=$lCategory->find(array('asArray'=>true));
  637. $data['veList']=$veList;
  638. $data['memu']="receipt";
  639. $data['staff']=$this->staff;
  640. $data['receiptMemu']='saeaBorad';
  641. $data['verifyId']=$this->verifyId;
  642. $data['executeId']=$this->executeId;
  643. $this->render ( "/admin/saeaLoanAdd", $data );
  644. }
  645. function saeaLoanAddDo(){
  646. $agency=$this->get_args('agency');
  647. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  648. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  649. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  650. //die;
  651. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  652. Doo::loadModel('receipt');
  653. Doo::loadModel('receiptDetail');
  654. Doo::loadModel('accountItem');
  655. $accountItem=new accountItem();
  656. $receipt=new receipt();
  657. Doo::loadModel('loanReceipt');
  658. $loanReceipt=new loanReceipt();
  659. Doo::loadModel('execute');
  660. $execute=new execute();
  661. Doo::loadModel('enclosur');
  662. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  663. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  664. // if(!empty($receiptDetail))
  665. // return "/referReceipt/".$receiptDetail['rid'];
  666. $aItem=$accountItem->find(array('asArray'=>true));
  667. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  668. $ag=$tr=$ta=$ot=0;
  669. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  670. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  671. $sum+=$agency;$agencySum+=$agency;
  672. $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, '.', ''));
  673. //借款数据备份
  674. $loanReceipt->loanItem=json_encode($accountJson);
  675. $loanReceipt->staff=$this->staff[0]['sid'];
  676. $loanReceipt->sum=number_format($sum, 2, '.', '');
  677. $loanReceipt->date=date("Y-m-d");
  678. $loanReceipt->cid=$cid;
  679. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  680. $loanReceipt->status=5;
  681. $loanReceipt->Rtype=1;
  682. $loanReceipt->verify=$verify;
  683. $receipt->receiptOrder=$receipt->receiptOrder;
  684. $loanReceipt->explanation=$explanation;
  685. $loanRid=$loanReceipt->insert();
  686. //报销单
  687. $receipt->loanItem=json_encode($accountJson);
  688. $receipt->staff=$this->staff[0]['sid'];
  689. $receipt->sum=number_format($sum, 2, '.', '');
  690. $receipt->date=date("Y-m-d");
  691. $receipt->cid=$cid;
  692. //特殊状态
  693. $receipt->status=5;
  694. $receipt->Rtype=1;
  695. $receipt->loanRid=$loanRid;
  696. //修改审批流程加入角色
  697. $receipt->verify=$verify;
  698. $receipt->executeCopy=$executeDetail['staff'];
  699. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  700. $receipt->explanation=$explanation;
  701. $rid=$receipt->insert();
  702. //执行数据备份
  703. // $executeCopy->rid=$rid;
  704. // $executeCopy->staff=$executeDetail['staff'];
  705. // $executeCopy->eid=$executeDetail['eid'];
  706. // $ecid=$executeCopy->insert();
  707. }
  708. return "/saeaBorad";
  709. }
  710. function saeaLoanEdi(){
  711. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  712. Doo::loadModel('verify');
  713. $verify=new verify();
  714. Doo::loadModel("role");
  715. $role=new role();
  716. Doo::loadModel('L_category');
  717. $lCategory=new L_category();
  718. Doo::loadModel('receipt');
  719. $receipt=new receipt();
  720. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  721. $veList=$verify->find(array('asArray'=>true));
  722. foreach ($veList as $key=>$value){
  723. $v=json_decode($value['staff']);
  724. $list=array();
  725. foreach ($v as $n=>$m){
  726. if ($m['1']=='ROLE'){
  727. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  728. $v[$n][1]=$roleInfo['name'];
  729. array_push($list, $roleInfo['name']);
  730. }else{
  731. array_push($list, $v[$n][1]);
  732. }
  733. }
  734. $veList[$key]['staff']=implode('>', $list);
  735. }
  736. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  737. $data['receiptInfo']=$receiptInfo;
  738. $data['category']=$lCategory->find(array('asArray'=>true));
  739. $data['veList']=$veList;
  740. $data['memu']="receipt";
  741. $data['staff']=$this->staff;
  742. $data['receiptMemu']='saeaBorad';
  743. $data['verifyId']=$this->verifyId;
  744. $data['executeId']=$this->executeId;
  745. $this->render ( "/admin/saeaLoanEdi", $data );
  746. }
  747. function saeaLoanEdiDo(){
  748. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  749. $agency=$this->get_args('agency');
  750. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  751. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  752. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  753. //die;
  754. if(!empty($cid)&&!empty($explanation)&&!empty($rid)){
  755. Doo::loadModel('receipt');
  756. Doo::loadModel('receiptDetail');
  757. Doo::loadModel('accountItem');
  758. $accountItem=new accountItem();
  759. $receipt=new receipt();
  760. Doo::loadModel('loanReceipt');
  761. $loanReceipt=new loanReceipt();
  762. Doo::loadModel('enclosur');
  763. Doo::loadModel('execute');
  764. $execute=new execute();
  765. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  766. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=5 or status=4) and rid='.$rid,'asArray'=>true));
  767. if(empty($receiptDetail))
  768. die('参数错误');
  769. $aItem=$accountItem->find(array('asArray'=>true));
  770. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  771. $ag=$tr=$ta=$ot=0;
  772. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  773. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  774. $sum+=$agency;$agencySum+=$agency;
  775. $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, '.', ''));
  776. //报销单
  777. $receipt->loanItem=json_encode($accountJson);
  778. $receipt->sum=number_format($sum, 2, '.', '');
  779. $receipt->cid=$cid;
  780. //特殊状态
  781. //修改审批流程加入角色
  782. if ($receiptDetail['status']!=4)
  783. $receipt->verify=$verify;
  784. $receipt->explanation=$explanation;
  785. $receipt->update(array('where'=>'rid='.$rid));
  786. //借款数据更新
  787. $loanReceipt->loanItem=json_encode($accountJson);
  788. $loanReceipt->sum=number_format($sum, 2, '.', '');
  789. $loanReceipt->cid=$cid;
  790. if ($receiptDetail['status']!=4)
  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($dateCondition,$this->staff[0]['sid']);
  1405. if(!isset($noPassSum['sum']))
  1406. $noPassSum['sum']=0;
  1407. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($noPassSum['sum']));
  1408. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1409. $Locate=0;$roleId=0;$button=0;
  1410. foreach ($receiptList as $key=>$value){
  1411. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1412. $receiptList[$key]['reviseDetail']=array();
  1413. if (!empty($value['reviseDetail']))
  1414. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1415. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1416. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1417. $receiptList[$key]['category']=$categoryDetil['title'];
  1418. //检测编辑状态
  1419. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1420. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1421. $verifyStaff=json_decode($value['verifyStaff'],true);
  1422. Doo::loadModel('role');
  1423. $role=new role();
  1424. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1425. foreach ($verifyList as $k=>$v){
  1426. //init verifyStaff
  1427. if ($v[1]=='ROLE'){
  1428. if (!empty($verifyStaff)){
  1429. $endStaffArray=end($verifyStaff);
  1430. // if ($v[0]==$endStaffArray['nextStaff']){
  1431. // $roleId=$v[0];
  1432. // }
  1433. }
  1434. $roleVerify=json_decode($v[3],true);
  1435. $roleKey=$k;$roleArray=array();
  1436. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1437. foreach ($roleVerify as $o=>$p){
  1438. $staffID=explode ('_',$p);
  1439. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1440. //print_r($staffID);
  1441. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1442. array_push($roleArray, $exp);
  1443. }
  1444. $roleArrayCopy[$v[0]]=$roleArray;
  1445. //$verifyList[$k]['roleArray']=$roleArray;
  1446. }
  1447. $verifyList[$k]['date']="";
  1448. $verifyList[$k]['opinion']="";
  1449. $verifyList[$k]['status']="";
  1450. if (empty($verifyStaff)){
  1451. $verifyList[$k]['date']="";
  1452. $verifyList[$k]['opinion']="";
  1453. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1454. $verifyList[$k]['status']=4;
  1455. $flag=false;
  1456. }
  1457. }else{
  1458. foreach ($verifyStaff as $m=>$u){
  1459. if ($v[0]==$m){
  1460. $verifyList[$k]['date']=$u['date'];
  1461. $verifyList[$k]['opinion']=$u['opinion'];
  1462. $verifyList[$k]['status']=$u['status'];
  1463. $flag=false;
  1464. break;
  1465. }
  1466. }
  1467. $endStaffArray=end($verifyStaff);
  1468. if (isset($endStaffArray['ROLE'])){
  1469. }else{
  1470. // $endKey=key($verifyStaff);
  1471. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1472. // $button=4;
  1473. // $verifyList[$k]['status']=4;
  1474. // }
  1475. }
  1476. }
  1477. }
  1478. $rolename['name']='';
  1479. if (!empty($roleId)){
  1480. Doo::loadModel('role');
  1481. $role=new role();
  1482. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1483. }
  1484. if (!empty($verifyStaff))
  1485. $endStaffArray=end($verifyStaff);
  1486. $KOP=false;
  1487. foreach ($roleArrayCopy as $P=>$A){
  1488. foreach ( $A as $MKI=>$AVL){
  1489. if (!empty($verifyStaff)){
  1490. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1491. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1492. $button=4;
  1493. $roleArrayCopy[$P][$MKI]['status']=4;
  1494. }
  1495. foreach ($verifyStaff as $m=>$u){
  1496. $AVLFK=$AVL[0].'_R';
  1497. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1498. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1499. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1500. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1501. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1502. break;
  1503. }
  1504. }
  1505. }else{
  1506. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1507. $button=4;
  1508. $roleArrayCopy[$P][$MKI]['status']=4;
  1509. }
  1510. }
  1511. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1512. $KOP=true;
  1513. }
  1514. }
  1515. foreach ($roleArrayCopy as $k=>$v){
  1516. foreach ($verifyList as $m=>$n){
  1517. if ($n[0]==$k){
  1518. array_splice($verifyList,$m,1,$v);
  1519. }
  1520. }
  1521. }
  1522. $receiptList[$key]['verifyList']=$verifyList;
  1523. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1524. $receiptList[$key]['button']=$button;
  1525. }
  1526. //print_r($receiptList);die;
  1527. $mothHtml="";
  1528. for($i=1;$i<=12;$i++){
  1529. if($moth==$i)
  1530. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1531. else
  1532. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1533. }
  1534. $data['mothHtml']=$mothHtml;
  1535. $data['receiptList']=$receiptList;
  1536. $data['memu']="receipt";
  1537. $data['staff']=$this->staff;
  1538. $data['receiptMemu']='expenses';
  1539. $data['verifyId']=$this->verifyId;
  1540. $data['executeId']=$this->executeId;
  1541. $data['item']=$item;
  1542. $data['year']=$year;
  1543. $this->render ( "/admin/expenses", $data );
  1544. }
  1545. function expensesCollect(){
  1546. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1547. Doo::loadModel('receipt');
  1548. $receipt=new receipt();
  1549. Doo::loadModel('L_category');
  1550. $Lcategory=new L_category();
  1551. Doo::loadModel('verify');
  1552. Doo::loadModel('statistics');
  1553. $statistics=new statistics();
  1554. $verify=new verify();
  1555. Doo::loadModel('staff');
  1556. $staff=new staff();
  1557. Doo::loadModel('loanReceipt');
  1558. $loanReceipt=new loanReceipt();
  1559. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1560. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1561. $Locate=0;$roleId=0;$button=0;
  1562. foreach ($loanList as $key=>$value){
  1563. $loanList[$key]['Locate']=$Locate;$Locate++;
  1564. $loanList[$key]['reviseDetail']=array();
  1565. if (!empty($value['reviseDetail']))
  1566. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1567. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1568. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1569. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1570. $loanList[$key]['category']=$categoryDetil['title'];
  1571. //检测编辑状态
  1572. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1573. $verifyList['staff']=$value['verifyBreakup'];
  1574. else
  1575. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1576. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1577. $verifyStaff=json_decode($value['verifyStaff'],true);
  1578. Doo::loadModel('role');
  1579. $role=new role();
  1580. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1581. foreach ($verifyList as $k=>$v){
  1582. //init verifyStaff
  1583. if ($v[1]=='ROLE'){
  1584. if (!empty($verifyStaff)){
  1585. $endStaffArray=end($verifyStaff);
  1586. // if ($v[0]==$endStaffArray['nextStaff']){
  1587. // $roleId=$v[0];
  1588. // }
  1589. }
  1590. $roleVerify=json_decode($v[3],true);
  1591. $roleKey=$k;$roleArray=array();
  1592. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1593. foreach ($roleVerify as $o=>$p){
  1594. $staffID=explode ('_',$p);
  1595. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1596. //print_r($staffID);
  1597. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1598. array_push($roleArray, $exp);
  1599. }
  1600. $roleArrayCopy[$v[0]]=$roleArray;
  1601. //$verifyList[$k]['roleArray']=$roleArray;
  1602. }
  1603. $verifyList[$k]['date']="";
  1604. $verifyList[$k]['opinion']="";
  1605. $verifyList[$k]['status']="";
  1606. if (empty($verifyStaff)){
  1607. $verifyList[$k]['date']="";
  1608. $verifyList[$k]['opinion']="";
  1609. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1610. $verifyList[$k]['status']=4;
  1611. $flag=false;
  1612. }
  1613. }else{
  1614. foreach ($verifyStaff as $m=>$u){
  1615. if ($v[0]==$m){
  1616. $verifyList[$k]['date']=$u['date'];
  1617. $verifyList[$k]['opinion']=$u['opinion'];
  1618. $verifyList[$k]['status']=$u['status'];
  1619. $flag=false;
  1620. break;
  1621. }
  1622. }
  1623. $endStaffArray=end($verifyStaff);
  1624. if (isset($endStaffArray['ROLE'])){
  1625. }else{
  1626. // $endKey=key($verifyStaff);
  1627. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1628. // $button=4;
  1629. // $verifyList[$k]['status']=4;
  1630. // }
  1631. }
  1632. }
  1633. }
  1634. $rolename['name']='';
  1635. if (!empty($roleId)){
  1636. Doo::loadModel('role');
  1637. $role=new role();
  1638. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1639. }
  1640. if (!empty($verifyStaff))
  1641. $endStaffArray=end($verifyStaff);
  1642. $KOP=false;
  1643. foreach ($roleArrayCopy as $P=>$A){
  1644. foreach ( $A as $MKI=>$AVL){
  1645. if (!empty($verifyStaff)){
  1646. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1647. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1648. $button=4;
  1649. $roleArrayCopy[$P][$MKI]['status']=4;
  1650. }
  1651. foreach ($verifyStaff as $m=>$u){
  1652. $AVLFK=$AVL[0].'_R';
  1653. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1654. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1655. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1656. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1657. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1658. break;
  1659. }
  1660. }
  1661. }else{
  1662. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1663. $button=4;
  1664. $roleArrayCopy[$P][$MKI]['status']=4;
  1665. }
  1666. }
  1667. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1668. $KOP=true;
  1669. }
  1670. }
  1671. foreach ($roleArrayCopy as $k=>$v){
  1672. foreach ($verifyList as $m=>$n){
  1673. if ($n[0]==$k){
  1674. array_splice($verifyList,$m,1,$v);
  1675. }
  1676. }
  1677. }
  1678. $loanList[$key]['verifyList']=$verifyList;
  1679. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1680. $loanList[$key]['button']=$button;
  1681. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1682. }
  1683. $data['loanList']=$loanList;
  1684. $Locate=0;$roleId=0;$button=0;
  1685. foreach ($receiptList as $key=>$value){
  1686. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1687. $receiptList[$key]['reviseDetail']=array();
  1688. if (!empty($value['reviseDetail']))
  1689. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1690. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1691. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1692. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1693. $receiptList[$key]['category']=$categoryDetil['title'];
  1694. //检测编辑状态
  1695. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1696. if($value['status']==8&&$value['Rtype']==1)
  1697. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1698. else
  1699. $verifyList['staff']=$value['verifyBreakup'];
  1700. }else
  1701. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1702. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1703. $verifyStaff=json_decode($value['verifyStaff'],true);
  1704. Doo::loadModel('role');
  1705. $role=new role();
  1706. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1707. foreach ($verifyList as $k=>$v){
  1708. //init verifyStaff
  1709. if ($v[1]=='ROLE'){
  1710. if (!empty($verifyStaff)){
  1711. $endStaffArray=end($verifyStaff);
  1712. // if ($v[0]==$endStaffArray['nextStaff']){
  1713. // $roleId=$v[0];
  1714. // }
  1715. }
  1716. $roleVerify=json_decode($v[3],true);
  1717. $roleKey=$k;$roleArray=array();
  1718. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1719. foreach ($roleVerify as $o=>$p){
  1720. $staffID=explode ('_',$p);
  1721. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1722. //print_r($staffID);
  1723. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1724. array_push($roleArray, $exp);
  1725. }
  1726. $roleArrayCopy[$v[0]]=$roleArray;
  1727. //$verifyList[$k]['roleArray']=$roleArray;
  1728. }
  1729. $verifyList[$k]['date']="";
  1730. $verifyList[$k]['opinion']="";
  1731. $verifyList[$k]['status']="";
  1732. if (empty($verifyStaff)){
  1733. $verifyList[$k]['date']="";
  1734. $verifyList[$k]['opinion']="";
  1735. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1736. $verifyList[$k]['status']=4;
  1737. $flag=false;
  1738. }
  1739. }else{
  1740. foreach ($verifyStaff as $m=>$u){
  1741. if ($v[0]==$m){
  1742. $verifyList[$k]['date']=$u['date'];
  1743. $verifyList[$k]['opinion']=$u['opinion'];
  1744. $verifyList[$k]['status']=$u['status'];
  1745. $flag=false;
  1746. break;
  1747. }
  1748. }
  1749. $endStaffArray=end($verifyStaff);
  1750. if (isset($endStaffArray['ROLE'])){
  1751. }else{
  1752. // $endKey=key($verifyStaff);
  1753. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1754. // $button=4;
  1755. // $verifyList[$k]['status']=4;
  1756. // }
  1757. }
  1758. }
  1759. }
  1760. $rolename['name']='';
  1761. if (!empty($roleId)){
  1762. Doo::loadModel('role');
  1763. $role=new role();
  1764. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1765. }
  1766. if (!empty($verifyStaff))
  1767. $endStaffArray=end($verifyStaff);
  1768. $KOP=false;
  1769. foreach ($roleArrayCopy as $P=>$A){
  1770. foreach ( $A as $MKI=>$AVL){
  1771. if (!empty($verifyStaff)){
  1772. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1773. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1774. $button=4;
  1775. $roleArrayCopy[$P][$MKI]['status']=4;
  1776. }
  1777. foreach ($verifyStaff as $m=>$u){
  1778. $AVLFK=$AVL[0].'_R';
  1779. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1780. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1781. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1782. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1783. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1784. break;
  1785. }
  1786. }
  1787. }else{
  1788. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1789. $button=4;
  1790. $roleArrayCopy[$P][$MKI]['status']=4;
  1791. }
  1792. }
  1793. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1794. $KOP=true;
  1795. }
  1796. }
  1797. foreach ($roleArrayCopy as $k=>$v){
  1798. foreach ($verifyList as $m=>$n){
  1799. if ($n[0]==$k){
  1800. array_splice($verifyList,$m,1,$v);
  1801. }
  1802. }
  1803. }
  1804. //费用执行人相关数据
  1805. $executeCopy=json_decode($value['executeCopy'],true);
  1806. $executeStaff=json_decode($value['executeStaff'],true);
  1807. foreach ($executeCopy as $k=>$v){
  1808. $executeCopy[$k]['date']='';
  1809. $executeCopy[$k]['opinion']='';
  1810. $executeCopy[$k]['status']='';
  1811. if (!empty($executeStaff))
  1812. foreach ($executeStaff as $m=>$u){
  1813. if ($v[0]==$m){
  1814. $executeCopy[$k]['date']=$u['date'];
  1815. $executeCopy[$k]['opinion']=$u['opinion'];
  1816. $executeCopy[$k]['status']=$u['status'];
  1817. break;
  1818. }
  1819. }
  1820. }
  1821. $receiptList[$key]['executeCopy']=$executeCopy;
  1822. $receiptList[$key]['verifyList']=$verifyList;
  1823. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1824. $receiptList[$key]['button']=$button;
  1825. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1826. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1827. $relust=$value['sum']-$value['loanSum'];
  1828. $receiptList[$key]['relust']=$relust;
  1829. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1830. }
  1831. $data['receiptList']=$receiptList;
  1832. $data['memu']="receipt";
  1833. $data['staff']=$this->staff;
  1834. $data['receiptMemu']='expenses';
  1835. $data['verifyId']=$this->verifyId;
  1836. $data['executeId']=$this->executeId;
  1837. $this->render ( "/admin/expensesCollect", $data );
  1838. }
  1839. function approvalExpenses(){
  1840. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1841. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1842. $month=$this->get_args('month')?$this->get_args('month'):"";
  1843. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1844. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1845. if (empty($status))
  1846. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1847. $page_size=12;
  1848. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1849. $vidList=array();
  1850. $button=0;
  1851. Doo::loadModel('verify');
  1852. $verify=new verify();
  1853. Doo::loadModel('receipt');
  1854. $receipt=new receipt();
  1855. Doo::loadModel('staff');
  1856. $staff=new staff();
  1857. Doo::loadModel('L_category');
  1858. $Lcategory=new L_category();
  1859. //user verify ID
  1860. $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));
  1861. foreach ($verifyDetail as $key=>$value){
  1862. array_push($vidList, $value['vid']);
  1863. }
  1864. $vid=implode(",", $vidList);
  1865. if(empty($verifyDetail))
  1866. $vid=0;
  1867. // if ($status==0)
  1868. // $dateCondition="";
  1869. // else
  1870. $dateCondition=" and Year(date) =".$year;
  1871. if(!empty($month))
  1872. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1873. $categoryList=$Lcategory->find(array('asArray'=>true));
  1874. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1875. $cateCondition="";$staffCondition="";$approvalCondition="";
  1876. if (!empty($cid))
  1877. $cateCondition=' and cid='.$cid;
  1878. if(!empty($sid)){
  1879. $staffCondition=' and staff='.$sid;
  1880. $cateCondition="";
  1881. }
  1882. $approvalCondition=" and status=".$status;
  1883. if($status==2){
  1884. //查找角色审批人
  1885. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1886. }
  1887. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1888. $approvalCondition=' and status=2 ';
  1889. }
  1890. if($status==1){
  1891. $approvalCondition=' and (status='.$status.' or status=6) ';
  1892. }
  1893. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1894. $pageinfo['page']=array('previous'=>'');
  1895. if ($status==0){
  1896. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1897. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1898. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1899. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1900. }else
  1901. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1902. ,'desc'=>'rid','asArray'=>true));
  1903. $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
  1904. ,'desc'=>'rid','asArray'=>true));
  1905. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1906. //print_r($pageinfo);
  1907. $Locate=0;
  1908. foreach ($receiptList as $key=>$value){
  1909. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1910. $receiptList[$key]['reviseDetail']=array();
  1911. if (!empty($value['reviseDetail']))
  1912. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1913. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1914. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1915. $receiptList[$key]['category']=$categoryDetil['title'];
  1916. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1917. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1918. $verifyStaff=json_decode($value['verifyStaff'],true);
  1919. foreach ($verifyList as $k=>$v){
  1920. //init verifyStaff
  1921. $verifyList[$k]['date']="";
  1922. $verifyList[$k]['opinion']="";
  1923. $verifyList[$k]['status']="";
  1924. if (empty($verifyStaff)){
  1925. $verifyList[$k]['date']="";
  1926. $verifyList[$k]['opinion']="";
  1927. if ($v[0]==$this->staff[0]['sid']){
  1928. $verifyList[$k]['status']=4;
  1929. $button=4;
  1930. }
  1931. }else{
  1932. $flag=true;
  1933. foreach ($verifyStaff as $m=>$u){
  1934. if ($v[0]==$m){
  1935. $verifyList[$k]['date']=$u['date'];
  1936. $verifyList[$k]['opinion']=$u['opinion'];
  1937. $verifyList[$k]['status']=$u['status'];
  1938. $flag=false;
  1939. break;
  1940. }
  1941. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1942. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1943. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1944. }
  1945. if($flag){//检测可编辑
  1946. if($v[0]==$this->staff[0]['sid']){
  1947. $verifyList[$k]['status']=4;$button=4;
  1948. }
  1949. }
  1950. }
  1951. }
  1952. $receiptList[$key]['verifyList']=$verifyList;
  1953. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1954. $receiptList[$key]['button']=$button;
  1955. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1956. }
  1957. //print_r($receiptList);die;
  1958. //$data['verifyDetail']=$verifyDetail;
  1959. $mothHtml="";
  1960. for($i=1;$i<=12;$i++){
  1961. if($month==$i)
  1962. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1963. else
  1964. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1965. }
  1966. $data['mothHtml']=$mothHtml;
  1967. $data['page']=$pageinfo;
  1968. $data['receiptList']=$receiptList;
  1969. $data['receiptApprovalCount']=count($rLRes);
  1970. $data['status']=$status;
  1971. $data['year']=$year;
  1972. $data['categoryList']=$categoryList;
  1973. $data['staffList']=$staffList;
  1974. $data['cid']=$cid;
  1975. $data['sid']=$sid;
  1976. //print_r($receiptList);
  1977. $data['memu']="receipt";
  1978. $data['staff']=$this->staff;
  1979. $data['receiptMemu']='approvalExpenses';
  1980. $data['verifyId']=$this->verifyId;
  1981. $data['executeId']=$this->executeId;
  1982. $this->render ( "/admin/approvalExpenses", $data );
  1983. }
  1984. function expensesDoc(){
  1985. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1986. Doo::loadModel('receipt');
  1987. $receipt=new receipt();
  1988. Doo::loadModel('L_category');
  1989. $Lcategory=new L_category();
  1990. Doo::loadModel('verify');
  1991. Doo::loadModel('statistics');
  1992. $statistics=new statistics();
  1993. $verify=new verify();
  1994. Doo::loadModel('staff');
  1995. $staff=new staff();
  1996. Doo::loadModel('loanReceipt');
  1997. $loanReceipt=new loanReceipt();
  1998. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  1999. $loanList=array();
  2000. if (!empty($receiptList))
  2001. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2002. $Locate=0;$roleId=0;$button=0;
  2003. foreach ($loanList as $key=>$value){
  2004. $loanList[$key]['Locate']=$Locate;$Locate++;
  2005. $loanList[$key]['reviseDetail']=array();
  2006. if (!empty($value['reviseDetail']))
  2007. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2008. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2009. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2010. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2011. $loanList[$key]['category']=$categoryDetil['title'];
  2012. //检测编辑状态
  2013. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  2014. $verifyList['staff']=$value['verifyBreakup'];
  2015. else
  2016. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2017. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2018. $verifyStaff=json_decode($value['verifyStaff'],true);
  2019. Doo::loadModel('role');
  2020. $role=new role();
  2021. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2022. foreach ($verifyList as $k=>$v){
  2023. //init verifyStaff
  2024. if ($v[1]=='ROLE'){
  2025. if (!empty($verifyStaff)){
  2026. $endStaffArray=end($verifyStaff);
  2027. // if ($v[0]==$endStaffArray['nextStaff']){
  2028. // $roleId=$v[0];
  2029. // }
  2030. }
  2031. $roleVerify=json_decode($v[3],true);
  2032. $roleKey=$k;$roleArray=array();
  2033. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2034. foreach ($roleVerify as $o=>$p){
  2035. $staffID=explode ('_',$p);
  2036. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2037. //print_r($staffID);
  2038. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2039. array_push($roleArray, $exp);
  2040. }
  2041. $roleArrayCopy[$v[0]]=$roleArray;
  2042. //$verifyList[$k]['roleArray']=$roleArray;
  2043. }
  2044. $verifyList[$k]['date']="";
  2045. $verifyList[$k]['opinion']="";
  2046. $verifyList[$k]['status']="";
  2047. if (empty($verifyStaff)){
  2048. $verifyList[$k]['date']="";
  2049. $verifyList[$k]['opinion']="";
  2050. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2051. $verifyList[$k]['status']=4;
  2052. $flag=false;
  2053. }
  2054. }else{
  2055. foreach ($verifyStaff as $m=>$u){
  2056. if ($v[0]==$m){
  2057. $verifyList[$k]['date']=$u['date'];
  2058. $verifyList[$k]['opinion']=$u['opinion'];
  2059. $verifyList[$k]['status']=$u['status'];
  2060. $flag=false;
  2061. break;
  2062. }
  2063. }
  2064. $endStaffArray=end($verifyStaff);
  2065. if (isset($endStaffArray['ROLE'])){
  2066. }else{
  2067. // $endKey=key($verifyStaff);
  2068. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2069. // $button=4;
  2070. // $verifyList[$k]['status']=4;
  2071. // }
  2072. }
  2073. }
  2074. }
  2075. $rolename['name']='';
  2076. if (!empty($roleId)){
  2077. Doo::loadModel('role');
  2078. $role=new role();
  2079. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2080. }
  2081. if (!empty($verifyStaff))
  2082. $endStaffArray=end($verifyStaff);
  2083. $KOP=false;
  2084. foreach ($roleArrayCopy as $P=>$A){
  2085. foreach ( $A as $MKI=>$AVL){
  2086. if (!empty($verifyStaff)){
  2087. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2088. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2089. $button=4;
  2090. $roleArrayCopy[$P][$MKI]['status']=4;
  2091. }
  2092. foreach ($verifyStaff as $m=>$u){
  2093. $AVLFK=$AVL[0].'_R';
  2094. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2095. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2096. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2097. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2098. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2099. break;
  2100. }
  2101. }
  2102. }else{
  2103. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2104. $button=4;
  2105. $roleArrayCopy[$P][$MKI]['status']=4;
  2106. }
  2107. }
  2108. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2109. $KOP=true;
  2110. }
  2111. }
  2112. foreach ($roleArrayCopy as $k=>$v){
  2113. foreach ($verifyList as $m=>$n){
  2114. if ($n[0]==$k){
  2115. array_splice($verifyList,$m,1,$v);
  2116. }
  2117. }
  2118. }
  2119. $loanList[$key]['verifyList']=$verifyList;
  2120. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2121. $loanList[$key]['button']=$button;
  2122. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2123. }
  2124. $data['loanList']=$loanList;
  2125. //print_r($loanList);
  2126. $Locate=0;$roleId=0;$button=0;
  2127. foreach ($receiptList as $key=>$value){
  2128. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2129. $receiptList[$key]['reviseDetail']=array();
  2130. if (!empty($value['reviseDetail']))
  2131. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2132. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2133. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2134. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2135. $receiptList[$key]['category']=$categoryDetil['title'];
  2136. //检测编辑状态
  2137. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2138. $verifyList['staff']=$value['verifyBreakup'];
  2139. }else
  2140. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2141. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2142. $verifyStaff=json_decode($value['verifyStaff'],true);
  2143. Doo::loadModel('role');
  2144. $role=new role();
  2145. if ($verifyList==NULL)
  2146. $verifyList=array();
  2147. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2148. foreach ($verifyList as $k=>$v){
  2149. //init verifyStaff
  2150. if ($v[1]=='ROLE'){
  2151. if (!empty($verifyStaff)){
  2152. $endStaffArray=end($verifyStaff);
  2153. // if ($v[0]==$endStaffArray['nextStaff']){
  2154. // $roleId=$v[0];
  2155. // }
  2156. }
  2157. $roleVerify=json_decode($v[3],true);
  2158. $roleKey=$k;$roleArray=array();
  2159. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2160. foreach ($roleVerify as $o=>$p){
  2161. $staffID=explode ('_',$p);
  2162. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2163. //print_r($staffID);
  2164. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2165. array_push($roleArray, $exp);
  2166. }
  2167. $roleArrayCopy[$v[0]]=$roleArray;
  2168. //$verifyList[$k]['roleArray']=$roleArray;
  2169. }
  2170. $verifyList[$k]['date']="";
  2171. $verifyList[$k]['opinion']="";
  2172. $verifyList[$k]['status']="";
  2173. if (empty($verifyStaff)){
  2174. $verifyList[$k]['date']="";
  2175. $verifyList[$k]['opinion']="";
  2176. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2177. $verifyList[$k]['status']=4;
  2178. $flag=false;
  2179. }
  2180. }else{
  2181. foreach ($verifyStaff as $m=>$u){
  2182. if ($v[0]==$m){
  2183. $verifyList[$k]['date']=$u['date'];
  2184. $verifyList[$k]['opinion']=$u['opinion'];
  2185. $verifyList[$k]['status']=$u['status'];
  2186. $flag=false;
  2187. break;
  2188. }
  2189. }
  2190. $endStaffArray=end($verifyStaff);
  2191. if (isset($endStaffArray['ROLE'])){
  2192. }else{
  2193. // $endKey=key($verifyStaff);
  2194. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2195. // $button=4;
  2196. // $verifyList[$k]['status']=4;
  2197. // }
  2198. }
  2199. }
  2200. }
  2201. $rolename['name']='';
  2202. if (!empty($roleId)){
  2203. Doo::loadModel('role');
  2204. $role=new role();
  2205. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2206. }
  2207. if (!empty($verifyStaff))
  2208. $endStaffArray=end($verifyStaff);
  2209. $KOP=false;
  2210. foreach ($roleArrayCopy as $P=>$A){
  2211. foreach ( $A as $MKI=>$AVL){
  2212. if (!empty($verifyStaff)){
  2213. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2214. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2215. $button=4;
  2216. $roleArrayCopy[$P][$MKI]['status']=4;
  2217. }
  2218. foreach ($verifyStaff as $m=>$u){
  2219. $AVLFK=$AVL[0].'_R';
  2220. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2221. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2222. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2223. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2224. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2225. break;
  2226. }
  2227. }
  2228. }else{
  2229. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2230. $button=4;
  2231. $roleArrayCopy[$P][$MKI]['status']=4;
  2232. }
  2233. }
  2234. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2235. $KOP=true;
  2236. }
  2237. }
  2238. foreach ($roleArrayCopy as $k=>$v){
  2239. foreach ($verifyList as $m=>$n){
  2240. if ($n[0]==$k){
  2241. array_splice($verifyList,$m,1,$v);
  2242. }
  2243. }
  2244. }
  2245. //费用执行人相关数据
  2246. $executeCopy=json_decode($value['executeCopy'],true);
  2247. $executeStaff=json_decode($value['executeStaff'],true);
  2248. foreach ($executeCopy as $k=>$v){
  2249. $executeCopy[$k]['date']='';
  2250. $executeCopy[$k]['opinion']='';
  2251. $executeCopy[$k]['status']='';
  2252. if (!empty($executeStaff))
  2253. foreach ($executeStaff as $m=>$u){
  2254. if ($v[0]==$m){
  2255. $executeCopy[$k]['date']=$u['date'];
  2256. $executeCopy[$k]['opinion']=$u['opinion'];
  2257. $executeCopy[$k]['status']=$u['status'];
  2258. break;
  2259. }
  2260. }
  2261. }
  2262. $receiptList[$key]['executeCopy']=$executeCopy;
  2263. $receiptList[$key]['verifyList']=$verifyList;
  2264. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2265. $receiptList[$key]['button']=$button;
  2266. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2267. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2268. }
  2269. //print_r($receiptList);
  2270. //获取审批日志
  2271. Doo::loadModel('receiptLog');
  2272. $receiptLog=new receiptLog();
  2273. $rlList=array();
  2274. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2275. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2276. if (!empty($rlInfo)){
  2277. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2278. }
  2279. $receiptList[0]['rlList']=$rlList;
  2280. $data['receiptList']=$receiptList;
  2281. $data['memu']="receipt";
  2282. $data['staff']=$this->staff;
  2283. $data['receiptMemu']='approvalExpenses';
  2284. $data['verifyId']=$this->verifyId;
  2285. $data['executeId']=$this->executeId;
  2286. $this->render ( "/admin/expensesDoc", $data );
  2287. }
  2288. function expensesEdi(){
  2289. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2290. $status=isset($this->params['status'])?$this->params['status']:'';
  2291. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2292. $month=$this->get_args('month')?$this->get_args('month'):"";
  2293. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2294. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2295. if (empty($status))
  2296. $status=$this->get_args('status')?$this->get_args('status'):2;
  2297. $vidList=array();
  2298. $button=0;
  2299. Doo::loadModel('verify');
  2300. Doo::loadModel('receipt');
  2301. Doo::loadModel('staff');
  2302. $staff=new staff();
  2303. $receipt=new receipt();
  2304. $verify=new verify();
  2305. Doo::loadModel('L_category');
  2306. $Lcategory=new L_category();
  2307. Doo::loadModel('enclosur');
  2308. $enclosur=new enclosur();
  2309. //user verify ID
  2310. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2311. foreach ($verifyDetail as $key=>$value){
  2312. array_push($vidList, $value['vid']);
  2313. }
  2314. $vid=implode(",", $vidList);
  2315. if(empty($verifyDetail))
  2316. $vid=0;
  2317. $categoryList=$Lcategory->find(array('asArray'=>true));
  2318. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2319. $ap="";
  2320. if($status==4){
  2321. $ap=4;$status=2;
  2322. }
  2323. //get Receipt By verifyID status 2
  2324. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2325. $Locate=0;$roleId=0;
  2326. if($ap==4)
  2327. $status=4;
  2328. foreach ($receiptList as $key=>$value){
  2329. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2330. $receiptList[$key]['reviseDetail']=array();
  2331. if (!empty($value['reviseDetail']))
  2332. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2333. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2334. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2335. $receiptList[$key]['category']=$categoryDetil['title'];
  2336. //检测编辑状态
  2337. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2338. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2339. $verifyStaff=json_decode($value['verifyStaff'],true);
  2340. Doo::loadModel('role');
  2341. $role=new role();
  2342. //print_r($verifyList);
  2343. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2344. foreach ($verifyList as $k=>$v){
  2345. //init verifyStaff
  2346. if ($v[1]=='ROLE'){
  2347. if (!empty($verifyStaff)){
  2348. $endStaffArray=end($verifyStaff);
  2349. if ($v[0]==$endStaffArray['nextStaff']){
  2350. $roleId=$v[0];
  2351. }
  2352. }
  2353. $roleVerify=json_decode($v[3],true);
  2354. $roleKey=$k;$roleArray=array();
  2355. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2356. foreach ($roleVerify as $o=>$p){
  2357. $staffID=explode ('_',$p);
  2358. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2359. //print_r($staffID);
  2360. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2361. array_push($roleArray, $exp);
  2362. }
  2363. $roleArrayCopy[$v[0]]=$roleArray;
  2364. //$verifyList[$k]['roleArray']=$roleArray;
  2365. }
  2366. //print_r($roleArray);
  2367. $verifyList[$k]['date']="";
  2368. $verifyList[$k]['opinion']="";
  2369. $verifyList[$k]['status']="";
  2370. if (empty($verifyStaff)){
  2371. $verifyList[$k]['date']="";
  2372. $verifyList[$k]['opinion']="";
  2373. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2374. $verifyList[$k]['status']=4;
  2375. $button=4;$flag=false;
  2376. }
  2377. }else{
  2378. foreach ($verifyStaff as $m=>$u){
  2379. if ($v[0]==$m){
  2380. $verifyList[$k]['date']=$u['date'];
  2381. $verifyList[$k]['opinion']=$u['opinion'];
  2382. $verifyList[$k]['status']=$u['status'];
  2383. $flag=false;
  2384. break;
  2385. }
  2386. }
  2387. $endStaffArray=end($verifyStaff);
  2388. if (isset($endStaffArray['ROLE'])){
  2389. }else{
  2390. $endKey=key($verifyStaff);
  2391. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2392. $button=4;
  2393. $verifyList[$k]['status']=4;
  2394. }
  2395. }
  2396. }
  2397. }
  2398. $rolename['name']='';
  2399. if (!empty($roleId)){
  2400. Doo::loadModel('role');
  2401. $role=new role();
  2402. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2403. }
  2404. if (!empty($verifyStaff))
  2405. $endStaffArray=end($verifyStaff);
  2406. $KOP=false;
  2407. foreach ($roleArrayCopy as $P=>$A){
  2408. foreach ( $A as $MKI=>$AVL){
  2409. if (!empty($verifyStaff)){
  2410. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2411. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2412. $button=4;
  2413. $roleArrayCopy[$P][$MKI]['status']=4;
  2414. }
  2415. foreach ($verifyStaff as $m=>$u){
  2416. $AVLFK=$AVL[0].'_R';
  2417. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2418. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2419. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2420. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2421. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2422. break;
  2423. }
  2424. }
  2425. }else{
  2426. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2427. $button=4;
  2428. $roleArrayCopy[$P][$MKI]['status']=4;
  2429. }
  2430. }
  2431. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2432. $KOP=true;
  2433. }
  2434. }
  2435. // print_r($roleArrayCopy);
  2436. // echo $roleKey;
  2437. foreach ($roleArrayCopy as $k=>$v){
  2438. foreach ($verifyList as $m=>$n){
  2439. if ($n[0]==$k){
  2440. array_splice($verifyList,$m,1,$v);
  2441. }
  2442. }
  2443. }
  2444. $receiptList[$key]['verifyList']=$verifyList;
  2445. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2446. $receiptList[$key]['button']=$button;
  2447. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2448. }
  2449. //$data['verifyDetail']=$verifyDetail;
  2450. $mothHtml="";
  2451. for($i=1;$i<=12;$i++){
  2452. if($month==$i)
  2453. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2454. else
  2455. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2456. }
  2457. //获取审批日志
  2458. Doo::loadModel('receiptLog');
  2459. $receiptLog=new receiptLog();
  2460. $rlList=array();
  2461. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2462. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2463. if (!empty($rlInfo)){
  2464. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2465. }
  2466. $receiptList[0]['rlList']=$rlList;
  2467. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2468. $enclosurHtml='';
  2469. foreach ($enclosurList as $value){
  2470. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2471. }
  2472. //print_r($receiptList);
  2473. $data['rid']=$rid;
  2474. $data['enclosurHtml']=$enclosurHtml;
  2475. $data['rolename']=$rolename['name'];
  2476. $data['datetij']=$tijdate['date'];
  2477. $data['mothHtml']=$mothHtml;
  2478. $data['receiptList']=$receiptList;
  2479. $data['receiptApprovalCount']=count($receiptList);
  2480. $data['status']=$status;
  2481. $data['year']=$year;
  2482. $data['categoryList']=$categoryList;
  2483. $data['staffList']=$staffList;
  2484. $data['cid']=$cid;
  2485. $data['sid']=$sid;
  2486. $data['ap']=$ap;
  2487. $data['memu']="receipt";
  2488. $data['staff']=$this->staff;
  2489. $data['receiptMemu']='approvalExpenses';
  2490. $data['verifyId']=$this->verifyId;
  2491. $data['executeId']=$this->executeId;
  2492. $this->render ( "/admin/expensesEdi", $data );
  2493. }
  2494. function expensesDefray(){
  2495. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2496. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2497. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2498. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2499. if(!empty($rid)){
  2500. Doo::loadModel("verify");
  2501. $verify=new verify();
  2502. Doo::loadModel("receiptDetail");
  2503. $receiptDetailObj=new receiptDetail();
  2504. Doo::loadModel("itemStatistics");
  2505. Doo::loadModel("statistics");
  2506. $statistics=new statistics();
  2507. $itemStatistics=new itemStatistics();
  2508. Doo::loadModel("receipt");
  2509. $receipt=new receipt();
  2510. Doo::loadModel("loanReceipt");
  2511. $loanReceipt=new loanReceipt();
  2512. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2513. if (empty($receiptDetail))
  2514. return "/approval";
  2515. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2516. $verifyString=$verifyDetail['staff'];
  2517. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2518. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2519. if(empty($opinion)){
  2520. if ($status==3)
  2521. $opinion="终止";
  2522. else
  2523. $opinion="同意支付";
  2524. }
  2525. $nowStaff=0;$nowStaffList=array();
  2526. if(empty($verifyStaff)){
  2527. //还需加入是否已经进入角色审批
  2528. if ($verifyDetail[0][1]=='ROLE'){
  2529. //print_r($verifyDetail);echo "ddd";
  2530. $vStaffString=json_decode($verifyDetail[0][3]);
  2531. foreach ($vStaffString as $key=>$value){
  2532. $staffK=explode("_", $value);
  2533. if ($staffK[0]!=$this->staff[0]['sid'])
  2534. array_push($nowStaffList, $staffK[0]);
  2535. }
  2536. //print_r($verifyDetail);
  2537. //die;
  2538. $nowStaff=implode(',', $nowStaffList);
  2539. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2540. }else{
  2541. if ($verifyDetail[1][1]=='ROLE'){
  2542. $vStaffString=json_decode($verifyDetail[1][3]);
  2543. //echo "dd";
  2544. foreach ($vStaffString as $key=>$value){
  2545. $staffK=explode("_", $value);
  2546. array_push($nowStaffList, $staffK[0]);
  2547. }
  2548. $nowStaff=implode(',', $nowStaffList);
  2549. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2550. }else{
  2551. $nowStaff=$verifyDetail[1][0];
  2552. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2553. }
  2554. }
  2555. if($status==3)
  2556. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2557. $vStaffString=json_encode($verifyStaff);
  2558. $receipt->nowStaff=$nowStaff;
  2559. $receipt->verifyStaff=$vStaffString;
  2560. $loanReceipt->nowStaff=$nowStaff;
  2561. $loanReceipt->verifyStaff=$vStaffString;
  2562. }else{
  2563. $VS=end($verifyStaff);
  2564. //非角色审批
  2565. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2566. $nextStaff=0;$roleSTF=false;
  2567. foreach ($verifyDetail as $key=>$value){
  2568. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2569. if (isset($verifyDetail[$key+1])){
  2570. $nextStaff=$verifyDetail[$key+1][0];
  2571. if ($verifyDetail[$key+1][1]=='ROLE')
  2572. $roleSTF=true;
  2573. }
  2574. break;
  2575. }
  2576. }
  2577. if (!$roleSTF){
  2578. $nowStaff=$nextStaff;
  2579. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2580. }else{
  2581. //获取角色下的所有用户ID
  2582. $nowStaffList=array();
  2583. foreach ($verifyDetail as $vfk){
  2584. if ($vfk[1]=='ROLE'){
  2585. $vStaffString=json_decode($vfk[3]);
  2586. foreach ($vStaffString as $key=>$value){
  2587. $staffK=explode("_", $value);
  2588. array_push($nowStaffList, $staffK[0]);
  2589. }
  2590. }
  2591. }
  2592. $nowStaff=implode(',', $nowStaffList);
  2593. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2594. }
  2595. if($status==3){
  2596. $verifyStaff['final']=$status;
  2597. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2598. }
  2599. $vStaffString=json_encode($verifyStaff);
  2600. $receipt->nowStaff=$nowStaff;
  2601. $receipt->verifyStaff=$vStaffString;
  2602. $loanReceipt->nowStaff=$nowStaff;
  2603. $loanReceipt->verifyStaff=$vStaffString;
  2604. }
  2605. //角色审批
  2606. if (isset($VS['ROLE'])){
  2607. //找出角色人 当前审批角色组
  2608. $verifyJSStaff=array();$nowStaffList2=array();
  2609. foreach ($verifyDetail as $key=>$value){
  2610. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2611. $verifyJSStaff=json_decode($value[3]);
  2612. foreach ($verifyJSStaff as $m){
  2613. $staffK=explode("_", $m);
  2614. array_push($nowStaffList2, $staffK[0]);
  2615. }
  2616. // print_r($nowStaffList2);
  2617. }
  2618. }
  2619. $RoleVerifyStaff=array();
  2620. foreach ($verifyStaff as $key=>$value){
  2621. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2622. foreach ($nowStaffList2 as $m) {
  2623. if ($key==$m."_R")
  2624. $RoleVerifyStaff[$key]=$value;
  2625. }
  2626. }
  2627. }
  2628. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2629. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2630. //下一个审批人ID
  2631. $nextStaff=0;$falg=false;
  2632. foreach ($verifyDetail as $key=>$value){
  2633. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2634. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2635. $falg=true;
  2636. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2637. foreach ($vStaffString as $v){
  2638. $staffK=explode("_", $v);
  2639. array_push($nowStaffList, $staffK[0]);
  2640. }
  2641. $nowStaff=implode(',', $nowStaffList);
  2642. $nextStaff=$verifyDetail[$key+1][0];
  2643. }elseif(isset($verifyDetail[$key+1])){
  2644. $nextStaff=$verifyDetail[$key+1][0];
  2645. $nowStaff=$nextStaff;
  2646. }else
  2647. $nowStaff='';
  2648. break;
  2649. }
  2650. }
  2651. if ($falg)
  2652. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2653. else
  2654. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2655. // print_r($verifyStaff);
  2656. // echo $nowStaff;die;
  2657. }else{ //进入下一个角色或者审批人
  2658. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2659. //
  2660. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2661. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2662. // print_r($verifyStaff);
  2663. // die;
  2664. }
  2665. if($status==3){
  2666. $verifyStaff['final']=$status;
  2667. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2668. }
  2669. $vStaffString=json_encode($verifyStaff);
  2670. $receipt->verifyStaff=$vStaffString;
  2671. $receipt->nowStaff=$nowStaff;
  2672. $loanReceipt->nowStaff=$nowStaff;
  2673. $loanReceipt->verifyStaff=$vStaffString;
  2674. //die;
  2675. //}
  2676. // print_r($verifyStaff);
  2677. // die;
  2678. }
  2679. //print_r($verifyStaff);die;
  2680. }
  2681. //print_r($verifyDetail);
  2682. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2683. foreach ($verifyDetail as $k=>$v){
  2684. if ($v[1]=='ROLE'){
  2685. $roleId=$v[0];
  2686. $roleVerify=json_decode($v[3],true);
  2687. $roleKey=$k;$roleArray=array();
  2688. foreach ($roleVerify as $o=>$p){
  2689. $staffID=explode ('_',$p);
  2690. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2691. array_push($roleArray, $exp);
  2692. }
  2693. $verifyDetailCopy[$v[0]]=$roleArray;
  2694. }
  2695. }
  2696. //print_r($verifyDetail);
  2697. foreach ($verifyDetailCopy as $k=>$v){
  2698. foreach ($verifyDetail as $m=>$n){
  2699. if ($n[0]==$k){
  2700. array_splice($verifyDetail,$m,1,$v);
  2701. }
  2702. }
  2703. }
  2704. //审批日志
  2705. if (!isset($verifyStaff['final'])){
  2706. Doo::loadModel("receiptLog");
  2707. $receiptLog=new receiptLog();
  2708. if (!empty($roleId)){
  2709. Doo::loadModel("role");
  2710. $role=new role();
  2711. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2712. $receiptLog->rolename=$roleInfo['name'];
  2713. }
  2714. $receiptLog->username=$this->staff[0]['username'];
  2715. $receiptLog->uid=$this->staff[0]['sid'];
  2716. $receiptLog->date=date("Y-m-d");
  2717. $receiptLog->opinion=$opinion;
  2718. $receiptLog->img=$this->staff[0]['avatar'];
  2719. $receiptLog->status=1;
  2720. $receiptLog->rid=$rid;
  2721. $receiptLog->insert();
  2722. }
  2723. if (isset($verifyStaff['final'])){//rDetail
  2724. $receipt->status=3;
  2725. $receipt->verifyBreakup=$verifyString;
  2726. $receiptDetailObj->status=3;
  2727. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2728. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2729. $receipt->status=6;
  2730. $receipt->pastDate=date("Y-m-d");
  2731. $receipt->isBK=1;
  2732. $loanReceipt->verifyBreakup=$verifyString;
  2733. $loanReceipt->status=1;
  2734. $loanReceipt->pastDate=date("Y-m-d");
  2735. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2736. }
  2737. $receipt->update(array('where'=>' rid = '.$rid));
  2738. return "/approvalExpenses/2";
  2739. }
  2740. }
  2741. function implement(){
  2742. Doo::loadModel('receipt');
  2743. $receipt=new receipt();
  2744. Doo::loadModel('L_category');
  2745. $Lcategory=new L_category();
  2746. Doo::loadModel('verify');
  2747. $verify=new verify();
  2748. Doo::loadModel('staff');
  2749. $staff=new staff();
  2750. Doo::loadModel("execute");
  2751. $execute=new execute();
  2752. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2753. Doo::loadModel('loanReceipt');
  2754. $loanReceipt=new loanReceipt();
  2755. //print_r($receiptList);
  2756. $loanList=array();
  2757. if (!isset($receiptList))
  2758. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2759. $Locate=0;$roleId=0;$button=0;
  2760. foreach ($loanList as $key=>$value){
  2761. $loanList[$key]['Locate']=$Locate;$Locate++;
  2762. $loanList[$key]['reviseDetail']=array();
  2763. if (!empty($value['reviseDetail']))
  2764. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2765. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2766. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2767. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2768. $loanList[$key]['category']=$categoryDetil['title'];
  2769. //检测编辑状态
  2770. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2771. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2772. $verifyStaff=json_decode($value['verifyStaff'],true);
  2773. Doo::loadModel('role');
  2774. $role=new role();
  2775. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2776. foreach ($verifyList as $k=>$v){
  2777. //init verifyStaff
  2778. if ($v[1]=='ROLE'){
  2779. if (!empty($verifyStaff)){
  2780. $endStaffArray=end($verifyStaff);
  2781. // if ($v[0]==$endStaffArray['nextStaff']){
  2782. // $roleId=$v[0];
  2783. // }
  2784. }
  2785. $roleVerify=json_decode($v[3],true);
  2786. $roleKey=$k;$roleArray=array();
  2787. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2788. foreach ($roleVerify as $o=>$p){
  2789. $staffID=explode ('_',$p);
  2790. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2791. //print_r($staffID);
  2792. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2793. array_push($roleArray, $exp);
  2794. }
  2795. $roleArrayCopy[$v[0]]=$roleArray;
  2796. //$verifyList[$k]['roleArray']=$roleArray;
  2797. }
  2798. $verifyList[$k]['date']="";
  2799. $verifyList[$k]['opinion']="";
  2800. $verifyList[$k]['status']="";
  2801. if (empty($verifyStaff)){
  2802. $verifyList[$k]['date']="";
  2803. $verifyList[$k]['opinion']="";
  2804. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2805. $verifyList[$k]['status']=4;
  2806. $flag=false;
  2807. }
  2808. }else{
  2809. foreach ($verifyStaff as $m=>$u){
  2810. if ($v[0]==$m){
  2811. $verifyList[$k]['date']=$u['date'];
  2812. $verifyList[$k]['opinion']=$u['opinion'];
  2813. $verifyList[$k]['status']=$u['status'];
  2814. $flag=false;
  2815. break;
  2816. }
  2817. }
  2818. $endStaffArray=end($verifyStaff);
  2819. if (isset($endStaffArray['ROLE'])){
  2820. }else{
  2821. // $endKey=key($verifyStaff);
  2822. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2823. // $button=4;
  2824. // $verifyList[$k]['status']=4;
  2825. // }
  2826. }
  2827. }
  2828. }
  2829. $rolename['name']='';
  2830. if (!empty($roleId)){
  2831. Doo::loadModel('role');
  2832. $role=new role();
  2833. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2834. }
  2835. if (!empty($verifyStaff))
  2836. $endStaffArray=end($verifyStaff);
  2837. $KOP=false;
  2838. foreach ($roleArrayCopy as $P=>$A){
  2839. foreach ( $A as $MKI=>$AVL){
  2840. if (!empty($verifyStaff)){
  2841. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2842. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2843. $button=4;
  2844. $roleArrayCopy[$P][$MKI]['status']=4;
  2845. }
  2846. foreach ($verifyStaff as $m=>$u){
  2847. $AVLFK=$AVL[0].'_R';
  2848. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2849. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2850. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2851. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2852. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2853. break;
  2854. }
  2855. }
  2856. }else{
  2857. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2858. $button=4;
  2859. $roleArrayCopy[$P][$MKI]['status']=4;
  2860. }
  2861. }
  2862. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2863. $KOP=true;
  2864. }
  2865. }
  2866. foreach ($roleArrayCopy as $k=>$v){
  2867. foreach ($verifyList as $m=>$n){
  2868. if ($n[0]==$k){
  2869. array_splice($verifyList,$m,1,$v);
  2870. }
  2871. }
  2872. }
  2873. $loanList[$key]['verifyList']=$verifyList;
  2874. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2875. }
  2876. $data['loanList']=$loanList;
  2877. $Locate=0;$roleId=0;$button=0;
  2878. foreach ($receiptList as $key=>$value){
  2879. $button2=0;
  2880. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2881. $receiptList[$key]['reviseDetail']=array();
  2882. if (!empty($value['reviseDetail']))
  2883. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2884. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2885. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2886. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2887. $receiptList[$key]['category']=$categoryDetil['title'];
  2888. $executeList=json_decode($value['executeCopy'],true);
  2889. $executeStaff=array();
  2890. if (!empty($value['executeStaff'] ))
  2891. $executeStaff=json_decode($value['executeStaff'],true);
  2892. if (isset($executeList)){
  2893. foreach ($executeList as $op=>$lo){
  2894. $executeList[$op]['date']="";
  2895. $executeList[$op]['opinion']="";
  2896. $executeList[$op]['status']="";
  2897. foreach ($executeStaff as $m=>$u){
  2898. if ($lo[0]==$m){
  2899. $executeList[$op]['date']=$u['date'];
  2900. $executeList[$op]['opinion']=$u['opinion'];
  2901. $executeList[$op]['status']=$u['status'];
  2902. break;
  2903. }
  2904. }
  2905. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2906. $button2=1;
  2907. $executeList[$op]['status']=4;
  2908. }
  2909. }
  2910. }
  2911. //检测编辑状态
  2912. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2913. $verifyList['staff']=$value['verifyBreakup'];
  2914. }else
  2915. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2916. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2917. $verifyStaff=json_decode($value['verifyStaff'],true);
  2918. Doo::loadModel('role');
  2919. $role=new role();
  2920. if ($verifyList==NULL)
  2921. $verifyList=array();
  2922. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2923. foreach ($verifyList as $k=>$v){
  2924. //init verifyStaff
  2925. if ($v[1]=='ROLE'){
  2926. if (!empty($verifyStaff)){
  2927. $endStaffArray=end($verifyStaff);
  2928. // if ($v[0]==$endStaffArray['nextStaff']){
  2929. // $roleId=$v[0];
  2930. // }
  2931. }
  2932. $roleVerify=json_decode($v[3],true);
  2933. $roleKey=$k;$roleArray=array();
  2934. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2935. foreach ($roleVerify as $o=>$p){
  2936. $staffID=explode ('_',$p);
  2937. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2938. //print_r($staffID);
  2939. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2940. array_push($roleArray, $exp);
  2941. }
  2942. $roleArrayCopy[$v[0]]=$roleArray;
  2943. //$verifyList[$k]['roleArray']=$roleArray;
  2944. }
  2945. $verifyList[$k]['date']="";
  2946. $verifyList[$k]['opinion']="";
  2947. $verifyList[$k]['status']="";
  2948. if (empty($verifyStaff)){
  2949. $verifyList[$k]['date']="";
  2950. $verifyList[$k]['opinion']="";
  2951. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2952. $verifyList[$k]['status']=4;
  2953. $flag=false;
  2954. }
  2955. }else{
  2956. foreach ($verifyStaff as $m=>$u){
  2957. if ($v[0]==$m){
  2958. $verifyList[$k]['date']=$u['date'];
  2959. $verifyList[$k]['opinion']=$u['opinion'];
  2960. $verifyList[$k]['status']=$u['status'];
  2961. $flag=false;
  2962. break;
  2963. }
  2964. }
  2965. $endStaffArray=end($verifyStaff);
  2966. if (isset($endStaffArray['ROLE'])){
  2967. }else{
  2968. // $endKey=key($verifyStaff);
  2969. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2970. // $button=4;
  2971. // $verifyList[$k]['status']=4;
  2972. // }
  2973. }
  2974. }
  2975. }
  2976. $rolename['name']='';
  2977. if (!empty($roleId)){
  2978. Doo::loadModel('role');
  2979. $role=new role();
  2980. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2981. }
  2982. if (!empty($verifyStaff))
  2983. $endStaffArray=end($verifyStaff);
  2984. $KOP=false;
  2985. foreach ($roleArrayCopy as $P=>$A){
  2986. foreach ( $A as $MKI=>$AVL){
  2987. if (!empty($verifyStaff)){
  2988. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2989. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2990. $button=4;
  2991. $roleArrayCopy[$P][$MKI]['status']=4;
  2992. }
  2993. foreach ($verifyStaff as $m=>$u){
  2994. $AVLFK=$AVL[0].'_R';
  2995. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2996. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2997. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2998. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2999. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3000. break;
  3001. }
  3002. }
  3003. }else{
  3004. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3005. $button=4;
  3006. $roleArrayCopy[$P][$MKI]['status']=4;
  3007. }
  3008. }
  3009. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3010. $KOP=true;
  3011. }
  3012. }
  3013. foreach ($roleArrayCopy as $k=>$v){
  3014. foreach ($verifyList as $m=>$n){
  3015. if ($n[0]==$k){
  3016. array_splice($verifyList,$m,1,$v);
  3017. }
  3018. }
  3019. }
  3020. $receiptList[$key]['verifyList']=$verifyList;
  3021. $receiptList[$key]['executeList']=$executeList;
  3022. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3023. $receiptList[$key]['button2']=$button2;
  3024. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3025. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3026. $relust=$value['sum']-$value['loanSum'];
  3027. $receiptList[$key]['relust']=$relust;
  3028. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3029. }
  3030. //print_r($receiptList[$key]['executeList']);
  3031. $data['receiptList']=$receiptList;
  3032. $data['memu']="receipt";
  3033. $data['staff']=$this->staff;
  3034. $data['receiptMemu']='implement';
  3035. $data['verifyId']=$this->verifyId;
  3036. $data['executeId']=$this->executeId;
  3037. $this->render ( "/admin/implement", $data );
  3038. }
  3039. function implementDo(){
  3040. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3041. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  3042. if (!empty($rid)){
  3043. Doo::loadModel('receipt');
  3044. $receipt=new receipt();
  3045. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  3046. $executeCopy=json_decode($rinfo['executeCopy'],true);
  3047. $executeStaff=json_decode($rinfo['executeStaff'],true);
  3048. if(empty($executeStaff)){
  3049. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3050. }else{
  3051. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3052. }
  3053. if (count($executeStaff)==count($executeCopy)){
  3054. $receipt->executeStaff=json_encode($executeStaff);
  3055. $receipt->status=8;
  3056. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3057. $receipt->status=9;
  3058. $receipt->executeDate= date("Y-m-d");
  3059. }else{
  3060. $receipt->executeStaff=json_encode($executeStaff);
  3061. }
  3062. $receipt->update(array('where'=>'rid='.$rid));
  3063. }
  3064. return "/implement";
  3065. }
  3066. function receiptburEdi(){
  3067. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3068. $status=isset($this->params['status'])?$this->params['status']:'';
  3069. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3070. $month=$this->get_args('month')?$this->get_args('month'):"";
  3071. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3072. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3073. if (empty($status))
  3074. $status=$this->get_args('status')?$this->get_args('status'):2;
  3075. $vidList=array();
  3076. $button=0;
  3077. Doo::loadModel('verify');
  3078. Doo::loadModel('receipt');
  3079. Doo::loadModel('staff');
  3080. $staff=new staff();
  3081. $receipt=new receipt();
  3082. $verify=new verify();
  3083. Doo::loadModel('L_category');
  3084. $Lcategory=new L_category();
  3085. Doo::loadModel('enclosur');
  3086. $enclosur=new enclosur();
  3087. Doo::loadModel('loanReceipt');
  3088. $loanReceipt=new loanReceipt();
  3089. //user verify ID
  3090. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3091. foreach ($verifyDetail as $key=>$value){
  3092. array_push($vidList, $value['vid']);
  3093. }
  3094. $vid=implode(",", $vidList);
  3095. if(empty($verifyDetail))
  3096. $vid=0;
  3097. $categoryList=$Lcategory->find(array('asArray'=>true));
  3098. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3099. $ap="";
  3100. if($status==4){
  3101. $ap=4;$status=2;
  3102. }
  3103. //get Receipt By verifyID status 2
  3104. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3105. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3106. $Locate=0;$roleId=0;$button=0;
  3107. foreach ($loanList as $key=>$value){
  3108. $loanList[$key]['Locate']=$Locate;$Locate++;
  3109. $loanList[$key]['reviseDetail']=array();
  3110. if (!empty($value['reviseDetail']))
  3111. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3112. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3113. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3114. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3115. $loanList[$key]['category']=$categoryDetil['title'];
  3116. //检测编辑状态
  3117. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3118. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3119. $verifyStaff=json_decode($value['verifyStaff'],true);
  3120. Doo::loadModel('role');
  3121. $role=new role();
  3122. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3123. foreach ($verifyList as $k=>$v){
  3124. //init verifyStaff
  3125. if ($v[1]=='ROLE'){
  3126. if (!empty($verifyStaff)){
  3127. $endStaffArray=end($verifyStaff);
  3128. }
  3129. $roleVerify=json_decode($v[3],true);
  3130. $roleKey=$k;$roleArray=array();
  3131. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3132. foreach ($roleVerify as $o=>$p){
  3133. $staffID=explode ('_',$p);
  3134. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3135. //print_r($staffID);
  3136. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3137. array_push($roleArray, $exp);
  3138. }
  3139. $roleArrayCopy[$v[0]]=$roleArray;
  3140. //$verifyList[$k]['roleArray']=$roleArray;
  3141. }
  3142. $verifyList[$k]['date']="";
  3143. $verifyList[$k]['opinion']="";
  3144. $verifyList[$k]['status']="";
  3145. if (empty($verifyStaff)){
  3146. $verifyList[$k]['date']="";
  3147. $verifyList[$k]['opinion']="";
  3148. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3149. $verifyList[$k]['status']=4;
  3150. $flag=false;
  3151. }
  3152. }else{
  3153. foreach ($verifyStaff as $m=>$u){
  3154. if ($v[0]==$m){
  3155. $verifyList[$k]['date']=$u['date'];
  3156. $verifyList[$k]['opinion']=$u['opinion'];
  3157. $verifyList[$k]['status']=$u['status'];
  3158. $flag=false;
  3159. break;
  3160. }
  3161. }
  3162. $endStaffArray=end($verifyStaff);
  3163. if (isset($endStaffArray['ROLE'])){
  3164. }else{
  3165. }
  3166. }
  3167. }
  3168. $rolename['name']='';
  3169. if (!empty($roleId)){
  3170. Doo::loadModel('role');
  3171. $role=new role();
  3172. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3173. }
  3174. if (!empty($verifyStaff))
  3175. $endStaffArray=end($verifyStaff);
  3176. $KOP=false;
  3177. foreach ($roleArrayCopy as $P=>$A){
  3178. foreach ( $A as $MKI=>$AVL){
  3179. if (!empty($verifyStaff)){
  3180. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3181. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3182. $button=4;
  3183. $roleArrayCopy[$P][$MKI]['status']=4;
  3184. }
  3185. foreach ($verifyStaff as $m=>$u){
  3186. $AVLFK=$AVL[0].'_R';
  3187. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3188. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3189. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3190. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3191. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3192. break;
  3193. }
  3194. }
  3195. }else{
  3196. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3197. $button=4;
  3198. $roleArrayCopy[$P][$MKI]['status']=4;
  3199. }
  3200. }
  3201. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3202. $KOP=true;
  3203. }
  3204. }
  3205. foreach ($roleArrayCopy as $k=>$v){
  3206. foreach ($verifyList as $m=>$n){
  3207. if ($n[0]==$k){
  3208. array_splice($verifyList,$m,1,$v);
  3209. }
  3210. }
  3211. }
  3212. $loanList[$key]['verifyList']=$verifyList;
  3213. }
  3214. $htmlLoan='';
  3215. if (isset($loanList[0])){
  3216. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3217. if ($value['status']==1)
  3218. $htmlLoan.='<li class="done" >';
  3219. elseif ($value['status']==3)
  3220. $htmlLoan.='<li class="undone" >';
  3221. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3222. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3223. if (isset($value['rolename']))
  3224. $htmlLoan.=$value['rolename'];
  3225. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3226. }
  3227. $data['loanDate']=$loanList[0]['date'];
  3228. }
  3229. $data['htmlLoan']=$htmlLoan;
  3230. //print_r($loanList);
  3231. $Locate=0;$roleId=0;$button=0;
  3232. if($ap==4)
  3233. $status=4;
  3234. foreach ($receiptList as $key=>$value){
  3235. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3236. $receiptList[$key]['reviseDetail']=array();
  3237. if (!empty($value['reviseDetail']))
  3238. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3239. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3240. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3241. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3242. $receiptList[$key]['category']=$categoryDetil['title'];
  3243. //检测编辑状态
  3244. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3245. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3246. $verifyStaff=json_decode($value['verifyStaff'],true);
  3247. Doo::loadModel('role');
  3248. $role=new role();
  3249. //print_r($verifyList);
  3250. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3251. foreach ($verifyList as $k=>$v){
  3252. //init verifyStaff
  3253. if ($v[1]=='ROLE'){
  3254. if (!empty($verifyStaff)){
  3255. $endStaffArray=end($verifyStaff);
  3256. if ($v[0]==$endStaffArray['nextStaff']){
  3257. $roleId=$v[0];
  3258. }
  3259. }
  3260. $roleVerify=json_decode($v[3],true);
  3261. $roleKey=$k;$roleArray=array();
  3262. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3263. foreach ($roleVerify as $o=>$p){
  3264. $staffID=explode ('_',$p);
  3265. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3266. //print_r($staffID);
  3267. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3268. array_push($roleArray, $exp);
  3269. }
  3270. $roleArrayCopy[$v[0]]=$roleArray;
  3271. //$verifyList[$k]['roleArray']=$roleArray;
  3272. }
  3273. //print_r($roleArray);
  3274. $verifyList[$k]['date']="";
  3275. $verifyList[$k]['opinion']="";
  3276. $verifyList[$k]['status']="";
  3277. if (empty($verifyStaff)){
  3278. $verifyList[$k]['date']="";
  3279. $verifyList[$k]['opinion']="";
  3280. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3281. $verifyList[$k]['status']=4;
  3282. $button=4;$flag=false;
  3283. }
  3284. }else{
  3285. foreach ($verifyStaff as $m=>$u){
  3286. if ($v[0]==$m){
  3287. $verifyList[$k]['date']=$u['date'];
  3288. $verifyList[$k]['opinion']=$u['opinion'];
  3289. $verifyList[$k]['status']=$u['status'];
  3290. $flag=false;
  3291. break;
  3292. }
  3293. }
  3294. $endStaffArray=end($verifyStaff);
  3295. if (isset($endStaffArray['ROLE'])){
  3296. }else{
  3297. $endKey=key($verifyStaff);
  3298. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3299. $button=4;
  3300. $verifyList[$k]['status']=4;
  3301. }
  3302. }
  3303. }
  3304. }
  3305. $rolename['name']='';
  3306. if (!empty($roleId)){
  3307. Doo::loadModel('role');
  3308. $role=new role();
  3309. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3310. }
  3311. if (!empty($verifyStaff))
  3312. $endStaffArray=end($verifyStaff);
  3313. $KOP=false;
  3314. foreach ($roleArrayCopy as $P=>$A){
  3315. foreach ( $A as $MKI=>$AVL){
  3316. if (!empty($verifyStaff)){
  3317. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3318. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3319. $button=4;
  3320. $roleArrayCopy[$P][$MKI]['status']=4;
  3321. }
  3322. foreach ($verifyStaff as $m=>$u){
  3323. $AVLFK=$AVL[0].'_R';
  3324. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3325. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3326. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3327. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3328. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3329. break;
  3330. }
  3331. }
  3332. }else{
  3333. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3334. $button=4;
  3335. $roleArrayCopy[$P][$MKI]['status']=4;
  3336. }
  3337. }
  3338. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3339. $KOP=true;
  3340. }
  3341. }
  3342. foreach ($roleArrayCopy as $k=>$v){
  3343. foreach ($verifyList as $m=>$n){
  3344. if ($n[0]==$k){
  3345. array_splice($verifyList,$m,1,$v);
  3346. }
  3347. }
  3348. }
  3349. //print_r($verifyList);
  3350. $receiptList[$key]['verifyList']=$verifyList;
  3351. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3352. $receiptList[$key]['button']=$button;
  3353. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3354. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3355. $relust=$value['sum']-$value['loanSum'];
  3356. $receiptList[$key]['relust']=$relust;
  3357. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3358. }
  3359. //print_r($receiptList);die;
  3360. //$data['verifyDetail']=$verifyDetail;
  3361. $mothHtml="";
  3362. for($i=1;$i<=12;$i++){
  3363. if($month==$i)
  3364. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3365. else
  3366. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3367. }
  3368. //获取审批日志
  3369. Doo::loadModel('receiptLog');
  3370. $receiptLog=new receiptLog();
  3371. $rlList=array();
  3372. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3373. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3374. if (!empty($rlInfo)){
  3375. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3376. }
  3377. //echo $rid;
  3378. //print_r($receiptList);
  3379. $receiptList[0]['rlList']=$rlList;
  3380. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3381. $enclosurHtml='';
  3382. foreach ($enclosurList as $value){
  3383. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3384. }
  3385. $data['enclosurHtml']=$enclosurHtml;
  3386. $data['rolename']=$rolename['name'];
  3387. // $data['datetij']=$tijdate['date'];
  3388. $data['mothHtml']=$mothHtml;
  3389. //print_r($receiptList);
  3390. $data['rid']=$rid;
  3391. $data['tijdate']=$tijdate['date'];
  3392. $data['receiptList']=$receiptList;
  3393. $data['receiptApprovalCount']=count($receiptList);
  3394. $data['status']=$status;
  3395. $data['year']=$year;
  3396. $data['categoryList']=$categoryList;
  3397. $data['staffList']=$staffList;
  3398. $data['cid']=$cid;
  3399. $data['sid']=$sid;
  3400. $data['ap']=$ap;
  3401. $data['memu']="receipt";
  3402. $data['staff']=$this->staff;
  3403. $data['receiptMemu']='approvalExpenses';
  3404. $data['verifyId']=$this->verifyId;
  3405. $data['executeId']=$this->executeId;
  3406. $this->render ( "/admin/receiptburEdi", $data );
  3407. }
  3408. function hisImplement(){
  3409. $item=isset($this->params['item'])?$this->params['item']:"";
  3410. if(empty($item))
  3411. $item=$this->get_args('item')?$this->get_args('item'):"";
  3412. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3413. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3414. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3415. $sop=$this->get_args('sop')?$this->get_args('sop'):'SOP';
  3416. Doo::loadModel('receipt');
  3417. $receipt=new receipt();
  3418. Doo::loadModel('L_category');
  3419. $Lcategory=new L_category();
  3420. Doo::loadModel('verify');
  3421. Doo::loadModel('statistics');
  3422. $statistics=new statistics();
  3423. $verify=new verify();
  3424. Doo::loadModel('staff');
  3425. $staff=new staff();
  3426. $condition="";
  3427. if($item=="expenses")
  3428. $condition=" and Rtype=1 ";
  3429. elseif ($item=="receipts")
  3430. $condition=" and Rtype=0 ";
  3431. elseif ($item=="remits")
  3432. $condition=" and Rtype=2 ";
  3433. $sopString="";
  3434. $dateCondition=" and Year(executeDate) =".$year;
  3435. if($moth!='MONTH'){
  3436. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3437. }
  3438. if($day!='DAY')
  3439. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3440. if ($sop!='SOP')
  3441. $sopString=" and staff=".$sop;
  3442. //$noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3443. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition.$sopString,'desc'=>'rid','asArray'=>true));
  3444. //员工筛选
  3445. $receiptList2=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3446. $sopStaff=array();
  3447. foreach ($receiptList2 as $key=>$value){
  3448. $staffDetail=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3449. $sopStaff[$value['staff']]=$staffDetail['username'];
  3450. }
  3451. $Locate=0;$roleId=0;$button=0;
  3452. foreach ($receiptList as $key=>$value){
  3453. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3454. $receiptList[$key]['reviseDetail']=array();
  3455. if (!empty($value['reviseDetail']))
  3456. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3457. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3458. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3459. $receiptList[$key]['category']=$categoryDetil['title'];
  3460. //检测编辑状态
  3461. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3462. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3463. $verifyStaff=json_decode($value['verifyStaff'],true);
  3464. Doo::loadModel('role');
  3465. $role=new role();
  3466. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3467. foreach ($verifyList as $k=>$v){
  3468. //init verifyStaff
  3469. if ($v[1]=='ROLE'){
  3470. if (!empty($verifyStaff)){
  3471. $endStaffArray=end($verifyStaff);
  3472. }
  3473. $roleVerify=json_decode($v[3],true);
  3474. $roleKey=$k;$roleArray=array();
  3475. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3476. foreach ($roleVerify as $o=>$p){
  3477. $staffID=explode ('_',$p);
  3478. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3479. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3480. array_push($roleArray, $exp);
  3481. }
  3482. $roleArrayCopy[$v[0]]=$roleArray;
  3483. }
  3484. $verifyList[$k]['date']="";
  3485. $verifyList[$k]['opinion']="";
  3486. $verifyList[$k]['status']="";
  3487. if (empty($verifyStaff)){
  3488. $verifyList[$k]['date']="";
  3489. $verifyList[$k]['opinion']="";
  3490. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3491. $verifyList[$k]['status']=4;
  3492. $flag=false;
  3493. }
  3494. }else{
  3495. foreach ($verifyStaff as $m=>$u){
  3496. if ($v[0]==$m){
  3497. $verifyList[$k]['date']=$u['date'];
  3498. $verifyList[$k]['opinion']=$u['opinion'];
  3499. $verifyList[$k]['status']=$u['status'];
  3500. $flag=false;
  3501. break;
  3502. }
  3503. }
  3504. $endStaffArray=end($verifyStaff);
  3505. }
  3506. }
  3507. $rolename['name']='';
  3508. if (!empty($roleId)){
  3509. Doo::loadModel('role');
  3510. $role=new role();
  3511. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3512. }
  3513. if (!empty($verifyStaff))
  3514. $endStaffArray=end($verifyStaff);
  3515. $KOP=false;
  3516. foreach ($roleArrayCopy as $P=>$A){
  3517. foreach ( $A as $MKI=>$AVL){
  3518. if (!empty($verifyStaff)){
  3519. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3520. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3521. $button=4;
  3522. $roleArrayCopy[$P][$MKI]['status']=4;
  3523. }
  3524. foreach ($verifyStaff as $m=>$u){
  3525. $AVLFK=$AVL[0].'_R';
  3526. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3527. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3528. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3529. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3530. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3531. break;
  3532. }
  3533. }
  3534. }else{
  3535. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3536. $button=4;
  3537. $roleArrayCopy[$P][$MKI]['status']=4;
  3538. }
  3539. }
  3540. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3541. $KOP=true;
  3542. }
  3543. }
  3544. foreach ($roleArrayCopy as $k=>$v){
  3545. foreach ($verifyList as $m=>$n){
  3546. if ($n[0]==$k){
  3547. array_splice($verifyList,$m,1,$v);
  3548. }
  3549. }
  3550. }
  3551. $receiptList[$key]['verifyList']=$verifyList;
  3552. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3553. $receiptList[$key]['button']=$button;
  3554. }
  3555. //print_r($sopStaff);
  3556. $mothHtml="";
  3557. for($i=1;$i<=12;$i++){
  3558. if($moth==$i)
  3559. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3560. else
  3561. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3562. }
  3563. $dayHtml="";
  3564. if ($day!="DAY"||$moth!="MONTH"){
  3565. for($i = 1; $i <= 31; $i ++) {
  3566. if($day==$i)
  3567. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3568. else
  3569. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3570. }
  3571. }
  3572. $sopHtml="";
  3573. foreach ($sopStaff as $key=>$value){
  3574. if($sop==$key)
  3575. $sopHtml.='<option value="'.$key.'" selected >'.$value.'</option>';
  3576. else
  3577. $sopHtml.='<option value="'.$key.'" >'.$value.'</option>';
  3578. }
  3579. $data['sopHtml']=$sopHtml;
  3580. $data['dayHtml']=$dayHtml;
  3581. $data['mothHtml']=$mothHtml;
  3582. $data['receiptList']=$receiptList;
  3583. $data['memu']="receipt";
  3584. $data['staff']=$this->staff;
  3585. $data['receiptMemu']='implement';
  3586. $data['verifyId']=$this->verifyId;
  3587. $data['executeId']=$this->executeId;
  3588. $data['item']=$item;
  3589. $data['year']=$year;
  3590. $data['moth']=$moth;
  3591. $data['day']=$day;
  3592. $data['sop']=$sop;
  3593. $this->render ( "/admin/hisImplement", $data );
  3594. }
  3595. function ajaxExamine(){
  3596. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3597. Doo::loadModel('receipt');
  3598. $receipt=new receipt();
  3599. if (!empty($rid)){
  3600. $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
  3601. ,'asArray'=>true));
  3602. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3603. }
  3604. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3605. }
  3606. /*
  3607. * 废弃
  3608. */
  3609. function myReceipt(){
  3610. //all approval past withdraw
  3611. $item=isset($this->params['item'])?$this->params['item']:"";
  3612. if(empty($item))
  3613. $item=$this->get_args('item')?$this->get_args('item'):"";
  3614. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3615. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3616. Doo::loadModel('receipt');
  3617. $receipt=new receipt();
  3618. //pre-loaded
  3619. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3620. //have cache
  3621. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3622. if(!empty($moth))//yearPage
  3623. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3624. $this->showCache($path);
  3625. }
  3626. Doo::loadModel('L_category');
  3627. $Lcategory=new L_category();
  3628. Doo::loadModel('verify');
  3629. Doo::loadModel('statistics');
  3630. $statistics=new statistics();
  3631. $verify=new verify();
  3632. Doo::loadModel('staff');
  3633. $staff=new staff();
  3634. $condition=" and status!=0 ";
  3635. if($item=="approval")
  3636. $condition=" and status=2 ";
  3637. elseif ($item=="withdraw")
  3638. $condition=" and status=3 ";
  3639. elseif ($item=="past")
  3640. $condition=" and status=1 ";
  3641. elseif ($item=="whdw")
  3642. $condition=" and status=4 ";
  3643. $dateCondition=" and Year(date) =".$year;
  3644. if(!empty($moth)){
  3645. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3646. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3647. }else
  3648. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3649. if(empty($stList))
  3650. $stList=array('rePrice'=>0,'agPrice'=>0);
  3651. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3652. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3653. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3654. $Locate=0;$roleId=0;$button=0;
  3655. foreach ($receiptList as $key=>$value){
  3656. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3657. $receiptList[$key]['reviseDetail']=array();
  3658. if (!empty($value['reviseDetail']))
  3659. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3660. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3661. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3662. $receiptList[$key]['category']=$categoryDetil['title'];
  3663. //检测编辑状态
  3664. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3665. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3666. $verifyStaff=json_decode($value['verifyStaff'],true);
  3667. Doo::loadModel('role');
  3668. $role=new role();
  3669. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3670. foreach ($verifyList as $k=>$v){
  3671. //init verifyStaff
  3672. if ($v[1]=='ROLE'){
  3673. if (!empty($verifyStaff)){
  3674. $endStaffArray=end($verifyStaff);
  3675. // if ($v[0]==$endStaffArray['nextStaff']){
  3676. // $roleId=$v[0];
  3677. // }
  3678. }
  3679. $roleVerify=json_decode($v[3],true);
  3680. $roleKey=$k;$roleArray=array();
  3681. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3682. foreach ($roleVerify as $o=>$p){
  3683. $staffID=explode ('_',$p);
  3684. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3685. //print_r($staffID);
  3686. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3687. array_push($roleArray, $exp);
  3688. }
  3689. $roleArrayCopy[$v[0]]=$roleArray;
  3690. //$verifyList[$k]['roleArray']=$roleArray;
  3691. }
  3692. $verifyList[$k]['date']="";
  3693. $verifyList[$k]['opinion']="";
  3694. $verifyList[$k]['status']="";
  3695. if (empty($verifyStaff)){
  3696. $verifyList[$k]['date']="";
  3697. $verifyList[$k]['opinion']="";
  3698. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3699. $verifyList[$k]['status']=4;
  3700. $flag=false;
  3701. }
  3702. }else{
  3703. foreach ($verifyStaff as $m=>$u){
  3704. if ($v[0]==$m){
  3705. $verifyList[$k]['date']=$u['date'];
  3706. $verifyList[$k]['opinion']=$u['opinion'];
  3707. $verifyList[$k]['status']=$u['status'];
  3708. $flag=false;
  3709. break;
  3710. }
  3711. }
  3712. $endStaffArray=end($verifyStaff);
  3713. if (isset($endStaffArray['ROLE'])){
  3714. }else{
  3715. // $endKey=key($verifyStaff);
  3716. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3717. // $button=4;
  3718. // $verifyList[$k]['status']=4;
  3719. // }
  3720. }
  3721. }
  3722. }
  3723. $rolename['name']='';
  3724. if (!empty($roleId)){
  3725. Doo::loadModel('role');
  3726. $role=new role();
  3727. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3728. }
  3729. if (!empty($verifyStaff))
  3730. $endStaffArray=end($verifyStaff);
  3731. $KOP=false;
  3732. foreach ($roleArrayCopy as $P=>$A){
  3733. foreach ( $A as $MKI=>$AVL){
  3734. if (!empty($verifyStaff)){
  3735. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3736. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3737. $button=4;
  3738. $roleArrayCopy[$P][$MKI]['status']=4;
  3739. }
  3740. foreach ($verifyStaff as $m=>$u){
  3741. $AVLFK=$AVL[0].'_R';
  3742. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3743. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3744. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3745. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3746. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3747. break;
  3748. }
  3749. }
  3750. }else{
  3751. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3752. $button=4;
  3753. $roleArrayCopy[$P][$MKI]['status']=4;
  3754. }
  3755. }
  3756. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3757. $KOP=true;
  3758. }
  3759. }
  3760. foreach ($roleArrayCopy as $k=>$v){
  3761. foreach ($verifyList as $m=>$n){
  3762. if ($n[0]==$k){
  3763. array_splice($verifyList,$m,1,$v);
  3764. }
  3765. }
  3766. }
  3767. $receiptList[$key]['verifyList']=$verifyList;
  3768. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3769. $receiptList[$key]['button']=$button;
  3770. }
  3771. //print_r($receiptList);die;
  3772. $mothHtml="";
  3773. for($i=1;$i<=12;$i++){
  3774. if($moth==$i)
  3775. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3776. else
  3777. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3778. }
  3779. $data['mothHtml']=$mothHtml;
  3780. $data['receiptList']=$receiptList;
  3781. $data['memu']="receipt";
  3782. $data['staff']=$this->staff;
  3783. $data['receiptMemu']='receipt';
  3784. $data['verifyId']=$this->verifyId;
  3785. $data['executeId']=$this->executeId;
  3786. $data['item']=$item;
  3787. $data['year']=$year;
  3788. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3789. //sufficient condition to generate cache
  3790. if(empty($moth)&&($year<date("Y"))){
  3791. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3792. if(empty($receiptList)){ //generated files
  3793. ob_start();
  3794. $this->render ( "/admin/saea_myList", $data );
  3795. $this->cacheFile($path);die;
  3796. // $content = ob_get_contents();
  3797. // $fp = fopen($path, "w");
  3798. // fwrite($fp, $content);
  3799. // fclose($fp);
  3800. }
  3801. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3802. $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));
  3803. if(empty($receiptList)){ //generated files
  3804. ob_start();
  3805. $this->render ( "/admin/saea_myList", $data );
  3806. $this->cacheFile($path);die;
  3807. }
  3808. }
  3809. }
  3810. $this->render ( "/admin/saea_myList", $data );
  3811. }
  3812. function saeaCreate(){
  3813. Doo::loadModel('accountItem');
  3814. Doo::loadModel('verify');
  3815. Doo::loadModel('receipt');
  3816. Doo::loadModel('L_category');
  3817. $lCategory=new L_category();
  3818. $receipt=new receipt();
  3819. $verify=new verify();
  3820. $accountItem=new accountItem();
  3821. Doo::loadModel("role");
  3822. $role=new role();
  3823. $acItem=$accountItem->find(array('asArray'=>true));
  3824. $veList=$verify->find(array('asArray'=>true));
  3825. foreach ($veList as $key=>$value){
  3826. $v=json_decode($value['staff']);
  3827. $list=array();
  3828. foreach ($v as $n=>$m){
  3829. if ($m['1']=='ROLE'){
  3830. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3831. $v[$n][1]=$roleInfo['name'];
  3832. array_push($list, $roleInfo['name']);
  3833. }else{
  3834. array_push($list, $v[$n][1]);
  3835. }
  3836. }
  3837. $veList[$key]['staff']=implode('>', $list);
  3838. }
  3839. $data['category']=$lCategory->find(array('asArray'=>true));
  3840. $data['veList']=$veList;
  3841. $data['acItem']=$acItem;
  3842. $data['memu']="receipt";
  3843. $data['staff']=$this->staff;
  3844. $data['receiptMemu']='saeaBorad';
  3845. $data['verifyId']=$this->verifyId;
  3846. $data['executeId']=$this->executeId;
  3847. $this->render ( "/admin/saea_create", $data );
  3848. }
  3849. function addReceipt(){
  3850. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3851. $agency=$this->get_args('agency');
  3852. $travel=$this->get_args('travel');
  3853. $train=$this->get_args('train');
  3854. $other=$this->get_args('other');
  3855. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3856. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3857. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3858. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3859. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3860. Doo::loadModel('receipt');
  3861. Doo::loadModel('receiptDetail');
  3862. Doo::loadModel('accountItem');
  3863. $accountItem=new accountItem();
  3864. $receipt=new receipt();
  3865. Doo::loadModel('enclosur');
  3866. Doo::loadModel('execute');
  3867. $execute=new execute();
  3868. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3869. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3870. // if(!empty($receiptDetail))
  3871. // return "/referReceipt/".$receiptDetail['rid'];
  3872. $aItem=$accountItem->find(array('asArray'=>true));
  3873. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3874. $ag=$tr=$ta=$ot=0;
  3875. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3876. foreach ($aItem as $key=>$value){
  3877. if ($value['category']==$this->AGENCY){
  3878. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3879. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3880. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3881. }
  3882. $ag++;
  3883. }
  3884. if($value['category']==$this->TRAVEL){
  3885. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3886. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3887. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3888. }
  3889. $tr++;
  3890. }
  3891. if($value['category']==$this->TRAIN){
  3892. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3893. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3894. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3895. }
  3896. $ta++;
  3897. }
  3898. if($value['category']==$this->OTHER){
  3899. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3900. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3901. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3902. }
  3903. $ot++;
  3904. }
  3905. }
  3906. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3907. //报销单
  3908. $receipt->accountItem=json_encode($accountJson);
  3909. $receipt->staff=$this->staff[0]['sid'];
  3910. $receipt->sum=number_format($sum, 2, '.', '');
  3911. $receipt->date=date("Y-m-d");
  3912. $receipt->cid=$cid;
  3913. $receipt->status=5;
  3914. //修改审批流程加入角色
  3915. $receipt->verify=$verify;
  3916. $receipt->executeCopy=$executeDetail['staff'];
  3917. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3918. $receipt->explanation=$explanation;
  3919. $rid=$receipt->insert();
  3920. //附件
  3921. if (!empty($enclosurName)){
  3922. $enclosurArray=explode('-', $enclosurName);
  3923. foreach ($enclosurArray as $value){
  3924. $enclosur=new enclosur();
  3925. $enclosur->name=$value;
  3926. $enclosur->rid=$rid;
  3927. $enclosur->insert();
  3928. }
  3929. //print_r($enclosurArray);die;
  3930. }
  3931. //报销详情
  3932. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3933. $receiptDetail=new receiptDetail();
  3934. $receiptDetail->staff=$this->staff[0]['sid'];
  3935. $receiptDetail->item=$value['name'];
  3936. $receiptDetail->itemCategory=$this->AGENCY;
  3937. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3938. $receiptDetail->date=date("Y-m-d");
  3939. $receiptDetail->cid=$cid;
  3940. $receiptDetail->rid=$rid;
  3941. $receiptDetail->status=4;
  3942. $receiptDetail->insert();
  3943. }
  3944. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3945. $receiptDetail=new receiptDetail();
  3946. $receiptDetail->staff=$this->staff[0]['sid'];
  3947. $receiptDetail->item=$value['name'];
  3948. $receiptDetail->itemCategory=$this->TRAVEL;
  3949. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3950. $receiptDetail->date=date("Y-m-d");
  3951. $receiptDetail->cid=$cid;
  3952. $receiptDetail->rid=$rid;
  3953. $receiptDetail->status=4;
  3954. $receiptDetail->insert();
  3955. }
  3956. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3957. $receiptDetail=new receiptDetail();
  3958. $receiptDetail->staff=$this->staff[0]['sid'];
  3959. $receiptDetail->item=$value['name'];
  3960. $receiptDetail->itemCategory=$this->TRAIN;
  3961. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3962. $receiptDetail->date=date("Y-m-d");
  3963. $receiptDetail->cid=$cid;
  3964. $receiptDetail->rid=$rid;
  3965. $receiptDetail->status=4;
  3966. $receiptDetail->insert();
  3967. }
  3968. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3969. $receiptDetail=new receiptDetail();
  3970. $receiptDetail->staff=$this->staff[0]['sid'];
  3971. $receiptDetail->item=$value['name'];
  3972. $receiptDetail->itemCategory=$this->OTHER;
  3973. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3974. $receiptDetail->date=date("Y-m-d");
  3975. $receiptDetail->cid=$cid;
  3976. $receiptDetail->rid=$rid;
  3977. $receiptDetail->status=4;
  3978. $receiptDetail->insert();
  3979. }
  3980. //return "/referReceipt/".$rid;
  3981. }
  3982. return "/saeaBorad";
  3983. }
  3984. function referReceipt(){
  3985. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3986. Doo::loadModel('receipt');
  3987. Doo::loadModel('verify');
  3988. $verify=new verify();
  3989. $receipt=new receipt();
  3990. Doo::loadModel('L_category');
  3991. $lCategory=new L_category();
  3992. Doo::loadModel("role");
  3993. $role=new role();
  3994. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  3995. if(empty($receiptDetail))
  3996. return "/addReceipt";
  3997. foreach ($receiptDetail as $key=>$value){
  3998. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  3999. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4000. $v=json_decode($veList['staff']);
  4001. array_push($v[0], $veList['description']);
  4002. foreach ($v as $n=>$m){
  4003. if ($m['1']=='ROLE'){
  4004. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4005. $v[$n][1]=$roleInfo['name'];
  4006. }
  4007. }
  4008. $receiptDetail[$key]['staff']=$v;
  4009. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4010. $receiptDetail[$key]['category']=$category['title'];
  4011. }
  4012. //print_r($receiptDetail);
  4013. $data['receiptDetail']=$receiptDetail;
  4014. $data['memu']="receipt";
  4015. $data['staff']=$this->staff;
  4016. $data['receiptMemu']='saeaCreate';
  4017. $data['verifyId']=$this->verifyId;
  4018. $data['executeId']=$this->executeId;
  4019. $this->render ( "/admin/saea_confirm", $data );
  4020. }
  4021. function editReceipt(){
  4022. //edit status 4
  4023. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4024. //echo $rid;
  4025. Doo::loadModel('accountItem');
  4026. Doo::loadModel('verify');
  4027. Doo::loadModel('receipt');
  4028. $receipt=new receipt();
  4029. $verify=new verify();
  4030. $accountItem=new accountItem();
  4031. Doo::loadModel('L_category');
  4032. $lCategory=new L_category();
  4033. Doo::loadModel("role");
  4034. $role=new role();
  4035. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  4036. if(empty($receiptDetail))
  4037. return "/saeaCreate";
  4038. $acItem=$accountItem->find(array('asArray'=>true));
  4039. $veList=$verify->find(array('asArray'=>true));
  4040. foreach ($veList as $key=>$value){
  4041. $v=json_decode($value['staff']);
  4042. $list=array();
  4043. foreach ($v as $n=>$m){
  4044. if ($m['1']=='ROLE'){
  4045. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4046. $v[$n][1]=$roleInfo['name'];
  4047. array_push($list, $roleInfo['name']);
  4048. }else{
  4049. array_push($list, $v[$n][1]);
  4050. }
  4051. }
  4052. $veList[$key]['staff']=implode('>', $list);
  4053. }
  4054. //配置编辑信息
  4055. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4056. foreach ($acItem as $key=>$value){
  4057. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4058. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4059. $acItem[$key]['price']=$v['price'];
  4060. }
  4061. }
  4062. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4063. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4064. $acItem[$key]['price']=$v['price'];
  4065. }
  4066. }
  4067. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4068. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4069. $acItem[$key]['price']=$v['price'];
  4070. }
  4071. }
  4072. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4073. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4074. $acItem[$key]['price']=$v['price'];
  4075. }
  4076. }
  4077. }
  4078. $data['category']=$lCategory->find(array('asArray'=>true));
  4079. $data['cSum']=$accountItemList['cSum'];
  4080. $data['sum']=$receiptDetail['sum'];
  4081. $data['receiptDetail']=$receiptDetail;
  4082. $data['veList']=$veList;
  4083. $data['acItem']=$acItem;
  4084. $data['memu']="receipt";
  4085. $data['staff']=$this->staff;
  4086. $data['receiptMemu']='saeaBorad';
  4087. $data['verify']=$receiptDetail['verify'];
  4088. $data['verifyId']=$this->verifyId;
  4089. $data['executeId']=$this->executeId;
  4090. $data['rid']=$rid;
  4091. $this->render ( "/admin/saea_edit", $data );
  4092. }
  4093. function updateReceipt(){
  4094. $agency=$this->get_args('agency');
  4095. $travel=$this->get_args('travel');
  4096. $train=$this->get_args('train');
  4097. $other=$this->get_args('other');
  4098. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4099. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4100. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4101. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4102. if(!empty($explanation)){
  4103. Doo::loadModel('receipt');
  4104. Doo::loadModel('receiptDetail');
  4105. Doo::loadModel('accountItem');
  4106. $accountItem=new accountItem();
  4107. $receipt=new receipt();
  4108. Doo::loadModel('execute');
  4109. $execute=new execute();
  4110. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4111. if(empty($receiptDetail))
  4112. return "/saeaBorad";
  4113. if ($receiptDetail['Rtype']==1)
  4114. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4115. else
  4116. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4117. $aItem=$accountItem->find(array('asArray'=>true));
  4118. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4119. $ag=$tr=$ta=$ot=0;
  4120. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4121. foreach ($aItem as $key=>$value){
  4122. if ($value['category']==$this->AGENCY){
  4123. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4124. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4125. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4126. }
  4127. $ag++;
  4128. }
  4129. if($value['category']==$this->TRAVEL){
  4130. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4131. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4132. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4133. }
  4134. $tr++;
  4135. }
  4136. if($value['category']==$this->TRAIN){
  4137. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4138. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4139. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4140. }
  4141. $ta++;
  4142. }
  4143. if($value['category']==$this->OTHER){
  4144. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4145. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4146. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4147. }
  4148. $ot++;
  4149. }
  4150. }
  4151. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4152. //报销单
  4153. $rid=$receipt->rid=$receiptDetail['rid'];
  4154. $receipt->accountItem=json_encode($accountJson);
  4155. $receipt->staff=$this->staff[0]['sid'];
  4156. $receipt->sum=number_format($sum, 2, '.', '');
  4157. $receipt->date=date("Y-m-d");
  4158. $receipt->cid=$cid;
  4159. if (($receiptDetail['status']!=4)){
  4160. if ($receiptDetail['Rtype']==1)
  4161. $receipt->status=7;
  4162. else
  4163. $receipt->status=5;
  4164. }
  4165. if ($receiptDetail!=4&&!empty($verify))
  4166. $receipt->verify=$verify;
  4167. $receipt->executeCopy=$executeDetail['staff'];
  4168. $receipt->explanation=$explanation;
  4169. $receipt->update();
  4170. $receiptDetail=new receiptDetail();
  4171. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4172. //报销详情
  4173. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4174. $receiptDetail=new receiptDetail();
  4175. $receiptDetail->staff=$this->staff[0]['sid'];
  4176. $receiptDetail->item=$value['name'];
  4177. $receiptDetail->itemCategory=$this->AGENCY;
  4178. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4179. $receiptDetail->date=date("Y-m-d");
  4180. $receiptDetail->cid=$cid;
  4181. $receiptDetail->rid=$rid;
  4182. $receiptDetail->status=4;
  4183. $receiptDetail->insert();
  4184. }
  4185. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4186. $receiptDetail=new receiptDetail();
  4187. $receiptDetail->staff=$this->staff[0]['sid'];
  4188. $receiptDetail->item=$value['name'];
  4189. $receiptDetail->itemCategory=$this->TRAVEL;
  4190. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4191. $receiptDetail->date=date("Y-m-d");
  4192. $receiptDetail->cid=$cid;
  4193. $receiptDetail->rid=$rid;
  4194. $receiptDetail->status=4;
  4195. $receiptDetail->insert();
  4196. }
  4197. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4198. $receiptDetail=new receiptDetail();
  4199. $receiptDetail->staff=$this->staff[0]['sid'];
  4200. $receiptDetail->item=$value['name'];
  4201. $receiptDetail->itemCategory=$this->TRAIN;
  4202. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4203. $receiptDetail->date=date("Y-m-d");
  4204. $receiptDetail->cid=$cid;
  4205. $receiptDetail->rid=$rid;
  4206. $receiptDetail->status=4;
  4207. $receiptDetail->insert();
  4208. }
  4209. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4210. $receiptDetail=new receiptDetail();
  4211. $receiptDetail->staff=$this->staff[0]['sid'];
  4212. $receiptDetail->item=$value['name'];
  4213. $receiptDetail->itemCategory=$this->OTHER;
  4214. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4215. $receiptDetail->date=date("Y-m-d");
  4216. $receiptDetail->cid=$cid;
  4217. $receiptDetail->rid=$rid;
  4218. $receiptDetail->status=4;
  4219. $receiptDetail->insert();
  4220. }
  4221. //return "/referReceipt/".$rid;
  4222. }
  4223. return "/saeaBorad";
  4224. }
  4225. function approvedReceipt(){
  4226. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4227. Doo::loadModel('receipt');
  4228. Doo::loadModel('receiptDetail');
  4229. $receipt=new receipt();
  4230. $receiptDetail=new receiptDetail();
  4231. Doo::loadModel('statistics');
  4232. Doo::loadModel('itemStatistics');
  4233. $statistics=new statistics();
  4234. $itemStatistics=new itemStatistics();
  4235. Doo::loadModel("verify");
  4236. $verify=new verify();
  4237. //审批状态的判定
  4238. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4239. if(empty($receiptDetailList))
  4240. return "/saeaBorad";
  4241. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4242. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4243. if (empty($receiptDetailList['nowStaff'])){
  4244. $nowStaff="";$nowStaffList=array();
  4245. if ($verifyDetail[0][1]=='ROLE'){
  4246. $vStaffString=json_decode($verifyDetail[0][3]);
  4247. foreach ($vStaffString as $key=>$value){
  4248. $staffK=explode("_", $value);
  4249. array_push($nowStaffList, $staffK[0]);
  4250. }
  4251. $nowStaff=implode(',', $nowStaffList);
  4252. }else{
  4253. $nowStaff=$verifyDetail[0][0];
  4254. }
  4255. $receipt->nowStaff=$nowStaff;
  4256. }
  4257. // echo $nowStaff;
  4258. // print_r($verifyDetail);die;
  4259. $receipt->rid=$receiptDetailList['rid'];
  4260. $receipt->date=date("Y-m-d");
  4261. $receipt->status=2;
  4262. $receipt->update();
  4263. $receiptDetail->status=2;
  4264. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4265. Doo::loadModel("receiptLog");
  4266. $receiptLog=new receiptLog();
  4267. Doo::loadModel("verify");
  4268. $verify=new verify();
  4269. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4270. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4271. $jd=json_decode($vr['staff']);$roleId=0;
  4272. foreach ($jd as $key=>$value){
  4273. if ($value[1]=='ROLE'){
  4274. $pos = strpos($value[3], $this->staff[0]['sid']);
  4275. if ($pos !== false) {
  4276. $roleId=$value[0];
  4277. }
  4278. }
  4279. }
  4280. //审批日志
  4281. //echo $roleId;die;
  4282. if (!empty($roleId)){
  4283. Doo::loadModel("role");
  4284. $role=new role();
  4285. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4286. $receiptLog->rolename=$roleInfo['name'];
  4287. }
  4288. $receiptLog->username=$this->staff[0]['username'];
  4289. $receiptLog->uid=$this->staff[0]['sid'];
  4290. $receiptLog->date=date("Y-m-d");
  4291. $receiptLog->opinion='提交审批';
  4292. $receiptLog->img=$this->staff[0]['avatar'];
  4293. $receiptLog->status=2;
  4294. $receiptLog->rid=$rid;
  4295. $receiptLog->insert();
  4296. //statistics item
  4297. $dateArray=explode("-", $receiptDetailList['date']);
  4298. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4299. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4300. //print_r($accountItem['cSum']['agencySum']);die;
  4301. // foreach ($accountItem['cSum'] as $key=>$value){
  4302. // if($key=="agencySum"){
  4303. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4304. // if(empty($iStatistics)){
  4305. // $itemStatistics->cid=$this->staff[0]['cid'];
  4306. // $itemStatistics->staff=$this->staff[0]['sid'];
  4307. // $itemStatistics->price=$value;
  4308. // $itemStatistics->itemCategory=$this->AGENCY;
  4309. // $itemStatistics->date=date("Y-m-d");
  4310. // $itemStatistics->insert();
  4311. // }else{
  4312. // if (!empty($value)){
  4313. // $itemStatistics->price=$value+$iStatistics['price'];
  4314. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4315. // }
  4316. // }
  4317. // }elseif($key=="travelSum"){
  4318. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4319. // if(empty($iStatistics)){
  4320. // $itemStatistics->cid=$this->staff[0]['cid'];
  4321. // $itemStatistics->staff=$this->staff[0]['sid'];
  4322. // $itemStatistics->price=$value;
  4323. // $itemStatistics->itemCategory=$this->TRAVEL;
  4324. // $itemStatistics->date=date("Y-m-d");
  4325. // $itemStatistics->insert();
  4326. // }else{
  4327. // if (!empty($value)){
  4328. // $itemStatistics->price=$value+$iStatistics['price'];
  4329. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4330. // }
  4331. // }
  4332. // }elseif($key=="trainSum"){
  4333. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4334. // if(empty($iStatistics)){
  4335. // $itemStatistics->cid=$this->staff[0]['cid'];
  4336. // $itemStatistics->staff=$this->staff[0]['sid'];
  4337. // $itemStatistics->price=$value;
  4338. // $itemStatistics->itemCategory=$this->TRAIN;
  4339. // $itemStatistics->date=date("Y-m-d");
  4340. // $itemStatistics->insert();
  4341. // }else{
  4342. // if (!empty($value)){
  4343. // $itemStatistics->price=$value+$iStatistics['price'];
  4344. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4345. // }
  4346. // }
  4347. // }elseif($key=="otherSum"){
  4348. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4349. // if(empty($iStatistics)){
  4350. // $itemStatistics->cid=$this->staff[0]['cid'];
  4351. // $itemStatistics->staff=$this->staff[0]['sid'];
  4352. // $itemStatistics->price=$value;
  4353. // $itemStatistics->itemCategory=$this->OTHER;
  4354. // $itemStatistics->date=date("Y-m-d");
  4355. // $itemStatistics->insert();
  4356. // }else{
  4357. // if (!empty($value)){
  4358. // $itemStatistics->price=$value+$iStatistics['price'];
  4359. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4360. // }
  4361. // }
  4362. // }
  4363. // }
  4364. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4365. if(empty($stat)){
  4366. $statistics->date=date("Y-m-d");
  4367. $statistics->cid=$this->staff[0]['cid'];
  4368. $statistics->staff=$this->staff[0]['sid'];
  4369. $statistics->agPrice=0;
  4370. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4371. $statistics->insert();
  4372. }else{
  4373. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4374. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4375. }
  4376. return "/expenses";
  4377. }
  4378. function approval(){
  4379. $status=isset($this->params['status'])?$this->params['status']:'';
  4380. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4381. $month=$this->get_args('month')?$this->get_args('month'):"";
  4382. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4383. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4384. if (empty($status))
  4385. $status=$this->get_args('status')?$this->get_args('status'):2;
  4386. $vidList=array();
  4387. $button=0;
  4388. Doo::loadModel('verify');
  4389. $verify=new verify();
  4390. Doo::loadModel('receipt');
  4391. $receipt=new receipt();
  4392. Doo::loadModel('staff');
  4393. $staff=new staff();
  4394. Doo::loadModel('L_category');
  4395. $Lcategory=new L_category();
  4396. //user verify ID
  4397. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4398. foreach ($verifyDetail as $key=>$value){
  4399. array_push($vidList, $value['vid']);
  4400. }
  4401. $vid=implode(",", $vidList);
  4402. if(empty($verifyDetail))
  4403. $vid=0;
  4404. /*
  4405. */
  4406. $dateCondition=" and Year(date) =".$year;
  4407. if(!empty($month))
  4408. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4409. $categoryList=$Lcategory->find(array('asArray'=>true));
  4410. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4411. $cateCondition="";$staffCondition="";$approvalCondition="";
  4412. if (!empty($cid))
  4413. $cateCondition=' and cid='.$cid;
  4414. if(!empty($sid)){
  4415. $staffCondition=' and staff='.$sid;
  4416. $cateCondition="";
  4417. }
  4418. // elseif($status==1){
  4419. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4420. // }
  4421. if($status==2){
  4422. //查找角色审批人
  4423. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4424. }
  4425. $ap="";
  4426. if($status==4){
  4427. $ap=4;$status=2;
  4428. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4429. }
  4430. if($status==5){
  4431. $status=4;$ap=5;
  4432. }
  4433. //echo $vid;
  4434. //get Receipt By verifyID status 2 .$approvalCondition
  4435. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4436. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4437. ,'desc'=>'rid','asArray'=>true));
  4438. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4439. $Locate=0;
  4440. if($ap==4)
  4441. $status=4;
  4442. elseif ($ap==5)
  4443. $status=5;
  4444. foreach ($receiptList as $key=>$value){
  4445. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4446. $receiptList[$key]['reviseDetail']=array();
  4447. if (!empty($value['reviseDetail']))
  4448. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4449. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4450. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4451. $receiptList[$key]['category']=$categoryDetil['title'];
  4452. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4453. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4454. $verifyStaff=json_decode($value['verifyStaff'],true);
  4455. foreach ($verifyList as $k=>$v){
  4456. //init verifyStaff
  4457. $verifyList[$k]['date']="";
  4458. $verifyList[$k]['opinion']="";
  4459. $verifyList[$k]['status']="";
  4460. if (empty($verifyStaff)){
  4461. $verifyList[$k]['date']="";
  4462. $verifyList[$k]['opinion']="";
  4463. if ($v[0]==$this->staff[0]['sid']){
  4464. $verifyList[$k]['status']=4;
  4465. $button=4;
  4466. }
  4467. }else{
  4468. $flag=true;
  4469. foreach ($verifyStaff as $m=>$u){
  4470. if ($v[0]==$m){
  4471. $verifyList[$k]['date']=$u['date'];
  4472. $verifyList[$k]['opinion']=$u['opinion'];
  4473. $verifyList[$k]['status']=$u['status'];
  4474. $flag=false;
  4475. break;
  4476. }
  4477. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4478. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4479. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4480. }
  4481. if($flag){//检测可编辑
  4482. if($v[0]==$this->staff[0]['sid']){
  4483. $verifyList[$k]['status']=4;$button=4;
  4484. }
  4485. }
  4486. }
  4487. }
  4488. $receiptList[$key]['verifyList']=$verifyList;
  4489. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4490. $receiptList[$key]['button']=$button;
  4491. }
  4492. //print_r($receiptList);die;
  4493. //$data['verifyDetail']=$verifyDetail;
  4494. $mothHtml="";
  4495. for($i=1;$i<=12;$i++){
  4496. if($month==$i)
  4497. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4498. else
  4499. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4500. }
  4501. $data['mothHtml']=$mothHtml;
  4502. $data['receiptList']=$receiptList;
  4503. $data['receiptApprovalCount']=count($receiptList);
  4504. $data['status']=$status;
  4505. $data['year']=$year;
  4506. $data['categoryList']=$categoryList;
  4507. $data['staffList']=$staffList;
  4508. $data['cid']=$cid;
  4509. $data['sid']=$sid;
  4510. $data['ap']=$ap;
  4511. $data['memu']="receipt";
  4512. $data['staff']=$this->staff;
  4513. $data['receiptMemu']='approval';
  4514. $data['verifyId']=$this->verifyId;
  4515. $data['executeId']=$this->executeId;
  4516. $this->render ( "/admin/saea_reportList", $data );
  4517. }
  4518. function approvalDetails(){
  4519. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4520. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4521. $month=$this->get_args('month')?$this->get_args('month'):"";
  4522. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4523. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4524. Doo::loadModel('verify');
  4525. $verify=new verify();
  4526. Doo::loadModel('receipt');
  4527. $receipt=new receipt();
  4528. Doo::loadModel('staff');
  4529. $staff=new staff();
  4530. Doo::loadModel('L_category');
  4531. $Lcategory=new L_category();
  4532. Doo::loadModel('enclosur');
  4533. $enclosur=new enclosur();
  4534. $vidList=array();
  4535. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4536. foreach ($verifyDetail as $key=>$value){
  4537. array_push($vidList, $value['vid']);
  4538. }
  4539. $vid=implode(",", $vidList);
  4540. if(empty($verifyDetail))
  4541. $vid=0;
  4542. $categoryList=$Lcategory->find(array('asArray'=>true));
  4543. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4544. $ap=0;
  4545. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4546. $Locate=0;$roleId=0;$button=0;
  4547. foreach ($receiptList as $key=>$value){
  4548. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4549. $receiptList[$key]['reviseDetail']=array();
  4550. if (!empty($value['reviseDetail']))
  4551. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4552. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4553. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4554. $receiptList[$key]['category']=$categoryDetil['title'];
  4555. //检测编辑状态
  4556. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4557. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4558. $verifyStaff=json_decode($value['verifyStaff'],true);
  4559. Doo::loadModel('role');
  4560. $role=new role();
  4561. //print_r($verifyList);
  4562. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4563. foreach ($verifyList as $k=>$v){
  4564. //init verifyStaff
  4565. if ($v[1]=='ROLE'){
  4566. if (!empty($verifyStaff)){
  4567. $endStaffArray=end($verifyStaff);
  4568. if ($v[0]==$endStaffArray['nextStaff']){
  4569. $roleId=$v[0];
  4570. }
  4571. }
  4572. $roleVerify=json_decode($v[3],true);
  4573. $roleKey=$k;$roleArray=array();
  4574. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4575. foreach ($roleVerify as $o=>$p){
  4576. $staffID=explode ('_',$p);
  4577. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4578. //print_r($staffID);
  4579. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4580. array_push($roleArray, $exp);
  4581. }
  4582. $roleArrayCopy[$v[0]]=$roleArray;
  4583. //$verifyList[$k]['roleArray']=$roleArray;
  4584. }
  4585. //print_r($roleArray);
  4586. $verifyList[$k]['date']="";
  4587. $verifyList[$k]['opinion']="";
  4588. $verifyList[$k]['status']="";
  4589. if (empty($verifyStaff)){
  4590. $verifyList[$k]['date']="";
  4591. $verifyList[$k]['opinion']="";
  4592. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4593. $verifyList[$k]['status']=4;
  4594. $button=4;$flag=false;
  4595. }
  4596. }else{
  4597. foreach ($verifyStaff as $m=>$u){
  4598. if ($v[0]==$m){
  4599. $verifyList[$k]['date']=$u['date'];
  4600. $verifyList[$k]['opinion']=$u['opinion'];
  4601. $verifyList[$k]['status']=$u['status'];
  4602. $flag=false;
  4603. break;
  4604. }
  4605. }
  4606. $endStaffArray=end($verifyStaff);
  4607. if (isset($endStaffArray['ROLE'])){
  4608. }else{
  4609. $endKey=key($verifyStaff);
  4610. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4611. $button=4;
  4612. $verifyList[$k]['status']=4;
  4613. }
  4614. }
  4615. }
  4616. }
  4617. $rolename['name']='';
  4618. if (!empty($roleId)){
  4619. Doo::loadModel('role');
  4620. $role=new role();
  4621. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4622. }
  4623. if (!empty($verifyStaff))
  4624. $endStaffArray=end($verifyStaff);
  4625. $KOP=false;
  4626. foreach ($roleArrayCopy as $P=>$A){
  4627. foreach ( $A as $MKI=>$AVL){
  4628. if (!empty($verifyStaff)){
  4629. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4630. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4631. $button=4;
  4632. $roleArrayCopy[$P][$MKI]['status']=4;
  4633. }
  4634. foreach ($verifyStaff as $m=>$u){
  4635. $AVLFK=$AVL[0].'_R';
  4636. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4637. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4638. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4639. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4640. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4641. break;
  4642. }
  4643. }
  4644. }else{
  4645. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4646. $button=4;
  4647. $roleArrayCopy[$P][$MKI]['status']=4;
  4648. }
  4649. }
  4650. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4651. $KOP=true;
  4652. }
  4653. }
  4654. foreach ($roleArrayCopy as $k=>$v){
  4655. foreach ($verifyList as $m=>$n){
  4656. if ($n[0]==$k){
  4657. array_splice($verifyList,$m,1,$v);
  4658. }
  4659. }
  4660. }
  4661. $receiptList[$key]['verifyList']=$verifyList;
  4662. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4663. $receiptList[$key]['button']=$button;
  4664. }
  4665. $mothHtml="";
  4666. for($i=1;$i<=12;$i++){
  4667. if($month==$i)
  4668. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4669. else
  4670. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4671. }
  4672. //获取审批日志
  4673. Doo::loadModel('receiptLog');
  4674. $receiptLog=new receiptLog();
  4675. $rlList=array();
  4676. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4677. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4678. if (!empty($rlInfo)){
  4679. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4680. }
  4681. $receiptList[0]['rlList']=$rlList;
  4682. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4683. $enclosurHtml='';
  4684. foreach ($enclosurList as $value){
  4685. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4686. }
  4687. $data['enclosurHtml']=$enclosurHtml;
  4688. $data['rolename']=$rolename['name'];
  4689. $data['datetij']=$tijdate['date'];
  4690. $data['mothHtml']=$mothHtml;
  4691. $data['receiptList']=$receiptList;
  4692. $data['receiptApprovalCount']=count($receiptList);
  4693. $data['year']=$year;
  4694. $data['categoryList']=$categoryList;
  4695. $data['staffList']=$staffList;
  4696. $data['cid']=$cid;
  4697. $data['sid']=$sid;
  4698. $data['status']=0;
  4699. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4700. $ap=4;
  4701. }else
  4702. $data['status']=$receiptList[0]['status'];
  4703. if ($receiptList[0]['status']==4){
  4704. $data['status']=5;
  4705. $ap=0;
  4706. }
  4707. $data['ap']=$ap;
  4708. $data['memu']="receipt";
  4709. $data['staff']=$this->staff;
  4710. $data['receiptMemu']='approval';
  4711. $data['verifyId']=$this->verifyId;
  4712. $data['executeId']=$this->executeId;
  4713. $this->render ( "/admin/saeaReportListReport", $data );
  4714. }
  4715. function approvalEdi(){
  4716. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4717. $status=isset($this->params['status'])?$this->params['status']:'';
  4718. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4719. $month=$this->get_args('month')?$this->get_args('month'):"";
  4720. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4721. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4722. if (empty($status))
  4723. $status=$this->get_args('status')?$this->get_args('status'):2;
  4724. $vidList=array();
  4725. $button=0;
  4726. Doo::loadModel('verify');
  4727. Doo::loadModel('receipt');
  4728. Doo::loadModel('staff');
  4729. $staff=new staff();
  4730. $receipt=new receipt();
  4731. $verify=new verify();
  4732. Doo::loadModel('L_category');
  4733. $Lcategory=new L_category();
  4734. Doo::loadModel('enclosur');
  4735. $enclosur=new enclosur();
  4736. //user verify ID
  4737. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4738. foreach ($verifyDetail as $key=>$value){
  4739. array_push($vidList, $value['vid']);
  4740. }
  4741. $vid=implode(",", $vidList);
  4742. if(empty($verifyDetail))
  4743. $vid=0;
  4744. $categoryList=$Lcategory->find(array('asArray'=>true));
  4745. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4746. $ap="";
  4747. if($status==4){
  4748. $ap=4;$status=2;
  4749. }
  4750. //get Receipt By verifyID status 2
  4751. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4752. $Locate=0;$roleId=0;
  4753. if($ap==4)
  4754. $status=4;
  4755. foreach ($receiptList as $key=>$value){
  4756. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4757. $receiptList[$key]['reviseDetail']=array();
  4758. if (!empty($value['reviseDetail']))
  4759. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4760. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4761. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4762. $receiptList[$key]['category']=$categoryDetil['title'];
  4763. //检测编辑状态
  4764. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4765. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4766. $verifyStaff=json_decode($value['verifyStaff'],true);
  4767. // print_r($verifyList);
  4768. //
  4769. // if (empty($verifyStaff)){
  4770. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4771. // $verifyList[0]['status']=4;$button=4;
  4772. // }
  4773. //
  4774. // }else{
  4775. //
  4776. // }
  4777. // die;
  4778. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4779. // echo array_search("green",$a);
  4780. //
  4781. Doo::loadModel('role');
  4782. $role=new role();
  4783. //print_r($verifyList);
  4784. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4785. foreach ($verifyList as $k=>$v){
  4786. //init verifyStaff
  4787. if ($v[1]=='ROLE'){
  4788. if (!empty($verifyStaff)){
  4789. $endStaffArray=end($verifyStaff);
  4790. if ($v[0]==$endStaffArray['nextStaff']){
  4791. $roleId=$v[0];
  4792. }
  4793. }
  4794. $roleVerify=json_decode($v[3],true);
  4795. $roleKey=$k;$roleArray=array();
  4796. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4797. foreach ($roleVerify as $o=>$p){
  4798. $staffID=explode ('_',$p);
  4799. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4800. //print_r($staffID);
  4801. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4802. array_push($roleArray, $exp);
  4803. }
  4804. $roleArrayCopy[$v[0]]=$roleArray;
  4805. //$verifyList[$k]['roleArray']=$roleArray;
  4806. }
  4807. //print_r($roleArray);
  4808. $verifyList[$k]['date']="";
  4809. $verifyList[$k]['opinion']="";
  4810. $verifyList[$k]['status']="";
  4811. if (empty($verifyStaff)){
  4812. $verifyList[$k]['date']="";
  4813. $verifyList[$k]['opinion']="";
  4814. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4815. $verifyList[$k]['status']=4;
  4816. $button=4;$flag=false;
  4817. }
  4818. }else{
  4819. foreach ($verifyStaff as $m=>$u){
  4820. if ($v[0]==$m){
  4821. $verifyList[$k]['date']=$u['date'];
  4822. $verifyList[$k]['opinion']=$u['opinion'];
  4823. $verifyList[$k]['status']=$u['status'];
  4824. $flag=false;
  4825. break;
  4826. }
  4827. }
  4828. $endStaffArray=end($verifyStaff);
  4829. if (isset($endStaffArray['ROLE'])){
  4830. }else{
  4831. $endKey=key($verifyStaff);
  4832. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4833. $button=4;
  4834. $verifyList[$k]['status']=4;
  4835. }
  4836. }
  4837. //print_r($endStaffArray);die;
  4838. // if (empty($verifyStaff)){
  4839. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4840. // $verifyList[$k]['status']=4;$button=4;
  4841. // }
  4842. //
  4843. // }else{
  4844. //
  4845. // }
  4846. // if($flag){//检测可编辑
  4847. // if($v[0]==$this->staff[0]['sid']){
  4848. // $verifyList[$k]['status']=4;$button=4;
  4849. // }
  4850. // }
  4851. }
  4852. }
  4853. $rolename['name']='';
  4854. if (!empty($roleId)){
  4855. Doo::loadModel('role');
  4856. $role=new role();
  4857. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4858. }
  4859. if (!empty($verifyStaff))
  4860. $endStaffArray=end($verifyStaff);
  4861. $KOP=false;
  4862. foreach ($roleArrayCopy as $P=>$A){
  4863. foreach ( $A as $MKI=>$AVL){
  4864. if (!empty($verifyStaff)){
  4865. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4866. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4867. $button=4;
  4868. $roleArrayCopy[$P][$MKI]['status']=4;
  4869. }
  4870. foreach ($verifyStaff as $m=>$u){
  4871. $AVLFK=$AVL[0].'_R';
  4872. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4873. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4874. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4875. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4876. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4877. break;
  4878. }
  4879. }
  4880. }else{
  4881. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4882. $button=4;
  4883. $roleArrayCopy[$P][$MKI]['status']=4;
  4884. }
  4885. }
  4886. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4887. $KOP=true;
  4888. }
  4889. }
  4890. // print_r($roleArrayCopy);
  4891. // echo $roleKey;
  4892. foreach ($roleArrayCopy as $k=>$v){
  4893. foreach ($verifyList as $m=>$n){
  4894. if ($n[0]==$k){
  4895. array_splice($verifyList,$m,1,$v);
  4896. }
  4897. }
  4898. }
  4899. // if ($KOP)
  4900. // array_splice($verifyList,$roleKey,1,$roleArray);
  4901. //print_r($verifyList);
  4902. $receiptList[$key]['verifyList']=$verifyList;
  4903. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4904. $receiptList[$key]['button']=$button;
  4905. }
  4906. //$data['verifyDetail']=$verifyDetail;
  4907. $mothHtml="";
  4908. for($i=1;$i<=12;$i++){
  4909. if($month==$i)
  4910. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4911. else
  4912. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4913. }
  4914. //获取审批日志
  4915. Doo::loadModel('receiptLog');
  4916. $receiptLog=new receiptLog();
  4917. $rlList=array();
  4918. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4919. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4920. if (!empty($rlInfo)){
  4921. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4922. }
  4923. $receiptList[0]['rlList']=$rlList;
  4924. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4925. $enclosurHtml='';
  4926. foreach ($enclosurList as $value){
  4927. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4928. }
  4929. $data['enclosurHtml']=$enclosurHtml;
  4930. $data['rolename']=$rolename['name'];
  4931. $data['datetij']=$tijdate['date'];
  4932. $data['mothHtml']=$mothHtml;
  4933. $data['receiptList']=$receiptList;
  4934. $data['receiptApprovalCount']=count($receiptList);
  4935. $data['status']=$status;
  4936. $data['year']=$year;
  4937. $data['categoryList']=$categoryList;
  4938. $data['staffList']=$staffList;
  4939. $data['cid']=$cid;
  4940. $data['sid']=$sid;
  4941. $data['ap']=$ap;
  4942. $data['memu']="receipt";
  4943. $data['staff']=$this->staff;
  4944. $data['receiptMemu']='approval';
  4945. $data['verifyId']=$this->verifyId;
  4946. $data['executeId']=$this->executeId;
  4947. $this->render ( "/admin/saeaReportListReport", $data );
  4948. }
  4949. function remittance(){
  4950. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4951. $month=$this->get_args('month')?$this->get_args('month'):"";
  4952. Doo::loadModel('receipt');
  4953. $receipt=new receipt();
  4954. Doo::loadModel('staff');
  4955. $staff=new staff();
  4956. $dateCondition=" and Year(pastDate) =".$year;
  4957. if(!empty($month))
  4958. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4959. //get Receipt By verifyID status 1
  4960. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4961. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4962. $dataList=array();
  4963. foreach ($dateList as $d=>$a){
  4964. $dataList[$a['pastDate']]=array();$daySum=0;
  4965. foreach ($receiptList as $key=>$value){
  4966. if($a['pastDate']==$value['pastDate']){
  4967. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4968. $list=array();$html="";
  4969. foreach ($oderList as $v){
  4970. array_push($list, $v['receiptOrder']);
  4971. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4972. }
  4973. $receiptList[$key]['receiptOrder']=$html;
  4974. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4975. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4976. $receiptList[$key]['username']=$sinfo['username'];
  4977. $daySum+=$value['sum'];
  4978. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4979. }
  4980. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4981. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4982. }
  4983. }
  4984. //print_r($dataList);
  4985. $data['dataList']=$dataList;
  4986. $mothHtml="";
  4987. for($i=1;$i<=12;$i++){
  4988. if($month==$i)
  4989. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4990. else
  4991. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4992. }
  4993. $data['year']=$year;
  4994. $data['mothHtml']=$mothHtml;
  4995. $data['memu']="receipt";
  4996. $data['staff']=$this->staff;
  4997. $data['receiptMemu']='approval';
  4998. $data['verifyId']=$this->verifyId;
  4999. $data['executeId']=$this->executeId;
  5000. $this->render ( "/admin/saeaReportListPay", $data );
  5001. }
  5002. function revocationAdjustment(){
  5003. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  5004. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  5005. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5006. //echo $price;die;
  5007. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  5008. Doo::loadModel('receipt');
  5009. $receipt=new receipt();
  5010. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5011. if (empty($receiptDetail['reviseDetail']))
  5012. return "/approval";
  5013. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5014. $RD=array();
  5015. foreach ($reviseDetail as $key=>$value){
  5016. if ($value['price']==$price&&$value['sid']==$sid)
  5017. continue;
  5018. array_push($RD, $value);
  5019. }
  5020. $reviseDetailString=json_encode($RD);
  5021. $receipt->reviseDetail=$reviseDetailString;
  5022. $receipt->sum=$receiptDetail['sum']-$price;
  5023. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  5024. $receipt->update(array('where'=>'rid='.$rid));
  5025. }
  5026. //approvalEdi/37
  5027. return "/approvalEdi/".$rid;
  5028. }
  5029. function updateApprovalReceipt(){
  5030. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5031. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  5032. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5033. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  5034. if(!empty($rid)){
  5035. Doo::loadModel("verify");
  5036. $verify=new verify();
  5037. Doo::loadModel("receiptDetail");
  5038. $receiptDetailObj=new receiptDetail();
  5039. Doo::loadModel("itemStatistics");
  5040. Doo::loadModel("statistics");
  5041. $statistics=new statistics();
  5042. $itemStatistics=new itemStatistics();
  5043. Doo::loadModel("receipt");
  5044. $receipt=new receipt();
  5045. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5046. if (empty($receiptDetail))
  5047. return "/approval";
  5048. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  5049. $verifyString=$verifyDetail['staff'];
  5050. $verifyDetail=json_decode($verifyDetail['staff'],true);
  5051. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  5052. if(empty($opinion)){
  5053. if ($status==3)
  5054. $opinion="终止";
  5055. else
  5056. $opinion="同意支付";
  5057. }
  5058. $nowStaff=0;$nowStaffList=array();
  5059. if(empty($verifyStaff)){
  5060. //还需加入是否已经进入角色审批
  5061. if ($verifyDetail[0][1]=='ROLE'){
  5062. $vStaffString=json_decode($verifyDetail[0][3]);
  5063. foreach ($vStaffString as $key=>$value){
  5064. $staffK=explode("_", $value);
  5065. if ($staffK[0]!=$this->staff[0]['sid'])
  5066. array_push($nowStaffList, $staffK[0]);
  5067. }
  5068. //print_r($verifyDetail);
  5069. //die;
  5070. if (!empty($nowStaffList)){
  5071. $nowStaff=implode(',', $nowStaffList);
  5072. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5073. }else{
  5074. $nowStaff=$verifyDetail[1][0];
  5075. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5076. }
  5077. }else{
  5078. if ($verifyDetail[1][1]=='ROLE'){
  5079. $vStaffString=json_decode($verifyDetail[1][3]);
  5080. //echo "dd";
  5081. foreach ($vStaffString as $key=>$value){
  5082. $staffK=explode("_", $value);
  5083. array_push($nowStaffList, $staffK[0]);
  5084. }
  5085. $nowStaff=implode(',', $nowStaffList);
  5086. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5087. }else{
  5088. $nowStaff=$verifyDetail[1][0];
  5089. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5090. }
  5091. }
  5092. if($status==3)
  5093. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5094. $vStaffString=json_encode($verifyStaff);
  5095. $receipt->nowStaff=$nowStaff;
  5096. $receipt->verifyStaff=$vStaffString;
  5097. }else{
  5098. $VS=end($verifyStaff);
  5099. //非角色审批
  5100. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5101. $nextStaff=0;$roleSTF=false;
  5102. foreach ($verifyDetail as $key=>$value){
  5103. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5104. if (isset($verifyDetail[$key+1])){
  5105. $nextStaff=$verifyDetail[$key+1][0];
  5106. if ($verifyDetail[$key+1][1]=='ROLE')
  5107. $roleSTF=true;
  5108. }
  5109. break;
  5110. }
  5111. }
  5112. if (!$roleSTF){
  5113. $nowStaff=$nextStaff;
  5114. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5115. }else{
  5116. //获取角色下的所有用户ID
  5117. $nowStaffList=array();
  5118. foreach ($verifyDetail as $vfk){
  5119. if ($vfk[1]=='ROLE'){
  5120. $vStaffString=json_decode($vfk[3]);
  5121. foreach ($vStaffString as $key=>$value){
  5122. $staffK=explode("_", $value);
  5123. array_push($nowStaffList, $staffK[0]);
  5124. }
  5125. }
  5126. }
  5127. $nowStaff=implode(',', $nowStaffList);
  5128. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5129. }
  5130. if($status==3){
  5131. $verifyStaff['final']=$status;
  5132. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5133. }
  5134. $vStaffString=json_encode($verifyStaff);
  5135. $receipt->nowStaff=$nowStaff;
  5136. $receipt->verifyStaff=$vStaffString;
  5137. }
  5138. //角色审批
  5139. if (isset($VS['ROLE'])){
  5140. //找出角色人 当前审批角色组
  5141. $verifyJSStaff=array();$nowStaffList2=array();
  5142. foreach ($verifyDetail as $key=>$value){
  5143. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5144. $verifyJSStaff=json_decode($value[3]);
  5145. foreach ($verifyJSStaff as $m){
  5146. $staffK=explode("_", $m);
  5147. array_push($nowStaffList2, $staffK[0]);
  5148. }
  5149. // print_r($nowStaffList2);
  5150. }
  5151. }
  5152. $RoleVerifyStaff=array();
  5153. foreach ($verifyStaff as $key=>$value){
  5154. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5155. foreach ($nowStaffList2 as $m) {
  5156. if ($key==$m."_R")
  5157. $RoleVerifyStaff[$key]=$value;
  5158. }
  5159. }
  5160. }
  5161. // print_r($verifyStaff);
  5162. // print_r($nowStaffList2);
  5163. // print_r($RoleVerifyStaff);
  5164. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5165. //print_r($verifyJSStaff);
  5166. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5167. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5168. //下一个审批人ID
  5169. $nextStaff=0;$falg=false;
  5170. foreach ($verifyDetail as $key=>$value){
  5171. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5172. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5173. $falg=true;
  5174. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5175. foreach ($vStaffString as $v){
  5176. $staffK=explode("_", $v);
  5177. array_push($nowStaffList, $staffK[0]);
  5178. }
  5179. $nowStaff=implode(',', $nowStaffList);
  5180. $nextStaff=$verifyDetail[$key+1][0];
  5181. }elseif(isset($verifyDetail[$key+1])){
  5182. $nextStaff=$verifyDetail[$key+1][0];
  5183. $nowStaff=$nextStaff;
  5184. }else
  5185. $nowStaff='';
  5186. break;
  5187. }
  5188. }
  5189. if ($falg)
  5190. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5191. else
  5192. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5193. // print_r($verifyStaff);
  5194. // echo $nowStaff;die;
  5195. }else{ //进入下一个角色或者审批人
  5196. /*
  5197. */
  5198. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5199. //
  5200. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5201. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5202. // print_r($verifyStaff);
  5203. // die;
  5204. }
  5205. if($status==3){
  5206. $verifyStaff['final']=$status;
  5207. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5208. }
  5209. $vStaffString=json_encode($verifyStaff);
  5210. $receipt->verifyStaff=$vStaffString;
  5211. $receipt->nowStaff=$nowStaff;
  5212. //die;
  5213. //}
  5214. // print_r($verifyStaff);
  5215. // die;
  5216. }
  5217. //print_r($verifyStaff);die;
  5218. }
  5219. //print_r($verifyDetail);
  5220. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5221. foreach ($verifyDetail as $k=>$v){
  5222. if ($v[1]=='ROLE'){
  5223. $roleId=$v[0];
  5224. $roleVerify=json_decode($v[3],true);
  5225. $roleKey=$k;$roleArray=array();
  5226. foreach ($roleVerify as $o=>$p){
  5227. $staffID=explode ('_',$p);
  5228. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5229. array_push($roleArray, $exp);
  5230. }
  5231. $verifyDetailCopy[$v[0]]=$roleArray;
  5232. }
  5233. }
  5234. //print_r($verifyDetail);
  5235. foreach ($verifyDetailCopy as $k=>$v){
  5236. foreach ($verifyDetail as $m=>$n){
  5237. if ($n[0]==$k){
  5238. array_splice($verifyDetail,$m,1,$v);
  5239. }
  5240. }
  5241. }
  5242. // die;
  5243. // if (!empty($roleArray))
  5244. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5245. // echo $roleId;
  5246. // print_r($verifyStaff);
  5247. // print_r($verifyDetail);
  5248. // die;
  5249. Doo::loadModel("receiptLog");
  5250. $receiptLog=new receiptLog();
  5251. //审批日志
  5252. if (!isset($verifyStaff['final'])){
  5253. if (!empty($roleId)){
  5254. Doo::loadModel("role");
  5255. $role=new role();
  5256. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5257. $receiptLog->rolename=$roleInfo['name'];
  5258. }
  5259. $receiptLog->username=$this->staff[0]['username'];
  5260. $receiptLog->uid=$this->staff[0]['sid'];
  5261. $receiptLog->date=date("Y-m-d");
  5262. $receiptLog->opinion=$opinion;
  5263. $receiptLog->img=$this->staff[0]['avatar'];
  5264. $receiptLog->status=1;
  5265. $receiptLog->rid=$rid;
  5266. $receiptLog->insert();
  5267. }
  5268. if (isset($verifyStaff['final'])){//rDetail
  5269. $receipt->verifyBreakup=$verifyString;
  5270. $receipt->status=3;
  5271. $receiptDetailObj->status=3;
  5272. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5273. if (!empty($roleId)){
  5274. Doo::loadModel("role");
  5275. $role=new role();
  5276. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5277. $receiptLog->rolename=$roleInfo['name'];
  5278. }
  5279. $receiptLog->username=$this->staff[0]['username'];
  5280. $receiptLog->uid=$this->staff[0]['sid'];
  5281. $receiptLog->date=date("Y-m-d");
  5282. $receiptLog->opinion=$opinion;
  5283. $receiptLog->img=$this->staff[0]['avatar'];
  5284. $receiptLog->status=3;
  5285. $receiptLog->rid=$rid;
  5286. $receiptLog->insert();
  5287. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5288. $receipt->status=1;$reviseSum=0;
  5289. $receipt->verifyBreakup=$verifyString;
  5290. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5291. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5292. foreach ($reviseDetail as $key=>$value){
  5293. $receiptDetailObj=new receiptDetail();
  5294. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5295. $receiptDetailObj->item=$value['description'];
  5296. $receiptDetailObj->itemCategory="报销金额调整";
  5297. $receiptDetailObj->price=$value['price'];
  5298. $receiptDetailObj->date=$receiptDetail['date'];
  5299. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5300. $receiptDetailObj->rid=$rid;
  5301. $receiptDetailObj->status=1;
  5302. $receiptDetailObj->insert();
  5303. $reviseSum+=$value['price'];
  5304. }
  5305. $itemStatistics=new itemStatistics();
  5306. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5307. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5308. $itemStatistics->price=$reviseSum;
  5309. $itemStatistics->itemCategory="报销金额调整";
  5310. $itemStatistics->date=$receiptDetail['date'];
  5311. $itemStatistics->insert();
  5312. }
  5313. $receiptDetailObj=new receiptDetail();
  5314. $receiptDetailObj->status=1;
  5315. $receiptDetailObj->pastDate=date("Y-m-d");
  5316. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5317. $dateArray=explode("-", $receiptDetail['date']);
  5318. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5319. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5320. if(empty($stat)){
  5321. $statistics->date=$receiptDetail['date'];
  5322. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5323. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5324. $statistics->agPrice=$receiptDetail['sum'];
  5325. $statistics->rePrice=$reviseSum;
  5326. $statistics->insert();
  5327. }else{
  5328. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5329. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5330. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5331. }
  5332. $dateArray=explode("-", $receiptDetail['date']);
  5333. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5334. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5335. foreach ($accountItem['cSum'] as $key=>$value){
  5336. if($key=="agencySum"){
  5337. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5338. if(empty($iStatistics)){
  5339. $itemStatistics->cid=$receiptDetail['cid'];;
  5340. $itemStatistics->staff=$receiptDetail['staff'];
  5341. $itemStatistics->price=$value;
  5342. $itemStatistics->itemCategory=$this->AGENCY;
  5343. $itemStatistics->date=$receiptDetail['date'];
  5344. $itemStatistics->insert();
  5345. }else{
  5346. if (!empty($value)){
  5347. $itemStatistics->price=$value+$iStatistics['price'];
  5348. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5349. }
  5350. }
  5351. }elseif($key=="travelSum"){
  5352. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5353. if(empty($iStatistics)){
  5354. $itemStatistics->cid=$receiptDetail['cid'];
  5355. $itemStatistics->staff=$receiptDetail['staff'];
  5356. $itemStatistics->price=$value;
  5357. $itemStatistics->itemCategory=$this->TRAVEL;
  5358. $itemStatistics->date=$receiptDetail['date'];
  5359. $itemStatistics->insert();
  5360. }else{
  5361. if (!empty($value)){
  5362. $itemStatistics->price=$value+$iStatistics['price'];
  5363. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5364. }
  5365. }
  5366. }elseif($key=="trainSum"){
  5367. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5368. if(empty($iStatistics)){
  5369. $itemStatistics->cid=$receiptDetail['cid'];
  5370. $itemStatistics->staff=$receiptDetail['staff'];
  5371. $itemStatistics->price=$value;
  5372. $itemStatistics->itemCategory=$this->TRAIN;
  5373. $itemStatistics->date=$receiptDetail['date'];
  5374. $itemStatistics->insert();
  5375. }else{
  5376. if (!empty($value)){
  5377. $itemStatistics->price=$value+$iStatistics['price'];
  5378. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5379. }
  5380. }
  5381. }elseif($key=="otherSum"){
  5382. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5383. if(empty($iStatistics)){
  5384. $itemStatistics->cid=$receiptDetail['cid'];
  5385. $itemStatistics->staff=$receiptDetail['staff'];
  5386. $itemStatistics->price=$value;
  5387. $itemStatistics->itemCategory=$this->OTHER;
  5388. $itemStatistics->date=$receiptDetail['date'];
  5389. $itemStatistics->insert();
  5390. }else{
  5391. if (!empty($value)){
  5392. $itemStatistics->price=$value+$iStatistics['price'];
  5393. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5394. }
  5395. }
  5396. }
  5397. }
  5398. $receipt->pastDate=date("Y-m-d");
  5399. }
  5400. $receipt->update(array('where'=>' rid = '.$rid));
  5401. return "/approvalExpenses/2";
  5402. }
  5403. }
  5404. function expensesRetreats(){
  5405. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5406. if (!empty($rid)){
  5407. //操作记录
  5408. Doo::loadModel("receipt");
  5409. $receipt=new receipt();
  5410. Doo::loadModel("receiptLog");
  5411. $receiptLog=new receiptLog();
  5412. Doo::loadModel("verify");
  5413. $verify=new verify();
  5414. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5415. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5416. $jd=json_decode($vr['staff']);$roleId=0;
  5417. foreach ($jd as $key=>$value){
  5418. if ($value[1]=='ROLE'){
  5419. $pos = strpos($value[3], $this->staff[0]['sid']);
  5420. if ($pos !== false) {
  5421. $roleId=$value[0];
  5422. }
  5423. }
  5424. }
  5425. //审批日志
  5426. //echo $roleId;die;
  5427. if (!empty($roleId)){
  5428. Doo::loadModel("role");
  5429. $role=new role();
  5430. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5431. $receiptLog->rolename=$roleInfo['name'];
  5432. }
  5433. $receiptLog->username=$this->staff[0]['username'];
  5434. $receiptLog->uid=$this->staff[0]['sid'];
  5435. $receiptLog->date=date("Y-m-d");
  5436. $receiptLog->opinion='撤回';
  5437. $receiptLog->img=$this->staff[0]['avatar'];
  5438. $receiptLog->status=4;
  5439. $receiptLog->rid=$rid;
  5440. $receiptLog->insert();
  5441. $receipt->status=4;
  5442. $receipt->update(array('where'=>'rid='.$rid));
  5443. }
  5444. //echo "ddd";
  5445. return '/approvalExpenses';
  5446. }
  5447. function updateCheReceipt(){
  5448. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5449. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5450. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5451. if (!empty($rid)){
  5452. //操作记录
  5453. Doo::loadModel("receipt");
  5454. $receipt=new receipt();
  5455. Doo::loadModel("receiptLog");
  5456. $receiptLog=new receiptLog();
  5457. Doo::loadModel("verify");
  5458. $verify=new verify();
  5459. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5460. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5461. $jd=json_decode($vr['staff']);$roleId=0;
  5462. foreach ($jd as $key=>$value){
  5463. if ($value[1]=='ROLE'){
  5464. $pos = strpos($value[3], $this->staff[0]['sid']);
  5465. if ($pos !== false) {
  5466. $roleId=$value[0];
  5467. }
  5468. }
  5469. }
  5470. //审批日志
  5471. //echo $roleId;die;
  5472. if (!empty($roleId)){
  5473. Doo::loadModel("role");
  5474. $role=new role();
  5475. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5476. $receiptLog->rolename=$roleInfo['name'];
  5477. }
  5478. $receiptLog->username=$this->staff[0]['username'];
  5479. $receiptLog->uid=$this->staff[0]['sid'];
  5480. $receiptLog->date=date("Y-m-d");
  5481. $receiptLog->opinion=$opinion;
  5482. $receiptLog->img=$this->staff[0]['avatar'];
  5483. $receiptLog->status=4;
  5484. $receiptLog->rid=$rid;
  5485. $receiptLog->insert();
  5486. $receipt->status=4;
  5487. $receipt->update(array('where'=>'rid='.$rid));
  5488. echo json_encode ( array (
  5489. 'status' => 1
  5490. ) );die;
  5491. }
  5492. echo json_encode ( array (
  5493. 'status' => 2
  5494. ) );die;
  5495. //echo "ddd";
  5496. //return '/saeaBorad';
  5497. }
  5498. function revisePrice(){
  5499. $description=$this->get_args('description')?$this->get_args('description'):"";
  5500. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5501. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5502. //echo $price;die;
  5503. if (!empty($rid)){
  5504. Doo::loadModel("receipt");
  5505. $receipt=new receipt();
  5506. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5507. if (empty($receiptDetail))
  5508. return "/approval";
  5509. $reviseDetail=array();
  5510. if (empty($receiptDetail['reviseDetail'])){
  5511. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5512. $reviseDetailString=json_encode($reviseDetail);
  5513. $receipt->reviseDetail=$reviseDetailString;
  5514. $receipt->revisePrice=$price;
  5515. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5516. }else{
  5517. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5518. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5519. $reviseDetailString=json_encode($reviseDetail);
  5520. $receipt->reviseDetail=$reviseDetailString;
  5521. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5522. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5523. }
  5524. $receipt->update(array('where'=>'rid='.$rid));
  5525. }
  5526. return '/approvalEdi/'.$rid;
  5527. }
  5528. function personalCollect(){
  5529. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5530. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5531. $this->showCache($path);
  5532. Doo::loadModel("receiptDetail");
  5533. Doo::loadModel("itemStatistics");
  5534. Doo::loadModel('statistics');
  5535. $statistics=new statistics();
  5536. $itemStatistics=new itemStatistics();
  5537. $receiptDetail=new receiptDetail();
  5538. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5539. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5540. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5541. //create collect html
  5542. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5543. $adjustment=array();
  5544. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5545. array_push($collectArray['日常相关费用'], $collectHtml);
  5546. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5547. array_push($collectArray['差旅相关费用'], $collectHtml);
  5548. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5549. array_push($collectArray['培训班费用'], $collectHtml);
  5550. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5551. array_push($collectArray['其他'], $collectHtml);
  5552. $data['collectArray']=$collectArray;
  5553. //statistics html
  5554. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5555. if(empty($stList))
  5556. $stList=array('rePrice'=>0,'agPrice'=>0);
  5557. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5558. //Adjustment price html
  5559. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5560. array_push($adjustment, $collectHtml);
  5561. $data['adjustment']=$adjustment;
  5562. //total price html
  5563. $collectHtml="";$total=0;
  5564. for ($i=1;$i<=12;$i++){
  5565. $sumPrice=0;
  5566. foreach ($receiptCollectList as $key=>$value){
  5567. if($value['month']==$i){
  5568. $sumPrice+=$value['price'];
  5569. }
  5570. }
  5571. if ($sumPrice==0)
  5572. $collectHtml.='<td class="taR">-</td>';
  5573. else
  5574. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5575. $total+=$sumPrice;
  5576. }
  5577. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5578. $data['totalPrice']=$collectHtml;
  5579. $data['year']=$year;
  5580. $data['totalYear']=$total;
  5581. $data['memu']="receipt";
  5582. $data['staff']=$this->staff;
  5583. $data['receiptMemu']='personalCollect';
  5584. $data['verifyId']=$this->verifyId;
  5585. $data['executeId']=$this->executeId;
  5586. //year staff status 2,4
  5587. if($year<date("Y")){
  5588. Doo::loadModel('receipt');
  5589. $receipt=new receipt();
  5590. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5591. if(empty($receiptList)){
  5592. ob_start();
  5593. $this->render ( "/admin/saea_slist_collect", $data );
  5594. $this->cacheFile($path);die;
  5595. }
  5596. }
  5597. $this->render ( "/admin/saea_slist_collect", $data );
  5598. }
  5599. function personalCollectDetail(){
  5600. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5601. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5602. $this->showCache($path);
  5603. Doo::loadModel("receiptDetail");
  5604. Doo::loadModel("itemStatistics");
  5605. Doo::loadModel('statistics');
  5606. Doo::loadModel('accountItem');
  5607. $accountItem=new accountItem();
  5608. $statistics=new statistics();
  5609. $itemStatistics=new itemStatistics();
  5610. $receiptDetail=new receiptDetail();
  5611. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5612. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5613. $accountList=$accountItem->find(array('asArray'=>true));
  5614. //create CollectDetail HTML
  5615. $collectHtml=array();
  5616. foreach ($accountList as $key=>$value){
  5617. $html="";$asum=0;
  5618. for ($i=1;$i<=12;$i++){
  5619. $falg=true;
  5620. foreach ($receiptCollectList as $v) {
  5621. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5622. $asum+=$v['price'];
  5623. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5624. }
  5625. }
  5626. if($falg)
  5627. $html.='<td class="taR">-</td>';
  5628. }
  5629. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5630. $collectHtml[$value['category']][$value['name']]=$html;
  5631. }
  5632. $data['collectHtml']=$collectHtml;
  5633. //create Adjustment price html
  5634. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5635. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5636. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5637. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5638. array_push($collectArray['日常相关费用'], $collectHtml);
  5639. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5640. array_push($collectArray['差旅相关费用'], $collectHtml);
  5641. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5642. array_push($collectArray['培训班费用'], $collectHtml);
  5643. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5644. array_push($collectArray['其他'], $collectHtml);
  5645. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5646. array_push($adjustment, $collectHtml);
  5647. //total price html
  5648. $collectHtml="";$total=0;
  5649. for ($i=1;$i<=12;$i++){
  5650. $sumPrice=0;
  5651. foreach ($receiptCollectList 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. //statistics html
  5664. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5665. if(empty($stList))
  5666. $stList=array('rePrice'=>0,'agPrice'=>0);
  5667. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5668. $data['collectArray']=$collectArray;
  5669. $data['adjustment']=$adjustment;
  5670. $data['totalPrice']=$collectHtml;
  5671. $data['totalYear']=$total;
  5672. $data['year']=$year;
  5673. $data['memu']="receipt";
  5674. $data['staff']=$this->staff;
  5675. $data['receiptMemu']='personalCollect';
  5676. $data['verifyId']=$this->verifyId;
  5677. $data['executeId']=$this->executeId;
  5678. //year staff status 2,4
  5679. if($year<date("Y")){
  5680. Doo::loadModel('receipt');
  5681. $receipt=new receipt();
  5682. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5683. if(empty($receiptList)){
  5684. ob_start();
  5685. $this->render ( "/admin/saeaCollectArticles", $data );
  5686. $this->cacheFile($path);die;
  5687. }
  5688. }
  5689. $this->render ( "/admin/saeaCollectArticles", $data );
  5690. }
  5691. function companyCategoryCollect(){
  5692. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5693. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5694. $this->showCache($path);
  5695. Doo::loadModel('L_category');
  5696. Doo::loadModel('itemStatistics');
  5697. Doo::loadModel('statistics');
  5698. $statistics=new statistics();
  5699. $Lcategory=new L_category();
  5700. $itemStatistics=new itemStatistics();
  5701. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5702. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5703. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5704. //ceatre companyCollectHtml
  5705. foreach ($LcategoryList as $value){
  5706. $html="";$asum=0;
  5707. for ($i=1;$i<=12;$i++){
  5708. $falg=true;
  5709. foreach ($itemStatisticsList as $v){
  5710. if($value['cid']==$v['cid']&&$i==$v['month']){
  5711. $asum+=$v['price'];
  5712. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5713. }
  5714. }
  5715. if($falg)
  5716. $html.='<td class="taR">-</td>';
  5717. }
  5718. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5719. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5720. }
  5721. $data['companyHtml']=$collectHtml;
  5722. //total price html
  5723. $collectHtml="";$total=0;
  5724. for ($i=1;$i<=12;$i++){
  5725. $sumPrice=0;
  5726. foreach ($itemStatisticsList as $key=>$value){
  5727. if($value['month']==$i){
  5728. $sumPrice+=$value['price'];
  5729. }
  5730. }
  5731. if ($sumPrice==0)
  5732. $collectHtml.='<td class="taR">-</td>';
  5733. else
  5734. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5735. $total+=$sumPrice;
  5736. }
  5737. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5738. $data['companyTotalHtml']=$collectHtml;
  5739. $data['total']=$total;
  5740. //statistics html
  5741. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5742. if(empty($stList))
  5743. $stList=array('rePrice'=>0,'agPrice'=>0);
  5744. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5745. $data['year']=$year;
  5746. $data['memu']="receipt";
  5747. $data['staff']=$this->staff;
  5748. $data['receiptMemu']='companyCategoryCollect';
  5749. $data['verifyId']=$this->verifyId;
  5750. $data['executeId']=$this->executeId;
  5751. //year staff status 2,4
  5752. if($year<date("Y")){
  5753. Doo::loadModel('receipt');
  5754. $receipt=new receipt();
  5755. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5756. if(empty($receiptList)){
  5757. ob_start();
  5758. $this->render ( "/admin/saeaCompanyCollect", $data );
  5759. $this->cacheFile($path);die;
  5760. }
  5761. }
  5762. $this->render ( "/admin/saeaCompanyCollect", $data );
  5763. }
  5764. function categoryCollectDetail(){
  5765. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5766. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5767. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5768. $this->showCache($path);
  5769. Doo::loadModel('statistics');
  5770. $statistics=new statistics();
  5771. Doo::loadModel("receiptDetail");
  5772. $receiptDetail=new receiptDetail();
  5773. Doo::loadModel('L_category');
  5774. $Lcategory=new L_category();
  5775. Doo::loadModel('accountItem');
  5776. $accountItem=new accountItem();
  5777. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5778. if ($cid==0){
  5779. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5780. if ($cid==0)
  5781. $cid=$LcategoryList[0]['cid'];
  5782. }
  5783. $data['LcategoryList']=$LcategoryList;
  5784. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5785. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5786. $accountList=$accountItem->find(array('asArray'=>true));
  5787. //create CollectDetail HTML
  5788. $collectHtml=array();
  5789. foreach ($accountList as $key=>$value){
  5790. $html="";$asum=0;
  5791. for ($i=1;$i<=12;$i++){
  5792. $falg=true;
  5793. foreach ($receiptCollectList as $v) {
  5794. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5795. $asum+=$v['price'];
  5796. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5797. }
  5798. }
  5799. if($falg)
  5800. $html.='<td class="taR">-</td>';
  5801. }
  5802. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5803. $collectHtml[$value['category']][$value['name']]=$html;
  5804. }
  5805. $data['collectHtml']=$collectHtml;
  5806. //create Adjustment price html
  5807. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5808. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5809. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5810. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5811. array_push($collectArray['日常相关费用'], $collectHtml);
  5812. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5813. array_push($collectArray['差旅相关费用'], $collectHtml);
  5814. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5815. array_push($collectArray['培训班费用'], $collectHtml);
  5816. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5817. array_push($collectArray['其他'], $collectHtml);
  5818. $data['collectArray']=$collectArray;
  5819. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5820. array_push($adjustment, $collectHtml);
  5821. $data['adjustment']=$adjustment;
  5822. //total price html
  5823. $collectHtml="";$total=0;
  5824. for ($i=1;$i<=12;$i++){
  5825. $sumPrice=0;
  5826. foreach ($receiptCollectList as $key=>$value){
  5827. if($value['month']==$i){
  5828. $sumPrice+=$value['price'];
  5829. }
  5830. }
  5831. if ($sumPrice==0)
  5832. $collectHtml.='<td class="taR">-</td>';
  5833. else
  5834. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5835. $total+=$sumPrice;
  5836. }
  5837. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5838. //statistics html
  5839. $stList=$statistics->statisticsByCid($year,$cid);
  5840. if(empty($stList))
  5841. $stList=array('rePrice'=>0,'agPrice'=>0);
  5842. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5843. $data['totalYear']=$total;
  5844. $data['year']=$year;
  5845. $data['cid']=$cid;
  5846. $data['memu']="receipt";
  5847. $data['staff']=$this->staff;
  5848. $data['receiptMemu']='companyCategoryCollect';
  5849. $data['verifyId']=$this->verifyId;
  5850. $data['executeId']=$this->executeId;
  5851. //year staff status 2,4
  5852. if($year<date("Y")){
  5853. Doo::loadModel('receipt');
  5854. $receipt=new receipt();
  5855. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5856. if(empty($receiptList)){
  5857. ob_start();
  5858. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5859. $this->cacheFile($path);die;
  5860. }
  5861. }
  5862. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5863. }
  5864. function staffCollect(){
  5865. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5866. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5867. //$this->showCache($path);
  5868. Doo::loadModel('statistics');
  5869. $statistics=new statistics();
  5870. Doo::loadModel("receiptDetail");
  5871. $receiptDetail=new receiptDetail();
  5872. Doo::loadModel('L_category');
  5873. $Lcategory=new L_category();
  5874. Doo::loadModel('accountItem');
  5875. $accountItem=new accountItem();
  5876. Doo::loadModel('staff');
  5877. $staff=new staff();
  5878. Doo::loadModel('itemStatistics');
  5879. $itemStatistics=new itemStatistics();
  5880. /*
  5881. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5882. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5883. if(empty($stList))
  5884. $stList=array('rePrice'=>0,'agPrice'=>0);
  5885. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5886. */
  5887. //statistics html
  5888. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5889. if(empty($stList))
  5890. $stList=array('rePrice'=>0,'agPrice'=>0);
  5891. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5892. //---
  5893. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5894. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5895. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5896. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5897. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5898. //print_r($itemStatisticsList);die;
  5899. //ceatre companyCollectHtml
  5900. foreach ($categoryList as $vlu){
  5901. $count=$vlu['count']+1;
  5902. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5903. $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;
  5904. foreach ($staffList as $value){
  5905. if ($vlu['cid']==$value['cid']){
  5906. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5907. $asum=0;
  5908. for ($i=1;$i<=12;$i++){
  5909. $falg=true;
  5910. foreach ($itemStatisticsList as $v){
  5911. if($value['sid']==$v['staff']&&$i==$v['month']){
  5912. if ($v['month']==1)
  5913. $m1+=$v['price'];
  5914. if ($v['month']==2)
  5915. $m2+=$v['price'];
  5916. if ($v['month']==3)
  5917. $m3+=$v['price'];
  5918. if ($v['month']==4)
  5919. $m4+=$v['price'];
  5920. if ($v['month']==5)
  5921. $m5+=$v['price'];
  5922. if ($v['month']==6)
  5923. $m6+=$v['price'];
  5924. if ($v['month']==7)
  5925. $m7+=$v['price'];
  5926. if ($v['month']==8)
  5927. $m8+=$v['price'];
  5928. if ($v['month']==9)
  5929. $m9+=$v['price'];
  5930. if ($v['month']==10)
  5931. $m10+=$v['price'];
  5932. if ($v['month']==11)
  5933. $m11+=$v['price'];
  5934. if ($v['month']==12)
  5935. $m12+=$v['price'];
  5936. $asum+=$v['price'];
  5937. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5938. }
  5939. }
  5940. if($falg)
  5941. $html.='<td class="taR">-</td>';
  5942. }
  5943. $m13+=$asum;
  5944. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5945. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5946. $html="";
  5947. }
  5948. }
  5949. $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>
  5950. <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>
  5951. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5952. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5953. }
  5954. $data['companyHtml']=$collectHtml;
  5955. //total price html
  5956. $collectHtml="";$total=0;
  5957. for ($i=1;$i<=12;$i++){
  5958. $sumPrice=0;
  5959. foreach ($itemStatisticsList as $key=>$value){
  5960. if($value['month']==$i){
  5961. $sumPrice+=$value['price'];
  5962. }
  5963. }
  5964. if ($sumPrice==0)
  5965. $collectHtml.='<td class="taR">-</td>';
  5966. else
  5967. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5968. $total+=$sumPrice;
  5969. }
  5970. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5971. $data['companyTotalHtml']=$collectHtml;
  5972. $data['total']=$total;
  5973. $data['year']=$year;
  5974. $data['memu']="receipt";
  5975. $data['staff']=$this->staff;
  5976. $data['receiptMemu']='companyCategoryCollect';
  5977. $data['verifyId']=$this->verifyId;
  5978. $data['executeId']=$this->executeId;
  5979. if ($year<=date("Y")){
  5980. Doo::loadModel('receipt');
  5981. $receipt=new receipt();
  5982. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5983. if(empty($receiptList)){ //generated files
  5984. ob_start();
  5985. $this->render ( "/admin/saeaStaffCollectB", $data );
  5986. $this->cacheFile($path);die;
  5987. }
  5988. }
  5989. $this->render ( "/admin/saeaStaffCollectB", $data );
  5990. }
  5991. function staffCollectBak(){
  5992. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5993. $month=$this->get_args('month')?$this->get_args('month'):1;
  5994. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  5995. $this->showCache($path);
  5996. Doo::loadModel('statistics');
  5997. $statistics=new statistics();
  5998. Doo::loadModel("receiptDetail");
  5999. $receiptDetail=new receiptDetail();
  6000. Doo::loadModel('L_category');
  6001. $Lcategory=new L_category();
  6002. Doo::loadModel('accountItem');
  6003. $accountItem=new accountItem();
  6004. Doo::loadModel('staff');
  6005. $staff=new staff();
  6006. Doo::loadModel('itemStatistics');
  6007. $itemStatistics=new itemStatistics();
  6008. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6009. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  6010. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6011. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  6012. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  6013. $staffList=$staff->find(array('asArray'=>true));
  6014. $htmlArray=array();
  6015. foreach ($LcategoryList as $value){
  6016. $htmlArray[$value['title']]=array();
  6017. foreach ($staffList as $v){
  6018. if($value['cid']==$v['cid']){
  6019. $html="";$falg=true;$staffSumPrice=0;
  6020. foreach ($itemStatisticsList as $a){
  6021. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  6022. if(empty($a['price'])){
  6023. $html.='<td class="taR">-</td>';$falg=false;break;
  6024. }else{
  6025. $staffSumPrice+=$a['price'];
  6026. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6027. }
  6028. }
  6029. }
  6030. if ($falg){
  6031. $html.='<td class="taR">-</td>';$falg=true;
  6032. }
  6033. $falg=true;
  6034. foreach ($itemStatisticsList as $a){
  6035. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  6036. if(empty($a['price'])){
  6037. $html.='<td class="taR">-</td>';$falg=false;break;
  6038. }else{
  6039. $staffSumPrice+=$a['price'];
  6040. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6041. }
  6042. }
  6043. }
  6044. if ($falg){
  6045. $html.='<td class="taR">-</td>';$falg=true;
  6046. }
  6047. $falg=true;
  6048. foreach ($itemStatisticsList as $a){
  6049. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  6050. if(empty($a['price'])){
  6051. $html.='<td class="taR">-</td>';$falg=false;break;
  6052. }else{
  6053. $staffSumPrice+=$a['price'];
  6054. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6055. }
  6056. }
  6057. }
  6058. if ($falg){
  6059. $html.='<td class="taR">-</td>';$falg=true;
  6060. }
  6061. $falg=true;
  6062. foreach ($itemStatisticsList as $a){
  6063. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6064. if(!empty($a['price'])){
  6065. $staffSumPrice+=$a['price'];
  6066. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6067. }else{
  6068. $html.='<td class="taR">-</td>';$falg=false;break;
  6069. }
  6070. }
  6071. }
  6072. if ($falg){
  6073. $html.='<td class="taR">-</td>';$falg=true;
  6074. }
  6075. $falg=true;
  6076. foreach ($itemStatisticsList as $a){
  6077. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6078. if(!empty($a['price'])){
  6079. $staffSumPrice+=$a['price'];
  6080. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6081. }else{
  6082. $html.='<td class="taR">-</td>';$falg=false;break;
  6083. }
  6084. }
  6085. }
  6086. if ($falg){
  6087. $html.='<td class="taR">-</td>';$falg=true;
  6088. }
  6089. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6090. $htmlArray[$value['title']][$v['username']]=$html;
  6091. }
  6092. }
  6093. /*-- ---*/
  6094. //合计费用
  6095. $cateHtml="";$catePrice=0;$cateFalg=true;
  6096. foreach ($itemCategoryList as $l){
  6097. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6098. if(empty($l['price'])){
  6099. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6100. }else{
  6101. $catePrice+=$l['price'];
  6102. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6103. }
  6104. }
  6105. }
  6106. if ($cateFalg){
  6107. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6108. }
  6109. $cateFalg=true;
  6110. foreach ($itemCategoryList as $l){
  6111. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6112. if(empty($l['price'])){
  6113. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6114. }else{
  6115. $catePrice+=$l['price'];
  6116. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6117. }
  6118. }
  6119. }
  6120. if ($cateFalg){
  6121. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6122. }
  6123. $cateFalg=true;
  6124. foreach ($itemCategoryList as $l){
  6125. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6126. if(empty($l['price'])){
  6127. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6128. }else{
  6129. $catePrice+=$l['price'];
  6130. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6131. }
  6132. }
  6133. }
  6134. if ($cateFalg){
  6135. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6136. }
  6137. $cateFalg=true;
  6138. foreach ($itemCategoryList as $l){
  6139. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6140. if(empty($l['price'])){
  6141. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6142. }else{
  6143. $catePrice+=$l['price'];
  6144. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6145. }
  6146. }
  6147. }
  6148. if ($cateFalg){
  6149. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6150. }
  6151. $cateFalg=true;
  6152. foreach ($itemCategoryList as $l){
  6153. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6154. if(empty($l['price'])){
  6155. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6156. }else{
  6157. $catePrice+=$l['price'];
  6158. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6159. }
  6160. }
  6161. }
  6162. if ($cateFalg){
  6163. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6164. }
  6165. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6166. $htmlArray[$value['title']]['合计']=$cateHtml;
  6167. /*-- ---*/
  6168. }
  6169. //print_r($htmlArray);die;
  6170. $data['htmlArray']=$htmlArray;
  6171. //statistics html
  6172. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6173. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6174. if(empty($stList))
  6175. $stList=array('rePrice'=>0,'agPrice'=>0);
  6176. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6177. $monthHtml="";
  6178. for ($i=1;$i<=12;$i++){
  6179. if ($i==$month)
  6180. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6181. else
  6182. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6183. }
  6184. $data['monthHtml']=$monthHtml;
  6185. $data['year']=$year;
  6186. $data['month']=$month;
  6187. $data['memu']="receipt";
  6188. $data['staff']=$this->staff;
  6189. $data['receiptMemu']='companyCategoryCollect';
  6190. $data['verifyId']=$this->verifyId;
  6191. $data['executeId']=$this->executeId;
  6192. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6193. Doo::loadModel('receipt');
  6194. $receipt=new receipt();
  6195. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6196. if(empty($receiptList)){ //generated files
  6197. ob_start();
  6198. $this->render ( "/admin/saeaStaffCollect", $data );
  6199. $this->cacheFile($path);die;
  6200. }
  6201. }
  6202. $this->render ( "/admin/saeaStaffCollect", $data );
  6203. }
  6204. function lyt(){
  6205. Doo::loadModel("receiptDetail");
  6206. $receiptDetail=new receiptDetail();
  6207. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6208. foreach ($receiptCollectList as $key=>$value){
  6209. $receiptDetail=new receiptDetail();
  6210. $receiptDetail->pastDate=$value['date'];
  6211. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6212. }
  6213. }
  6214. function staffCollectMonthDetail(){
  6215. $year=$this->get_args('year')?$this->get_args('year'):"";
  6216. $month=$this->get_args('month')?$this->get_args('month'):"";
  6217. if(!$year)
  6218. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6219. if(!$month)
  6220. $month=isset($this->params['month'])?$this->params['month']:1;
  6221. Doo::loadModel('staff');
  6222. $staff=new staff();
  6223. Doo::loadModel("receiptDetail");
  6224. $receiptDetail=new receiptDetail();
  6225. Doo::loadModel('accountItem');
  6226. $accountItem=new accountItem();
  6227. Doo::loadModel('statistics');
  6228. $statistics=new statistics();
  6229. Doo::loadModel('L_category');
  6230. $lCategory=new L_category();
  6231. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6232. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6233. $list=array();
  6234. foreach ($categoryList as $vlu){
  6235. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6236. $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;
  6237. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6238. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6239. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6240. $s1=0;
  6241. $m1=0;
  6242. foreach ($staffList as $value){
  6243. if ($vlu['cid']==$value['cid']){
  6244. //pastDate
  6245. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6246. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6247. // if ($value['sid']==42){
  6248. // print_r($receiptCollectList);die;
  6249. // }
  6250. if(!empty($receiptCollectList)){
  6251. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6252. $html="";
  6253. $psum=0;
  6254. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6255. foreach ($item as $va){
  6256. $falg=true;
  6257. foreach ($receiptCollectList as $v){
  6258. if($v['itemCategory']=='日常相关费用'){
  6259. if($v['item']==$va){
  6260. if ($va=='市内交通费')
  6261. $r1+=$v['price'];
  6262. if ($va=='市内出租费')
  6263. $r2+=$v['price'];
  6264. if ($va=='办事处房租')
  6265. $r3+=$v['price'];
  6266. if ($va=='电话费')
  6267. $r4+=$v['price'];
  6268. if ($va=='水费')
  6269. $r5+=$v['price'];
  6270. if ($va=='电费')
  6271. $r6+=$v['price'];
  6272. if ($va=='办公费用')
  6273. $r7+=$v['price'];
  6274. if ($va=='邮寄费')
  6275. $r8+=$v['price'];
  6276. if ($va=='其他费用')
  6277. $r9+=$v['price'];
  6278. if ($va=='车辆费用')
  6279. $r10+=$v['price'];
  6280. if ($va=='广告费')
  6281. $r11+=$v['price'];
  6282. if ($va=='团队建设费')
  6283. $r13+=$v['price'];
  6284. if ($va=='物业管理费')
  6285. $r14+=$v['price'];
  6286. if ($va=='宽带费')
  6287. $r15+=$v['price'];
  6288. $psum+=$v['price'];
  6289. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6290. }
  6291. }
  6292. }
  6293. if($falg)
  6294. $html.='<td class="taR">-</td>';
  6295. }
  6296. $r12+=$psum;
  6297. if(!empty($psum))
  6298. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6299. else
  6300. $psum='<td class="colGreen taR">-</td>';
  6301. $receiptL['日常相关费用']=$psum.$html;
  6302. /*-----------------------------------*/
  6303. $html="";
  6304. $psum=0;
  6305. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6306. foreach ($item as $va){
  6307. $falg=true;
  6308. foreach ($receiptCollectList as $v){
  6309. if($v['itemCategory']=='差旅相关费用'){
  6310. if($v['item']==$va){
  6311. if ($va=='往来交通费')
  6312. $c1+=$v['price'];
  6313. if ($va=='市内交通费')
  6314. $c2+=$v['price'];
  6315. if ($va=='出差住宿费')
  6316. $c3+=$v['price'];
  6317. if ($va=='出差补助')
  6318. $c4+=$v['price'];
  6319. if ($va=='其他费用')
  6320. $c5+=$v['price'];
  6321. $psum+=$v['price'];
  6322. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6323. }
  6324. }
  6325. }
  6326. if($falg)
  6327. $html.='<td class="taR">-</td>';
  6328. }
  6329. $c6+=$psum;
  6330. if(!empty($psum))
  6331. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6332. else
  6333. $psum='<td class="colGreen taR">-</td>';
  6334. $receiptL['差旅相关费用']=$psum.$html;
  6335. /*-------------------------------------*/
  6336. $html="";
  6337. $psum=0;
  6338. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6339. foreach ($item as $va){
  6340. $falg=true;
  6341. foreach ($receiptCollectList as $v){
  6342. if($v['itemCategory']=='培训班费用'){
  6343. if($v['item']==$va){
  6344. if ($va=='场租费')
  6345. $p1+=$v['price'];
  6346. if ($va=='薪酬')
  6347. $p2+=$v['price'];
  6348. if ($va=='住宿费')
  6349. $p3+=$v['price'];
  6350. if ($va=='交通费')
  6351. $p4+=$v['price'];
  6352. if ($va=='餐饮费')
  6353. $p5+=$v['price'];
  6354. if ($va=='办公费')
  6355. $p6+=$v['price'];
  6356. if ($va=='公关费')
  6357. $p7+=$v['price'];
  6358. if ($va=='其他')
  6359. $p8+=$v['price'];
  6360. $psum+=$v['price'];
  6361. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6362. }
  6363. }
  6364. }
  6365. if($falg)
  6366. $html.='<td class="taR">-</td>';
  6367. }
  6368. $p9+=$psum;
  6369. if(!empty($psum))
  6370. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6371. else
  6372. $psum='<td class="colGreen taR">-</td>';
  6373. $receiptL['培训班费用']=$psum.$html;
  6374. /*-------------------------------------*/
  6375. $html="";
  6376. $psum=0;
  6377. $item=array('公关费','广告费','借款','可自加费用');
  6378. foreach ($item as $va){
  6379. $falg=true;
  6380. foreach ($receiptCollectList as $v){
  6381. if($v['itemCategory']=='其他'){
  6382. // if ($value['sid']==42){
  6383. //
  6384. // echo var_dump($v['item']);
  6385. // echo var_dump($va);
  6386. // echo var_dump($v['item']==" ".$va);
  6387. // echo $v['item']."==".$va."/<br/>";
  6388. // //print_r( $receiptCollectList);//echo $va;
  6389. // }
  6390. if(trim($v['item'])==$va){
  6391. if ($va=='公关费')
  6392. $t1+=$v['price'];
  6393. if ($va=='广告费'){
  6394. $t2+=$v['price'];
  6395. }
  6396. if ($va=='借款')
  6397. $t3+=$v['price'];
  6398. if ($va=='可自加费用')
  6399. $t4+=$v['price'];
  6400. $psum+=$v['price'];
  6401. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6402. }
  6403. }
  6404. }
  6405. if($falg)
  6406. $html.='<td class="taR">-</td>';
  6407. }
  6408. $t5+=$psum;
  6409. if(!empty($psum))
  6410. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6411. else
  6412. $psum='<td class="colGreen taR">-</td>';
  6413. $receiptL['其他']=$psum.$html;
  6414. /*-------------------------------------*/
  6415. $html="";
  6416. $psum=0;
  6417. foreach ($receiptCollectList as $v){
  6418. if($v['itemCategory']=='报销金额调整'){
  6419. if (!empty($v['price'])){
  6420. $psum+=$v['price'];
  6421. }
  6422. }
  6423. }
  6424. $s1+=$psum;
  6425. if(!empty($psum))
  6426. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6427. else
  6428. $psum='<td class="taR colOrange">-</td>';
  6429. $receiptL['报销金额调整']=$psum.$html;
  6430. }else{
  6431. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6432. <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>
  6433. <td class="taR">-</td><td class="taR">-</td>';
  6434. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6435. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6436. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6437. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6438. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6439. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6440. }
  6441. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6442. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6443. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6444. if(!empty($monthStaffPrice[0]['price'])){
  6445. $m1+=$monthStaffPrice[0]['price'];
  6446. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6447. }else
  6448. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6449. $list[$value['username']]=$receiptL;
  6450. }
  6451. }
  6452. $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>
  6453. <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>
  6454. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6455. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6456. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6457. $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>
  6458. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6459. $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>';
  6460. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6461. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6462. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6463. }
  6464. $data['list']=$list;
  6465. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6466. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6467. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6468. //statistics html
  6469. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6470. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6471. if(empty($stList))
  6472. $stList=array('rePrice'=>0,'agPrice'=>0);
  6473. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6474. $monthHtml="";
  6475. for ($i=1;$i<=12;$i++){
  6476. if ($i==$month)
  6477. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6478. else
  6479. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6480. }
  6481. $data['monthHtml']=$monthHtml;
  6482. $data['year']=$year;
  6483. $data['month']=$month;
  6484. $data['memu']="receipt";
  6485. $data['staff']=$this->staff;
  6486. $data['receiptMemu']='companyCategoryCollect';
  6487. $data['verifyId']=$this->verifyId;
  6488. $data['executeId']=$this->executeId;
  6489. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6490. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6491. }
  6492. function staffCollectMonthDetail2(){
  6493. $year=$this->get_args('year')?$this->get_args('year'):"";
  6494. $month=$this->get_args('month')?$this->get_args('month'):"";
  6495. if(!$year)
  6496. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6497. if(!$month)
  6498. $month=isset($this->params['month'])?$this->params['month']:1;
  6499. Doo::loadModel('staff');
  6500. $staff=new staff();
  6501. Doo::loadModel("receiptDetail");
  6502. $receiptDetail=new receiptDetail();
  6503. Doo::loadModel('accountItem');
  6504. $accountItem=new accountItem();
  6505. Doo::loadModel('statistics');
  6506. $statistics=new statistics();
  6507. Doo::loadModel('L_category');
  6508. $lCategory=new L_category();
  6509. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6510. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6511. $list=array();
  6512. foreach ($categoryList as $vlu){
  6513. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6514. $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;
  6515. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6516. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6517. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6518. $s1=0;
  6519. $m1=0;
  6520. foreach ($staffList as $value){
  6521. if ($vlu['cid']==$value['cid']){
  6522. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6523. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6524. if(!empty($receiptCollectList)){
  6525. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6526. $html="";
  6527. $psum=0;
  6528. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6529. foreach ($item as $va){
  6530. $falg=true;
  6531. foreach ($receiptCollectList as $v){
  6532. if($v['itemCategory']=='日常相关费用'){
  6533. if($v['item']==$va){
  6534. if ($va=='市内交通费')
  6535. $r1+=$v['price'];
  6536. if ($va=='市内出租费')
  6537. $r2+=$v['price'];
  6538. if ($va=='办事处房租')
  6539. $r3+=$v['price'];
  6540. if ($va=='电话费')
  6541. $r4+=$v['price'];
  6542. if ($va=='水费')
  6543. $r5+=$v['price'];
  6544. if ($va=='电费')
  6545. $r6+=$v['price'];
  6546. if ($va=='办公费用')
  6547. $r7+=$v['price'];
  6548. if ($va=='邮寄费')
  6549. $r8+=$v['price'];
  6550. if ($va=='其他费用')
  6551. $r9+=$v['price'];
  6552. if ($va=='车辆费用')
  6553. $r10+=$v['price'];
  6554. if ($va=='广告费')
  6555. $r11+=$v['price'];
  6556. if ($va=='团队建设费')
  6557. $r13+=$v['price'];
  6558. if ($va=='物业管理费')
  6559. $r14+=$v['price'];
  6560. if ($va=='宽带费')
  6561. $r15+=$v['price'];
  6562. $psum+=$v['price'];
  6563. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6564. }
  6565. }
  6566. }
  6567. if($falg)
  6568. $html.='<td class="taR">-</td>';
  6569. }
  6570. $r12+=$psum;
  6571. if(!empty($psum))
  6572. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6573. else
  6574. $psum='<td class="colGreen taR">-</td>';
  6575. $receiptL['日常相关费用']=$psum.$html;
  6576. /*-----------------------------------*/
  6577. $html="";
  6578. $psum=0;
  6579. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6580. foreach ($item as $va){
  6581. $falg=true;
  6582. foreach ($receiptCollectList as $v){
  6583. if($v['itemCategory']=='差旅相关费用'){
  6584. if($v['item']==$va){
  6585. if ($va=='往来交通费')
  6586. $c1+=$v['price'];
  6587. if ($va=='市内交通费')
  6588. $c2+=$v['price'];
  6589. if ($va=='出差住宿费')
  6590. $c3+=$v['price'];
  6591. if ($va=='出差补助')
  6592. $c4+=$v['price'];
  6593. if ($va=='其他费用')
  6594. $c5+=$v['price'];
  6595. $psum+=$v['price'];
  6596. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6597. }
  6598. }
  6599. }
  6600. if($falg)
  6601. $html.='<td class="taR">-</td>';
  6602. }
  6603. $c6+=$psum;
  6604. if(!empty($psum))
  6605. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6606. else
  6607. $psum='<td class="colGreen taR">-</td>';
  6608. $receiptL['差旅相关费用']=$psum.$html;
  6609. /*-------------------------------------*/
  6610. $html="";
  6611. $psum=0;
  6612. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6613. foreach ($item as $va){
  6614. $falg=true;
  6615. foreach ($receiptCollectList as $v){
  6616. if($v['itemCategory']=='培训班费用'){
  6617. if($v['item']==$va){
  6618. if ($va=='场租费')
  6619. $p1+=$v['price'];
  6620. if ($va=='薪酬')
  6621. $p2+=$v['price'];
  6622. if ($va=='住宿费')
  6623. $p3+=$v['price'];
  6624. if ($va=='交通费')
  6625. $p4+=$v['price'];
  6626. if ($va=='餐饮费')
  6627. $p5+=$v['price'];
  6628. if ($va=='办公费')
  6629. $p6+=$v['price'];
  6630. if ($va=='公关费')
  6631. $p7+=$v['price'];
  6632. if ($va=='其他')
  6633. $p8+=$v['price'];
  6634. $psum+=$v['price'];
  6635. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6636. }
  6637. }
  6638. }
  6639. if($falg)
  6640. $html.='<td class="taR">-</td>';
  6641. }
  6642. $p9+=$psum;
  6643. if(!empty($psum))
  6644. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6645. else
  6646. $psum='<td class="colGreen taR">-</td>';
  6647. $receiptL['培训班费用']=$psum.$html;
  6648. /*-------------------------------------*/
  6649. $html="";
  6650. $psum=0;
  6651. $item=array('公关费','广告费','借款','可自加费用');
  6652. foreach ($item as $va){
  6653. $falg=true;
  6654. foreach ($receiptCollectList as $v){
  6655. if($v['itemCategory']=='其他'){
  6656. if($v['item']==$va){
  6657. if ($va=='公关费')
  6658. $t1+=$v['price'];
  6659. if ($va=='广告费')
  6660. $t2+=$v['price'];
  6661. if ($va=='借款')
  6662. $t3+=$v['price'];
  6663. if ($va=='可自加费用')
  6664. $t4+=$v['price'];
  6665. $psum+=$v['price'];
  6666. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6667. }
  6668. }
  6669. }
  6670. if($falg)
  6671. $html.='<td class="taR">-</td>';
  6672. }
  6673. $t5+=$psum;
  6674. if(!empty($psum))
  6675. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6676. else
  6677. $psum='<td class="colGreen taR">-</td>';
  6678. $receiptL['其他']=$psum.$html;
  6679. /*-------------------------------------*/
  6680. $html="";
  6681. $psum=0;
  6682. foreach ($receiptCollectList as $v){
  6683. if($v['itemCategory']=='报销金额调整'){
  6684. if (!empty($v['price'])){
  6685. $psum+=$v['price'];
  6686. }
  6687. }
  6688. }
  6689. $s1+=$psum;
  6690. if(!empty($psum))
  6691. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6692. else
  6693. $psum='<td class="taR colOrange">-</td>';
  6694. $receiptL['报销金额调整']=$psum.$html;
  6695. }else{
  6696. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6697. <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>';
  6698. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6699. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6700. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6701. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6702. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6703. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6704. }
  6705. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6706. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6707. if(!empty($monthStaffPrice[0]['price'])){
  6708. $m1+=$monthStaffPrice[0]['price'];
  6709. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6710. }else
  6711. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6712. $list[$value['username']]=$receiptL;
  6713. }
  6714. }
  6715. $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>
  6716. <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>
  6717. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6718. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6719. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6720. $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>
  6721. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6722. $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>';
  6723. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6724. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6725. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6726. }
  6727. $data['list']=$list;
  6728. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6729. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6730. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6731. //statistics html
  6732. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6733. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6734. if(empty($stList))
  6735. $stList=array('rePrice'=>0,'agPrice'=>0);
  6736. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6737. $monthHtml="";
  6738. for ($i=1;$i<=12;$i++){
  6739. if ($i==$month)
  6740. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6741. else
  6742. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6743. }
  6744. $data['monthHtml']=$monthHtml;
  6745. $data['year']=$year;
  6746. $data['month']=$month;
  6747. $data['memu']="receipt";
  6748. $data['staff']=$this->staff;
  6749. $data['receiptMemu']='companyCategoryCollect';
  6750. $data['verifyId']=$this->verifyId;
  6751. $data['executeId']=$this->executeId;
  6752. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6753. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6754. }
  6755. function companyMonthCollectDetail(){
  6756. $year=$this->get_args('year')?$this->get_args('year'):"";
  6757. $month=$this->get_args('month')?$this->get_args('month'):"";
  6758. if(!$year)
  6759. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6760. if(!$month)
  6761. $month=isset($this->params['month'])?$this->params['month']:1;
  6762. Doo::loadModel('staff');
  6763. $staff=new staff();
  6764. Doo::loadModel("receiptDetail");
  6765. $receiptDetail=new receiptDetail();
  6766. Doo::loadModel('accountItem');
  6767. $accountItem=new accountItem();
  6768. Doo::loadModel('statistics');
  6769. $statistics=new statistics();
  6770. Doo::loadModel('L_category');
  6771. $lCategory=new L_category();
  6772. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6773. $categoryList=$lCategory->find(array('asArray'=>true));
  6774. $list=array();
  6775. foreach ($categoryList as $value){
  6776. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6777. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6778. if(!empty($receiptCollectList)){
  6779. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6780. $html="";
  6781. $psum=0;
  6782. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6783. foreach ($item as $va){
  6784. $falg=true;
  6785. foreach ($receiptCollectList as $v){
  6786. if($v['itemCategory']=='日常相关费用'){
  6787. if($v['item']==$va){
  6788. $psum+=$v['price'];
  6789. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6790. }
  6791. }
  6792. }
  6793. if($falg)
  6794. $html.='<td class="taR">-</td>';
  6795. }
  6796. if(!empty($psum))
  6797. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6798. else
  6799. $psum='<td class="colGreen taR">-</td>';
  6800. $receiptL['日常相关费用']=$psum.$html;
  6801. /*-----------------------------------*/
  6802. $html="";
  6803. $psum=0;
  6804. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6805. foreach ($item as $va){
  6806. $falg=true;
  6807. foreach ($receiptCollectList as $v){
  6808. if($v['itemCategory']=='差旅相关费用'){
  6809. if($v['item']==$va){
  6810. $psum+=$v['price'];
  6811. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6812. }
  6813. }
  6814. }
  6815. if($falg)
  6816. $html.='<td class="taR">-</td>';
  6817. }
  6818. if(!empty($psum))
  6819. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6820. else
  6821. $psum='<td class="colGreen taR">-</td>';
  6822. $receiptL['差旅相关费用']=$psum.$html;
  6823. /*-------------------------------------*/
  6824. $html="";
  6825. $psum=0;
  6826. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6827. foreach ($item as $va){
  6828. $falg=true;
  6829. foreach ($receiptCollectList as $v){
  6830. if($v['itemCategory']=='培训班费用'){
  6831. if($v['item']==$va){
  6832. $psum+=$v['price'];
  6833. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6834. }
  6835. }
  6836. }
  6837. if($falg)
  6838. $html.='<td class="taR">-</td>';
  6839. }
  6840. if(!empty($psum))
  6841. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6842. else
  6843. $psum='<td class="colGreen taR">-</td>';
  6844. $receiptL['培训班费用']=$psum.$html;
  6845. /*-------------------------------------*/
  6846. $html="";
  6847. $psum=0;
  6848. $item=array('公关费','广告费','借款','可自加费用');
  6849. foreach ($item as $va){
  6850. $falg=true;
  6851. foreach ($receiptCollectList as $v){
  6852. if($v['itemCategory']=='其他'){
  6853. if($v['item']==$va){
  6854. $psum+=$v['price'];
  6855. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6856. }
  6857. }
  6858. }
  6859. if($falg)
  6860. $html.='<td class="taR">-</td>';
  6861. }
  6862. if(!empty($psum))
  6863. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6864. else
  6865. $psum='<td class="colGreen taR">-</td>';
  6866. $receiptL['其他']=$psum.$html;
  6867. /*-------------------------------------*/
  6868. $html="";
  6869. $psum=0;
  6870. foreach ($receiptCollectList as $v){
  6871. if($v['itemCategory']=='报销金额调整'){
  6872. if (!empty($v['price']))
  6873. $psum+=$v['price'];
  6874. }
  6875. }
  6876. if(!empty($psum))
  6877. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6878. else
  6879. $psum='<td class="taR colOrange">-</td>';
  6880. $receiptL['报销金额调整']=$psum.$html;
  6881. }else{
  6882. $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>
  6883. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6884. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6885. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6886. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6887. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6888. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6889. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6890. }
  6891. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6892. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6893. if(!empty($monthStaffPrice[0]['price']))
  6894. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6895. else
  6896. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6897. $list[$value['title']]=$receiptL;
  6898. }
  6899. $data['list']=$list;
  6900. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6901. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6902. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6903. //print_r($data['monthPriceHtml']);
  6904. // foreach ($data['monthPriceHtml'] as $value){
  6905. // echo $value;
  6906. // }
  6907. // die;
  6908. //statistics html
  6909. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6910. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6911. if(empty($stList))
  6912. $stList=array('rePrice'=>0,'agPrice'=>0);
  6913. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6914. $monthHtml="";
  6915. for ($i=1;$i<=12;$i++){
  6916. if ($i==$month)
  6917. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6918. else
  6919. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6920. }
  6921. $data['monthHtml']=$monthHtml;
  6922. $data['year']=$year;
  6923. $data['month']=$month;
  6924. $data['memu']="receipt";
  6925. $data['staff']=$this->staff;
  6926. $data['receiptMemu']='companyCategoryCollect';
  6927. $data['verifyId']=$this->verifyId;
  6928. $data['executeId']=$this->executeId;
  6929. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6930. }
  6931. function staffCollectDetail(){
  6932. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6933. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6934. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6935. if(!$staffname){
  6936. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6937. $staffname= urldecode($staffname);
  6938. }
  6939. Doo::loadModel('staff');
  6940. $staff=new staff();
  6941. Doo::loadModel("receiptDetail");
  6942. $receiptDetail=new receiptDetail();
  6943. Doo::loadModel('accountItem');
  6944. $accountItem=new accountItem();
  6945. Doo::loadModel('statistics');
  6946. $statistics=new statistics();
  6947. Doo::loadModel('L_category');
  6948. $lCategory=new L_category();
  6949. $staffList=$staff->find(array('asArray'=>true));
  6950. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6951. foreach ($staffList as $value){
  6952. if ($value['username']==$staffname&&$value['username']!='admin'){
  6953. $stTitle=$value['category'].'-'.$value['username'];
  6954. $staffId=$value['sid'];
  6955. $cid=$value['cid'];
  6956. $ocid=$value['cid'];
  6957. if (!empty($value['othercid']))
  6958. $cid=$value['cid'].','.$value['othercid'];
  6959. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6960. }elseif ($value['username']!='admin')
  6961. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6962. }
  6963. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6964. if(empty($pcid))
  6965. $pcid=$ocid;
  6966. $data['ocid']=$pcid;
  6967. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6968. $this->showCache($path);
  6969. //
  6970. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6971. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6972. $accountList=$accountItem->find(array('asArray'=>true));
  6973. //create CollectDetail HTML
  6974. $collectHtml=array();
  6975. foreach ($accountList as $key=>$value){
  6976. $html="";$asum=0;
  6977. for ($i=1;$i<=12;$i++){
  6978. $falg=true;
  6979. foreach ($receiptCollectList as $v) {
  6980. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  6981. $asum+=$v['price'];
  6982. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  6983. }
  6984. }
  6985. if($falg)
  6986. $html.='<td class="taR">-</td>';
  6987. }
  6988. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  6989. $collectHtml[$value['category']][$value['name']]=$html;
  6990. }
  6991. $data['collectHtml']=$collectHtml;
  6992. //create Adjustment price html
  6993. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  6994. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  6995. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6996. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  6997. array_push($collectArray['日常相关费用'], $collectHtml);
  6998. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  6999. array_push($collectArray['差旅相关费用'], $collectHtml);
  7000. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  7001. array_push($collectArray['培训班费用'], $collectHtml);
  7002. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  7003. array_push($collectArray['其他'], $collectHtml);
  7004. $data['collectArray']=$collectArray;
  7005. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  7006. array_push($adjustment, $collectHtml);
  7007. $data['adjustment']=$adjustment;
  7008. //total price html
  7009. $collectHtml="";$total=0;
  7010. for ($i=1;$i<=12;$i++){
  7011. $sumPrice=0;
  7012. foreach ($receiptCollectList as $key=>$value){
  7013. if($value['month']==$i){
  7014. $sumPrice+=$value['price'];
  7015. }
  7016. }
  7017. if ($sumPrice==0)
  7018. $collectHtml.='<td class="taR">-</td>';
  7019. else
  7020. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  7021. $total+=$sumPrice;
  7022. }
  7023. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  7024. //statistics html
  7025. $stList=$statistics->statisticsByYear($year,$staffId);
  7026. if(empty($stList))
  7027. $stList=array('rePrice'=>0,'agPrice'=>0);
  7028. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  7029. $data['totalPrice']=$collectHtml;
  7030. $data['totalYear']=$total;
  7031. $data['stHtml']=$stHtml;
  7032. $data['year']=$year;
  7033. $data['stTitle']=$stTitle;
  7034. $data['memu']="receipt";
  7035. $data['staff']=$this->staff;
  7036. $data['receiptMemu']='companyCategoryCollect';
  7037. $data['verifyId']=$this->verifyId;
  7038. $data['executeId']=$this->executeId;
  7039. if ($year<date("Y")){
  7040. Doo::loadModel('receipt');
  7041. $receipt=new receipt();
  7042. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  7043. if(empty($receiptList)){ //generated files
  7044. ob_start();
  7045. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7046. $this->cacheFile($path);die;
  7047. }
  7048. }
  7049. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7050. }
  7051. function BUGFLAG(){
  7052. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  7053. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  7054. $month=$this->get_args('month')?$this->get_args('month'):"";
  7055. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  7056. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  7057. if (empty($status))
  7058. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  7059. $page_size=12;
  7060. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7061. $vidList=array();
  7062. $button=0;
  7063. Doo::loadModel('verify');
  7064. $verify=new verify();
  7065. Doo::loadModel('receipt');
  7066. $receipt=new receipt();
  7067. Doo::loadModel('staff');
  7068. $staff=new staff();
  7069. Doo::loadModel('L_category');
  7070. $Lcategory=new L_category();
  7071. $dateCondition=" and Year(date) =".$year;
  7072. if(!empty($month))
  7073. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  7074. $categoryList=$Lcategory->find(array('asArray'=>true));
  7075. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7076. $cateCondition="";$staffCondition="";$approvalCondition="";
  7077. if (!empty($cid))
  7078. $cateCondition=' and cid='.$cid;
  7079. if(!empty($sid)){
  7080. $staffCondition=' and staff='.$sid;
  7081. $cateCondition="";
  7082. }
  7083. $approvalCondition=" and status=".$status;
  7084. if($status==2){
  7085. //查找角色审批人
  7086. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7087. }
  7088. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7089. $approvalCondition=' and status=2 ';
  7090. }
  7091. if($status==1){
  7092. $approvalCondition=' and (status='.$status.' or status=6) ';
  7093. }
  7094. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7095. $pageinfo['page']=array('previous'=>'');
  7096. if ($status==0){
  7097. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7098. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7099. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7100. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7101. }else
  7102. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7103. ,'desc'=>'rid','asArray'=>true));
  7104. $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
  7105. ,'desc'=>'rid','asArray'=>true));
  7106. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7107. //print_r($pageinfo);
  7108. $Locate=0;
  7109. foreach ($receiptList as $key=>$value){
  7110. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7111. $receiptList[$key]['reviseDetail']=array();
  7112. if (!empty($value['reviseDetail']))
  7113. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7114. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7115. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7116. $receiptList[$key]['category']=$categoryDetil['title'];
  7117. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7118. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7119. $verifyStaff=json_decode($value['verifyStaff'],true);
  7120. foreach ($verifyList as $k=>$v){
  7121. //init verifyStaff
  7122. $verifyList[$k]['date']="";
  7123. $verifyList[$k]['opinion']="";
  7124. $verifyList[$k]['status']="";
  7125. if (empty($verifyStaff)){
  7126. $verifyList[$k]['date']="";
  7127. $verifyList[$k]['opinion']="";
  7128. if ($v[0]==$this->staff[0]['sid']){
  7129. $verifyList[$k]['status']=4;
  7130. $button=4;
  7131. }
  7132. }else{
  7133. $flag=true;
  7134. foreach ($verifyStaff as $m=>$u){
  7135. if ($v[0]==$m){
  7136. $verifyList[$k]['date']=$u['date'];
  7137. $verifyList[$k]['opinion']=$u['opinion'];
  7138. $verifyList[$k]['status']=$u['status'];
  7139. $flag=false;
  7140. break;
  7141. }
  7142. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7143. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7144. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7145. }
  7146. if($flag){//检测可编辑
  7147. if($v[0]==$this->staff[0]['sid']){
  7148. $verifyList[$k]['status']=4;$button=4;
  7149. }
  7150. }
  7151. }
  7152. }
  7153. $receiptList[$key]['verifyList']=$verifyList;
  7154. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7155. $receiptList[$key]['button']=$button;
  7156. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7157. }
  7158. //print_r($receiptList);die;
  7159. //$data['verifyDetail']=$verifyDetail;
  7160. $mothHtml="";
  7161. for($i=1;$i<=12;$i++){
  7162. if($month==$i)
  7163. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7164. else
  7165. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7166. }
  7167. $data['mothHtml']=$mothHtml;
  7168. $data['page']=$pageinfo;
  7169. $data['receiptList']=$receiptList;
  7170. $data['receiptApprovalCount']=count($rLRes);
  7171. $data['status']=$status;
  7172. $data['year']=$year;
  7173. $data['categoryList']=$categoryList;
  7174. $data['staffList']=$staffList;
  7175. $data['cid']=$cid;
  7176. $data['sid']=$sid;
  7177. //print_r($receiptList);
  7178. $data['memu']="receipt";
  7179. $data['staff']=$this->staff;
  7180. $data['receiptMemu']='approvalExpenses';
  7181. $data['verifyId']=$this->verifyId;
  7182. $data['executeId']=$this->executeId;
  7183. $this->render ( "/admin/FALG", $data );
  7184. }
  7185. function ajaxGetReceiptOrder(){
  7186. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7187. if (!empty($receiptOrder)){
  7188. Doo::loadModel('receipt');
  7189. $receipt=new receipt();
  7190. Doo::loadModel ( 'staff' );
  7191. $staff = new staff ();
  7192. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7193. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7194. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7195. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7196. </tbody></table><table class="table table table-bordered"><tbody>';
  7197. foreach ($verifyStaff as $key=>$value){
  7198. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7199. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7200. }
  7201. $html.='</tbody></table></div></div>';
  7202. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7203. }
  7204. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7205. }
  7206. function _getMonthCollectDetail($receiptCollectList){
  7207. if(!empty($receiptCollectList)){
  7208. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7209. $html="";
  7210. $psum=0;
  7211. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7212. foreach ($item as $value){
  7213. $falg=true;
  7214. foreach ($receiptCollectList as $v){
  7215. if($v['itemCategory']=='日常相关费用'){
  7216. if($v['item']==$value){
  7217. $psum+=$v['price'];
  7218. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7219. }
  7220. }
  7221. }
  7222. if($falg)
  7223. $html.='<td class="taR">-</td>';
  7224. }
  7225. if(!empty($psum))
  7226. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7227. else
  7228. $psum='<td class="colGreen taR">-</td>';
  7229. $receiptL['日常相关费用']=$psum.$html;
  7230. /*-----------------------------------*/
  7231. $html="";
  7232. $psum=0;
  7233. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7234. foreach ($item as $value){
  7235. $falg=true;
  7236. foreach ($receiptCollectList as $v){
  7237. if($v['itemCategory']=='差旅相关费用'){
  7238. if($v['item']==$value){
  7239. $psum+=$v['price'];
  7240. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7241. }
  7242. }
  7243. }
  7244. if($falg)
  7245. $html.='<td class="taR">-</td>';
  7246. }
  7247. if(!empty($psum))
  7248. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7249. else
  7250. $psum='<td class="colGreen taR">-</td>';
  7251. $receiptL['差旅相关费用']=$psum.$html;
  7252. /*-------------------------------------*/
  7253. $html="";
  7254. $psum=0;
  7255. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7256. foreach ($item as $value){
  7257. $falg=true;
  7258. foreach ($receiptCollectList as $v){
  7259. if($v['itemCategory']=='培训班费用'){
  7260. if($v['item']==$value){
  7261. $psum+=$v['price'];
  7262. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7263. }
  7264. }
  7265. }
  7266. if($falg)
  7267. $html.='<td class="taR">-</td>';
  7268. }
  7269. if(!empty($psum))
  7270. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7271. else
  7272. $psum='<td class="colGreen taR">-</td>';
  7273. $receiptL['培训班费用']=$psum.$html;
  7274. /*-------------------------------------*/
  7275. $html="";
  7276. $psum=0;
  7277. $item=array('公关费','广告费','借款','可自加费用');
  7278. foreach ($item as $value){
  7279. $falg=true;
  7280. foreach ($receiptCollectList as $v){
  7281. if($v['itemCategory']=='其他'){
  7282. if($v['item']==$value){
  7283. $psum+=$v['price'];
  7284. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7285. }
  7286. }
  7287. }
  7288. if($falg)
  7289. $html.='<td class="taR">-</td>';
  7290. }
  7291. if(!empty($psum))
  7292. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7293. else
  7294. $psum='<td class="colGreen taR">-</td>';
  7295. $receiptL['其他']=$psum.$html;
  7296. /*-------------------------------------*/
  7297. $html="";
  7298. $psum=0;
  7299. foreach ($receiptCollectList as $v){
  7300. if($v['itemCategory']=='报销金额调整'){
  7301. if (!empty($v['price']))
  7302. $psum+=$v['price'];
  7303. }
  7304. }
  7305. if(!empty($psum))
  7306. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7307. else
  7308. $psum='<td class="taR colOrange">-</td>';
  7309. $receiptL['报销金额调整']=$psum.$html;
  7310. }else{
  7311. $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>
  7312. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7313. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7314. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7315. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7316. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7317. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7318. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7319. }
  7320. return $receiptL;
  7321. }
  7322. function eMail(){
  7323. Doo::loadModel('staff');
  7324. $staff=new staff();
  7325. Doo::loadModel('receipt');
  7326. $receipt=new receipt();
  7327. Doo::loadModel('L_category');
  7328. $Lcategory=new L_category();
  7329. Doo::loadModel("verify");
  7330. $verify=new verify();
  7331. $staffList=$staff->find(array('asArray'=>true));
  7332. foreach ($staffList as $key=>$value){
  7333. if($value['username']!='admin'){
  7334. //提交人
  7335. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7336. if(!empty($receiptList)){
  7337. $html='<br><div><style></style>
  7338. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7339. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7340. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7341. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7342. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7343. <tbody><tr>
  7344. <td style="padding: 0 40px;" align="left">
  7345. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7346. </td></tr><tr>
  7347. <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>
  7348. </tr>
  7349. </tbody> </table></td> </tr> <tr><td>
  7350. <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">
  7351. <tbody> <tr><td>
  7352. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7353. 以下报销单完成了审批,等着收款吧:</p>
  7354. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7355. foreach ($receiptList as $k=>$v){
  7356. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7357. $html.='
  7358. <tr>
  7359. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7360. <td align="left">
  7361. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7362. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7363. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7364. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7365. </tr>';
  7366. }
  7367. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7368. <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>
  7369. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7370. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7371. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7372. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7373. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7374. $receipt=new receipt();
  7375. $receipt->notice=1;
  7376. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7377. }
  7378. }
  7379. //审批人
  7380. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7381. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7382. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7383. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7384. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7385. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7386. <tbody><tr><td style="padding: 0 40px;" align="left">
  7387. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7388. </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>
  7389. </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">
  7390. <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>
  7391. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7392. foreach ($verifyList as $k=>$v){
  7393. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7394. foreach ($receiptList as $r=>$l){
  7395. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7396. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7397. $html.='
  7398. <tr>
  7399. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7400. <td align="left">
  7401. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7402. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7403. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7404. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7405. </tr>';
  7406. }
  7407. }
  7408. $html.='
  7409. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7410. <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>
  7411. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7412. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7413. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7414. // $receipt=new receipt();
  7415. // $receipt->notice=1;
  7416. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7417. }
  7418. }
  7419. }
  7420. }
  7421. // Email发送函数
  7422. function SMail($toemail, $subject, $contents) {
  7423. Doo::loadClass('class.phpmailer');
  7424. $mail = new PHPMailer();
  7425. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7426. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7427. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7428. $mail->Password = "cDO1GjtY1seH"; //密码
  7429. $mail->CharSet = "UTF8";
  7430. $mail->SMTPAuth = true;
  7431. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7432. $mail->Mailer = "smtp";
  7433. $mail->Port = 25;
  7434. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7435. $mail->MsgHTML($contents);
  7436. $mail->AddAddress($toemail);
  7437. $mail->CharSet = "UTF-8";
  7438. return $mail->Send();
  7439. }
  7440. function swfupload(){
  7441. $POST_MAX_SIZE = ini_get('post_max_size');
  7442. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7443. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7444. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7445. header("HTTP/1.1 500 Internal Server Error");
  7446. echo "POST exceeded maximum allowed size.";
  7447. exit(0);
  7448. }
  7449. // Settings
  7450. $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)
  7451. $upload_name = "Filedata";
  7452. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7453. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7454. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7455. // Other variables
  7456. $MAX_FILENAME_LENGTH = 260;
  7457. $file_name = "";
  7458. $file_extension = "";
  7459. $uploadErrors = array(
  7460. 0=>"文件上传成功",
  7461. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7462. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7463. 3=>"上传的文件仅为部分文件",
  7464. 4=>"没有文件上传",
  7465. 6=>"缺少临时文件夹"
  7466. );
  7467. $nk= time();
  7468. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7469. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7470. echo "文件无法保存.";
  7471. exit(0);
  7472. }
  7473. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7474. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7475. exit(0);
  7476. }
  7477. function _GetFileEXT($filename) {
  7478. $pics = explode ( '.', $filename );
  7479. $num = count ( $pics );
  7480. return $pics [$num - 1];
  7481. }
  7482. /**
  7483. * 获取get或者POST值
  7484. * @param string $name 属性名称
  7485. * @return fixed 值
  7486. */
  7487. function get_args($name) {
  7488. if (isset ( $_GET [$name] )) {
  7489. if (is_array ( $_GET [$name] ))
  7490. return $_GET [$name];
  7491. else
  7492. return addslashes ( $_GET [$name] );
  7493. } elseif (isset ( $_POST [$name] )) {
  7494. if (is_array ( $_POST [$name] ))
  7495. return $_POST [$name];
  7496. else
  7497. return addslashes ( $_POST [$name] );
  7498. } else
  7499. return false;
  7500. }
  7501. function num_to_rmb($num){
  7502. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7503. $c2 = "分角元拾佰仟万拾佰仟亿";
  7504. //精确到分后面就不要了,所以只留两个小数位
  7505. $num = round($num, 2);
  7506. //将数字转化为整数
  7507. $num = $num * 100;
  7508. if (strlen($num) > 10) {
  7509. return "金额太大,请检查";
  7510. }
  7511. $i = 0;
  7512. $c = "";
  7513. while (1) {
  7514. if ($i == 0) {
  7515. //获取最后一位数字
  7516. $n = substr($num, strlen($num)-1, 1);
  7517. } else {
  7518. $n = $num % 10;
  7519. }
  7520. //每次将最后一位数字转化为中文
  7521. $p1 = substr($c1, 3 * $n, 3);
  7522. $p2 = substr($c2, 3 * $i, 3);
  7523. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7524. $c = $p1 . $p2 . $c;
  7525. } else {
  7526. $c = $p1 . $c;
  7527. }
  7528. $i = $i + 1;
  7529. //去掉数字最后一位了
  7530. $num = $num / 10;
  7531. $num = (int)$num;
  7532. //结束循环
  7533. if ($num == 0) {
  7534. break;
  7535. }
  7536. }
  7537. $j = 0;
  7538. $slen = strlen($c);
  7539. while ($j < $slen) {
  7540. //utf8一个汉字相当3个字符
  7541. $m = substr($c, $j, 6);
  7542. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7543. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7544. $left = substr($c, 0, $j);
  7545. $right = substr($c, $j + 3);
  7546. $c = $left . $right;
  7547. $j = $j-3;
  7548. $slen = $slen-3;
  7549. }
  7550. $j = $j + 3;
  7551. }
  7552. //这个是为了去掉类似23.0中最后一个“零”字
  7553. if (substr($c, strlen($c)-3, 3) == '零') {
  7554. $c = substr($c, 0, strlen($c)-3);
  7555. }
  7556. //将处理的汉字加上“整”
  7557. if (empty($c)) {
  7558. return "零元整";
  7559. }else{
  7560. return $c . "整";
  7561. }
  7562. }
  7563. /**
  7564. * 获得分页数据
  7565. * @param unknown_type $table
  7566. * @param unknown_type $condition
  7567. * @param unknown_type $on_page
  7568. * @param unknown_type $page_size
  7569. */
  7570. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7571. $page_c = "";
  7572. $page ['previous'] = $this->get_previous ( $on_page );
  7573. $page ['on_page'] = $on_page;
  7574. $total_count = $this->get_table_count ( $table, $condition );
  7575. $total = intval ( $total_count / $page_size );
  7576. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7577. $page ['total_data'] = $total_count;
  7578. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7579. $i = 1;
  7580. $page_max = 1;
  7581. $page_width=3;
  7582. if ($on_page >= $page_width) {
  7583. $page_max = intval ( $on_page / $page_width ) + 1;
  7584. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7585. }
  7586. for(; $i <= $page ['total_page']; $i ++) {
  7587. if ($i == $on_page)
  7588. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7589. else
  7590. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7591. if ($i == ($page_width * $page_max))
  7592. break;
  7593. }
  7594. $page ['page'] = $page_c;
  7595. $page ['lower'] = (-- $on_page) * $page_size;
  7596. return $page;
  7597. }
  7598. /**
  7599. * 获取总页数
  7600. * @param unknown_type $table
  7601. * @param unknown_type $condition
  7602. */
  7603. public function get_table_count($table = "", $condition = "") {
  7604. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7605. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7606. //echo $sql;die;
  7607. $query = Doo::db ()->query ( $sql );
  7608. $result = $query->fetch ();
  7609. return $result ['count'];
  7610. }
  7611. /**
  7612. * 获取上一页
  7613. * @param unknown_type $on_page
  7614. */
  7615. function get_previous($on_page = 1) {
  7616. return $on_page != 0 ? $on_page - 1 : $on_page;
  7617. }
  7618. }
  7619. ?>