ReceiptController.php 305 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321
  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. /*
  1562. $Locate=0;$roleId=0;$button=0;
  1563. foreach ($loanList as $key=>$value){
  1564. $loanList[$key]['Locate']=$Locate;$Locate++;
  1565. $loanList[$key]['reviseDetail']=array();
  1566. if (!empty($value['reviseDetail']))
  1567. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1568. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1569. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1570. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1571. $loanList[$key]['category']=$categoryDetil['title'];
  1572. //检测编辑状态
  1573. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1574. $verifyList['staff']=$value['verifyBreakup'];
  1575. else
  1576. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1577. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1578. $verifyStaff=json_decode($value['verifyStaff'],true);
  1579. Doo::loadModel('role');
  1580. $role=new role();
  1581. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1582. foreach ($verifyList as $k=>$v){
  1583. //init verifyStaff
  1584. if ($v[1]=='ROLE'){
  1585. if (!empty($verifyStaff)){
  1586. $endStaffArray=end($verifyStaff);
  1587. // if ($v[0]==$endStaffArray['nextStaff']){
  1588. // $roleId=$v[0];
  1589. // }
  1590. }
  1591. $roleVerify=json_decode($v[3],true);
  1592. $roleKey=$k;$roleArray=array();
  1593. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1594. foreach ($roleVerify as $o=>$p){
  1595. $staffID=explode ('_',$p);
  1596. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1597. //print_r($staffID);
  1598. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1599. array_push($roleArray, $exp);
  1600. }
  1601. $roleArrayCopy[$v[0]]=$roleArray;
  1602. //$verifyList[$k]['roleArray']=$roleArray;
  1603. }
  1604. $verifyList[$k]['date']="";
  1605. $verifyList[$k]['opinion']="";
  1606. $verifyList[$k]['status']="";
  1607. if (empty($verifyStaff)){
  1608. $verifyList[$k]['date']="";
  1609. $verifyList[$k]['opinion']="";
  1610. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1611. $verifyList[$k]['status']=4;
  1612. $flag=false;
  1613. }
  1614. }else{
  1615. foreach ($verifyStaff as $m=>$u){
  1616. if ($v[0]==$m){
  1617. $verifyList[$k]['date']=$u['date'];
  1618. $verifyList[$k]['opinion']=$u['opinion'];
  1619. $verifyList[$k]['status']=$u['status'];
  1620. $flag=false;
  1621. break;
  1622. }
  1623. }
  1624. $endStaffArray=end($verifyStaff);
  1625. if (isset($endStaffArray['ROLE'])){
  1626. }else{
  1627. // $endKey=key($verifyStaff);
  1628. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1629. // $button=4;
  1630. // $verifyList[$k]['status']=4;
  1631. // }
  1632. }
  1633. }
  1634. }
  1635. $rolename['name']='';
  1636. if (!empty($roleId)){
  1637. Doo::loadModel('role');
  1638. $role=new role();
  1639. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1640. }
  1641. if (!empty($verifyStaff))
  1642. $endStaffArray=end($verifyStaff);
  1643. $KOP=false;
  1644. foreach ($roleArrayCopy as $P=>$A){
  1645. foreach ( $A as $MKI=>$AVL){
  1646. if (!empty($verifyStaff)){
  1647. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1648. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1649. $button=4;
  1650. $roleArrayCopy[$P][$MKI]['status']=4;
  1651. }
  1652. foreach ($verifyStaff as $m=>$u){
  1653. $AVLFK=$AVL[0].'_R';
  1654. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1655. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1656. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1657. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1658. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1659. break;
  1660. }
  1661. }
  1662. }else{
  1663. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1664. $button=4;
  1665. $roleArrayCopy[$P][$MKI]['status']=4;
  1666. }
  1667. }
  1668. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1669. $KOP=true;
  1670. }
  1671. }
  1672. foreach ($roleArrayCopy as $k=>$v){
  1673. foreach ($verifyList as $m=>$n){
  1674. if ($n[0]==$k){
  1675. array_splice($verifyList,$m,1,$v);
  1676. }
  1677. }
  1678. }
  1679. $loanList[$key]['verifyList']=$verifyList;
  1680. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1681. $loanList[$key]['button']=$button;
  1682. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1683. }
  1684. $data['loanList']=$loanList;
  1685. */
  1686. $Locate=0;$roleId=0;$button=0;
  1687. foreach ($receiptList as $key=>$value){
  1688. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1689. $receiptList[$key]['reviseDetail']=array();
  1690. if (!empty($value['reviseDetail']))
  1691. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1692. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1693. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1694. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1695. $receiptList[$key]['category']=$categoryDetil['title'];
  1696. //检测编辑状态
  1697. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1698. if($value['status']==8&&$value['Rtype']==1)
  1699. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1700. else
  1701. $verifyList['staff']=$value['verifyBreakup'];
  1702. }else
  1703. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1704. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1705. $verifyStaff=json_decode($value['verifyStaff'],true);
  1706. Doo::loadModel('role');
  1707. $role=new role();
  1708. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1709. foreach ($verifyList as $k=>$v){
  1710. //init verifyStaff
  1711. if ($v[1]=='ROLE'){
  1712. if (!empty($verifyStaff)){
  1713. $endStaffArray=end($verifyStaff);
  1714. // if ($v[0]==$endStaffArray['nextStaff']){
  1715. // $roleId=$v[0];
  1716. // }
  1717. }
  1718. $roleVerify=json_decode($v[3],true);
  1719. $roleKey=$k;$roleArray=array();
  1720. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1721. foreach ($roleVerify as $o=>$p){
  1722. $staffID=explode ('_',$p);
  1723. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1724. //print_r($staffID);
  1725. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1726. array_push($roleArray, $exp);
  1727. }
  1728. $roleArrayCopy[$v[0]]=$roleArray;
  1729. //$verifyList[$k]['roleArray']=$roleArray;
  1730. }
  1731. $verifyList[$k]['date']="";
  1732. $verifyList[$k]['opinion']="";
  1733. $verifyList[$k]['status']="";
  1734. if (empty($verifyStaff)){
  1735. $verifyList[$k]['date']="";
  1736. $verifyList[$k]['opinion']="";
  1737. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1738. $verifyList[$k]['status']=4;
  1739. $flag=false;
  1740. }
  1741. }else{
  1742. foreach ($verifyStaff as $m=>$u){
  1743. if ($v[0]==$m){
  1744. $verifyList[$k]['date']=$u['date'];
  1745. $verifyList[$k]['opinion']=$u['opinion'];
  1746. $verifyList[$k]['status']=$u['status'];
  1747. $flag=false;
  1748. break;
  1749. }
  1750. }
  1751. $endStaffArray=end($verifyStaff);
  1752. if (isset($endStaffArray['ROLE'])){
  1753. }else{
  1754. // $endKey=key($verifyStaff);
  1755. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1756. // $button=4;
  1757. // $verifyList[$k]['status']=4;
  1758. // }
  1759. }
  1760. }
  1761. }
  1762. $rolename['name']='';
  1763. if (!empty($roleId)){
  1764. Doo::loadModel('role');
  1765. $role=new role();
  1766. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1767. }
  1768. if (!empty($verifyStaff))
  1769. $endStaffArray=end($verifyStaff);
  1770. $KOP=false;
  1771. foreach ($roleArrayCopy as $P=>$A){
  1772. foreach ( $A as $MKI=>$AVL){
  1773. if (!empty($verifyStaff)){
  1774. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1775. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1776. $button=4;
  1777. $roleArrayCopy[$P][$MKI]['status']=4;
  1778. }
  1779. foreach ($verifyStaff as $m=>$u){
  1780. $AVLFK=$AVL[0].'_R';
  1781. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1782. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1783. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1784. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1785. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1786. break;
  1787. }
  1788. }
  1789. }else{
  1790. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1791. $button=4;
  1792. $roleArrayCopy[$P][$MKI]['status']=4;
  1793. }
  1794. }
  1795. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1796. $KOP=true;
  1797. }
  1798. }
  1799. foreach ($roleArrayCopy as $k=>$v){
  1800. foreach ($verifyList as $m=>$n){
  1801. if ($n[0]==$k){
  1802. array_splice($verifyList,$m,1,$v);
  1803. }
  1804. }
  1805. }
  1806. //费用执行人相关数据
  1807. $executeCopy=json_decode($value['executeCopy'],true);
  1808. $executeStaff=json_decode($value['executeStaff'],true);
  1809. foreach ($executeCopy as $k=>$v){
  1810. $executeCopy[$k]['date']='';
  1811. $executeCopy[$k]['opinion']='';
  1812. $executeCopy[$k]['status']='';
  1813. if (!empty($executeStaff))
  1814. foreach ($executeStaff as $m=>$u){
  1815. if ($v[0]==$m){
  1816. $executeCopy[$k]['date']=$u['date'];
  1817. $executeCopy[$k]['opinion']=$u['opinion'];
  1818. $executeCopy[$k]['status']=$u['status'];
  1819. break;
  1820. }
  1821. }
  1822. }
  1823. $receiptList[$key]['executeCopy']=$executeCopy;
  1824. $receiptList[$key]['verifyList']=$verifyList;
  1825. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1826. $receiptList[$key]['button']=$button;
  1827. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1828. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1829. $relust=$value['sum']-$value['loanSum'];
  1830. $receiptList[$key]['relust']=$relust;
  1831. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1832. }
  1833. //print_r($receiptList);
  1834. $data['receiptList']=$receiptList;
  1835. $data['memu']="receipt";
  1836. $data['staff']=$this->staff;
  1837. $data['receiptMemu']='expenses';
  1838. $data['verifyId']=$this->verifyId;
  1839. $data['executeId']=$this->executeId;
  1840. $this->render ( "/admin/expensesCollect", $data );
  1841. }
  1842. function approvalExpenses(){
  1843. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1844. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1845. $month=$this->get_args('month')?$this->get_args('month'):"";
  1846. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1847. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1848. if (empty($status))
  1849. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1850. $page_size=12;
  1851. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1852. $vidList=array();
  1853. $button=0;
  1854. Doo::loadModel('verify');
  1855. $verify=new verify();
  1856. Doo::loadModel('receipt');
  1857. $receipt=new receipt();
  1858. Doo::loadModel('staff');
  1859. $staff=new staff();
  1860. Doo::loadModel('L_category');
  1861. $Lcategory=new L_category();
  1862. //user verify ID
  1863. $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));
  1864. foreach ($verifyDetail as $key=>$value){
  1865. array_push($vidList, $value['vid']);
  1866. }
  1867. $vid=implode(",", $vidList);
  1868. if(empty($verifyDetail))
  1869. $vid=0;
  1870. // if ($status==0)
  1871. // $dateCondition="";
  1872. // else
  1873. $dateCondition=" and Year(date) =".$year;
  1874. if(!empty($month))
  1875. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1876. $categoryList=$Lcategory->find(array('asArray'=>true));
  1877. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1878. $cateCondition="";$staffCondition="";$approvalCondition="";
  1879. if (!empty($cid))
  1880. $cateCondition=' and cid='.$cid;
  1881. if(!empty($sid)){
  1882. $staffCondition=' and staff='.$sid;
  1883. $cateCondition="";
  1884. }
  1885. $approvalCondition=" and status=".$status;
  1886. if($status==2){
  1887. //查找角色审批人
  1888. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1889. }
  1890. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1891. $approvalCondition=' and status=2 ';
  1892. }
  1893. if($status==1){
  1894. $approvalCondition=' and (status='.$status.' or status=6) ';
  1895. }
  1896. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1897. $pageinfo['page']=array('previous'=>'');
  1898. if ($status==0){
  1899. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1900. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1901. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1902. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1903. }else
  1904. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1905. ,'desc'=>'rid','asArray'=>true));
  1906. $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
  1907. ,'desc'=>'rid','asArray'=>true));
  1908. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1909. //print_r($pageinfo);
  1910. $Locate=0;
  1911. foreach ($receiptList as $key=>$value){
  1912. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1913. $receiptList[$key]['reviseDetail']=array();
  1914. if (!empty($value['reviseDetail']))
  1915. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1916. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1917. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1918. $receiptList[$key]['category']=$categoryDetil['title'];
  1919. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1920. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1921. $verifyStaff=json_decode($value['verifyStaff'],true);
  1922. foreach ($verifyList as $k=>$v){
  1923. //init verifyStaff
  1924. $verifyList[$k]['date']="";
  1925. $verifyList[$k]['opinion']="";
  1926. $verifyList[$k]['status']="";
  1927. if (empty($verifyStaff)){
  1928. $verifyList[$k]['date']="";
  1929. $verifyList[$k]['opinion']="";
  1930. if ($v[0]==$this->staff[0]['sid']){
  1931. $verifyList[$k]['status']=4;
  1932. $button=4;
  1933. }
  1934. }else{
  1935. $flag=true;
  1936. foreach ($verifyStaff as $m=>$u){
  1937. if ($v[0]==$m){
  1938. $verifyList[$k]['date']=$u['date'];
  1939. $verifyList[$k]['opinion']=$u['opinion'];
  1940. $verifyList[$k]['status']=$u['status'];
  1941. $flag=false;
  1942. break;
  1943. }
  1944. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1945. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1946. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1947. }
  1948. if($flag){//检测可编辑
  1949. if($v[0]==$this->staff[0]['sid']){
  1950. $verifyList[$k]['status']=4;$button=4;
  1951. }
  1952. }
  1953. }
  1954. }
  1955. $receiptList[$key]['verifyList']=$verifyList;
  1956. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1957. $receiptList[$key]['button']=$button;
  1958. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1959. }
  1960. //print_r($receiptList);die;
  1961. //$data['verifyDetail']=$verifyDetail;
  1962. $mothHtml="";
  1963. for($i=1;$i<=12;$i++){
  1964. if($month==$i)
  1965. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1966. else
  1967. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1968. }
  1969. $data['mothHtml']=$mothHtml;
  1970. $data['page']=$pageinfo;
  1971. $data['receiptList']=$receiptList;
  1972. $data['receiptApprovalCount']=count($rLRes);
  1973. $data['status']=$status;
  1974. $data['year']=$year;
  1975. $data['categoryList']=$categoryList;
  1976. $data['staffList']=$staffList;
  1977. $data['cid']=$cid;
  1978. $data['sid']=$sid;
  1979. //print_r($receiptList);
  1980. $data['memu']="receipt";
  1981. $data['staff']=$this->staff;
  1982. $data['receiptMemu']='approvalExpenses';
  1983. $data['verifyId']=$this->verifyId;
  1984. $data['executeId']=$this->executeId;
  1985. $this->render ( "/admin/approvalExpenses", $data );
  1986. }
  1987. function expensesDoc(){
  1988. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1989. Doo::loadModel('receipt');
  1990. $receipt=new receipt();
  1991. Doo::loadModel('L_category');
  1992. $Lcategory=new L_category();
  1993. Doo::loadModel('verify');
  1994. Doo::loadModel('statistics');
  1995. $statistics=new statistics();
  1996. $verify=new verify();
  1997. Doo::loadModel('staff');
  1998. $staff=new staff();
  1999. Doo::loadModel('loanReceipt');
  2000. $loanReceipt=new loanReceipt();
  2001. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  2002. $loanList=array();
  2003. if (!empty($receiptList))
  2004. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2005. $Locate=0;$roleId=0;$button=0;
  2006. foreach ($loanList as $key=>$value){
  2007. $loanList[$key]['Locate']=$Locate;$Locate++;
  2008. $loanList[$key]['reviseDetail']=array();
  2009. if (!empty($value['reviseDetail']))
  2010. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2011. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2012. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2013. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2014. $loanList[$key]['category']=$categoryDetil['title'];
  2015. //检测编辑状态
  2016. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  2017. $verifyList['staff']=$value['verifyBreakup'];
  2018. else
  2019. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2020. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2021. $verifyStaff=json_decode($value['verifyStaff'],true);
  2022. Doo::loadModel('role');
  2023. $role=new role();
  2024. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2025. foreach ($verifyList as $k=>$v){
  2026. //init verifyStaff
  2027. if ($v[1]=='ROLE'){
  2028. if (!empty($verifyStaff)){
  2029. $endStaffArray=end($verifyStaff);
  2030. // if ($v[0]==$endStaffArray['nextStaff']){
  2031. // $roleId=$v[0];
  2032. // }
  2033. }
  2034. $roleVerify=json_decode($v[3],true);
  2035. $roleKey=$k;$roleArray=array();
  2036. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2037. foreach ($roleVerify as $o=>$p){
  2038. $staffID=explode ('_',$p);
  2039. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2040. //print_r($staffID);
  2041. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2042. array_push($roleArray, $exp);
  2043. }
  2044. $roleArrayCopy[$v[0]]=$roleArray;
  2045. //$verifyList[$k]['roleArray']=$roleArray;
  2046. }
  2047. $verifyList[$k]['date']="";
  2048. $verifyList[$k]['opinion']="";
  2049. $verifyList[$k]['status']="";
  2050. if (empty($verifyStaff)){
  2051. $verifyList[$k]['date']="";
  2052. $verifyList[$k]['opinion']="";
  2053. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2054. $verifyList[$k]['status']=4;
  2055. $flag=false;
  2056. }
  2057. }else{
  2058. foreach ($verifyStaff as $m=>$u){
  2059. if ($v[0]==$m){
  2060. $verifyList[$k]['date']=$u['date'];
  2061. $verifyList[$k]['opinion']=$u['opinion'];
  2062. $verifyList[$k]['status']=$u['status'];
  2063. $flag=false;
  2064. break;
  2065. }
  2066. }
  2067. $endStaffArray=end($verifyStaff);
  2068. if (isset($endStaffArray['ROLE'])){
  2069. }else{
  2070. // $endKey=key($verifyStaff);
  2071. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2072. // $button=4;
  2073. // $verifyList[$k]['status']=4;
  2074. // }
  2075. }
  2076. }
  2077. }
  2078. $rolename['name']='';
  2079. if (!empty($roleId)){
  2080. Doo::loadModel('role');
  2081. $role=new role();
  2082. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2083. }
  2084. if (!empty($verifyStaff))
  2085. $endStaffArray=end($verifyStaff);
  2086. $KOP=false;
  2087. foreach ($roleArrayCopy as $P=>$A){
  2088. foreach ( $A as $MKI=>$AVL){
  2089. if (!empty($verifyStaff)){
  2090. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2091. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2092. $button=4;
  2093. $roleArrayCopy[$P][$MKI]['status']=4;
  2094. }
  2095. foreach ($verifyStaff as $m=>$u){
  2096. $AVLFK=$AVL[0].'_R';
  2097. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2098. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2099. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2100. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2101. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2102. break;
  2103. }
  2104. }
  2105. }else{
  2106. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2107. $button=4;
  2108. $roleArrayCopy[$P][$MKI]['status']=4;
  2109. }
  2110. }
  2111. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2112. $KOP=true;
  2113. }
  2114. }
  2115. foreach ($roleArrayCopy as $k=>$v){
  2116. foreach ($verifyList as $m=>$n){
  2117. if ($n[0]==$k){
  2118. array_splice($verifyList,$m,1,$v);
  2119. }
  2120. }
  2121. }
  2122. $loanList[$key]['verifyList']=$verifyList;
  2123. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2124. $loanList[$key]['button']=$button;
  2125. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2126. }
  2127. $data['loanList']=$loanList;
  2128. //print_r($loanList);
  2129. $Locate=0;$roleId=0;$button=0;
  2130. foreach ($receiptList as $key=>$value){
  2131. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2132. $receiptList[$key]['reviseDetail']=array();
  2133. if (!empty($value['reviseDetail']))
  2134. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2135. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2136. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2137. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2138. $receiptList[$key]['category']=$categoryDetil['title'];
  2139. //检测编辑状态
  2140. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2141. $verifyList['staff']=$value['verifyBreakup'];
  2142. }else
  2143. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2144. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2145. $verifyStaff=json_decode($value['verifyStaff'],true);
  2146. Doo::loadModel('role');
  2147. $role=new role();
  2148. if ($verifyList==NULL)
  2149. $verifyList=array();
  2150. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2151. foreach ($verifyList as $k=>$v){
  2152. //init verifyStaff
  2153. if ($v[1]=='ROLE'){
  2154. if (!empty($verifyStaff)){
  2155. $endStaffArray=end($verifyStaff);
  2156. // if ($v[0]==$endStaffArray['nextStaff']){
  2157. // $roleId=$v[0];
  2158. // }
  2159. }
  2160. $roleVerify=json_decode($v[3],true);
  2161. $roleKey=$k;$roleArray=array();
  2162. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2163. foreach ($roleVerify as $o=>$p){
  2164. $staffID=explode ('_',$p);
  2165. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2166. //print_r($staffID);
  2167. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2168. array_push($roleArray, $exp);
  2169. }
  2170. $roleArrayCopy[$v[0]]=$roleArray;
  2171. //$verifyList[$k]['roleArray']=$roleArray;
  2172. }
  2173. $verifyList[$k]['date']="";
  2174. $verifyList[$k]['opinion']="";
  2175. $verifyList[$k]['status']="";
  2176. if (empty($verifyStaff)){
  2177. $verifyList[$k]['date']="";
  2178. $verifyList[$k]['opinion']="";
  2179. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2180. $verifyList[$k]['status']=4;
  2181. $flag=false;
  2182. }
  2183. }else{
  2184. foreach ($verifyStaff as $m=>$u){
  2185. if ($v[0]==$m){
  2186. $verifyList[$k]['date']=$u['date'];
  2187. $verifyList[$k]['opinion']=$u['opinion'];
  2188. $verifyList[$k]['status']=$u['status'];
  2189. $flag=false;
  2190. break;
  2191. }
  2192. }
  2193. $endStaffArray=end($verifyStaff);
  2194. if (isset($endStaffArray['ROLE'])){
  2195. }else{
  2196. // $endKey=key($verifyStaff);
  2197. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2198. // $button=4;
  2199. // $verifyList[$k]['status']=4;
  2200. // }
  2201. }
  2202. }
  2203. }
  2204. $rolename['name']='';
  2205. if (!empty($roleId)){
  2206. Doo::loadModel('role');
  2207. $role=new role();
  2208. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2209. }
  2210. if (!empty($verifyStaff))
  2211. $endStaffArray=end($verifyStaff);
  2212. $KOP=false;
  2213. foreach ($roleArrayCopy as $P=>$A){
  2214. foreach ( $A as $MKI=>$AVL){
  2215. if (!empty($verifyStaff)){
  2216. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2217. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2218. $button=4;
  2219. $roleArrayCopy[$P][$MKI]['status']=4;
  2220. }
  2221. foreach ($verifyStaff as $m=>$u){
  2222. $AVLFK=$AVL[0].'_R';
  2223. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2224. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2225. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2226. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2227. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2228. break;
  2229. }
  2230. }
  2231. }else{
  2232. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2233. $button=4;
  2234. $roleArrayCopy[$P][$MKI]['status']=4;
  2235. }
  2236. }
  2237. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2238. $KOP=true;
  2239. }
  2240. }
  2241. foreach ($roleArrayCopy as $k=>$v){
  2242. foreach ($verifyList as $m=>$n){
  2243. if ($n[0]==$k){
  2244. array_splice($verifyList,$m,1,$v);
  2245. }
  2246. }
  2247. }
  2248. //费用执行人相关数据
  2249. $executeCopy=json_decode($value['executeCopy'],true);
  2250. $executeStaff=json_decode($value['executeStaff'],true);
  2251. foreach ($executeCopy as $k=>$v){
  2252. $executeCopy[$k]['date']='';
  2253. $executeCopy[$k]['opinion']='';
  2254. $executeCopy[$k]['status']='';
  2255. if (!empty($executeStaff))
  2256. foreach ($executeStaff as $m=>$u){
  2257. if ($v[0]==$m){
  2258. $executeCopy[$k]['date']=$u['date'];
  2259. $executeCopy[$k]['opinion']=$u['opinion'];
  2260. $executeCopy[$k]['status']=$u['status'];
  2261. break;
  2262. }
  2263. }
  2264. }
  2265. $receiptList[$key]['executeCopy']=$executeCopy;
  2266. $receiptList[$key]['verifyList']=$verifyList;
  2267. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2268. $receiptList[$key]['button']=$button;
  2269. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2270. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2271. }
  2272. //print_r($receiptList);
  2273. //获取审批日志
  2274. Doo::loadModel('receiptLog');
  2275. $receiptLog=new receiptLog();
  2276. $rlList=array();
  2277. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2278. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2279. if (!empty($rlInfo)){
  2280. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2281. }
  2282. $receiptList[0]['rlList']=$rlList;
  2283. $data['receiptList']=$receiptList;
  2284. $data['memu']="receipt";
  2285. $data['staff']=$this->staff;
  2286. $data['receiptMemu']='approvalExpenses';
  2287. $data['verifyId']=$this->verifyId;
  2288. $data['executeId']=$this->executeId;
  2289. $this->render ( "/admin/expensesDoc", $data );
  2290. }
  2291. function expensesEdi(){
  2292. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2293. $status=isset($this->params['status'])?$this->params['status']:'';
  2294. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2295. $month=$this->get_args('month')?$this->get_args('month'):"";
  2296. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2297. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2298. if (empty($status))
  2299. $status=$this->get_args('status')?$this->get_args('status'):2;
  2300. $vidList=array();
  2301. $button=0;
  2302. Doo::loadModel('verify');
  2303. Doo::loadModel('receipt');
  2304. Doo::loadModel('staff');
  2305. $staff=new staff();
  2306. $receipt=new receipt();
  2307. $verify=new verify();
  2308. Doo::loadModel('L_category');
  2309. $Lcategory=new L_category();
  2310. Doo::loadModel('enclosur');
  2311. $enclosur=new enclosur();
  2312. //user verify ID
  2313. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2314. foreach ($verifyDetail as $key=>$value){
  2315. array_push($vidList, $value['vid']);
  2316. }
  2317. $vid=implode(",", $vidList);
  2318. if(empty($verifyDetail))
  2319. $vid=0;
  2320. $categoryList=$Lcategory->find(array('asArray'=>true));
  2321. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2322. $ap="";
  2323. if($status==4){
  2324. $ap=4;$status=2;
  2325. }
  2326. //get Receipt By verifyID status 2
  2327. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2328. $Locate=0;$roleId=0;
  2329. if($ap==4)
  2330. $status=4;
  2331. foreach ($receiptList as $key=>$value){
  2332. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2333. $receiptList[$key]['reviseDetail']=array();
  2334. if (!empty($value['reviseDetail']))
  2335. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2336. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2337. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2338. $receiptList[$key]['category']=$categoryDetil['title'];
  2339. //检测编辑状态
  2340. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2341. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2342. $verifyStaff=json_decode($value['verifyStaff'],true);
  2343. Doo::loadModel('role');
  2344. $role=new role();
  2345. //print_r($verifyList);
  2346. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2347. foreach ($verifyList as $k=>$v){
  2348. //init verifyStaff
  2349. if ($v[1]=='ROLE'){
  2350. if (!empty($verifyStaff)){
  2351. $endStaffArray=end($verifyStaff);
  2352. if ($v[0]==$endStaffArray['nextStaff']){
  2353. $roleId=$v[0];
  2354. }
  2355. }
  2356. $roleVerify=json_decode($v[3],true);
  2357. $roleKey=$k;$roleArray=array();
  2358. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2359. foreach ($roleVerify as $o=>$p){
  2360. $staffID=explode ('_',$p);
  2361. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2362. //print_r($staffID);
  2363. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2364. array_push($roleArray, $exp);
  2365. }
  2366. $roleArrayCopy[$v[0]]=$roleArray;
  2367. //$verifyList[$k]['roleArray']=$roleArray;
  2368. }
  2369. //print_r($roleArray);
  2370. $verifyList[$k]['date']="";
  2371. $verifyList[$k]['opinion']="";
  2372. $verifyList[$k]['status']="";
  2373. if (empty($verifyStaff)){
  2374. $verifyList[$k]['date']="";
  2375. $verifyList[$k]['opinion']="";
  2376. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2377. $verifyList[$k]['status']=4;
  2378. $button=4;$flag=false;
  2379. }
  2380. }else{
  2381. foreach ($verifyStaff as $m=>$u){
  2382. if ($v[0]==$m){
  2383. $verifyList[$k]['date']=$u['date'];
  2384. $verifyList[$k]['opinion']=$u['opinion'];
  2385. $verifyList[$k]['status']=$u['status'];
  2386. $flag=false;
  2387. break;
  2388. }
  2389. }
  2390. $endStaffArray=end($verifyStaff);
  2391. if (isset($endStaffArray['ROLE'])){
  2392. }else{
  2393. $endKey=key($verifyStaff);
  2394. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2395. $button=4;
  2396. $verifyList[$k]['status']=4;
  2397. }
  2398. }
  2399. }
  2400. }
  2401. $rolename['name']='';
  2402. if (!empty($roleId)){
  2403. Doo::loadModel('role');
  2404. $role=new role();
  2405. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2406. }
  2407. if (!empty($verifyStaff))
  2408. $endStaffArray=end($verifyStaff);
  2409. $KOP=false;
  2410. foreach ($roleArrayCopy as $P=>$A){
  2411. foreach ( $A as $MKI=>$AVL){
  2412. if (!empty($verifyStaff)){
  2413. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2414. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2415. $button=4;
  2416. $roleArrayCopy[$P][$MKI]['status']=4;
  2417. }
  2418. foreach ($verifyStaff as $m=>$u){
  2419. $AVLFK=$AVL[0].'_R';
  2420. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2421. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2422. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2423. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2424. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2425. break;
  2426. }
  2427. }
  2428. }else{
  2429. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2430. $button=4;
  2431. $roleArrayCopy[$P][$MKI]['status']=4;
  2432. }
  2433. }
  2434. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2435. $KOP=true;
  2436. }
  2437. }
  2438. // print_r($roleArrayCopy);
  2439. // echo $roleKey;
  2440. foreach ($roleArrayCopy as $k=>$v){
  2441. foreach ($verifyList as $m=>$n){
  2442. if ($n[0]==$k){
  2443. array_splice($verifyList,$m,1,$v);
  2444. }
  2445. }
  2446. }
  2447. $receiptList[$key]['verifyList']=$verifyList;
  2448. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2449. $receiptList[$key]['button']=$button;
  2450. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2451. }
  2452. //$data['verifyDetail']=$verifyDetail;
  2453. $mothHtml="";
  2454. for($i=1;$i<=12;$i++){
  2455. if($month==$i)
  2456. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2457. else
  2458. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2459. }
  2460. //获取审批日志
  2461. Doo::loadModel('receiptLog');
  2462. $receiptLog=new receiptLog();
  2463. $rlList=array();
  2464. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2465. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2466. if (!empty($rlInfo)){
  2467. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2468. }
  2469. $receiptList[0]['rlList']=$rlList;
  2470. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2471. $enclosurHtml='';
  2472. foreach ($enclosurList as $value){
  2473. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2474. }
  2475. //print_r($receiptList);
  2476. $data['rid']=$rid;
  2477. $data['enclosurHtml']=$enclosurHtml;
  2478. $data['rolename']=$rolename['name'];
  2479. $data['datetij']=$tijdate['date'];
  2480. $data['mothHtml']=$mothHtml;
  2481. $data['receiptList']=$receiptList;
  2482. $data['receiptApprovalCount']=count($receiptList);
  2483. $data['status']=$status;
  2484. $data['year']=$year;
  2485. $data['categoryList']=$categoryList;
  2486. $data['staffList']=$staffList;
  2487. $data['cid']=$cid;
  2488. $data['sid']=$sid;
  2489. $data['ap']=$ap;
  2490. $data['memu']="receipt";
  2491. $data['staff']=$this->staff;
  2492. $data['receiptMemu']='approvalExpenses';
  2493. $data['verifyId']=$this->verifyId;
  2494. $data['executeId']=$this->executeId;
  2495. $this->render ( "/admin/expensesEdi", $data );
  2496. }
  2497. function expensesDefray(){
  2498. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2499. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2500. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2501. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2502. if(!empty($rid)){
  2503. Doo::loadModel("verify");
  2504. $verify=new verify();
  2505. Doo::loadModel("receiptDetail");
  2506. $receiptDetailObj=new receiptDetail();
  2507. Doo::loadModel("itemStatistics");
  2508. Doo::loadModel("statistics");
  2509. $statistics=new statistics();
  2510. $itemStatistics=new itemStatistics();
  2511. Doo::loadModel("receipt");
  2512. $receipt=new receipt();
  2513. Doo::loadModel("loanReceipt");
  2514. $loanReceipt=new loanReceipt();
  2515. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2516. if (empty($receiptDetail))
  2517. return "/approval";
  2518. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2519. $verifyString=$verifyDetail['staff'];
  2520. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2521. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2522. if(empty($opinion)){
  2523. if ($status==3)
  2524. $opinion="终止";
  2525. else
  2526. $opinion="同意支付";
  2527. }
  2528. $nowStaff=0;$nowStaffList=array();
  2529. if(empty($verifyStaff)){
  2530. //还需加入是否已经进入角色审批
  2531. if ($verifyDetail[0][1]=='ROLE'){
  2532. //print_r($verifyDetail);echo "ddd";
  2533. $vStaffString=json_decode($verifyDetail[0][3]);
  2534. foreach ($vStaffString as $key=>$value){
  2535. $staffK=explode("_", $value);
  2536. if ($staffK[0]!=$this->staff[0]['sid'])
  2537. array_push($nowStaffList, $staffK[0]);
  2538. }
  2539. //print_r($verifyDetail);
  2540. //die;
  2541. if (!empty($nowStaffList)){
  2542. $nowStaff=implode(',', $nowStaffList);
  2543. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2544. }else{
  2545. $nowStaff=$verifyDetail[1][0];
  2546. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2547. }
  2548. }else{
  2549. if ($verifyDetail[1][1]=='ROLE'){
  2550. $vStaffString=json_decode($verifyDetail[1][3]);
  2551. //echo "dd";
  2552. foreach ($vStaffString as $key=>$value){
  2553. $staffK=explode("_", $value);
  2554. array_push($nowStaffList, $staffK[0]);
  2555. }
  2556. $nowStaff=implode(',', $nowStaffList);
  2557. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2558. }else{
  2559. $nowStaff=$verifyDetail[1][0];
  2560. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2561. }
  2562. }
  2563. if($status==3)
  2564. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2565. $vStaffString=json_encode($verifyStaff);
  2566. $receipt->nowStaff=$nowStaff;
  2567. $receipt->verifyStaff=$vStaffString;
  2568. $loanReceipt->nowStaff=$nowStaff;
  2569. $loanReceipt->verifyStaff=$vStaffString;
  2570. }else{
  2571. $VS=end($verifyStaff);
  2572. //非角色审批
  2573. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2574. $nextStaff=0;$roleSTF=false;
  2575. foreach ($verifyDetail as $key=>$value){
  2576. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2577. if (isset($verifyDetail[$key+1])){
  2578. $nextStaff=$verifyDetail[$key+1][0];
  2579. if ($verifyDetail[$key+1][1]=='ROLE')
  2580. $roleSTF=true;
  2581. }
  2582. break;
  2583. }
  2584. }
  2585. if (!$roleSTF){
  2586. $nowStaff=$nextStaff;
  2587. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2588. }else{
  2589. //获取角色下的所有用户ID
  2590. $nowStaffList=array();
  2591. foreach ($verifyDetail as $vfk){
  2592. if ($vfk[1]=='ROLE'){
  2593. $vStaffString=json_decode($vfk[3]);
  2594. foreach ($vStaffString as $key=>$value){
  2595. $staffK=explode("_", $value);
  2596. array_push($nowStaffList, $staffK[0]);
  2597. }
  2598. }
  2599. }
  2600. $nowStaff=implode(',', $nowStaffList);
  2601. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2602. }
  2603. if($status==3){
  2604. $verifyStaff['final']=$status;
  2605. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2606. }
  2607. $vStaffString=json_encode($verifyStaff);
  2608. $receipt->nowStaff=$nowStaff;
  2609. $receipt->verifyStaff=$vStaffString;
  2610. $loanReceipt->nowStaff=$nowStaff;
  2611. $loanReceipt->verifyStaff=$vStaffString;
  2612. }
  2613. //角色审批
  2614. if (isset($VS['ROLE'])){
  2615. //找出角色人 当前审批角色组
  2616. $verifyJSStaff=array();$nowStaffList2=array();
  2617. foreach ($verifyDetail as $key=>$value){
  2618. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2619. $verifyJSStaff=json_decode($value[3]);
  2620. foreach ($verifyJSStaff as $m){
  2621. $staffK=explode("_", $m);
  2622. array_push($nowStaffList2, $staffK[0]);
  2623. }
  2624. // print_r($nowStaffList2);
  2625. }
  2626. }
  2627. $RoleVerifyStaff=array();
  2628. foreach ($verifyStaff as $key=>$value){
  2629. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2630. foreach ($nowStaffList2 as $m) {
  2631. if ($key==$m."_R")
  2632. $RoleVerifyStaff[$key]=$value;
  2633. }
  2634. }
  2635. }
  2636. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2637. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2638. //下一个审批人ID
  2639. $nextStaff=0;$falg=false;
  2640. foreach ($verifyDetail as $key=>$value){
  2641. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2642. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2643. $falg=true;
  2644. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2645. foreach ($vStaffString as $v){
  2646. $staffK=explode("_", $v);
  2647. array_push($nowStaffList, $staffK[0]);
  2648. }
  2649. $nowStaff=implode(',', $nowStaffList);
  2650. $nextStaff=$verifyDetail[$key+1][0];
  2651. }elseif(isset($verifyDetail[$key+1])){
  2652. $nextStaff=$verifyDetail[$key+1][0];
  2653. $nowStaff=$nextStaff;
  2654. }else
  2655. $nowStaff='';
  2656. break;
  2657. }
  2658. }
  2659. if ($falg)
  2660. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2661. else
  2662. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2663. // print_r($verifyStaff);
  2664. // echo $nowStaff;die;
  2665. }else{ //进入下一个角色或者审批人
  2666. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2667. //
  2668. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2669. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2670. // print_r($verifyStaff);
  2671. // die;
  2672. }
  2673. if($status==3){
  2674. $verifyStaff['final']=$status;
  2675. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2676. }
  2677. $vStaffString=json_encode($verifyStaff);
  2678. $receipt->verifyStaff=$vStaffString;
  2679. $receipt->nowStaff=$nowStaff;
  2680. $loanReceipt->nowStaff=$nowStaff;
  2681. $loanReceipt->verifyStaff=$vStaffString;
  2682. //die;
  2683. //}
  2684. // print_r($verifyStaff);
  2685. // die;
  2686. }
  2687. //print_r($verifyStaff);die;
  2688. }
  2689. //print_r($verifyDetail);
  2690. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2691. foreach ($verifyDetail as $k=>$v){
  2692. if ($v[1]=='ROLE'){
  2693. $roleId=$v[0];
  2694. $roleVerify=json_decode($v[3],true);
  2695. $roleKey=$k;$roleArray=array();
  2696. foreach ($roleVerify as $o=>$p){
  2697. $staffID=explode ('_',$p);
  2698. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2699. array_push($roleArray, $exp);
  2700. }
  2701. $verifyDetailCopy[$v[0]]=$roleArray;
  2702. }
  2703. }
  2704. //print_r($verifyDetail);
  2705. foreach ($verifyDetailCopy as $k=>$v){
  2706. foreach ($verifyDetail as $m=>$n){
  2707. if ($n[0]==$k){
  2708. array_splice($verifyDetail,$m,1,$v);
  2709. }
  2710. }
  2711. }
  2712. //审批日志
  2713. if (!isset($verifyStaff['final'])){
  2714. Doo::loadModel("receiptLog");
  2715. $receiptLog=new receiptLog();
  2716. if (!empty($roleId)){
  2717. Doo::loadModel("role");
  2718. $role=new role();
  2719. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2720. $receiptLog->rolename=$roleInfo['name'];
  2721. }
  2722. $receiptLog->username=$this->staff[0]['username'];
  2723. $receiptLog->uid=$this->staff[0]['sid'];
  2724. $receiptLog->date=date("Y-m-d");
  2725. $receiptLog->opinion=$opinion;
  2726. $receiptLog->img=$this->staff[0]['avatar'];
  2727. $receiptLog->status=1;
  2728. $receiptLog->rid=$rid;
  2729. $receiptLog->insert();
  2730. }
  2731. if (isset($verifyStaff['final'])){//rDetail
  2732. $receipt->status=3;
  2733. $receipt->verifyBreakup=$verifyString;
  2734. $receiptDetailObj->status=3;
  2735. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2736. //微信企业号通知
  2737. $this->setWXMsg($rid,3);
  2738. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2739. $receipt->status=6;
  2740. $receipt->pastDate=date("Y-m-d");
  2741. $receipt->isBK=1;
  2742. $loanReceipt->verifyBreakup=$verifyString;
  2743. $loanReceipt->status=1;
  2744. $loanReceipt->pastDate=date("Y-m-d");
  2745. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2746. //微信企业号通知
  2747. $this->setWXMsg($rid,1);
  2748. }
  2749. $receipt->update(array('where'=>' rid = '.$rid));
  2750. return "/approvalExpenses/2";
  2751. }
  2752. }
  2753. function implement(){
  2754. Doo::loadModel('receipt');
  2755. $receipt=new receipt();
  2756. Doo::loadModel('L_category');
  2757. $Lcategory=new L_category();
  2758. Doo::loadModel('verify');
  2759. $verify=new verify();
  2760. Doo::loadModel('staff');
  2761. $staff=new staff();
  2762. Doo::loadModel("execute");
  2763. $execute=new execute();
  2764. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2765. Doo::loadModel('loanReceipt');
  2766. $loanReceipt=new loanReceipt();
  2767. //print_r($receiptList);
  2768. $loanList=array();
  2769. if (!isset($receiptList))
  2770. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2771. $Locate=0;$roleId=0;$button=0;
  2772. foreach ($loanList as $key=>$value){
  2773. $loanList[$key]['Locate']=$Locate;$Locate++;
  2774. $loanList[$key]['reviseDetail']=array();
  2775. if (!empty($value['reviseDetail']))
  2776. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2777. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2778. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2779. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2780. $loanList[$key]['category']=$categoryDetil['title'];
  2781. //检测编辑状态
  2782. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2783. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2784. $verifyStaff=json_decode($value['verifyStaff'],true);
  2785. Doo::loadModel('role');
  2786. $role=new role();
  2787. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2788. foreach ($verifyList as $k=>$v){
  2789. //init verifyStaff
  2790. if ($v[1]=='ROLE'){
  2791. if (!empty($verifyStaff)){
  2792. $endStaffArray=end($verifyStaff);
  2793. // if ($v[0]==$endStaffArray['nextStaff']){
  2794. // $roleId=$v[0];
  2795. // }
  2796. }
  2797. $roleVerify=json_decode($v[3],true);
  2798. $roleKey=$k;$roleArray=array();
  2799. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2800. foreach ($roleVerify as $o=>$p){
  2801. $staffID=explode ('_',$p);
  2802. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2803. //print_r($staffID);
  2804. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2805. array_push($roleArray, $exp);
  2806. }
  2807. $roleArrayCopy[$v[0]]=$roleArray;
  2808. //$verifyList[$k]['roleArray']=$roleArray;
  2809. }
  2810. $verifyList[$k]['date']="";
  2811. $verifyList[$k]['opinion']="";
  2812. $verifyList[$k]['status']="";
  2813. if (empty($verifyStaff)){
  2814. $verifyList[$k]['date']="";
  2815. $verifyList[$k]['opinion']="";
  2816. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2817. $verifyList[$k]['status']=4;
  2818. $flag=false;
  2819. }
  2820. }else{
  2821. foreach ($verifyStaff as $m=>$u){
  2822. if ($v[0]==$m){
  2823. $verifyList[$k]['date']=$u['date'];
  2824. $verifyList[$k]['opinion']=$u['opinion'];
  2825. $verifyList[$k]['status']=$u['status'];
  2826. $flag=false;
  2827. break;
  2828. }
  2829. }
  2830. $endStaffArray=end($verifyStaff);
  2831. if (isset($endStaffArray['ROLE'])){
  2832. }else{
  2833. // $endKey=key($verifyStaff);
  2834. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2835. // $button=4;
  2836. // $verifyList[$k]['status']=4;
  2837. // }
  2838. }
  2839. }
  2840. }
  2841. $rolename['name']='';
  2842. if (!empty($roleId)){
  2843. Doo::loadModel('role');
  2844. $role=new role();
  2845. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2846. }
  2847. if (!empty($verifyStaff))
  2848. $endStaffArray=end($verifyStaff);
  2849. $KOP=false;
  2850. foreach ($roleArrayCopy as $P=>$A){
  2851. foreach ( $A as $MKI=>$AVL){
  2852. if (!empty($verifyStaff)){
  2853. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2854. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2855. $button=4;
  2856. $roleArrayCopy[$P][$MKI]['status']=4;
  2857. }
  2858. foreach ($verifyStaff as $m=>$u){
  2859. $AVLFK=$AVL[0].'_R';
  2860. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2861. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2862. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2863. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2864. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2865. break;
  2866. }
  2867. }
  2868. }else{
  2869. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2870. $button=4;
  2871. $roleArrayCopy[$P][$MKI]['status']=4;
  2872. }
  2873. }
  2874. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2875. $KOP=true;
  2876. }
  2877. }
  2878. foreach ($roleArrayCopy as $k=>$v){
  2879. foreach ($verifyList as $m=>$n){
  2880. if ($n[0]==$k){
  2881. array_splice($verifyList,$m,1,$v);
  2882. }
  2883. }
  2884. }
  2885. $loanList[$key]['verifyList']=$verifyList;
  2886. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2887. }
  2888. $data['loanList']=$loanList;
  2889. $Locate=0;$roleId=0;$button=0;
  2890. foreach ($receiptList as $key=>$value){
  2891. $button2=0;
  2892. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2893. $receiptList[$key]['reviseDetail']=array();
  2894. if (!empty($value['reviseDetail']))
  2895. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2896. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2897. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2898. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2899. $receiptList[$key]['category']=$categoryDetil['title'];
  2900. $executeList=json_decode($value['executeCopy'],true);
  2901. $executeStaff=array();
  2902. if (!empty($value['executeStaff'] ))
  2903. $executeStaff=json_decode($value['executeStaff'],true);
  2904. if (isset($executeList)){
  2905. foreach ($executeList as $op=>$lo){
  2906. $executeList[$op]['date']="";
  2907. $executeList[$op]['opinion']="";
  2908. $executeList[$op]['status']="";
  2909. foreach ($executeStaff as $m=>$u){
  2910. if ($lo[0]==$m){
  2911. $executeList[$op]['date']=$u['date'];
  2912. $executeList[$op]['opinion']=$u['opinion'];
  2913. $executeList[$op]['status']=$u['status'];
  2914. break;
  2915. }
  2916. }
  2917. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2918. $button2=1;
  2919. $executeList[$op]['status']=4;
  2920. }
  2921. }
  2922. }
  2923. //检测编辑状态
  2924. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2925. $verifyList['staff']=$value['verifyBreakup'];
  2926. }else
  2927. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2928. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2929. $verifyStaff=json_decode($value['verifyStaff'],true);
  2930. Doo::loadModel('role');
  2931. $role=new role();
  2932. if ($verifyList==NULL)
  2933. $verifyList=array();
  2934. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2935. foreach ($verifyList as $k=>$v){
  2936. //init verifyStaff
  2937. if ($v[1]=='ROLE'){
  2938. if (!empty($verifyStaff)){
  2939. $endStaffArray=end($verifyStaff);
  2940. // if ($v[0]==$endStaffArray['nextStaff']){
  2941. // $roleId=$v[0];
  2942. // }
  2943. }
  2944. $roleVerify=json_decode($v[3],true);
  2945. $roleKey=$k;$roleArray=array();
  2946. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2947. foreach ($roleVerify as $o=>$p){
  2948. $staffID=explode ('_',$p);
  2949. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2950. //print_r($staffID);
  2951. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2952. array_push($roleArray, $exp);
  2953. }
  2954. $roleArrayCopy[$v[0]]=$roleArray;
  2955. //$verifyList[$k]['roleArray']=$roleArray;
  2956. }
  2957. $verifyList[$k]['date']="";
  2958. $verifyList[$k]['opinion']="";
  2959. $verifyList[$k]['status']="";
  2960. if (empty($verifyStaff)){
  2961. $verifyList[$k]['date']="";
  2962. $verifyList[$k]['opinion']="";
  2963. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2964. $verifyList[$k]['status']=4;
  2965. $flag=false;
  2966. }
  2967. }else{
  2968. foreach ($verifyStaff as $m=>$u){
  2969. if ($v[0]==$m){
  2970. $verifyList[$k]['date']=$u['date'];
  2971. $verifyList[$k]['opinion']=$u['opinion'];
  2972. $verifyList[$k]['status']=$u['status'];
  2973. $flag=false;
  2974. break;
  2975. }
  2976. }
  2977. $endStaffArray=end($verifyStaff);
  2978. if (isset($endStaffArray['ROLE'])){
  2979. }else{
  2980. // $endKey=key($verifyStaff);
  2981. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2982. // $button=4;
  2983. // $verifyList[$k]['status']=4;
  2984. // }
  2985. }
  2986. }
  2987. }
  2988. $rolename['name']='';
  2989. if (!empty($roleId)){
  2990. Doo::loadModel('role');
  2991. $role=new role();
  2992. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2993. }
  2994. if (!empty($verifyStaff))
  2995. $endStaffArray=end($verifyStaff);
  2996. $KOP=false;
  2997. foreach ($roleArrayCopy as $P=>$A){
  2998. foreach ( $A as $MKI=>$AVL){
  2999. if (!empty($verifyStaff)){
  3000. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3001. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3002. $button=4;
  3003. $roleArrayCopy[$P][$MKI]['status']=4;
  3004. }
  3005. foreach ($verifyStaff as $m=>$u){
  3006. $AVLFK=$AVL[0].'_R';
  3007. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3008. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3009. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3010. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3011. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3012. break;
  3013. }
  3014. }
  3015. }else{
  3016. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3017. $button=4;
  3018. $roleArrayCopy[$P][$MKI]['status']=4;
  3019. }
  3020. }
  3021. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3022. $KOP=true;
  3023. }
  3024. }
  3025. foreach ($roleArrayCopy as $k=>$v){
  3026. foreach ($verifyList as $m=>$n){
  3027. if ($n[0]==$k){
  3028. array_splice($verifyList,$m,1,$v);
  3029. }
  3030. }
  3031. }
  3032. $receiptList[$key]['verifyList']=$verifyList;
  3033. $receiptList[$key]['executeList']=$executeList;
  3034. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3035. $receiptList[$key]['button2']=$button2;
  3036. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3037. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3038. $relust=$value['sum']-$value['loanSum'];
  3039. $receiptList[$key]['relust']=$relust;
  3040. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3041. }
  3042. //print_r($receiptList[$key]['executeList']);
  3043. $data['receiptList']=$receiptList;
  3044. $data['memu']="receipt";
  3045. $data['staff']=$this->staff;
  3046. $data['receiptMemu']='implement';
  3047. $data['verifyId']=$this->verifyId;
  3048. $data['executeId']=$this->executeId;
  3049. $this->render ( "/admin/implement", $data );
  3050. }
  3051. function implementDo(){
  3052. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3053. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  3054. if (!empty($rid)){
  3055. Doo::loadModel('receipt');
  3056. $receipt=new receipt();
  3057. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  3058. $executeCopy=json_decode($rinfo['executeCopy'],true);
  3059. $executeStaff=json_decode($rinfo['executeStaff'],true);
  3060. if(empty($executeStaff)){
  3061. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3062. }else{
  3063. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3064. }
  3065. if (count($executeStaff)==count($executeCopy)){
  3066. $receipt->executeStaff=json_encode($executeStaff);
  3067. $receipt->status=8;
  3068. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3069. $receipt->status=9;
  3070. $receipt->executeDate= date("Y-m-d");
  3071. }else{
  3072. $receipt->executeStaff=json_encode($executeStaff);
  3073. }
  3074. $receipt->update(array('where'=>'rid='.$rid));
  3075. }
  3076. return "/implement";
  3077. }
  3078. function receiptburEdi(){
  3079. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3080. $status=isset($this->params['status'])?$this->params['status']:'';
  3081. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3082. $month=$this->get_args('month')?$this->get_args('month'):"";
  3083. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3084. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3085. if (empty($status))
  3086. $status=$this->get_args('status')?$this->get_args('status'):2;
  3087. $vidList=array();
  3088. $button=0;
  3089. Doo::loadModel('verify');
  3090. Doo::loadModel('receipt');
  3091. Doo::loadModel('staff');
  3092. $staff=new staff();
  3093. $receipt=new receipt();
  3094. $verify=new verify();
  3095. Doo::loadModel('L_category');
  3096. $Lcategory=new L_category();
  3097. Doo::loadModel('enclosur');
  3098. $enclosur=new enclosur();
  3099. Doo::loadModel('loanReceipt');
  3100. $loanReceipt=new loanReceipt();
  3101. //user verify ID
  3102. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3103. foreach ($verifyDetail as $key=>$value){
  3104. array_push($vidList, $value['vid']);
  3105. }
  3106. $vid=implode(",", $vidList);
  3107. if(empty($verifyDetail))
  3108. $vid=0;
  3109. $categoryList=$Lcategory->find(array('asArray'=>true));
  3110. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3111. $ap="";
  3112. if($status==4){
  3113. $ap=4;$status=2;
  3114. }
  3115. //get Receipt By verifyID status 2
  3116. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3117. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3118. $Locate=0;$roleId=0;$button=0;
  3119. foreach ($loanList as $key=>$value){
  3120. $loanList[$key]['Locate']=$Locate;$Locate++;
  3121. $loanList[$key]['reviseDetail']=array();
  3122. if (!empty($value['reviseDetail']))
  3123. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3124. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3125. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3126. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3127. $loanList[$key]['category']=$categoryDetil['title'];
  3128. //检测编辑状态
  3129. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3130. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3131. $verifyStaff=json_decode($value['verifyStaff'],true);
  3132. Doo::loadModel('role');
  3133. $role=new role();
  3134. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3135. foreach ($verifyList as $k=>$v){
  3136. //init verifyStaff
  3137. if ($v[1]=='ROLE'){
  3138. if (!empty($verifyStaff)){
  3139. $endStaffArray=end($verifyStaff);
  3140. }
  3141. $roleVerify=json_decode($v[3],true);
  3142. $roleKey=$k;$roleArray=array();
  3143. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3144. foreach ($roleVerify as $o=>$p){
  3145. $staffID=explode ('_',$p);
  3146. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3147. //print_r($staffID);
  3148. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3149. array_push($roleArray, $exp);
  3150. }
  3151. $roleArrayCopy[$v[0]]=$roleArray;
  3152. //$verifyList[$k]['roleArray']=$roleArray;
  3153. }
  3154. $verifyList[$k]['date']="";
  3155. $verifyList[$k]['opinion']="";
  3156. $verifyList[$k]['status']="";
  3157. if (empty($verifyStaff)){
  3158. $verifyList[$k]['date']="";
  3159. $verifyList[$k]['opinion']="";
  3160. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3161. $verifyList[$k]['status']=4;
  3162. $flag=false;
  3163. }
  3164. }else{
  3165. foreach ($verifyStaff as $m=>$u){
  3166. if ($v[0]==$m){
  3167. $verifyList[$k]['date']=$u['date'];
  3168. $verifyList[$k]['opinion']=$u['opinion'];
  3169. $verifyList[$k]['status']=$u['status'];
  3170. $flag=false;
  3171. break;
  3172. }
  3173. }
  3174. $endStaffArray=end($verifyStaff);
  3175. if (isset($endStaffArray['ROLE'])){
  3176. }else{
  3177. }
  3178. }
  3179. }
  3180. $rolename['name']='';
  3181. if (!empty($roleId)){
  3182. Doo::loadModel('role');
  3183. $role=new role();
  3184. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3185. }
  3186. if (!empty($verifyStaff))
  3187. $endStaffArray=end($verifyStaff);
  3188. $KOP=false;
  3189. foreach ($roleArrayCopy as $P=>$A){
  3190. foreach ( $A as $MKI=>$AVL){
  3191. if (!empty($verifyStaff)){
  3192. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3193. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3194. $button=4;
  3195. $roleArrayCopy[$P][$MKI]['status']=4;
  3196. }
  3197. foreach ($verifyStaff as $m=>$u){
  3198. $AVLFK=$AVL[0].'_R';
  3199. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3200. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3201. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3202. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3203. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3204. break;
  3205. }
  3206. }
  3207. }else{
  3208. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3209. $button=4;
  3210. $roleArrayCopy[$P][$MKI]['status']=4;
  3211. }
  3212. }
  3213. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3214. $KOP=true;
  3215. }
  3216. }
  3217. foreach ($roleArrayCopy as $k=>$v){
  3218. foreach ($verifyList as $m=>$n){
  3219. if ($n[0]==$k){
  3220. array_splice($verifyList,$m,1,$v);
  3221. }
  3222. }
  3223. }
  3224. $loanList[$key]['verifyList']=$verifyList;
  3225. }
  3226. $htmlLoan='';
  3227. if (isset($loanList[0])){
  3228. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3229. if ($value['status']==1)
  3230. $htmlLoan.='<li class="done" >';
  3231. elseif ($value['status']==3)
  3232. $htmlLoan.='<li class="undone" >';
  3233. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3234. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3235. if (isset($value['rolename']))
  3236. $htmlLoan.=$value['rolename'];
  3237. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3238. }
  3239. $data['loanDate']=$loanList[0]['date'];
  3240. }
  3241. $data['htmlLoan']=$htmlLoan;
  3242. //print_r($loanList);
  3243. $Locate=0;$roleId=0;$button=0;
  3244. if($ap==4)
  3245. $status=4;
  3246. foreach ($receiptList as $key=>$value){
  3247. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3248. $receiptList[$key]['reviseDetail']=array();
  3249. if (!empty($value['reviseDetail']))
  3250. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3251. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3252. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3253. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3254. $receiptList[$key]['category']=$categoryDetil['title'];
  3255. //检测编辑状态
  3256. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3257. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3258. $verifyStaff=json_decode($value['verifyStaff'],true);
  3259. Doo::loadModel('role');
  3260. $role=new role();
  3261. //print_r($verifyList);
  3262. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3263. foreach ($verifyList as $k=>$v){
  3264. //init verifyStaff
  3265. if ($v[1]=='ROLE'){
  3266. if (!empty($verifyStaff)){
  3267. $endStaffArray=end($verifyStaff);
  3268. if ($v[0]==$endStaffArray['nextStaff']){
  3269. $roleId=$v[0];
  3270. }
  3271. }
  3272. $roleVerify=json_decode($v[3],true);
  3273. $roleKey=$k;$roleArray=array();
  3274. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3275. foreach ($roleVerify as $o=>$p){
  3276. $staffID=explode ('_',$p);
  3277. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3278. //print_r($staffID);
  3279. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3280. array_push($roleArray, $exp);
  3281. }
  3282. $roleArrayCopy[$v[0]]=$roleArray;
  3283. //$verifyList[$k]['roleArray']=$roleArray;
  3284. }
  3285. //print_r($roleArray);
  3286. $verifyList[$k]['date']="";
  3287. $verifyList[$k]['opinion']="";
  3288. $verifyList[$k]['status']="";
  3289. if (empty($verifyStaff)){
  3290. $verifyList[$k]['date']="";
  3291. $verifyList[$k]['opinion']="";
  3292. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3293. $verifyList[$k]['status']=4;
  3294. $button=4;$flag=false;
  3295. }
  3296. }else{
  3297. foreach ($verifyStaff as $m=>$u){
  3298. if ($v[0]==$m){
  3299. $verifyList[$k]['date']=$u['date'];
  3300. $verifyList[$k]['opinion']=$u['opinion'];
  3301. $verifyList[$k]['status']=$u['status'];
  3302. $flag=false;
  3303. break;
  3304. }
  3305. }
  3306. $endStaffArray=end($verifyStaff);
  3307. if (isset($endStaffArray['ROLE'])){
  3308. }else{
  3309. $endKey=key($verifyStaff);
  3310. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3311. $button=4;
  3312. $verifyList[$k]['status']=4;
  3313. }
  3314. }
  3315. }
  3316. }
  3317. $rolename['name']='';
  3318. if (!empty($roleId)){
  3319. Doo::loadModel('role');
  3320. $role=new role();
  3321. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3322. }
  3323. if (!empty($verifyStaff))
  3324. $endStaffArray=end($verifyStaff);
  3325. $KOP=false;
  3326. foreach ($roleArrayCopy as $P=>$A){
  3327. foreach ( $A as $MKI=>$AVL){
  3328. if (!empty($verifyStaff)){
  3329. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3330. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3331. $button=4;
  3332. $roleArrayCopy[$P][$MKI]['status']=4;
  3333. }
  3334. foreach ($verifyStaff as $m=>$u){
  3335. $AVLFK=$AVL[0].'_R';
  3336. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3337. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3338. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3339. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3340. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3341. break;
  3342. }
  3343. }
  3344. }else{
  3345. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3346. $button=4;
  3347. $roleArrayCopy[$P][$MKI]['status']=4;
  3348. }
  3349. }
  3350. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3351. $KOP=true;
  3352. }
  3353. }
  3354. foreach ($roleArrayCopy as $k=>$v){
  3355. foreach ($verifyList as $m=>$n){
  3356. if ($n[0]==$k){
  3357. array_splice($verifyList,$m,1,$v);
  3358. }
  3359. }
  3360. }
  3361. //print_r($verifyList);
  3362. $receiptList[$key]['verifyList']=$verifyList;
  3363. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3364. $receiptList[$key]['button']=$button;
  3365. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3366. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3367. $relust=$value['sum']-$value['loanSum'];
  3368. $receiptList[$key]['relust']=$relust;
  3369. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3370. }
  3371. //print_r($receiptList);die;
  3372. //$data['verifyDetail']=$verifyDetail;
  3373. $mothHtml="";
  3374. for($i=1;$i<=12;$i++){
  3375. if($month==$i)
  3376. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3377. else
  3378. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3379. }
  3380. //获取审批日志
  3381. Doo::loadModel('receiptLog');
  3382. $receiptLog=new receiptLog();
  3383. $rlList=array();
  3384. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3385. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3386. if (!empty($rlInfo)){
  3387. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3388. }
  3389. //echo $rid;
  3390. //print_r($receiptList);
  3391. $receiptList[0]['rlList']=$rlList;
  3392. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3393. $enclosurHtml='';
  3394. foreach ($enclosurList as $value){
  3395. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3396. }
  3397. $data['enclosurHtml']=$enclosurHtml;
  3398. $data['rolename']=$rolename['name'];
  3399. // $data['datetij']=$tijdate['date'];
  3400. $data['mothHtml']=$mothHtml;
  3401. //print_r($receiptList);
  3402. $data['rid']=$rid;
  3403. $data['tijdate']=$tijdate['date'];
  3404. $data['receiptList']=$receiptList;
  3405. $data['receiptApprovalCount']=count($receiptList);
  3406. $data['status']=$status;
  3407. $data['year']=$year;
  3408. $data['categoryList']=$categoryList;
  3409. $data['staffList']=$staffList;
  3410. $data['cid']=$cid;
  3411. $data['sid']=$sid;
  3412. $data['ap']=$ap;
  3413. $data['memu']="receipt";
  3414. $data['staff']=$this->staff;
  3415. $data['receiptMemu']='approvalExpenses';
  3416. $data['verifyId']=$this->verifyId;
  3417. $data['executeId']=$this->executeId;
  3418. $this->render ( "/admin/receiptburEdi", $data );
  3419. }
  3420. function hisImplement(){
  3421. $item=isset($this->params['item'])?$this->params['item']:"";
  3422. if(empty($item))
  3423. $item=$this->get_args('item')?$this->get_args('item'):"";
  3424. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3425. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3426. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3427. $sop=$this->get_args('sop')?$this->get_args('sop'):'SOP';
  3428. Doo::loadModel('receipt');
  3429. $receipt=new receipt();
  3430. Doo::loadModel('L_category');
  3431. $Lcategory=new L_category();
  3432. Doo::loadModel('verify');
  3433. Doo::loadModel('statistics');
  3434. $statistics=new statistics();
  3435. $verify=new verify();
  3436. Doo::loadModel('staff');
  3437. $staff=new staff();
  3438. $condition="";
  3439. if($item=="expenses")
  3440. $condition=" and Rtype=1 ";
  3441. elseif ($item=="receipts")
  3442. $condition=" and Rtype=0 ";
  3443. elseif ($item=="remits")
  3444. $condition=" and Rtype=2 ";
  3445. $sopString="";
  3446. $dateCondition=" and Year(executeDate) =".$year;
  3447. if($moth!='MONTH'){
  3448. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3449. }
  3450. if($day!='DAY')
  3451. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3452. if ($sop!='SOP')
  3453. $sopString=" and staff=".$sop;
  3454. //$noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3455. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition.$sopString,'desc'=>'rid','asArray'=>true));
  3456. //员工筛选
  3457. $receiptList2=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3458. $sopStaff=array();
  3459. foreach ($receiptList2 as $key=>$value){
  3460. $staffDetail=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3461. $sopStaff[$value['staff']]=$staffDetail['username'];
  3462. }
  3463. $Locate=0;$roleId=0;$button=0;
  3464. foreach ($receiptList as $key=>$value){
  3465. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3466. $receiptList[$key]['reviseDetail']=array();
  3467. if (!empty($value['reviseDetail']))
  3468. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3469. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3470. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3471. $receiptList[$key]['category']=$categoryDetil['title'];
  3472. //检测编辑状态
  3473. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3474. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3475. $verifyStaff=json_decode($value['verifyStaff'],true);
  3476. Doo::loadModel('role');
  3477. $role=new role();
  3478. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3479. foreach ($verifyList as $k=>$v){
  3480. //init verifyStaff
  3481. if ($v[1]=='ROLE'){
  3482. if (!empty($verifyStaff)){
  3483. $endStaffArray=end($verifyStaff);
  3484. }
  3485. $roleVerify=json_decode($v[3],true);
  3486. $roleKey=$k;$roleArray=array();
  3487. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3488. foreach ($roleVerify as $o=>$p){
  3489. $staffID=explode ('_',$p);
  3490. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3491. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3492. array_push($roleArray, $exp);
  3493. }
  3494. $roleArrayCopy[$v[0]]=$roleArray;
  3495. }
  3496. $verifyList[$k]['date']="";
  3497. $verifyList[$k]['opinion']="";
  3498. $verifyList[$k]['status']="";
  3499. if (empty($verifyStaff)){
  3500. $verifyList[$k]['date']="";
  3501. $verifyList[$k]['opinion']="";
  3502. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3503. $verifyList[$k]['status']=4;
  3504. $flag=false;
  3505. }
  3506. }else{
  3507. foreach ($verifyStaff as $m=>$u){
  3508. if ($v[0]==$m){
  3509. $verifyList[$k]['date']=$u['date'];
  3510. $verifyList[$k]['opinion']=$u['opinion'];
  3511. $verifyList[$k]['status']=$u['status'];
  3512. $flag=false;
  3513. break;
  3514. }
  3515. }
  3516. $endStaffArray=end($verifyStaff);
  3517. }
  3518. }
  3519. $rolename['name']='';
  3520. if (!empty($roleId)){
  3521. Doo::loadModel('role');
  3522. $role=new role();
  3523. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3524. }
  3525. if (!empty($verifyStaff))
  3526. $endStaffArray=end($verifyStaff);
  3527. $KOP=false;
  3528. foreach ($roleArrayCopy as $P=>$A){
  3529. foreach ( $A as $MKI=>$AVL){
  3530. if (!empty($verifyStaff)){
  3531. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3532. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3533. $button=4;
  3534. $roleArrayCopy[$P][$MKI]['status']=4;
  3535. }
  3536. foreach ($verifyStaff as $m=>$u){
  3537. $AVLFK=$AVL[0].'_R';
  3538. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3539. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3540. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3541. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3542. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3543. break;
  3544. }
  3545. }
  3546. }else{
  3547. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3548. $button=4;
  3549. $roleArrayCopy[$P][$MKI]['status']=4;
  3550. }
  3551. }
  3552. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3553. $KOP=true;
  3554. }
  3555. }
  3556. foreach ($roleArrayCopy as $k=>$v){
  3557. foreach ($verifyList as $m=>$n){
  3558. if ($n[0]==$k){
  3559. array_splice($verifyList,$m,1,$v);
  3560. }
  3561. }
  3562. }
  3563. $receiptList[$key]['verifyList']=$verifyList;
  3564. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3565. $receiptList[$key]['button']=$button;
  3566. }
  3567. //print_r($sopStaff);
  3568. $mothHtml="";
  3569. for($i=1;$i<=12;$i++){
  3570. if($moth==$i)
  3571. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3572. else
  3573. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3574. }
  3575. $dayHtml="";
  3576. if ($day!="DAY"||$moth!="MONTH"){
  3577. for($i = 1; $i <= 31; $i ++) {
  3578. if($day==$i)
  3579. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3580. else
  3581. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3582. }
  3583. }
  3584. $sopHtml="";
  3585. foreach ($sopStaff as $key=>$value){
  3586. if($sop==$key)
  3587. $sopHtml.='<option value="'.$key.'" selected >'.$value.'</option>';
  3588. else
  3589. $sopHtml.='<option value="'.$key.'" >'.$value.'</option>';
  3590. }
  3591. $data['sopHtml']=$sopHtml;
  3592. $data['dayHtml']=$dayHtml;
  3593. $data['mothHtml']=$mothHtml;
  3594. $data['receiptList']=$receiptList;
  3595. $data['memu']="receipt";
  3596. $data['staff']=$this->staff;
  3597. $data['receiptMemu']='implement';
  3598. $data['verifyId']=$this->verifyId;
  3599. $data['executeId']=$this->executeId;
  3600. $data['item']=$item;
  3601. $data['year']=$year;
  3602. $data['moth']=$moth;
  3603. $data['day']=$day;
  3604. $data['sop']=$sop;
  3605. $this->render ( "/admin/hisImplement", $data );
  3606. }
  3607. function ajaxExamine(){
  3608. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3609. Doo::loadModel('receipt');
  3610. $receipt=new receipt();
  3611. if (!empty($rid)){
  3612. $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
  3613. ,'asArray'=>true));
  3614. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3615. }
  3616. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3617. }
  3618. /*
  3619. * 废弃
  3620. */
  3621. function myReceipt(){
  3622. //all approval past withdraw
  3623. $item=isset($this->params['item'])?$this->params['item']:"";
  3624. if(empty($item))
  3625. $item=$this->get_args('item')?$this->get_args('item'):"";
  3626. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3627. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3628. Doo::loadModel('receipt');
  3629. $receipt=new receipt();
  3630. //pre-loaded
  3631. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3632. //have cache
  3633. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3634. if(!empty($moth))//yearPage
  3635. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3636. $this->showCache($path);
  3637. }
  3638. Doo::loadModel('L_category');
  3639. $Lcategory=new L_category();
  3640. Doo::loadModel('verify');
  3641. Doo::loadModel('statistics');
  3642. $statistics=new statistics();
  3643. $verify=new verify();
  3644. Doo::loadModel('staff');
  3645. $staff=new staff();
  3646. $condition=" and status!=0 ";
  3647. if($item=="approval")
  3648. $condition=" and status=2 ";
  3649. elseif ($item=="withdraw")
  3650. $condition=" and status=3 ";
  3651. elseif ($item=="past")
  3652. $condition=" and status=1 ";
  3653. elseif ($item=="whdw")
  3654. $condition=" and status=4 ";
  3655. $dateCondition=" and Year(date) =".$year;
  3656. if(!empty($moth)){
  3657. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3658. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3659. }else
  3660. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3661. if(empty($stList))
  3662. $stList=array('rePrice'=>0,'agPrice'=>0);
  3663. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3664. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3665. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3666. $Locate=0;$roleId=0;$button=0;
  3667. foreach ($receiptList as $key=>$value){
  3668. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3669. $receiptList[$key]['reviseDetail']=array();
  3670. if (!empty($value['reviseDetail']))
  3671. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3672. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3673. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3674. $receiptList[$key]['category']=$categoryDetil['title'];
  3675. //检测编辑状态
  3676. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3677. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3678. $verifyStaff=json_decode($value['verifyStaff'],true);
  3679. Doo::loadModel('role');
  3680. $role=new role();
  3681. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3682. foreach ($verifyList as $k=>$v){
  3683. //init verifyStaff
  3684. if ($v[1]=='ROLE'){
  3685. if (!empty($verifyStaff)){
  3686. $endStaffArray=end($verifyStaff);
  3687. // if ($v[0]==$endStaffArray['nextStaff']){
  3688. // $roleId=$v[0];
  3689. // }
  3690. }
  3691. $roleVerify=json_decode($v[3],true);
  3692. $roleKey=$k;$roleArray=array();
  3693. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3694. foreach ($roleVerify as $o=>$p){
  3695. $staffID=explode ('_',$p);
  3696. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3697. //print_r($staffID);
  3698. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3699. array_push($roleArray, $exp);
  3700. }
  3701. $roleArrayCopy[$v[0]]=$roleArray;
  3702. //$verifyList[$k]['roleArray']=$roleArray;
  3703. }
  3704. $verifyList[$k]['date']="";
  3705. $verifyList[$k]['opinion']="";
  3706. $verifyList[$k]['status']="";
  3707. if (empty($verifyStaff)){
  3708. $verifyList[$k]['date']="";
  3709. $verifyList[$k]['opinion']="";
  3710. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3711. $verifyList[$k]['status']=4;
  3712. $flag=false;
  3713. }
  3714. }else{
  3715. foreach ($verifyStaff as $m=>$u){
  3716. if ($v[0]==$m){
  3717. $verifyList[$k]['date']=$u['date'];
  3718. $verifyList[$k]['opinion']=$u['opinion'];
  3719. $verifyList[$k]['status']=$u['status'];
  3720. $flag=false;
  3721. break;
  3722. }
  3723. }
  3724. $endStaffArray=end($verifyStaff);
  3725. if (isset($endStaffArray['ROLE'])){
  3726. }else{
  3727. // $endKey=key($verifyStaff);
  3728. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3729. // $button=4;
  3730. // $verifyList[$k]['status']=4;
  3731. // }
  3732. }
  3733. }
  3734. }
  3735. $rolename['name']='';
  3736. if (!empty($roleId)){
  3737. Doo::loadModel('role');
  3738. $role=new role();
  3739. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3740. }
  3741. if (!empty($verifyStaff))
  3742. $endStaffArray=end($verifyStaff);
  3743. $KOP=false;
  3744. foreach ($roleArrayCopy as $P=>$A){
  3745. foreach ( $A as $MKI=>$AVL){
  3746. if (!empty($verifyStaff)){
  3747. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3748. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3749. $button=4;
  3750. $roleArrayCopy[$P][$MKI]['status']=4;
  3751. }
  3752. foreach ($verifyStaff as $m=>$u){
  3753. $AVLFK=$AVL[0].'_R';
  3754. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3755. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3756. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3757. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3758. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3759. break;
  3760. }
  3761. }
  3762. }else{
  3763. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3764. $button=4;
  3765. $roleArrayCopy[$P][$MKI]['status']=4;
  3766. }
  3767. }
  3768. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3769. $KOP=true;
  3770. }
  3771. }
  3772. foreach ($roleArrayCopy as $k=>$v){
  3773. foreach ($verifyList as $m=>$n){
  3774. if ($n[0]==$k){
  3775. array_splice($verifyList,$m,1,$v);
  3776. }
  3777. }
  3778. }
  3779. $receiptList[$key]['verifyList']=$verifyList;
  3780. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3781. $receiptList[$key]['button']=$button;
  3782. }
  3783. //print_r($receiptList);die;
  3784. $mothHtml="";
  3785. for($i=1;$i<=12;$i++){
  3786. if($moth==$i)
  3787. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3788. else
  3789. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3790. }
  3791. $data['mothHtml']=$mothHtml;
  3792. $data['receiptList']=$receiptList;
  3793. $data['memu']="receipt";
  3794. $data['staff']=$this->staff;
  3795. $data['receiptMemu']='receipt';
  3796. $data['verifyId']=$this->verifyId;
  3797. $data['executeId']=$this->executeId;
  3798. $data['item']=$item;
  3799. $data['year']=$year;
  3800. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3801. //sufficient condition to generate cache
  3802. if(empty($moth)&&($year<date("Y"))){
  3803. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3804. if(empty($receiptList)){ //generated files
  3805. ob_start();
  3806. $this->render ( "/admin/saea_myList", $data );
  3807. $this->cacheFile($path);die;
  3808. // $content = ob_get_contents();
  3809. // $fp = fopen($path, "w");
  3810. // fwrite($fp, $content);
  3811. // fclose($fp);
  3812. }
  3813. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3814. $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));
  3815. if(empty($receiptList)){ //generated files
  3816. ob_start();
  3817. $this->render ( "/admin/saea_myList", $data );
  3818. $this->cacheFile($path);die;
  3819. }
  3820. }
  3821. }
  3822. $this->render ( "/admin/saea_myList", $data );
  3823. }
  3824. function saeaCreate(){
  3825. Doo::loadModel('accountItem');
  3826. Doo::loadModel('verify');
  3827. Doo::loadModel('receipt');
  3828. Doo::loadModel('L_category');
  3829. $lCategory=new L_category();
  3830. $receipt=new receipt();
  3831. $verify=new verify();
  3832. $accountItem=new accountItem();
  3833. Doo::loadModel("role");
  3834. $role=new role();
  3835. $acItem=$accountItem->find(array('asArray'=>true));
  3836. $veList=$verify->find(array('asArray'=>true));
  3837. foreach ($veList as $key=>$value){
  3838. $v=json_decode($value['staff']);
  3839. $list=array();
  3840. foreach ($v as $n=>$m){
  3841. if ($m['1']=='ROLE'){
  3842. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3843. $v[$n][1]=$roleInfo['name'];
  3844. array_push($list, $roleInfo['name']);
  3845. }else{
  3846. array_push($list, $v[$n][1]);
  3847. }
  3848. }
  3849. $veList[$key]['staff']=implode('>', $list);
  3850. }
  3851. $data['category']=$lCategory->find(array('asArray'=>true));
  3852. $data['veList']=$veList;
  3853. $data['acItem']=$acItem;
  3854. $data['memu']="receipt";
  3855. $data['staff']=$this->staff;
  3856. $data['receiptMemu']='saeaBorad';
  3857. $data['verifyId']=$this->verifyId;
  3858. $data['executeId']=$this->executeId;
  3859. $this->render ( "/admin/saea_create", $data );
  3860. }
  3861. function addReceipt(){
  3862. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3863. $agency=$this->get_args('agency');
  3864. $travel=$this->get_args('travel');
  3865. $train=$this->get_args('train');
  3866. $other=$this->get_args('other');
  3867. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3868. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3869. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3870. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3871. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3872. Doo::loadModel('receipt');
  3873. Doo::loadModel('receiptDetail');
  3874. Doo::loadModel('accountItem');
  3875. $accountItem=new accountItem();
  3876. $receipt=new receipt();
  3877. Doo::loadModel('enclosur');
  3878. Doo::loadModel('execute');
  3879. $execute=new execute();
  3880. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3881. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3882. // if(!empty($receiptDetail))
  3883. // return "/referReceipt/".$receiptDetail['rid'];
  3884. $aItem=$accountItem->find(array('asArray'=>true));
  3885. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3886. $ag=$tr=$ta=$ot=0;
  3887. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3888. foreach ($aItem as $key=>$value){
  3889. if ($value['category']==$this->AGENCY){
  3890. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3891. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3892. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3893. }
  3894. $ag++;
  3895. }
  3896. if($value['category']==$this->TRAVEL){
  3897. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3898. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3899. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3900. }
  3901. $tr++;
  3902. }
  3903. if($value['category']==$this->TRAIN){
  3904. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3905. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3906. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3907. }
  3908. $ta++;
  3909. }
  3910. if($value['category']==$this->OTHER){
  3911. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3912. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3913. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3914. }
  3915. $ot++;
  3916. }
  3917. }
  3918. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3919. //报销单
  3920. $receipt->accountItem=json_encode($accountJson);
  3921. $receipt->staff=$this->staff[0]['sid'];
  3922. $receipt->sum=number_format($sum, 2, '.', '');
  3923. $receipt->date=date("Y-m-d");
  3924. $receipt->cid=$cid;
  3925. $receipt->status=5;
  3926. //修改审批流程加入角色
  3927. $receipt->verify=$verify;
  3928. $receipt->executeCopy=$executeDetail['staff'];
  3929. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3930. $receipt->explanation=$explanation;
  3931. $rid=$receipt->insert();
  3932. //附件
  3933. if (!empty($enclosurName)){
  3934. $enclosurArray=explode('-', $enclosurName);
  3935. foreach ($enclosurArray as $value){
  3936. $enclosur=new enclosur();
  3937. $enclosur->name=$value;
  3938. $enclosur->rid=$rid;
  3939. $enclosur->insert();
  3940. }
  3941. //print_r($enclosurArray);die;
  3942. }
  3943. //报销详情
  3944. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3945. $receiptDetail=new receiptDetail();
  3946. $receiptDetail->staff=$this->staff[0]['sid'];
  3947. $receiptDetail->item=$value['name'];
  3948. $receiptDetail->itemCategory=$this->AGENCY;
  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->TRAVEL] as $key=>$value){
  3957. $receiptDetail=new receiptDetail();
  3958. $receiptDetail->staff=$this->staff[0]['sid'];
  3959. $receiptDetail->item=$value['name'];
  3960. $receiptDetail->itemCategory=$this->TRAVEL;
  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->TRAIN] as $key=>$value){
  3969. $receiptDetail=new receiptDetail();
  3970. $receiptDetail->staff=$this->staff[0]['sid'];
  3971. $receiptDetail->item=$value['name'];
  3972. $receiptDetail->itemCategory=$this->TRAIN;
  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. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3981. $receiptDetail=new receiptDetail();
  3982. $receiptDetail->staff=$this->staff[0]['sid'];
  3983. $receiptDetail->item=$value['name'];
  3984. $receiptDetail->itemCategory=$this->OTHER;
  3985. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3986. $receiptDetail->date=date("Y-m-d");
  3987. $receiptDetail->cid=$cid;
  3988. $receiptDetail->rid=$rid;
  3989. $receiptDetail->status=4;
  3990. $receiptDetail->insert();
  3991. }
  3992. //return "/referReceipt/".$rid;
  3993. }
  3994. return "/saeaBorad";
  3995. }
  3996. function referReceipt(){
  3997. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3998. Doo::loadModel('receipt');
  3999. Doo::loadModel('verify');
  4000. $verify=new verify();
  4001. $receipt=new receipt();
  4002. Doo::loadModel('L_category');
  4003. $lCategory=new L_category();
  4004. Doo::loadModel("role");
  4005. $role=new role();
  4006. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  4007. if(empty($receiptDetail))
  4008. return "/addReceipt";
  4009. foreach ($receiptDetail as $key=>$value){
  4010. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  4011. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4012. $v=json_decode($veList['staff']);
  4013. array_push($v[0], $veList['description']);
  4014. foreach ($v as $n=>$m){
  4015. if ($m['1']=='ROLE'){
  4016. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4017. $v[$n][1]=$roleInfo['name'];
  4018. }
  4019. }
  4020. $receiptDetail[$key]['staff']=$v;
  4021. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4022. $receiptDetail[$key]['category']=$category['title'];
  4023. }
  4024. //print_r($receiptDetail);
  4025. $data['receiptDetail']=$receiptDetail;
  4026. $data['memu']="receipt";
  4027. $data['staff']=$this->staff;
  4028. $data['receiptMemu']='saeaCreate';
  4029. $data['verifyId']=$this->verifyId;
  4030. $data['executeId']=$this->executeId;
  4031. $this->render ( "/admin/saea_confirm", $data );
  4032. }
  4033. function editReceipt(){
  4034. //edit status 4
  4035. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4036. //echo $rid;
  4037. Doo::loadModel('accountItem');
  4038. Doo::loadModel('verify');
  4039. Doo::loadModel('receipt');
  4040. $receipt=new receipt();
  4041. $verify=new verify();
  4042. $accountItem=new accountItem();
  4043. Doo::loadModel('L_category');
  4044. $lCategory=new L_category();
  4045. Doo::loadModel("role");
  4046. $role=new role();
  4047. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  4048. if(empty($receiptDetail))
  4049. return "/saeaCreate";
  4050. $acItem=$accountItem->find(array('asArray'=>true));
  4051. $veList=$verify->find(array('asArray'=>true));
  4052. foreach ($veList as $key=>$value){
  4053. $v=json_decode($value['staff']);
  4054. $list=array();
  4055. foreach ($v as $n=>$m){
  4056. if ($m['1']=='ROLE'){
  4057. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4058. $v[$n][1]=$roleInfo['name'];
  4059. array_push($list, $roleInfo['name']);
  4060. }else{
  4061. array_push($list, $v[$n][1]);
  4062. }
  4063. }
  4064. $veList[$key]['staff']=implode('>', $list);
  4065. }
  4066. //配置编辑信息
  4067. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4068. foreach ($acItem as $key=>$value){
  4069. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4070. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4071. $acItem[$key]['price']=$v['price'];
  4072. }
  4073. }
  4074. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4075. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4076. $acItem[$key]['price']=$v['price'];
  4077. }
  4078. }
  4079. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4080. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4081. $acItem[$key]['price']=$v['price'];
  4082. }
  4083. }
  4084. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4085. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4086. $acItem[$key]['price']=$v['price'];
  4087. }
  4088. }
  4089. }
  4090. $data['category']=$lCategory->find(array('asArray'=>true));
  4091. $data['cSum']=$accountItemList['cSum'];
  4092. $data['sum']=$receiptDetail['sum'];
  4093. $data['receiptDetail']=$receiptDetail;
  4094. $data['veList']=$veList;
  4095. $data['acItem']=$acItem;
  4096. $data['memu']="receipt";
  4097. $data['staff']=$this->staff;
  4098. $data['receiptMemu']='saeaBorad';
  4099. $data['verify']=$receiptDetail['verify'];
  4100. $data['verifyId']=$this->verifyId;
  4101. $data['executeId']=$this->executeId;
  4102. $data['rid']=$rid;
  4103. $this->render ( "/admin/saea_edit", $data );
  4104. }
  4105. function updateReceipt(){
  4106. $agency=$this->get_args('agency');
  4107. $travel=$this->get_args('travel');
  4108. $train=$this->get_args('train');
  4109. $other=$this->get_args('other');
  4110. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4111. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4112. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4113. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4114. if(!empty($explanation)){
  4115. Doo::loadModel('receipt');
  4116. Doo::loadModel('receiptDetail');
  4117. Doo::loadModel('accountItem');
  4118. $accountItem=new accountItem();
  4119. $receipt=new receipt();
  4120. Doo::loadModel('execute');
  4121. $execute=new execute();
  4122. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4123. if(empty($receiptDetail))
  4124. return "/saeaBorad";
  4125. if ($receiptDetail['Rtype']==1)
  4126. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4127. else
  4128. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4129. $aItem=$accountItem->find(array('asArray'=>true));
  4130. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4131. $ag=$tr=$ta=$ot=0;
  4132. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4133. foreach ($aItem as $key=>$value){
  4134. if ($value['category']==$this->AGENCY){
  4135. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4136. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4137. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4138. }
  4139. $ag++;
  4140. }
  4141. if($value['category']==$this->TRAVEL){
  4142. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4143. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4144. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4145. }
  4146. $tr++;
  4147. }
  4148. if($value['category']==$this->TRAIN){
  4149. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4150. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4151. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4152. }
  4153. $ta++;
  4154. }
  4155. if($value['category']==$this->OTHER){
  4156. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4157. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4158. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4159. }
  4160. $ot++;
  4161. }
  4162. }
  4163. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4164. //报销单
  4165. $rid=$receipt->rid=$receiptDetail['rid'];
  4166. $receipt->accountItem=json_encode($accountJson);
  4167. $receipt->staff=$this->staff[0]['sid'];
  4168. $receipt->sum=number_format($sum, 2, '.', '');
  4169. $receipt->date=date("Y-m-d");
  4170. $receipt->cid=$cid;
  4171. if (($receiptDetail['status']!=4)){
  4172. if ($receiptDetail['Rtype']==1)
  4173. $receipt->status=7;
  4174. else
  4175. $receipt->status=5;
  4176. }
  4177. if ($receiptDetail!=4&&!empty($verify))
  4178. $receipt->verify=$verify;
  4179. $receipt->executeCopy=$executeDetail['staff'];
  4180. $receipt->explanation=$explanation;
  4181. $receipt->update();
  4182. $receiptDetail=new receiptDetail();
  4183. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4184. //报销详情
  4185. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4186. $receiptDetail=new receiptDetail();
  4187. $receiptDetail->staff=$this->staff[0]['sid'];
  4188. $receiptDetail->item=$value['name'];
  4189. $receiptDetail->itemCategory=$this->AGENCY;
  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->TRAVEL] as $key=>$value){
  4198. $receiptDetail=new receiptDetail();
  4199. $receiptDetail->staff=$this->staff[0]['sid'];
  4200. $receiptDetail->item=$value['name'];
  4201. $receiptDetail->itemCategory=$this->TRAVEL;
  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->TRAIN] as $key=>$value){
  4210. $receiptDetail=new receiptDetail();
  4211. $receiptDetail->staff=$this->staff[0]['sid'];
  4212. $receiptDetail->item=$value['name'];
  4213. $receiptDetail->itemCategory=$this->TRAIN;
  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. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4222. $receiptDetail=new receiptDetail();
  4223. $receiptDetail->staff=$this->staff[0]['sid'];
  4224. $receiptDetail->item=$value['name'];
  4225. $receiptDetail->itemCategory=$this->OTHER;
  4226. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4227. $receiptDetail->date=date("Y-m-d");
  4228. $receiptDetail->cid=$cid;
  4229. $receiptDetail->rid=$rid;
  4230. $receiptDetail->status=4;
  4231. $receiptDetail->insert();
  4232. }
  4233. //return "/referReceipt/".$rid;
  4234. }
  4235. return "/saeaBorad";
  4236. }
  4237. function approvedReceipt(){
  4238. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4239. Doo::loadModel('receipt');
  4240. Doo::loadModel('receiptDetail');
  4241. $receipt=new receipt();
  4242. $receiptDetail=new receiptDetail();
  4243. Doo::loadModel('statistics');
  4244. Doo::loadModel('itemStatistics');
  4245. $statistics=new statistics();
  4246. $itemStatistics=new itemStatistics();
  4247. Doo::loadModel("verify");
  4248. $verify=new verify();
  4249. //审批状态的判定
  4250. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4251. if(empty($receiptDetailList))
  4252. return "/saeaBorad";
  4253. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4254. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4255. if (empty($receiptDetailList['nowStaff'])){
  4256. $nowStaff="";$nowStaffList=array();
  4257. if ($verifyDetail[0][1]=='ROLE'){
  4258. $vStaffString=json_decode($verifyDetail[0][3]);
  4259. foreach ($vStaffString as $key=>$value){
  4260. $staffK=explode("_", $value);
  4261. array_push($nowStaffList, $staffK[0]);
  4262. }
  4263. $nowStaff=implode(',', $nowStaffList);
  4264. }else{
  4265. $nowStaff=$verifyDetail[0][0];
  4266. }
  4267. $receipt->nowStaff=$nowStaff;
  4268. }
  4269. // echo $nowStaff;
  4270. // print_r($verifyDetail);die;
  4271. $receipt->rid=$receiptDetailList['rid'];
  4272. $receipt->date=date("Y-m-d");
  4273. $receipt->status=2;
  4274. $receipt->update();
  4275. $receiptDetail->status=2;
  4276. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4277. Doo::loadModel("receiptLog");
  4278. $receiptLog=new receiptLog();
  4279. Doo::loadModel("verify");
  4280. $verify=new verify();
  4281. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4282. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4283. $jd=json_decode($vr['staff']);$roleId=0;
  4284. foreach ($jd as $key=>$value){
  4285. if ($value[1]=='ROLE'){
  4286. $pos = strpos($value[3], $this->staff[0]['sid']);
  4287. if ($pos !== false) {
  4288. $roleId=$value[0];
  4289. }
  4290. }
  4291. }
  4292. //审批日志
  4293. //echo $roleId;die;
  4294. if (!empty($roleId)){
  4295. Doo::loadModel("role");
  4296. $role=new role();
  4297. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4298. $receiptLog->rolename=$roleInfo['name'];
  4299. }
  4300. $receiptLog->username=$this->staff[0]['username'];
  4301. $receiptLog->uid=$this->staff[0]['sid'];
  4302. $receiptLog->date=date("Y-m-d");
  4303. $receiptLog->opinion='提交审批';
  4304. $receiptLog->img=$this->staff[0]['avatar'];
  4305. $receiptLog->status=2;
  4306. $receiptLog->rid=$rid;
  4307. $receiptLog->insert();
  4308. //statistics item
  4309. $dateArray=explode("-", $receiptDetailList['date']);
  4310. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4311. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4312. //print_r($accountItem['cSum']['agencySum']);die;
  4313. // foreach ($accountItem['cSum'] as $key=>$value){
  4314. // if($key=="agencySum"){
  4315. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4316. // if(empty($iStatistics)){
  4317. // $itemStatistics->cid=$this->staff[0]['cid'];
  4318. // $itemStatistics->staff=$this->staff[0]['sid'];
  4319. // $itemStatistics->price=$value;
  4320. // $itemStatistics->itemCategory=$this->AGENCY;
  4321. // $itemStatistics->date=date("Y-m-d");
  4322. // $itemStatistics->insert();
  4323. // }else{
  4324. // if (!empty($value)){
  4325. // $itemStatistics->price=$value+$iStatistics['price'];
  4326. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4327. // }
  4328. // }
  4329. // }elseif($key=="travelSum"){
  4330. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4331. // if(empty($iStatistics)){
  4332. // $itemStatistics->cid=$this->staff[0]['cid'];
  4333. // $itemStatistics->staff=$this->staff[0]['sid'];
  4334. // $itemStatistics->price=$value;
  4335. // $itemStatistics->itemCategory=$this->TRAVEL;
  4336. // $itemStatistics->date=date("Y-m-d");
  4337. // $itemStatistics->insert();
  4338. // }else{
  4339. // if (!empty($value)){
  4340. // $itemStatistics->price=$value+$iStatistics['price'];
  4341. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4342. // }
  4343. // }
  4344. // }elseif($key=="trainSum"){
  4345. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4346. // if(empty($iStatistics)){
  4347. // $itemStatistics->cid=$this->staff[0]['cid'];
  4348. // $itemStatistics->staff=$this->staff[0]['sid'];
  4349. // $itemStatistics->price=$value;
  4350. // $itemStatistics->itemCategory=$this->TRAIN;
  4351. // $itemStatistics->date=date("Y-m-d");
  4352. // $itemStatistics->insert();
  4353. // }else{
  4354. // if (!empty($value)){
  4355. // $itemStatistics->price=$value+$iStatistics['price'];
  4356. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4357. // }
  4358. // }
  4359. // }elseif($key=="otherSum"){
  4360. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4361. // if(empty($iStatistics)){
  4362. // $itemStatistics->cid=$this->staff[0]['cid'];
  4363. // $itemStatistics->staff=$this->staff[0]['sid'];
  4364. // $itemStatistics->price=$value;
  4365. // $itemStatistics->itemCategory=$this->OTHER;
  4366. // $itemStatistics->date=date("Y-m-d");
  4367. // $itemStatistics->insert();
  4368. // }else{
  4369. // if (!empty($value)){
  4370. // $itemStatistics->price=$value+$iStatistics['price'];
  4371. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4372. // }
  4373. // }
  4374. // }
  4375. // }
  4376. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4377. if(empty($stat)){
  4378. $statistics->date=date("Y-m-d");
  4379. $statistics->cid=$this->staff[0]['cid'];
  4380. $statistics->staff=$this->staff[0]['sid'];
  4381. $statistics->agPrice=0;
  4382. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4383. $statistics->insert();
  4384. }else{
  4385. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4386. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4387. }
  4388. return "/expenses";
  4389. }
  4390. function approval(){
  4391. $status=isset($this->params['status'])?$this->params['status']:'';
  4392. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4393. $month=$this->get_args('month')?$this->get_args('month'):"";
  4394. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4395. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4396. if (empty($status))
  4397. $status=$this->get_args('status')?$this->get_args('status'):2;
  4398. $vidList=array();
  4399. $button=0;
  4400. Doo::loadModel('verify');
  4401. $verify=new verify();
  4402. Doo::loadModel('receipt');
  4403. $receipt=new receipt();
  4404. Doo::loadModel('staff');
  4405. $staff=new staff();
  4406. Doo::loadModel('L_category');
  4407. $Lcategory=new L_category();
  4408. //user verify ID
  4409. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4410. foreach ($verifyDetail as $key=>$value){
  4411. array_push($vidList, $value['vid']);
  4412. }
  4413. $vid=implode(",", $vidList);
  4414. if(empty($verifyDetail))
  4415. $vid=0;
  4416. /*
  4417. */
  4418. $dateCondition=" and Year(date) =".$year;
  4419. if(!empty($month))
  4420. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4421. $categoryList=$Lcategory->find(array('asArray'=>true));
  4422. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4423. $cateCondition="";$staffCondition="";$approvalCondition="";
  4424. if (!empty($cid))
  4425. $cateCondition=' and cid='.$cid;
  4426. if(!empty($sid)){
  4427. $staffCondition=' and staff='.$sid;
  4428. $cateCondition="";
  4429. }
  4430. // elseif($status==1){
  4431. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4432. // }
  4433. if($status==2){
  4434. //查找角色审批人
  4435. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4436. }
  4437. $ap="";
  4438. if($status==4){
  4439. $ap=4;$status=2;
  4440. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4441. }
  4442. if($status==5){
  4443. $status=4;$ap=5;
  4444. }
  4445. //echo $vid;
  4446. //get Receipt By verifyID status 2 .$approvalCondition
  4447. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4448. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4449. ,'desc'=>'rid','asArray'=>true));
  4450. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4451. $Locate=0;
  4452. if($ap==4)
  4453. $status=4;
  4454. elseif ($ap==5)
  4455. $status=5;
  4456. foreach ($receiptList as $key=>$value){
  4457. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4458. $receiptList[$key]['reviseDetail']=array();
  4459. if (!empty($value['reviseDetail']))
  4460. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4461. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4462. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4463. $receiptList[$key]['category']=$categoryDetil['title'];
  4464. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4465. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4466. $verifyStaff=json_decode($value['verifyStaff'],true);
  4467. foreach ($verifyList as $k=>$v){
  4468. //init verifyStaff
  4469. $verifyList[$k]['date']="";
  4470. $verifyList[$k]['opinion']="";
  4471. $verifyList[$k]['status']="";
  4472. if (empty($verifyStaff)){
  4473. $verifyList[$k]['date']="";
  4474. $verifyList[$k]['opinion']="";
  4475. if ($v[0]==$this->staff[0]['sid']){
  4476. $verifyList[$k]['status']=4;
  4477. $button=4;
  4478. }
  4479. }else{
  4480. $flag=true;
  4481. foreach ($verifyStaff as $m=>$u){
  4482. if ($v[0]==$m){
  4483. $verifyList[$k]['date']=$u['date'];
  4484. $verifyList[$k]['opinion']=$u['opinion'];
  4485. $verifyList[$k]['status']=$u['status'];
  4486. $flag=false;
  4487. break;
  4488. }
  4489. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4490. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4491. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4492. }
  4493. if($flag){//检测可编辑
  4494. if($v[0]==$this->staff[0]['sid']){
  4495. $verifyList[$k]['status']=4;$button=4;
  4496. }
  4497. }
  4498. }
  4499. }
  4500. $receiptList[$key]['verifyList']=$verifyList;
  4501. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4502. $receiptList[$key]['button']=$button;
  4503. }
  4504. //print_r($receiptList);die;
  4505. //$data['verifyDetail']=$verifyDetail;
  4506. $mothHtml="";
  4507. for($i=1;$i<=12;$i++){
  4508. if($month==$i)
  4509. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4510. else
  4511. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4512. }
  4513. $data['mothHtml']=$mothHtml;
  4514. $data['receiptList']=$receiptList;
  4515. $data['receiptApprovalCount']=count($receiptList);
  4516. $data['status']=$status;
  4517. $data['year']=$year;
  4518. $data['categoryList']=$categoryList;
  4519. $data['staffList']=$staffList;
  4520. $data['cid']=$cid;
  4521. $data['sid']=$sid;
  4522. $data['ap']=$ap;
  4523. $data['memu']="receipt";
  4524. $data['staff']=$this->staff;
  4525. $data['receiptMemu']='approval';
  4526. $data['verifyId']=$this->verifyId;
  4527. $data['executeId']=$this->executeId;
  4528. $this->render ( "/admin/saea_reportList", $data );
  4529. }
  4530. function approvalDetails(){
  4531. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4532. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4533. $month=$this->get_args('month')?$this->get_args('month'):"";
  4534. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4535. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4536. Doo::loadModel('verify');
  4537. $verify=new verify();
  4538. Doo::loadModel('receipt');
  4539. $receipt=new receipt();
  4540. Doo::loadModel('staff');
  4541. $staff=new staff();
  4542. Doo::loadModel('L_category');
  4543. $Lcategory=new L_category();
  4544. Doo::loadModel('enclosur');
  4545. $enclosur=new enclosur();
  4546. $vidList=array();
  4547. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4548. foreach ($verifyDetail as $key=>$value){
  4549. array_push($vidList, $value['vid']);
  4550. }
  4551. $vid=implode(",", $vidList);
  4552. if(empty($verifyDetail))
  4553. $vid=0;
  4554. $categoryList=$Lcategory->find(array('asArray'=>true));
  4555. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4556. $ap=0;
  4557. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4558. $Locate=0;$roleId=0;$button=0;
  4559. foreach ($receiptList as $key=>$value){
  4560. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4561. $receiptList[$key]['reviseDetail']=array();
  4562. if (!empty($value['reviseDetail']))
  4563. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4564. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4565. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4566. $receiptList[$key]['category']=$categoryDetil['title'];
  4567. //检测编辑状态
  4568. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4569. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4570. $verifyStaff=json_decode($value['verifyStaff'],true);
  4571. Doo::loadModel('role');
  4572. $role=new role();
  4573. //print_r($verifyList);
  4574. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4575. foreach ($verifyList as $k=>$v){
  4576. //init verifyStaff
  4577. if ($v[1]=='ROLE'){
  4578. if (!empty($verifyStaff)){
  4579. $endStaffArray=end($verifyStaff);
  4580. if ($v[0]==$endStaffArray['nextStaff']){
  4581. $roleId=$v[0];
  4582. }
  4583. }
  4584. $roleVerify=json_decode($v[3],true);
  4585. $roleKey=$k;$roleArray=array();
  4586. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4587. foreach ($roleVerify as $o=>$p){
  4588. $staffID=explode ('_',$p);
  4589. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4590. //print_r($staffID);
  4591. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4592. array_push($roleArray, $exp);
  4593. }
  4594. $roleArrayCopy[$v[0]]=$roleArray;
  4595. //$verifyList[$k]['roleArray']=$roleArray;
  4596. }
  4597. //print_r($roleArray);
  4598. $verifyList[$k]['date']="";
  4599. $verifyList[$k]['opinion']="";
  4600. $verifyList[$k]['status']="";
  4601. if (empty($verifyStaff)){
  4602. $verifyList[$k]['date']="";
  4603. $verifyList[$k]['opinion']="";
  4604. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4605. $verifyList[$k]['status']=4;
  4606. $button=4;$flag=false;
  4607. }
  4608. }else{
  4609. foreach ($verifyStaff as $m=>$u){
  4610. if ($v[0]==$m){
  4611. $verifyList[$k]['date']=$u['date'];
  4612. $verifyList[$k]['opinion']=$u['opinion'];
  4613. $verifyList[$k]['status']=$u['status'];
  4614. $flag=false;
  4615. break;
  4616. }
  4617. }
  4618. $endStaffArray=end($verifyStaff);
  4619. if (isset($endStaffArray['ROLE'])){
  4620. }else{
  4621. $endKey=key($verifyStaff);
  4622. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4623. $button=4;
  4624. $verifyList[$k]['status']=4;
  4625. }
  4626. }
  4627. }
  4628. }
  4629. $rolename['name']='';
  4630. if (!empty($roleId)){
  4631. Doo::loadModel('role');
  4632. $role=new role();
  4633. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4634. }
  4635. if (!empty($verifyStaff))
  4636. $endStaffArray=end($verifyStaff);
  4637. $KOP=false;
  4638. foreach ($roleArrayCopy as $P=>$A){
  4639. foreach ( $A as $MKI=>$AVL){
  4640. if (!empty($verifyStaff)){
  4641. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4642. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4643. $button=4;
  4644. $roleArrayCopy[$P][$MKI]['status']=4;
  4645. }
  4646. foreach ($verifyStaff as $m=>$u){
  4647. $AVLFK=$AVL[0].'_R';
  4648. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4649. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4650. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4651. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4652. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4653. break;
  4654. }
  4655. }
  4656. }else{
  4657. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4658. $button=4;
  4659. $roleArrayCopy[$P][$MKI]['status']=4;
  4660. }
  4661. }
  4662. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4663. $KOP=true;
  4664. }
  4665. }
  4666. foreach ($roleArrayCopy as $k=>$v){
  4667. foreach ($verifyList as $m=>$n){
  4668. if ($n[0]==$k){
  4669. array_splice($verifyList,$m,1,$v);
  4670. }
  4671. }
  4672. }
  4673. $receiptList[$key]['verifyList']=$verifyList;
  4674. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4675. $receiptList[$key]['button']=$button;
  4676. }
  4677. $mothHtml="";
  4678. for($i=1;$i<=12;$i++){
  4679. if($month==$i)
  4680. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4681. else
  4682. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4683. }
  4684. //获取审批日志
  4685. Doo::loadModel('receiptLog');
  4686. $receiptLog=new receiptLog();
  4687. $rlList=array();
  4688. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4689. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4690. if (!empty($rlInfo)){
  4691. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4692. }
  4693. $receiptList[0]['rlList']=$rlList;
  4694. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4695. $enclosurHtml='';
  4696. foreach ($enclosurList as $value){
  4697. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4698. }
  4699. $data['enclosurHtml']=$enclosurHtml;
  4700. $data['rolename']=$rolename['name'];
  4701. $data['datetij']=$tijdate['date'];
  4702. $data['mothHtml']=$mothHtml;
  4703. $data['receiptList']=$receiptList;
  4704. $data['receiptApprovalCount']=count($receiptList);
  4705. $data['year']=$year;
  4706. $data['categoryList']=$categoryList;
  4707. $data['staffList']=$staffList;
  4708. $data['cid']=$cid;
  4709. $data['sid']=$sid;
  4710. $data['status']=0;
  4711. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4712. $ap=4;
  4713. }else
  4714. $data['status']=$receiptList[0]['status'];
  4715. if ($receiptList[0]['status']==4){
  4716. $data['status']=5;
  4717. $ap=0;
  4718. }
  4719. $data['ap']=$ap;
  4720. $data['memu']="receipt";
  4721. $data['staff']=$this->staff;
  4722. $data['receiptMemu']='approval';
  4723. $data['verifyId']=$this->verifyId;
  4724. $data['executeId']=$this->executeId;
  4725. $this->render ( "/admin/saeaReportListReport", $data );
  4726. }
  4727. function approvalEdi(){
  4728. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4729. $status=isset($this->params['status'])?$this->params['status']:'';
  4730. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4731. $month=$this->get_args('month')?$this->get_args('month'):"";
  4732. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4733. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4734. if (empty($status))
  4735. $status=$this->get_args('status')?$this->get_args('status'):2;
  4736. $vidList=array();
  4737. $button=0;
  4738. Doo::loadModel('verify');
  4739. Doo::loadModel('receipt');
  4740. Doo::loadModel('staff');
  4741. $staff=new staff();
  4742. $receipt=new receipt();
  4743. $verify=new verify();
  4744. Doo::loadModel('L_category');
  4745. $Lcategory=new L_category();
  4746. Doo::loadModel('enclosur');
  4747. $enclosur=new enclosur();
  4748. //user verify ID
  4749. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4750. foreach ($verifyDetail as $key=>$value){
  4751. array_push($vidList, $value['vid']);
  4752. }
  4753. $vid=implode(",", $vidList);
  4754. if(empty($verifyDetail))
  4755. $vid=0;
  4756. $categoryList=$Lcategory->find(array('asArray'=>true));
  4757. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4758. $ap="";
  4759. if($status==4){
  4760. $ap=4;$status=2;
  4761. }
  4762. //get Receipt By verifyID status 2
  4763. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4764. $Locate=0;$roleId=0;
  4765. if($ap==4)
  4766. $status=4;
  4767. foreach ($receiptList as $key=>$value){
  4768. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4769. $receiptList[$key]['reviseDetail']=array();
  4770. if (!empty($value['reviseDetail']))
  4771. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4772. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4773. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4774. $receiptList[$key]['category']=$categoryDetil['title'];
  4775. //检测编辑状态
  4776. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4777. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4778. $verifyStaff=json_decode($value['verifyStaff'],true);
  4779. // print_r($verifyList);
  4780. //
  4781. // if (empty($verifyStaff)){
  4782. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4783. // $verifyList[0]['status']=4;$button=4;
  4784. // }
  4785. //
  4786. // }else{
  4787. //
  4788. // }
  4789. // die;
  4790. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4791. // echo array_search("green",$a);
  4792. //
  4793. Doo::loadModel('role');
  4794. $role=new role();
  4795. //print_r($verifyList);
  4796. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4797. foreach ($verifyList as $k=>$v){
  4798. //init verifyStaff
  4799. if ($v[1]=='ROLE'){
  4800. if (!empty($verifyStaff)){
  4801. $endStaffArray=end($verifyStaff);
  4802. if ($v[0]==$endStaffArray['nextStaff']){
  4803. $roleId=$v[0];
  4804. }
  4805. }
  4806. $roleVerify=json_decode($v[3],true);
  4807. $roleKey=$k;$roleArray=array();
  4808. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4809. foreach ($roleVerify as $o=>$p){
  4810. $staffID=explode ('_',$p);
  4811. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4812. //print_r($staffID);
  4813. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4814. array_push($roleArray, $exp);
  4815. }
  4816. $roleArrayCopy[$v[0]]=$roleArray;
  4817. //$verifyList[$k]['roleArray']=$roleArray;
  4818. }
  4819. //print_r($roleArray);
  4820. $verifyList[$k]['date']="";
  4821. $verifyList[$k]['opinion']="";
  4822. $verifyList[$k]['status']="";
  4823. if (empty($verifyStaff)){
  4824. $verifyList[$k]['date']="";
  4825. $verifyList[$k]['opinion']="";
  4826. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4827. $verifyList[$k]['status']=4;
  4828. $button=4;$flag=false;
  4829. }
  4830. }else{
  4831. foreach ($verifyStaff as $m=>$u){
  4832. if ($v[0]==$m){
  4833. $verifyList[$k]['date']=$u['date'];
  4834. $verifyList[$k]['opinion']=$u['opinion'];
  4835. $verifyList[$k]['status']=$u['status'];
  4836. $flag=false;
  4837. break;
  4838. }
  4839. }
  4840. $endStaffArray=end($verifyStaff);
  4841. if (isset($endStaffArray['ROLE'])){
  4842. }else{
  4843. $endKey=key($verifyStaff);
  4844. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4845. $button=4;
  4846. $verifyList[$k]['status']=4;
  4847. }
  4848. }
  4849. //print_r($endStaffArray);die;
  4850. // if (empty($verifyStaff)){
  4851. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4852. // $verifyList[$k]['status']=4;$button=4;
  4853. // }
  4854. //
  4855. // }else{
  4856. //
  4857. // }
  4858. // if($flag){//检测可编辑
  4859. // if($v[0]==$this->staff[0]['sid']){
  4860. // $verifyList[$k]['status']=4;$button=4;
  4861. // }
  4862. // }
  4863. }
  4864. }
  4865. $rolename['name']='';
  4866. if (!empty($roleId)){
  4867. Doo::loadModel('role');
  4868. $role=new role();
  4869. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4870. }
  4871. if (!empty($verifyStaff))
  4872. $endStaffArray=end($verifyStaff);
  4873. $KOP=false;
  4874. foreach ($roleArrayCopy as $P=>$A){
  4875. foreach ( $A as $MKI=>$AVL){
  4876. if (!empty($verifyStaff)){
  4877. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4878. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4879. $button=4;
  4880. $roleArrayCopy[$P][$MKI]['status']=4;
  4881. }
  4882. foreach ($verifyStaff as $m=>$u){
  4883. $AVLFK=$AVL[0].'_R';
  4884. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4885. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4886. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4887. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4888. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4889. break;
  4890. }
  4891. }
  4892. }else{
  4893. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4894. $button=4;
  4895. $roleArrayCopy[$P][$MKI]['status']=4;
  4896. }
  4897. }
  4898. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4899. $KOP=true;
  4900. }
  4901. }
  4902. // print_r($roleArrayCopy);
  4903. // echo $roleKey;
  4904. foreach ($roleArrayCopy as $k=>$v){
  4905. foreach ($verifyList as $m=>$n){
  4906. if ($n[0]==$k){
  4907. array_splice($verifyList,$m,1,$v);
  4908. }
  4909. }
  4910. }
  4911. // if ($KOP)
  4912. // array_splice($verifyList,$roleKey,1,$roleArray);
  4913. //print_r($verifyList);
  4914. $receiptList[$key]['verifyList']=$verifyList;
  4915. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4916. $receiptList[$key]['button']=$button;
  4917. }
  4918. //$data['verifyDetail']=$verifyDetail;
  4919. $mothHtml="";
  4920. for($i=1;$i<=12;$i++){
  4921. if($month==$i)
  4922. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4923. else
  4924. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4925. }
  4926. //获取审批日志
  4927. Doo::loadModel('receiptLog');
  4928. $receiptLog=new receiptLog();
  4929. $rlList=array();
  4930. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4931. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4932. if (!empty($rlInfo)){
  4933. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4934. }
  4935. $receiptList[0]['rlList']=$rlList;
  4936. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4937. $enclosurHtml='';
  4938. foreach ($enclosurList as $value){
  4939. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4940. }
  4941. $data['enclosurHtml']=$enclosurHtml;
  4942. $data['rolename']=$rolename['name'];
  4943. $data['datetij']=$tijdate['date'];
  4944. $data['mothHtml']=$mothHtml;
  4945. $data['receiptList']=$receiptList;
  4946. $data['receiptApprovalCount']=count($receiptList);
  4947. $data['status']=$status;
  4948. $data['year']=$year;
  4949. $data['categoryList']=$categoryList;
  4950. $data['staffList']=$staffList;
  4951. $data['cid']=$cid;
  4952. $data['sid']=$sid;
  4953. $data['ap']=$ap;
  4954. $data['memu']="receipt";
  4955. $data['staff']=$this->staff;
  4956. $data['receiptMemu']='approval';
  4957. $data['verifyId']=$this->verifyId;
  4958. $data['executeId']=$this->executeId;
  4959. $this->render ( "/admin/saeaReportListReport", $data );
  4960. }
  4961. function remittance(){
  4962. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4963. $month=$this->get_args('month')?$this->get_args('month'):"";
  4964. Doo::loadModel('receipt');
  4965. $receipt=new receipt();
  4966. Doo::loadModel('staff');
  4967. $staff=new staff();
  4968. $dateCondition=" and Year(pastDate) =".$year;
  4969. if(!empty($month))
  4970. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4971. //get Receipt By verifyID status 1
  4972. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4973. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4974. $dataList=array();
  4975. foreach ($dateList as $d=>$a){
  4976. $dataList[$a['pastDate']]=array();$daySum=0;
  4977. foreach ($receiptList as $key=>$value){
  4978. if($a['pastDate']==$value['pastDate']){
  4979. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4980. $list=array();$html="";
  4981. foreach ($oderList as $v){
  4982. array_push($list, $v['receiptOrder']);
  4983. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4984. }
  4985. $receiptList[$key]['receiptOrder']=$html;
  4986. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4987. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4988. $receiptList[$key]['username']=$sinfo['username'];
  4989. $daySum+=$value['sum'];
  4990. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4991. }
  4992. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4993. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4994. }
  4995. }
  4996. //print_r($dataList);
  4997. $data['dataList']=$dataList;
  4998. $mothHtml="";
  4999. for($i=1;$i<=12;$i++){
  5000. if($month==$i)
  5001. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  5002. else
  5003. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  5004. }
  5005. $data['year']=$year;
  5006. $data['mothHtml']=$mothHtml;
  5007. $data['memu']="receipt";
  5008. $data['staff']=$this->staff;
  5009. $data['receiptMemu']='approval';
  5010. $data['verifyId']=$this->verifyId;
  5011. $data['executeId']=$this->executeId;
  5012. $this->render ( "/admin/saeaReportListPay", $data );
  5013. }
  5014. function revocationAdjustment(){
  5015. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  5016. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  5017. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5018. //echo $price;die;
  5019. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  5020. Doo::loadModel('receipt');
  5021. $receipt=new receipt();
  5022. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5023. if (empty($receiptDetail['reviseDetail']))
  5024. return "/approval";
  5025. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5026. $RD=array();
  5027. foreach ($reviseDetail as $key=>$value){
  5028. if ($value['price']==$price&&$value['sid']==$sid)
  5029. continue;
  5030. array_push($RD, $value);
  5031. }
  5032. $reviseDetailString=json_encode($RD);
  5033. $receipt->reviseDetail=$reviseDetailString;
  5034. $receipt->sum=$receiptDetail['sum']-$price;
  5035. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  5036. $receipt->update(array('where'=>'rid='.$rid));
  5037. }
  5038. //approvalEdi/37
  5039. return "/approvalEdi/".$rid;
  5040. }
  5041. function updateApprovalReceipt(){
  5042. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5043. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  5044. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5045. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  5046. if(!empty($rid)){
  5047. Doo::loadModel("verify");
  5048. $verify=new verify();
  5049. Doo::loadModel("receiptDetail");
  5050. $receiptDetailObj=new receiptDetail();
  5051. Doo::loadModel("itemStatistics");
  5052. Doo::loadModel("statistics");
  5053. $statistics=new statistics();
  5054. $itemStatistics=new itemStatistics();
  5055. Doo::loadModel("receipt");
  5056. $receipt=new receipt();
  5057. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5058. if (empty($receiptDetail))
  5059. return "/approval";
  5060. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  5061. $verifyString=$verifyDetail['staff'];
  5062. $verifyDetail=json_decode($verifyDetail['staff'],true);
  5063. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  5064. if(empty($opinion)){
  5065. if ($status==3)
  5066. $opinion="终止";
  5067. else
  5068. $opinion="同意支付";
  5069. }
  5070. $nowStaff=0;$nowStaffList=array();
  5071. if(empty($verifyStaff)){
  5072. //还需加入是否已经进入角色审批
  5073. if ($verifyDetail[0][1]=='ROLE'){
  5074. $vStaffString=json_decode($verifyDetail[0][3]);
  5075. foreach ($vStaffString as $key=>$value){
  5076. $staffK=explode("_", $value);
  5077. if ($staffK[0]!=$this->staff[0]['sid'])
  5078. array_push($nowStaffList, $staffK[0]);
  5079. }
  5080. //print_r($verifyDetail);
  5081. //die;
  5082. if (!empty($nowStaffList)){
  5083. $nowStaff=implode(',', $nowStaffList);
  5084. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5085. }else{
  5086. $nowStaff=$verifyDetail[1][0];
  5087. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5088. }
  5089. }else{
  5090. if ($verifyDetail[1][1]=='ROLE'){
  5091. $vStaffString=json_decode($verifyDetail[1][3]);
  5092. //echo "dd";
  5093. foreach ($vStaffString as $key=>$value){
  5094. $staffK=explode("_", $value);
  5095. array_push($nowStaffList, $staffK[0]);
  5096. }
  5097. $nowStaff=implode(',', $nowStaffList);
  5098. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5099. }else{
  5100. $nowStaff=$verifyDetail[1][0];
  5101. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5102. }
  5103. }
  5104. if($status==3)
  5105. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5106. $vStaffString=json_encode($verifyStaff);
  5107. $receipt->nowStaff=$nowStaff;
  5108. $receipt->verifyStaff=$vStaffString;
  5109. }else{
  5110. $VS=end($verifyStaff);
  5111. //非角色审批
  5112. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5113. $nextStaff=0;$roleSTF=false;
  5114. foreach ($verifyDetail as $key=>$value){
  5115. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5116. if (isset($verifyDetail[$key+1])){
  5117. $nextStaff=$verifyDetail[$key+1][0];
  5118. if ($verifyDetail[$key+1][1]=='ROLE')
  5119. $roleSTF=true;
  5120. }
  5121. break;
  5122. }
  5123. }
  5124. if (!$roleSTF){
  5125. $nowStaff=$nextStaff;
  5126. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5127. }else{
  5128. //获取角色下的所有用户ID
  5129. $nowStaffList=array();
  5130. foreach ($verifyDetail as $vfk){
  5131. if ($vfk[1]=='ROLE'){
  5132. $vStaffString=json_decode($vfk[3]);
  5133. foreach ($vStaffString as $key=>$value){
  5134. $staffK=explode("_", $value);
  5135. array_push($nowStaffList, $staffK[0]);
  5136. }
  5137. }
  5138. }
  5139. $nowStaff=implode(',', $nowStaffList);
  5140. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5141. }
  5142. if($status==3){
  5143. $verifyStaff['final']=$status;
  5144. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5145. }
  5146. $vStaffString=json_encode($verifyStaff);
  5147. $receipt->nowStaff=$nowStaff;
  5148. $receipt->verifyStaff=$vStaffString;
  5149. }
  5150. //角色审批
  5151. if (isset($VS['ROLE'])){
  5152. //找出角色人 当前审批角色组
  5153. $verifyJSStaff=array();$nowStaffList2=array();
  5154. foreach ($verifyDetail as $key=>$value){
  5155. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5156. $verifyJSStaff=json_decode($value[3]);
  5157. foreach ($verifyJSStaff as $m){
  5158. $staffK=explode("_", $m);
  5159. array_push($nowStaffList2, $staffK[0]);
  5160. }
  5161. // print_r($nowStaffList2);
  5162. }
  5163. }
  5164. $RoleVerifyStaff=array();
  5165. foreach ($verifyStaff as $key=>$value){
  5166. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5167. foreach ($nowStaffList2 as $m) {
  5168. if ($key==$m."_R")
  5169. $RoleVerifyStaff[$key]=$value;
  5170. }
  5171. }
  5172. }
  5173. // print_r($verifyStaff);
  5174. // print_r($nowStaffList2);
  5175. // print_r($RoleVerifyStaff);
  5176. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5177. //print_r($verifyJSStaff);
  5178. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5179. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5180. //下一个审批人ID
  5181. $nextStaff=0;$falg=false;
  5182. foreach ($verifyDetail as $key=>$value){
  5183. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5184. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5185. $falg=true;
  5186. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5187. foreach ($vStaffString as $v){
  5188. $staffK=explode("_", $v);
  5189. array_push($nowStaffList, $staffK[0]);
  5190. }
  5191. $nowStaff=implode(',', $nowStaffList);
  5192. $nextStaff=$verifyDetail[$key+1][0];
  5193. }elseif(isset($verifyDetail[$key+1])){
  5194. $nextStaff=$verifyDetail[$key+1][0];
  5195. $nowStaff=$nextStaff;
  5196. }else
  5197. $nowStaff='';
  5198. break;
  5199. }
  5200. }
  5201. if ($falg)
  5202. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5203. else
  5204. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5205. // print_r($verifyStaff);
  5206. // echo $nowStaff;die;
  5207. }else{ //进入下一个角色或者审批人
  5208. /*
  5209. */
  5210. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5211. //
  5212. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5213. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5214. // print_r($verifyStaff);
  5215. // die;
  5216. }
  5217. if($status==3){
  5218. $verifyStaff['final']=$status;
  5219. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5220. }
  5221. $vStaffString=json_encode($verifyStaff);
  5222. $receipt->verifyStaff=$vStaffString;
  5223. $receipt->nowStaff=$nowStaff;
  5224. //die;
  5225. //}
  5226. // print_r($verifyStaff);
  5227. // die;
  5228. }
  5229. //print_r($verifyStaff);die;
  5230. }
  5231. //print_r($verifyDetail);
  5232. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5233. foreach ($verifyDetail as $k=>$v){
  5234. if ($v[1]=='ROLE'){
  5235. $roleId=$v[0];
  5236. $roleVerify=json_decode($v[3],true);
  5237. $roleKey=$k;$roleArray=array();
  5238. foreach ($roleVerify as $o=>$p){
  5239. $staffID=explode ('_',$p);
  5240. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5241. array_push($roleArray, $exp);
  5242. }
  5243. $verifyDetailCopy[$v[0]]=$roleArray;
  5244. }
  5245. }
  5246. //print_r($verifyDetail);
  5247. foreach ($verifyDetailCopy as $k=>$v){
  5248. foreach ($verifyDetail as $m=>$n){
  5249. if ($n[0]==$k){
  5250. array_splice($verifyDetail,$m,1,$v);
  5251. }
  5252. }
  5253. }
  5254. // die;
  5255. // if (!empty($roleArray))
  5256. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5257. // echo $roleId;
  5258. // print_r($verifyStaff);
  5259. // print_r($verifyDetail);
  5260. // die;
  5261. Doo::loadModel("receiptLog");
  5262. $receiptLog=new receiptLog();
  5263. //审批日志
  5264. if (!isset($verifyStaff['final'])){
  5265. if (!empty($roleId)){
  5266. Doo::loadModel("role");
  5267. $role=new role();
  5268. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5269. $receiptLog->rolename=$roleInfo['name'];
  5270. }
  5271. $receiptLog->username=$this->staff[0]['username'];
  5272. $receiptLog->uid=$this->staff[0]['sid'];
  5273. $receiptLog->date=date("Y-m-d");
  5274. $receiptLog->opinion=$opinion;
  5275. $receiptLog->img=$this->staff[0]['avatar'];
  5276. $receiptLog->status=1;
  5277. $receiptLog->rid=$rid;
  5278. $receiptLog->insert();
  5279. }
  5280. if (isset($verifyStaff['final'])){//rDetail
  5281. $receipt->verifyBreakup=$verifyString;
  5282. $receipt->status=3;
  5283. $receiptDetailObj->status=3;
  5284. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5285. if (!empty($roleId)){
  5286. Doo::loadModel("role");
  5287. $role=new role();
  5288. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5289. $receiptLog->rolename=$roleInfo['name'];
  5290. }
  5291. $receiptLog->username=$this->staff[0]['username'];
  5292. $receiptLog->uid=$this->staff[0]['sid'];
  5293. $receiptLog->date=date("Y-m-d");
  5294. $receiptLog->opinion=$opinion;
  5295. $receiptLog->img=$this->staff[0]['avatar'];
  5296. $receiptLog->status=3;
  5297. $receiptLog->rid=$rid;
  5298. $receiptLog->insert();
  5299. //微信企业号通知
  5300. $this->setWXMsg($rid,3);
  5301. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5302. $receipt->status=1;$reviseSum=0;
  5303. $receipt->verifyBreakup=$verifyString;
  5304. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5305. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5306. foreach ($reviseDetail as $key=>$value){
  5307. $receiptDetailObj=new receiptDetail();
  5308. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5309. $receiptDetailObj->item=$value['description'];
  5310. $receiptDetailObj->itemCategory="报销金额调整";
  5311. $receiptDetailObj->price=$value['price'];
  5312. $receiptDetailObj->date=$receiptDetail['date'];
  5313. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5314. $receiptDetailObj->rid=$rid;
  5315. $receiptDetailObj->status=1;
  5316. $receiptDetailObj->insert();
  5317. $reviseSum+=$value['price'];
  5318. }
  5319. $itemStatistics=new itemStatistics();
  5320. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5321. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5322. $itemStatistics->price=$reviseSum;
  5323. $itemStatistics->itemCategory="报销金额调整";
  5324. $itemStatistics->date=$receiptDetail['date'];
  5325. $itemStatistics->insert();
  5326. }
  5327. $receiptDetailObj=new receiptDetail();
  5328. $receiptDetailObj->status=1;
  5329. $receiptDetailObj->pastDate=date("Y-m-d");
  5330. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5331. $dateArray=explode("-", $receiptDetail['date']);
  5332. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5333. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5334. if(empty($stat)){
  5335. $statistics->date=$receiptDetail['date'];
  5336. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5337. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5338. $statistics->agPrice=$receiptDetail['sum'];
  5339. $statistics->rePrice=$reviseSum;
  5340. $statistics->insert();
  5341. }else{
  5342. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5343. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5344. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5345. }
  5346. $dateArray=explode("-", $receiptDetail['date']);
  5347. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5348. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5349. foreach ($accountItem['cSum'] as $key=>$value){
  5350. if($key=="agencySum"){
  5351. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5352. if(empty($iStatistics)){
  5353. $itemStatistics->cid=$receiptDetail['cid'];;
  5354. $itemStatistics->staff=$receiptDetail['staff'];
  5355. $itemStatistics->price=$value;
  5356. $itemStatistics->itemCategory=$this->AGENCY;
  5357. $itemStatistics->date=$receiptDetail['date'];
  5358. $itemStatistics->insert();
  5359. }else{
  5360. if (!empty($value)){
  5361. $itemStatistics->price=$value+$iStatistics['price'];
  5362. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5363. }
  5364. }
  5365. }elseif($key=="travelSum"){
  5366. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5367. if(empty($iStatistics)){
  5368. $itemStatistics->cid=$receiptDetail['cid'];
  5369. $itemStatistics->staff=$receiptDetail['staff'];
  5370. $itemStatistics->price=$value;
  5371. $itemStatistics->itemCategory=$this->TRAVEL;
  5372. $itemStatistics->date=$receiptDetail['date'];
  5373. $itemStatistics->insert();
  5374. }else{
  5375. if (!empty($value)){
  5376. $itemStatistics->price=$value+$iStatistics['price'];
  5377. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5378. }
  5379. }
  5380. }elseif($key=="trainSum"){
  5381. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5382. if(empty($iStatistics)){
  5383. $itemStatistics->cid=$receiptDetail['cid'];
  5384. $itemStatistics->staff=$receiptDetail['staff'];
  5385. $itemStatistics->price=$value;
  5386. $itemStatistics->itemCategory=$this->TRAIN;
  5387. $itemStatistics->date=$receiptDetail['date'];
  5388. $itemStatistics->insert();
  5389. }else{
  5390. if (!empty($value)){
  5391. $itemStatistics->price=$value+$iStatistics['price'];
  5392. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5393. }
  5394. }
  5395. }elseif($key=="otherSum"){
  5396. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5397. if(empty($iStatistics)){
  5398. $itemStatistics->cid=$receiptDetail['cid'];
  5399. $itemStatistics->staff=$receiptDetail['staff'];
  5400. $itemStatistics->price=$value;
  5401. $itemStatistics->itemCategory=$this->OTHER;
  5402. $itemStatistics->date=$receiptDetail['date'];
  5403. $itemStatistics->insert();
  5404. }else{
  5405. if (!empty($value)){
  5406. $itemStatistics->price=$value+$iStatistics['price'];
  5407. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5408. }
  5409. }
  5410. }
  5411. }
  5412. $receipt->pastDate=date("Y-m-d");
  5413. //微信企业号通知
  5414. $this->setWXMsg($rid,1);
  5415. }
  5416. $receipt->update(array('where'=>' rid = '.$rid));
  5417. return "/approvalExpenses/2";
  5418. }
  5419. }
  5420. function expensesRetreats(){
  5421. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5422. if (!empty($rid)){
  5423. //操作记录
  5424. Doo::loadModel("receipt");
  5425. $receipt=new receipt();
  5426. Doo::loadModel("receiptLog");
  5427. $receiptLog=new receiptLog();
  5428. Doo::loadModel("verify");
  5429. $verify=new verify();
  5430. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5431. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5432. $jd=json_decode($vr['staff']);$roleId=0;
  5433. foreach ($jd as $key=>$value){
  5434. if ($value[1]=='ROLE'){
  5435. $pos = strpos($value[3], $this->staff[0]['sid']);
  5436. if ($pos !== false) {
  5437. $roleId=$value[0];
  5438. }
  5439. }
  5440. }
  5441. //审批日志
  5442. //echo $roleId;die;
  5443. if (!empty($roleId)){
  5444. Doo::loadModel("role");
  5445. $role=new role();
  5446. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5447. $receiptLog->rolename=$roleInfo['name'];
  5448. }
  5449. $receiptLog->username=$this->staff[0]['username'];
  5450. $receiptLog->uid=$this->staff[0]['sid'];
  5451. $receiptLog->date=date("Y-m-d");
  5452. $receiptLog->opinion='撤回';
  5453. $receiptLog->img=$this->staff[0]['avatar'];
  5454. $receiptLog->status=4;
  5455. $receiptLog->rid=$rid;
  5456. $receiptLog->insert();
  5457. $receipt->status=4;
  5458. $receipt->update(array('where'=>'rid='.$rid));
  5459. //微信企业号通知
  5460. $this->setWXMsg($rid,2);
  5461. }
  5462. //echo "ddd";
  5463. return '/approvalExpenses';
  5464. }
  5465. function updateCheReceipt(){
  5466. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5467. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5468. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5469. if (!empty($rid)){
  5470. //操作记录
  5471. Doo::loadModel("receipt");
  5472. $receipt=new receipt();
  5473. Doo::loadModel("receiptLog");
  5474. $receiptLog=new receiptLog();
  5475. Doo::loadModel("verify");
  5476. $verify=new verify();
  5477. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5478. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5479. $jd=json_decode($vr['staff']);$roleId=0;
  5480. foreach ($jd as $key=>$value){
  5481. if ($value[1]=='ROLE'){
  5482. $pos = strpos($value[3], $this->staff[0]['sid']);
  5483. if ($pos !== false) {
  5484. $roleId=$value[0];
  5485. }
  5486. }
  5487. }
  5488. //审批日志
  5489. //echo $roleId;die;
  5490. if (!empty($roleId)){
  5491. Doo::loadModel("role");
  5492. $role=new role();
  5493. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5494. $receiptLog->rolename=$roleInfo['name'];
  5495. }
  5496. $receiptLog->username=$this->staff[0]['username'];
  5497. $receiptLog->uid=$this->staff[0]['sid'];
  5498. $receiptLog->date=date("Y-m-d");
  5499. $receiptLog->opinion=$opinion;
  5500. $receiptLog->img=$this->staff[0]['avatar'];
  5501. $receiptLog->status=4;
  5502. $receiptLog->rid=$rid;
  5503. $receiptLog->insert();
  5504. $receipt->status=4;
  5505. $receipt->update(array('where'=>'rid='.$rid));
  5506. //微信企业号通知
  5507. $this->setWXMsg($rid,2);
  5508. echo json_encode ( array (
  5509. 'status' => 1
  5510. ) );die;
  5511. }
  5512. echo json_encode ( array (
  5513. 'status' => 2
  5514. ) );die;
  5515. //echo "ddd";
  5516. //return '/saeaBorad';
  5517. }
  5518. function revisePrice(){
  5519. $description=$this->get_args('description')?$this->get_args('description'):"";
  5520. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5521. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5522. //echo $price;die;
  5523. if (!empty($rid)){
  5524. Doo::loadModel("receipt");
  5525. $receipt=new receipt();
  5526. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5527. if (empty($receiptDetail))
  5528. return "/approval";
  5529. $reviseDetail=array();
  5530. if (empty($receiptDetail['reviseDetail'])){
  5531. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5532. $reviseDetailString=json_encode($reviseDetail);
  5533. $receipt->reviseDetail=$reviseDetailString;
  5534. $receipt->revisePrice=$price;
  5535. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5536. }else{
  5537. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5538. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5539. $reviseDetailString=json_encode($reviseDetail);
  5540. $receipt->reviseDetail=$reviseDetailString;
  5541. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5542. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5543. }
  5544. $receipt->update(array('where'=>'rid='.$rid));
  5545. }
  5546. return '/approvalEdi/'.$rid;
  5547. }
  5548. function personalCollect(){
  5549. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5550. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5551. $this->showCache($path);
  5552. Doo::loadModel("receiptDetail");
  5553. Doo::loadModel("itemStatistics");
  5554. Doo::loadModel('statistics');
  5555. $statistics=new statistics();
  5556. $itemStatistics=new itemStatistics();
  5557. $receiptDetail=new receiptDetail();
  5558. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5559. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5560. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5561. //create collect html
  5562. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5563. $adjustment=array();
  5564. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5565. array_push($collectArray['日常相关费用'], $collectHtml);
  5566. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5567. array_push($collectArray['差旅相关费用'], $collectHtml);
  5568. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5569. array_push($collectArray['培训班费用'], $collectHtml);
  5570. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5571. array_push($collectArray['其他'], $collectHtml);
  5572. $data['collectArray']=$collectArray;
  5573. //statistics html
  5574. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5575. if(empty($stList))
  5576. $stList=array('rePrice'=>0,'agPrice'=>0);
  5577. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5578. //Adjustment price html
  5579. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5580. array_push($adjustment, $collectHtml);
  5581. $data['adjustment']=$adjustment;
  5582. //total price html
  5583. $collectHtml="";$total=0;
  5584. for ($i=1;$i<=12;$i++){
  5585. $sumPrice=0;
  5586. foreach ($receiptCollectList as $key=>$value){
  5587. if($value['month']==$i){
  5588. $sumPrice+=$value['price'];
  5589. }
  5590. }
  5591. if ($sumPrice==0)
  5592. $collectHtml.='<td class="taR">-</td>';
  5593. else
  5594. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5595. $total+=$sumPrice;
  5596. }
  5597. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5598. $data['totalPrice']=$collectHtml;
  5599. $data['year']=$year;
  5600. $data['totalYear']=$total;
  5601. $data['memu']="receipt";
  5602. $data['staff']=$this->staff;
  5603. $data['receiptMemu']='personalCollect';
  5604. $data['verifyId']=$this->verifyId;
  5605. $data['executeId']=$this->executeId;
  5606. //year staff status 2,4
  5607. if($year<date("Y")){
  5608. Doo::loadModel('receipt');
  5609. $receipt=new receipt();
  5610. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5611. if(empty($receiptList)){
  5612. ob_start();
  5613. $this->render ( "/admin/saea_slist_collect", $data );
  5614. $this->cacheFile($path);die;
  5615. }
  5616. }
  5617. $this->render ( "/admin/saea_slist_collect", $data );
  5618. }
  5619. function personalCollectDetail(){
  5620. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5621. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5622. $this->showCache($path);
  5623. Doo::loadModel("receiptDetail");
  5624. Doo::loadModel("itemStatistics");
  5625. Doo::loadModel('statistics');
  5626. Doo::loadModel('accountItem');
  5627. $accountItem=new accountItem();
  5628. $statistics=new statistics();
  5629. $itemStatistics=new itemStatistics();
  5630. $receiptDetail=new receiptDetail();
  5631. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5632. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5633. $accountList=$accountItem->find(array('asArray'=>true));
  5634. //create CollectDetail HTML
  5635. $collectHtml=array();
  5636. foreach ($accountList as $key=>$value){
  5637. $html="";$asum=0;
  5638. for ($i=1;$i<=12;$i++){
  5639. $falg=true;
  5640. foreach ($receiptCollectList as $v) {
  5641. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5642. $asum+=$v['price'];
  5643. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5644. }
  5645. }
  5646. if($falg)
  5647. $html.='<td class="taR">-</td>';
  5648. }
  5649. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5650. $collectHtml[$value['category']][$value['name']]=$html;
  5651. }
  5652. $data['collectHtml']=$collectHtml;
  5653. //create Adjustment price html
  5654. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5655. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5656. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5657. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5658. array_push($collectArray['日常相关费用'], $collectHtml);
  5659. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5660. array_push($collectArray['差旅相关费用'], $collectHtml);
  5661. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5662. array_push($collectArray['培训班费用'], $collectHtml);
  5663. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5664. array_push($collectArray['其他'], $collectHtml);
  5665. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5666. array_push($adjustment, $collectHtml);
  5667. //total price html
  5668. $collectHtml="";$total=0;
  5669. for ($i=1;$i<=12;$i++){
  5670. $sumPrice=0;
  5671. foreach ($receiptCollectList as $key=>$value){
  5672. if($value['month']==$i){
  5673. $sumPrice+=$value['price'];
  5674. }
  5675. }
  5676. if ($sumPrice==0)
  5677. $collectHtml.='<td class="taR">-</td>';
  5678. else
  5679. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5680. $total+=$sumPrice;
  5681. }
  5682. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5683. //statistics html
  5684. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5685. if(empty($stList))
  5686. $stList=array('rePrice'=>0,'agPrice'=>0);
  5687. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5688. $data['collectArray']=$collectArray;
  5689. $data['adjustment']=$adjustment;
  5690. $data['totalPrice']=$collectHtml;
  5691. $data['totalYear']=$total;
  5692. $data['year']=$year;
  5693. $data['memu']="receipt";
  5694. $data['staff']=$this->staff;
  5695. $data['receiptMemu']='personalCollect';
  5696. $data['verifyId']=$this->verifyId;
  5697. $data['executeId']=$this->executeId;
  5698. //year staff status 2,4
  5699. if($year<date("Y")){
  5700. Doo::loadModel('receipt');
  5701. $receipt=new receipt();
  5702. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5703. if(empty($receiptList)){
  5704. ob_start();
  5705. $this->render ( "/admin/saeaCollectArticles", $data );
  5706. $this->cacheFile($path);die;
  5707. }
  5708. }
  5709. $this->render ( "/admin/saeaCollectArticles", $data );
  5710. }
  5711. function companyCategoryCollect(){
  5712. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5713. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5714. $this->showCache($path);
  5715. Doo::loadModel('L_category');
  5716. Doo::loadModel('itemStatistics');
  5717. Doo::loadModel('statistics');
  5718. $statistics=new statistics();
  5719. $Lcategory=new L_category();
  5720. $itemStatistics=new itemStatistics();
  5721. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5722. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5723. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5724. //ceatre companyCollectHtml
  5725. foreach ($LcategoryList as $value){
  5726. $html="";$asum=0;
  5727. for ($i=1;$i<=12;$i++){
  5728. $falg=true;
  5729. foreach ($itemStatisticsList as $v){
  5730. if($value['cid']==$v['cid']&&$i==$v['month']){
  5731. $asum+=$v['price'];
  5732. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5733. }
  5734. }
  5735. if($falg)
  5736. $html.='<td class="taR">-</td>';
  5737. }
  5738. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5739. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5740. }
  5741. $data['companyHtml']=$collectHtml;
  5742. //total price html
  5743. $collectHtml="";$total=0;
  5744. for ($i=1;$i<=12;$i++){
  5745. $sumPrice=0;
  5746. foreach ($itemStatisticsList as $key=>$value){
  5747. if($value['month']==$i){
  5748. $sumPrice+=$value['price'];
  5749. }
  5750. }
  5751. if ($sumPrice==0)
  5752. $collectHtml.='<td class="taR">-</td>';
  5753. else
  5754. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5755. $total+=$sumPrice;
  5756. }
  5757. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5758. $data['companyTotalHtml']=$collectHtml;
  5759. $data['total']=$total;
  5760. //statistics html
  5761. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5762. if(empty($stList))
  5763. $stList=array('rePrice'=>0,'agPrice'=>0);
  5764. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5765. $data['year']=$year;
  5766. $data['memu']="receipt";
  5767. $data['staff']=$this->staff;
  5768. $data['receiptMemu']='companyCategoryCollect';
  5769. $data['verifyId']=$this->verifyId;
  5770. $data['executeId']=$this->executeId;
  5771. //year staff status 2,4
  5772. if($year<date("Y")){
  5773. Doo::loadModel('receipt');
  5774. $receipt=new receipt();
  5775. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5776. if(empty($receiptList)){
  5777. ob_start();
  5778. $this->render ( "/admin/saeaCompanyCollect", $data );
  5779. $this->cacheFile($path);die;
  5780. }
  5781. }
  5782. $this->render ( "/admin/saeaCompanyCollect", $data );
  5783. }
  5784. function categoryCollectDetail(){
  5785. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5786. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5787. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5788. $this->showCache($path);
  5789. Doo::loadModel('statistics');
  5790. $statistics=new statistics();
  5791. Doo::loadModel("receiptDetail");
  5792. $receiptDetail=new receiptDetail();
  5793. Doo::loadModel('L_category');
  5794. $Lcategory=new L_category();
  5795. Doo::loadModel('accountItem');
  5796. $accountItem=new accountItem();
  5797. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5798. if ($cid==0){
  5799. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5800. if ($cid==0)
  5801. $cid=$LcategoryList[0]['cid'];
  5802. }
  5803. $data['LcategoryList']=$LcategoryList;
  5804. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5805. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5806. $accountList=$accountItem->find(array('asArray'=>true));
  5807. //create CollectDetail HTML
  5808. $collectHtml=array();
  5809. foreach ($accountList as $key=>$value){
  5810. $html="";$asum=0;
  5811. for ($i=1;$i<=12;$i++){
  5812. $falg=true;
  5813. foreach ($receiptCollectList as $v) {
  5814. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5815. $asum+=$v['price'];
  5816. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5817. }
  5818. }
  5819. if($falg)
  5820. $html.='<td class="taR">-</td>';
  5821. }
  5822. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5823. $collectHtml[$value['category']][$value['name']]=$html;
  5824. }
  5825. $data['collectHtml']=$collectHtml;
  5826. //create Adjustment price html
  5827. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5828. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5829. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5830. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5831. array_push($collectArray['日常相关费用'], $collectHtml);
  5832. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5833. array_push($collectArray['差旅相关费用'], $collectHtml);
  5834. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5835. array_push($collectArray['培训班费用'], $collectHtml);
  5836. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5837. array_push($collectArray['其他'], $collectHtml);
  5838. $data['collectArray']=$collectArray;
  5839. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5840. array_push($adjustment, $collectHtml);
  5841. $data['adjustment']=$adjustment;
  5842. //total price html
  5843. $collectHtml="";$total=0;
  5844. for ($i=1;$i<=12;$i++){
  5845. $sumPrice=0;
  5846. foreach ($receiptCollectList as $key=>$value){
  5847. if($value['month']==$i){
  5848. $sumPrice+=$value['price'];
  5849. }
  5850. }
  5851. if ($sumPrice==0)
  5852. $collectHtml.='<td class="taR">-</td>';
  5853. else
  5854. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5855. $total+=$sumPrice;
  5856. }
  5857. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5858. //statistics html
  5859. $stList=$statistics->statisticsByCid($year,$cid);
  5860. if(empty($stList))
  5861. $stList=array('rePrice'=>0,'agPrice'=>0);
  5862. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5863. $data['totalYear']=$total;
  5864. $data['year']=$year;
  5865. $data['cid']=$cid;
  5866. $data['memu']="receipt";
  5867. $data['staff']=$this->staff;
  5868. $data['receiptMemu']='companyCategoryCollect';
  5869. $data['verifyId']=$this->verifyId;
  5870. $data['executeId']=$this->executeId;
  5871. //year staff status 2,4
  5872. if($year<date("Y")){
  5873. Doo::loadModel('receipt');
  5874. $receipt=new receipt();
  5875. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5876. if(empty($receiptList)){
  5877. ob_start();
  5878. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5879. $this->cacheFile($path);die;
  5880. }
  5881. }
  5882. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5883. }
  5884. function staffCollect(){
  5885. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5886. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5887. //$this->showCache($path);
  5888. Doo::loadModel('statistics');
  5889. $statistics=new statistics();
  5890. Doo::loadModel("receiptDetail");
  5891. $receiptDetail=new receiptDetail();
  5892. Doo::loadModel('L_category');
  5893. $Lcategory=new L_category();
  5894. Doo::loadModel('accountItem');
  5895. $accountItem=new accountItem();
  5896. Doo::loadModel('staff');
  5897. $staff=new staff();
  5898. Doo::loadModel('itemStatistics');
  5899. $itemStatistics=new itemStatistics();
  5900. /*
  5901. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5902. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5903. if(empty($stList))
  5904. $stList=array('rePrice'=>0,'agPrice'=>0);
  5905. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5906. */
  5907. //statistics html
  5908. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5909. if(empty($stList))
  5910. $stList=array('rePrice'=>0,'agPrice'=>0);
  5911. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5912. //---
  5913. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5914. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5915. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5916. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5917. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5918. //print_r($itemStatisticsList);die;
  5919. //ceatre companyCollectHtml
  5920. foreach ($categoryList as $vlu){
  5921. $count=$vlu['count']+1;
  5922. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5923. $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;
  5924. foreach ($staffList as $value){
  5925. if ($vlu['cid']==$value['cid']){
  5926. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5927. $asum=0;
  5928. for ($i=1;$i<=12;$i++){
  5929. $falg=true;
  5930. foreach ($itemStatisticsList as $v){
  5931. if($value['sid']==$v['staff']&&$i==$v['month']){
  5932. if ($v['month']==1)
  5933. $m1+=$v['price'];
  5934. if ($v['month']==2)
  5935. $m2+=$v['price'];
  5936. if ($v['month']==3)
  5937. $m3+=$v['price'];
  5938. if ($v['month']==4)
  5939. $m4+=$v['price'];
  5940. if ($v['month']==5)
  5941. $m5+=$v['price'];
  5942. if ($v['month']==6)
  5943. $m6+=$v['price'];
  5944. if ($v['month']==7)
  5945. $m7+=$v['price'];
  5946. if ($v['month']==8)
  5947. $m8+=$v['price'];
  5948. if ($v['month']==9)
  5949. $m9+=$v['price'];
  5950. if ($v['month']==10)
  5951. $m10+=$v['price'];
  5952. if ($v['month']==11)
  5953. $m11+=$v['price'];
  5954. if ($v['month']==12)
  5955. $m12+=$v['price'];
  5956. $asum+=$v['price'];
  5957. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5958. }
  5959. }
  5960. if($falg)
  5961. $html.='<td class="taR">-</td>';
  5962. }
  5963. $m13+=$asum;
  5964. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5965. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5966. $html="";
  5967. }
  5968. }
  5969. $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>
  5970. <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>
  5971. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5972. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5973. }
  5974. $data['companyHtml']=$collectHtml;
  5975. //total price html
  5976. $collectHtml="";$total=0;
  5977. for ($i=1;$i<=12;$i++){
  5978. $sumPrice=0;
  5979. foreach ($itemStatisticsList as $key=>$value){
  5980. if($value['month']==$i){
  5981. $sumPrice+=$value['price'];
  5982. }
  5983. }
  5984. if ($sumPrice==0)
  5985. $collectHtml.='<td class="taR">-</td>';
  5986. else
  5987. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5988. $total+=$sumPrice;
  5989. }
  5990. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5991. $data['companyTotalHtml']=$collectHtml;
  5992. $data['total']=$total;
  5993. $data['year']=$year;
  5994. $data['memu']="receipt";
  5995. $data['staff']=$this->staff;
  5996. $data['receiptMemu']='companyCategoryCollect';
  5997. $data['verifyId']=$this->verifyId;
  5998. $data['executeId']=$this->executeId;
  5999. if ($year<=date("Y")){
  6000. Doo::loadModel('receipt');
  6001. $receipt=new receipt();
  6002. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  6003. if(empty($receiptList)){ //generated files
  6004. ob_start();
  6005. $this->render ( "/admin/saeaStaffCollectB", $data );
  6006. $this->cacheFile($path);die;
  6007. }
  6008. }
  6009. $this->render ( "/admin/saeaStaffCollectB", $data );
  6010. }
  6011. function staffCollectBak(){
  6012. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6013. $month=$this->get_args('month')?$this->get_args('month'):1;
  6014. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  6015. $this->showCache($path);
  6016. Doo::loadModel('statistics');
  6017. $statistics=new statistics();
  6018. Doo::loadModel("receiptDetail");
  6019. $receiptDetail=new receiptDetail();
  6020. Doo::loadModel('L_category');
  6021. $Lcategory=new L_category();
  6022. Doo::loadModel('accountItem');
  6023. $accountItem=new accountItem();
  6024. Doo::loadModel('staff');
  6025. $staff=new staff();
  6026. Doo::loadModel('itemStatistics');
  6027. $itemStatistics=new itemStatistics();
  6028. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6029. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  6030. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6031. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  6032. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  6033. $staffList=$staff->find(array('asArray'=>true));
  6034. $htmlArray=array();
  6035. foreach ($LcategoryList as $value){
  6036. $htmlArray[$value['title']]=array();
  6037. foreach ($staffList as $v){
  6038. if($value['cid']==$v['cid']){
  6039. $html="";$falg=true;$staffSumPrice=0;
  6040. foreach ($itemStatisticsList as $a){
  6041. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  6042. if(empty($a['price'])){
  6043. $html.='<td class="taR">-</td>';$falg=false;break;
  6044. }else{
  6045. $staffSumPrice+=$a['price'];
  6046. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6047. }
  6048. }
  6049. }
  6050. if ($falg){
  6051. $html.='<td class="taR">-</td>';$falg=true;
  6052. }
  6053. $falg=true;
  6054. foreach ($itemStatisticsList as $a){
  6055. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  6056. if(empty($a['price'])){
  6057. $html.='<td class="taR">-</td>';$falg=false;break;
  6058. }else{
  6059. $staffSumPrice+=$a['price'];
  6060. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6061. }
  6062. }
  6063. }
  6064. if ($falg){
  6065. $html.='<td class="taR">-</td>';$falg=true;
  6066. }
  6067. $falg=true;
  6068. foreach ($itemStatisticsList as $a){
  6069. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  6070. if(empty($a['price'])){
  6071. $html.='<td class="taR">-</td>';$falg=false;break;
  6072. }else{
  6073. $staffSumPrice+=$a['price'];
  6074. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6075. }
  6076. }
  6077. }
  6078. if ($falg){
  6079. $html.='<td class="taR">-</td>';$falg=true;
  6080. }
  6081. $falg=true;
  6082. foreach ($itemStatisticsList as $a){
  6083. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6084. if(!empty($a['price'])){
  6085. $staffSumPrice+=$a['price'];
  6086. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6087. }else{
  6088. $html.='<td class="taR">-</td>';$falg=false;break;
  6089. }
  6090. }
  6091. }
  6092. if ($falg){
  6093. $html.='<td class="taR">-</td>';$falg=true;
  6094. }
  6095. $falg=true;
  6096. foreach ($itemStatisticsList as $a){
  6097. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6098. if(!empty($a['price'])){
  6099. $staffSumPrice+=$a['price'];
  6100. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6101. }else{
  6102. $html.='<td class="taR">-</td>';$falg=false;break;
  6103. }
  6104. }
  6105. }
  6106. if ($falg){
  6107. $html.='<td class="taR">-</td>';$falg=true;
  6108. }
  6109. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6110. $htmlArray[$value['title']][$v['username']]=$html;
  6111. }
  6112. }
  6113. /*-- ---*/
  6114. //合计费用
  6115. $cateHtml="";$catePrice=0;$cateFalg=true;
  6116. foreach ($itemCategoryList as $l){
  6117. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6118. if(empty($l['price'])){
  6119. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6120. }else{
  6121. $catePrice+=$l['price'];
  6122. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6123. }
  6124. }
  6125. }
  6126. if ($cateFalg){
  6127. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6128. }
  6129. $cateFalg=true;
  6130. foreach ($itemCategoryList as $l){
  6131. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6132. if(empty($l['price'])){
  6133. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6134. }else{
  6135. $catePrice+=$l['price'];
  6136. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6137. }
  6138. }
  6139. }
  6140. if ($cateFalg){
  6141. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6142. }
  6143. $cateFalg=true;
  6144. foreach ($itemCategoryList as $l){
  6145. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6146. if(empty($l['price'])){
  6147. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6148. }else{
  6149. $catePrice+=$l['price'];
  6150. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6151. }
  6152. }
  6153. }
  6154. if ($cateFalg){
  6155. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6156. }
  6157. $cateFalg=true;
  6158. foreach ($itemCategoryList as $l){
  6159. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6160. if(empty($l['price'])){
  6161. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6162. }else{
  6163. $catePrice+=$l['price'];
  6164. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6165. }
  6166. }
  6167. }
  6168. if ($cateFalg){
  6169. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6170. }
  6171. $cateFalg=true;
  6172. foreach ($itemCategoryList as $l){
  6173. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6174. if(empty($l['price'])){
  6175. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6176. }else{
  6177. $catePrice+=$l['price'];
  6178. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6179. }
  6180. }
  6181. }
  6182. if ($cateFalg){
  6183. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6184. }
  6185. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6186. $htmlArray[$value['title']]['合计']=$cateHtml;
  6187. /*-- ---*/
  6188. }
  6189. //print_r($htmlArray);die;
  6190. $data['htmlArray']=$htmlArray;
  6191. //statistics html
  6192. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6193. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6194. if(empty($stList))
  6195. $stList=array('rePrice'=>0,'agPrice'=>0);
  6196. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6197. $monthHtml="";
  6198. for ($i=1;$i<=12;$i++){
  6199. if ($i==$month)
  6200. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6201. else
  6202. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6203. }
  6204. $data['monthHtml']=$monthHtml;
  6205. $data['year']=$year;
  6206. $data['month']=$month;
  6207. $data['memu']="receipt";
  6208. $data['staff']=$this->staff;
  6209. $data['receiptMemu']='companyCategoryCollect';
  6210. $data['verifyId']=$this->verifyId;
  6211. $data['executeId']=$this->executeId;
  6212. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6213. Doo::loadModel('receipt');
  6214. $receipt=new receipt();
  6215. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6216. if(empty($receiptList)){ //generated files
  6217. ob_start();
  6218. $this->render ( "/admin/saeaStaffCollect", $data );
  6219. $this->cacheFile($path);die;
  6220. }
  6221. }
  6222. $this->render ( "/admin/saeaStaffCollect", $data );
  6223. }
  6224. function lyt(){
  6225. Doo::loadModel("receiptDetail");
  6226. $receiptDetail=new receiptDetail();
  6227. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6228. foreach ($receiptCollectList as $key=>$value){
  6229. $receiptDetail=new receiptDetail();
  6230. $receiptDetail->pastDate=$value['date'];
  6231. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6232. }
  6233. }
  6234. function staffCollectMonthDetail(){
  6235. $year=$this->get_args('year')?$this->get_args('year'):"";
  6236. $month=$this->get_args('month')?$this->get_args('month'):"";
  6237. if(!$year)
  6238. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6239. if(!$month)
  6240. $month=isset($this->params['month'])?$this->params['month']:1;
  6241. Doo::loadModel('staff');
  6242. $staff=new staff();
  6243. Doo::loadModel("receiptDetail");
  6244. $receiptDetail=new receiptDetail();
  6245. Doo::loadModel('accountItem');
  6246. $accountItem=new accountItem();
  6247. Doo::loadModel('statistics');
  6248. $statistics=new statistics();
  6249. Doo::loadModel('L_category');
  6250. $lCategory=new L_category();
  6251. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6252. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6253. $list=array();
  6254. foreach ($categoryList as $vlu){
  6255. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6256. $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;
  6257. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6258. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6259. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6260. $s1=0;
  6261. $m1=0;
  6262. foreach ($staffList as $value){
  6263. if ($vlu['cid']==$value['cid']){
  6264. //pastDate
  6265. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6266. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6267. // if ($value['sid']==42){
  6268. // print_r($receiptCollectList);die;
  6269. // }
  6270. if(!empty($receiptCollectList)){
  6271. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6272. $html="";
  6273. $psum=0;
  6274. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6275. foreach ($item as $va){
  6276. $falg=true;
  6277. foreach ($receiptCollectList as $v){
  6278. if($v['itemCategory']=='日常相关费用'){
  6279. if($v['item']==$va){
  6280. if ($va=='市内交通费')
  6281. $r1+=$v['price'];
  6282. if ($va=='市内出租费')
  6283. $r2+=$v['price'];
  6284. if ($va=='办事处房租')
  6285. $r3+=$v['price'];
  6286. if ($va=='电话费')
  6287. $r4+=$v['price'];
  6288. if ($va=='水费')
  6289. $r5+=$v['price'];
  6290. if ($va=='电费')
  6291. $r6+=$v['price'];
  6292. if ($va=='办公费用')
  6293. $r7+=$v['price'];
  6294. if ($va=='邮寄费')
  6295. $r8+=$v['price'];
  6296. if ($va=='其他费用')
  6297. $r9+=$v['price'];
  6298. if ($va=='车辆费用')
  6299. $r10+=$v['price'];
  6300. if ($va=='广告费')
  6301. $r11+=$v['price'];
  6302. if ($va=='团队建设费')
  6303. $r13+=$v['price'];
  6304. if ($va=='物业管理费')
  6305. $r14+=$v['price'];
  6306. if ($va=='宽带费')
  6307. $r15+=$v['price'];
  6308. $psum+=$v['price'];
  6309. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6310. }
  6311. }
  6312. }
  6313. if($falg)
  6314. $html.='<td class="taR">-</td>';
  6315. }
  6316. $r12+=$psum;
  6317. if(!empty($psum))
  6318. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6319. else
  6320. $psum='<td class="colGreen taR">-</td>';
  6321. $receiptL['日常相关费用']=$psum.$html;
  6322. /*-----------------------------------*/
  6323. $html="";
  6324. $psum=0;
  6325. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6326. foreach ($item as $va){
  6327. $falg=true;
  6328. foreach ($receiptCollectList as $v){
  6329. if($v['itemCategory']=='差旅相关费用'){
  6330. if($v['item']==$va){
  6331. if ($va=='往来交通费')
  6332. $c1+=$v['price'];
  6333. if ($va=='市内交通费')
  6334. $c2+=$v['price'];
  6335. if ($va=='出差住宿费')
  6336. $c3+=$v['price'];
  6337. if ($va=='出差补助')
  6338. $c4+=$v['price'];
  6339. if ($va=='其他费用')
  6340. $c5+=$v['price'];
  6341. $psum+=$v['price'];
  6342. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6343. }
  6344. }
  6345. }
  6346. if($falg)
  6347. $html.='<td class="taR">-</td>';
  6348. }
  6349. $c6+=$psum;
  6350. if(!empty($psum))
  6351. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6352. else
  6353. $psum='<td class="colGreen taR">-</td>';
  6354. $receiptL['差旅相关费用']=$psum.$html;
  6355. /*-------------------------------------*/
  6356. $html="";
  6357. $psum=0;
  6358. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6359. foreach ($item as $va){
  6360. $falg=true;
  6361. foreach ($receiptCollectList as $v){
  6362. if($v['itemCategory']=='培训班费用'){
  6363. if($v['item']==$va){
  6364. if ($va=='场租费')
  6365. $p1+=$v['price'];
  6366. if ($va=='薪酬')
  6367. $p2+=$v['price'];
  6368. if ($va=='住宿费')
  6369. $p3+=$v['price'];
  6370. if ($va=='交通费')
  6371. $p4+=$v['price'];
  6372. if ($va=='餐饮费')
  6373. $p5+=$v['price'];
  6374. if ($va=='办公费')
  6375. $p6+=$v['price'];
  6376. if ($va=='公关费')
  6377. $p7+=$v['price'];
  6378. if ($va=='其他')
  6379. $p8+=$v['price'];
  6380. $psum+=$v['price'];
  6381. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6382. }
  6383. }
  6384. }
  6385. if($falg)
  6386. $html.='<td class="taR">-</td>';
  6387. }
  6388. $p9+=$psum;
  6389. if(!empty($psum))
  6390. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6391. else
  6392. $psum='<td class="colGreen taR">-</td>';
  6393. $receiptL['培训班费用']=$psum.$html;
  6394. /*-------------------------------------*/
  6395. $html="";
  6396. $psum=0;
  6397. $item=array('公关费','广告费','借款','可自加费用');
  6398. foreach ($item as $va){
  6399. $falg=true;
  6400. foreach ($receiptCollectList as $v){
  6401. if($v['itemCategory']=='其他'){
  6402. // if ($value['sid']==42){
  6403. //
  6404. // echo var_dump($v['item']);
  6405. // echo var_dump($va);
  6406. // echo var_dump($v['item']==" ".$va);
  6407. // echo $v['item']."==".$va."/<br/>";
  6408. // //print_r( $receiptCollectList);//echo $va;
  6409. // }
  6410. if(trim($v['item'])==$va){
  6411. if ($va=='公关费')
  6412. $t1+=$v['price'];
  6413. if ($va=='广告费'){
  6414. $t2+=$v['price'];
  6415. }
  6416. if ($va=='借款')
  6417. $t3+=$v['price'];
  6418. if ($va=='可自加费用')
  6419. $t4+=$v['price'];
  6420. $psum+=$v['price'];
  6421. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6422. }
  6423. }
  6424. }
  6425. if($falg)
  6426. $html.='<td class="taR">-</td>';
  6427. }
  6428. $t5+=$psum;
  6429. if(!empty($psum))
  6430. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6431. else
  6432. $psum='<td class="colGreen taR">-</td>';
  6433. $receiptL['其他']=$psum.$html;
  6434. /*-------------------------------------*/
  6435. $html="";
  6436. $psum=0;
  6437. foreach ($receiptCollectList as $v){
  6438. if($v['itemCategory']=='报销金额调整'){
  6439. if (!empty($v['price'])){
  6440. $psum+=$v['price'];
  6441. }
  6442. }
  6443. }
  6444. $s1+=$psum;
  6445. if(!empty($psum))
  6446. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6447. else
  6448. $psum='<td class="taR colOrange">-</td>';
  6449. $receiptL['报销金额调整']=$psum.$html;
  6450. }else{
  6451. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6452. <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>
  6453. <td class="taR">-</td><td class="taR">-</td>';
  6454. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6455. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6456. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6457. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6458. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6459. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6460. }
  6461. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6462. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6463. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6464. if(!empty($monthStaffPrice[0]['price'])){
  6465. $m1+=$monthStaffPrice[0]['price'];
  6466. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6467. }else
  6468. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6469. $list[$value['username']]=$receiptL;
  6470. }
  6471. }
  6472. $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>
  6473. <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>
  6474. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6475. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6476. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6477. $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>
  6478. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6479. $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>';
  6480. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6481. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6482. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6483. }
  6484. $data['list']=$list;
  6485. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6486. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6487. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6488. //statistics html
  6489. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6490. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6491. if(empty($stList))
  6492. $stList=array('rePrice'=>0,'agPrice'=>0);
  6493. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6494. $monthHtml="";
  6495. for ($i=1;$i<=12;$i++){
  6496. if ($i==$month)
  6497. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6498. else
  6499. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6500. }
  6501. $data['monthHtml']=$monthHtml;
  6502. $data['year']=$year;
  6503. $data['month']=$month;
  6504. $data['memu']="receipt";
  6505. $data['staff']=$this->staff;
  6506. $data['receiptMemu']='companyCategoryCollect';
  6507. $data['verifyId']=$this->verifyId;
  6508. $data['executeId']=$this->executeId;
  6509. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6510. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6511. }
  6512. function staffCollectMonthDetail2(){
  6513. $year=$this->get_args('year')?$this->get_args('year'):"";
  6514. $month=$this->get_args('month')?$this->get_args('month'):"";
  6515. if(!$year)
  6516. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6517. if(!$month)
  6518. $month=isset($this->params['month'])?$this->params['month']:1;
  6519. Doo::loadModel('staff');
  6520. $staff=new staff();
  6521. Doo::loadModel("receiptDetail");
  6522. $receiptDetail=new receiptDetail();
  6523. Doo::loadModel('accountItem');
  6524. $accountItem=new accountItem();
  6525. Doo::loadModel('statistics');
  6526. $statistics=new statistics();
  6527. Doo::loadModel('L_category');
  6528. $lCategory=new L_category();
  6529. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6530. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6531. $list=array();
  6532. foreach ($categoryList as $vlu){
  6533. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6534. $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;
  6535. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6536. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6537. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6538. $s1=0;
  6539. $m1=0;
  6540. foreach ($staffList as $value){
  6541. if ($vlu['cid']==$value['cid']){
  6542. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6543. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6544. if(!empty($receiptCollectList)){
  6545. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6546. $html="";
  6547. $psum=0;
  6548. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6549. foreach ($item as $va){
  6550. $falg=true;
  6551. foreach ($receiptCollectList as $v){
  6552. if($v['itemCategory']=='日常相关费用'){
  6553. if($v['item']==$va){
  6554. if ($va=='市内交通费')
  6555. $r1+=$v['price'];
  6556. if ($va=='市内出租费')
  6557. $r2+=$v['price'];
  6558. if ($va=='办事处房租')
  6559. $r3+=$v['price'];
  6560. if ($va=='电话费')
  6561. $r4+=$v['price'];
  6562. if ($va=='水费')
  6563. $r5+=$v['price'];
  6564. if ($va=='电费')
  6565. $r6+=$v['price'];
  6566. if ($va=='办公费用')
  6567. $r7+=$v['price'];
  6568. if ($va=='邮寄费')
  6569. $r8+=$v['price'];
  6570. if ($va=='其他费用')
  6571. $r9+=$v['price'];
  6572. if ($va=='车辆费用')
  6573. $r10+=$v['price'];
  6574. if ($va=='广告费')
  6575. $r11+=$v['price'];
  6576. if ($va=='团队建设费')
  6577. $r13+=$v['price'];
  6578. if ($va=='物业管理费')
  6579. $r14+=$v['price'];
  6580. if ($va=='宽带费')
  6581. $r15+=$v['price'];
  6582. $psum+=$v['price'];
  6583. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6584. }
  6585. }
  6586. }
  6587. if($falg)
  6588. $html.='<td class="taR">-</td>';
  6589. }
  6590. $r12+=$psum;
  6591. if(!empty($psum))
  6592. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6593. else
  6594. $psum='<td class="colGreen taR">-</td>';
  6595. $receiptL['日常相关费用']=$psum.$html;
  6596. /*-----------------------------------*/
  6597. $html="";
  6598. $psum=0;
  6599. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6600. foreach ($item as $va){
  6601. $falg=true;
  6602. foreach ($receiptCollectList as $v){
  6603. if($v['itemCategory']=='差旅相关费用'){
  6604. if($v['item']==$va){
  6605. if ($va=='往来交通费')
  6606. $c1+=$v['price'];
  6607. if ($va=='市内交通费')
  6608. $c2+=$v['price'];
  6609. if ($va=='出差住宿费')
  6610. $c3+=$v['price'];
  6611. if ($va=='出差补助')
  6612. $c4+=$v['price'];
  6613. if ($va=='其他费用')
  6614. $c5+=$v['price'];
  6615. $psum+=$v['price'];
  6616. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6617. }
  6618. }
  6619. }
  6620. if($falg)
  6621. $html.='<td class="taR">-</td>';
  6622. }
  6623. $c6+=$psum;
  6624. if(!empty($psum))
  6625. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6626. else
  6627. $psum='<td class="colGreen taR">-</td>';
  6628. $receiptL['差旅相关费用']=$psum.$html;
  6629. /*-------------------------------------*/
  6630. $html="";
  6631. $psum=0;
  6632. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6633. foreach ($item as $va){
  6634. $falg=true;
  6635. foreach ($receiptCollectList as $v){
  6636. if($v['itemCategory']=='培训班费用'){
  6637. if($v['item']==$va){
  6638. if ($va=='场租费')
  6639. $p1+=$v['price'];
  6640. if ($va=='薪酬')
  6641. $p2+=$v['price'];
  6642. if ($va=='住宿费')
  6643. $p3+=$v['price'];
  6644. if ($va=='交通费')
  6645. $p4+=$v['price'];
  6646. if ($va=='餐饮费')
  6647. $p5+=$v['price'];
  6648. if ($va=='办公费')
  6649. $p6+=$v['price'];
  6650. if ($va=='公关费')
  6651. $p7+=$v['price'];
  6652. if ($va=='其他')
  6653. $p8+=$v['price'];
  6654. $psum+=$v['price'];
  6655. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6656. }
  6657. }
  6658. }
  6659. if($falg)
  6660. $html.='<td class="taR">-</td>';
  6661. }
  6662. $p9+=$psum;
  6663. if(!empty($psum))
  6664. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6665. else
  6666. $psum='<td class="colGreen taR">-</td>';
  6667. $receiptL['培训班费用']=$psum.$html;
  6668. /*-------------------------------------*/
  6669. $html="";
  6670. $psum=0;
  6671. $item=array('公关费','广告费','借款','可自加费用');
  6672. foreach ($item as $va){
  6673. $falg=true;
  6674. foreach ($receiptCollectList as $v){
  6675. if($v['itemCategory']=='其他'){
  6676. if($v['item']==$va){
  6677. if ($va=='公关费')
  6678. $t1+=$v['price'];
  6679. if ($va=='广告费')
  6680. $t2+=$v['price'];
  6681. if ($va=='借款')
  6682. $t3+=$v['price'];
  6683. if ($va=='可自加费用')
  6684. $t4+=$v['price'];
  6685. $psum+=$v['price'];
  6686. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6687. }
  6688. }
  6689. }
  6690. if($falg)
  6691. $html.='<td class="taR">-</td>';
  6692. }
  6693. $t5+=$psum;
  6694. if(!empty($psum))
  6695. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6696. else
  6697. $psum='<td class="colGreen taR">-</td>';
  6698. $receiptL['其他']=$psum.$html;
  6699. /*-------------------------------------*/
  6700. $html="";
  6701. $psum=0;
  6702. foreach ($receiptCollectList as $v){
  6703. if($v['itemCategory']=='报销金额调整'){
  6704. if (!empty($v['price'])){
  6705. $psum+=$v['price'];
  6706. }
  6707. }
  6708. }
  6709. $s1+=$psum;
  6710. if(!empty($psum))
  6711. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6712. else
  6713. $psum='<td class="taR colOrange">-</td>';
  6714. $receiptL['报销金额调整']=$psum.$html;
  6715. }else{
  6716. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6717. <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>';
  6718. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6719. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6720. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6721. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6722. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6723. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6724. }
  6725. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6726. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6727. if(!empty($monthStaffPrice[0]['price'])){
  6728. $m1+=$monthStaffPrice[0]['price'];
  6729. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6730. }else
  6731. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6732. $list[$value['username']]=$receiptL;
  6733. }
  6734. }
  6735. $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>
  6736. <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>
  6737. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6738. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6739. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6740. $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>
  6741. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6742. $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>';
  6743. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6744. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6745. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6746. }
  6747. $data['list']=$list;
  6748. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6749. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6750. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6751. //statistics html
  6752. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6753. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6754. if(empty($stList))
  6755. $stList=array('rePrice'=>0,'agPrice'=>0);
  6756. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6757. $monthHtml="";
  6758. for ($i=1;$i<=12;$i++){
  6759. if ($i==$month)
  6760. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6761. else
  6762. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6763. }
  6764. $data['monthHtml']=$monthHtml;
  6765. $data['year']=$year;
  6766. $data['month']=$month;
  6767. $data['memu']="receipt";
  6768. $data['staff']=$this->staff;
  6769. $data['receiptMemu']='companyCategoryCollect';
  6770. $data['verifyId']=$this->verifyId;
  6771. $data['executeId']=$this->executeId;
  6772. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6773. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6774. }
  6775. function companyMonthCollectDetail(){
  6776. $year=$this->get_args('year')?$this->get_args('year'):"";
  6777. $month=$this->get_args('month')?$this->get_args('month'):"";
  6778. if(!$year)
  6779. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6780. if(!$month)
  6781. $month=isset($this->params['month'])?$this->params['month']:1;
  6782. Doo::loadModel('staff');
  6783. $staff=new staff();
  6784. Doo::loadModel("receiptDetail");
  6785. $receiptDetail=new receiptDetail();
  6786. Doo::loadModel('accountItem');
  6787. $accountItem=new accountItem();
  6788. Doo::loadModel('statistics');
  6789. $statistics=new statistics();
  6790. Doo::loadModel('L_category');
  6791. $lCategory=new L_category();
  6792. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6793. $categoryList=$lCategory->find(array('asArray'=>true));
  6794. $list=array();
  6795. foreach ($categoryList as $value){
  6796. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6797. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6798. if(!empty($receiptCollectList)){
  6799. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6800. $html="";
  6801. $psum=0;
  6802. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6803. foreach ($item as $va){
  6804. $falg=true;
  6805. foreach ($receiptCollectList as $v){
  6806. if($v['itemCategory']=='日常相关费用'){
  6807. if($v['item']==$va){
  6808. $psum+=$v['price'];
  6809. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6810. }
  6811. }
  6812. }
  6813. if($falg)
  6814. $html.='<td class="taR">-</td>';
  6815. }
  6816. if(!empty($psum))
  6817. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6818. else
  6819. $psum='<td class="colGreen taR">-</td>';
  6820. $receiptL['日常相关费用']=$psum.$html;
  6821. /*-----------------------------------*/
  6822. $html="";
  6823. $psum=0;
  6824. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6825. foreach ($item as $va){
  6826. $falg=true;
  6827. foreach ($receiptCollectList as $v){
  6828. if($v['itemCategory']=='差旅相关费用'){
  6829. if($v['item']==$va){
  6830. $psum+=$v['price'];
  6831. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6832. }
  6833. }
  6834. }
  6835. if($falg)
  6836. $html.='<td class="taR">-</td>';
  6837. }
  6838. if(!empty($psum))
  6839. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6840. else
  6841. $psum='<td class="colGreen taR">-</td>';
  6842. $receiptL['差旅相关费用']=$psum.$html;
  6843. /*-------------------------------------*/
  6844. $html="";
  6845. $psum=0;
  6846. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6847. foreach ($item as $va){
  6848. $falg=true;
  6849. foreach ($receiptCollectList as $v){
  6850. if($v['itemCategory']=='培训班费用'){
  6851. if($v['item']==$va){
  6852. $psum+=$v['price'];
  6853. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6854. }
  6855. }
  6856. }
  6857. if($falg)
  6858. $html.='<td class="taR">-</td>';
  6859. }
  6860. if(!empty($psum))
  6861. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6862. else
  6863. $psum='<td class="colGreen taR">-</td>';
  6864. $receiptL['培训班费用']=$psum.$html;
  6865. /*-------------------------------------*/
  6866. $html="";
  6867. $psum=0;
  6868. $item=array('公关费','广告费','借款','可自加费用');
  6869. foreach ($item as $va){
  6870. $falg=true;
  6871. foreach ($receiptCollectList as $v){
  6872. if($v['itemCategory']=='其他'){
  6873. if($v['item']==$va){
  6874. $psum+=$v['price'];
  6875. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6876. }
  6877. }
  6878. }
  6879. if($falg)
  6880. $html.='<td class="taR">-</td>';
  6881. }
  6882. if(!empty($psum))
  6883. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6884. else
  6885. $psum='<td class="colGreen taR">-</td>';
  6886. $receiptL['其他']=$psum.$html;
  6887. /*-------------------------------------*/
  6888. $html="";
  6889. $psum=0;
  6890. foreach ($receiptCollectList as $v){
  6891. if($v['itemCategory']=='报销金额调整'){
  6892. if (!empty($v['price']))
  6893. $psum+=$v['price'];
  6894. }
  6895. }
  6896. if(!empty($psum))
  6897. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6898. else
  6899. $psum='<td class="taR colOrange">-</td>';
  6900. $receiptL['报销金额调整']=$psum.$html;
  6901. }else{
  6902. $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>
  6903. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6904. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6905. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6906. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6907. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6908. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6909. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6910. }
  6911. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6912. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6913. if(!empty($monthStaffPrice[0]['price']))
  6914. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6915. else
  6916. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6917. $list[$value['title']]=$receiptL;
  6918. }
  6919. $data['list']=$list;
  6920. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6921. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6922. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6923. //print_r($data['monthPriceHtml']);
  6924. // foreach ($data['monthPriceHtml'] as $value){
  6925. // echo $value;
  6926. // }
  6927. // die;
  6928. //statistics html
  6929. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6930. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6931. if(empty($stList))
  6932. $stList=array('rePrice'=>0,'agPrice'=>0);
  6933. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6934. $monthHtml="";
  6935. for ($i=1;$i<=12;$i++){
  6936. if ($i==$month)
  6937. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6938. else
  6939. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6940. }
  6941. $data['monthHtml']=$monthHtml;
  6942. $data['year']=$year;
  6943. $data['month']=$month;
  6944. $data['memu']="receipt";
  6945. $data['staff']=$this->staff;
  6946. $data['receiptMemu']='companyCategoryCollect';
  6947. $data['verifyId']=$this->verifyId;
  6948. $data['executeId']=$this->executeId;
  6949. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6950. }
  6951. function staffCollectDetail(){
  6952. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6953. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6954. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6955. if(!$staffname){
  6956. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6957. $staffname= urldecode($staffname);
  6958. }
  6959. Doo::loadModel('staff');
  6960. $staff=new staff();
  6961. Doo::loadModel("receiptDetail");
  6962. $receiptDetail=new receiptDetail();
  6963. Doo::loadModel('accountItem');
  6964. $accountItem=new accountItem();
  6965. Doo::loadModel('statistics');
  6966. $statistics=new statistics();
  6967. Doo::loadModel('L_category');
  6968. $lCategory=new L_category();
  6969. $staffList=$staff->find(array('asArray'=>true));
  6970. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6971. foreach ($staffList as $value){
  6972. if ($value['username']==$staffname&&$value['username']!='admin'){
  6973. $stTitle=$value['category'].'-'.$value['username'];
  6974. $staffId=$value['sid'];
  6975. $cid=$value['cid'];
  6976. $ocid=$value['cid'];
  6977. if (!empty($value['othercid']))
  6978. $cid=$value['cid'].','.$value['othercid'];
  6979. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6980. }elseif ($value['username']!='admin')
  6981. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6982. }
  6983. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6984. if(empty($pcid))
  6985. $pcid=$ocid;
  6986. $data['ocid']=$pcid;
  6987. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6988. $this->showCache($path);
  6989. //
  6990. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6991. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6992. $accountList=$accountItem->find(array('asArray'=>true));
  6993. //create CollectDetail HTML
  6994. $collectHtml=array();
  6995. foreach ($accountList as $key=>$value){
  6996. $html="";$asum=0;
  6997. for ($i=1;$i<=12;$i++){
  6998. $falg=true;
  6999. foreach ($receiptCollectList as $v) {
  7000. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  7001. $asum+=$v['price'];
  7002. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  7003. }
  7004. }
  7005. if($falg)
  7006. $html.='<td class="taR">-</td>';
  7007. }
  7008. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  7009. $collectHtml[$value['category']][$value['name']]=$html;
  7010. }
  7011. $data['collectHtml']=$collectHtml;
  7012. //create Adjustment price html
  7013. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  7014. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  7015. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7016. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  7017. array_push($collectArray['日常相关费用'], $collectHtml);
  7018. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  7019. array_push($collectArray['差旅相关费用'], $collectHtml);
  7020. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  7021. array_push($collectArray['培训班费用'], $collectHtml);
  7022. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  7023. array_push($collectArray['其他'], $collectHtml);
  7024. $data['collectArray']=$collectArray;
  7025. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  7026. array_push($adjustment, $collectHtml);
  7027. $data['adjustment']=$adjustment;
  7028. //total price html
  7029. $collectHtml="";$total=0;
  7030. for ($i=1;$i<=12;$i++){
  7031. $sumPrice=0;
  7032. foreach ($receiptCollectList as $key=>$value){
  7033. if($value['month']==$i){
  7034. $sumPrice+=$value['price'];
  7035. }
  7036. }
  7037. if ($sumPrice==0)
  7038. $collectHtml.='<td class="taR">-</td>';
  7039. else
  7040. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  7041. $total+=$sumPrice;
  7042. }
  7043. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  7044. //statistics html
  7045. $stList=$statistics->statisticsByYear($year,$staffId);
  7046. if(empty($stList))
  7047. $stList=array('rePrice'=>0,'agPrice'=>0);
  7048. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  7049. $data['totalPrice']=$collectHtml;
  7050. $data['totalYear']=$total;
  7051. $data['stHtml']=$stHtml;
  7052. $data['year']=$year;
  7053. $data['stTitle']=$stTitle;
  7054. $data['memu']="receipt";
  7055. $data['staff']=$this->staff;
  7056. $data['receiptMemu']='companyCategoryCollect';
  7057. $data['verifyId']=$this->verifyId;
  7058. $data['executeId']=$this->executeId;
  7059. if ($year<date("Y")){
  7060. Doo::loadModel('receipt');
  7061. $receipt=new receipt();
  7062. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  7063. if(empty($receiptList)){ //generated files
  7064. ob_start();
  7065. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7066. $this->cacheFile($path);die;
  7067. }
  7068. }
  7069. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7070. }
  7071. function BUGFLAG(){
  7072. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  7073. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  7074. $month=$this->get_args('month')?$this->get_args('month'):"";
  7075. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  7076. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  7077. if (empty($status))
  7078. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  7079. $page_size=12;
  7080. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7081. $vidList=array();
  7082. $button=0;
  7083. Doo::loadModel('verify');
  7084. $verify=new verify();
  7085. Doo::loadModel('receipt');
  7086. $receipt=new receipt();
  7087. Doo::loadModel('staff');
  7088. $staff=new staff();
  7089. Doo::loadModel('L_category');
  7090. $Lcategory=new L_category();
  7091. $dateCondition=" and Year(date) =".$year;
  7092. if(!empty($month))
  7093. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  7094. $categoryList=$Lcategory->find(array('asArray'=>true));
  7095. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7096. $cateCondition="";$staffCondition="";$approvalCondition="";
  7097. if (!empty($cid))
  7098. $cateCondition=' and cid='.$cid;
  7099. if(!empty($sid)){
  7100. $staffCondition=' and staff='.$sid;
  7101. $cateCondition="";
  7102. }
  7103. $approvalCondition=" and status=".$status;
  7104. if($status==2){
  7105. //查找角色审批人
  7106. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7107. }
  7108. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7109. $approvalCondition=' and status=2 ';
  7110. }
  7111. if($status==1){
  7112. $approvalCondition=' and (status='.$status.' or status=6) ';
  7113. }
  7114. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7115. $pageinfo['page']=array('previous'=>'');
  7116. if ($status==0){
  7117. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7118. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7119. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7120. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7121. }else
  7122. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7123. ,'desc'=>'rid','asArray'=>true));
  7124. $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
  7125. ,'desc'=>'rid','asArray'=>true));
  7126. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7127. //print_r($pageinfo);
  7128. $Locate=0;
  7129. foreach ($receiptList as $key=>$value){
  7130. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7131. $receiptList[$key]['reviseDetail']=array();
  7132. if (!empty($value['reviseDetail']))
  7133. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7134. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7135. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7136. $receiptList[$key]['category']=$categoryDetil['title'];
  7137. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7138. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7139. $verifyStaff=json_decode($value['verifyStaff'],true);
  7140. foreach ($verifyList as $k=>$v){
  7141. //init verifyStaff
  7142. $verifyList[$k]['date']="";
  7143. $verifyList[$k]['opinion']="";
  7144. $verifyList[$k]['status']="";
  7145. if (empty($verifyStaff)){
  7146. $verifyList[$k]['date']="";
  7147. $verifyList[$k]['opinion']="";
  7148. if ($v[0]==$this->staff[0]['sid']){
  7149. $verifyList[$k]['status']=4;
  7150. $button=4;
  7151. }
  7152. }else{
  7153. $flag=true;
  7154. foreach ($verifyStaff as $m=>$u){
  7155. if ($v[0]==$m){
  7156. $verifyList[$k]['date']=$u['date'];
  7157. $verifyList[$k]['opinion']=$u['opinion'];
  7158. $verifyList[$k]['status']=$u['status'];
  7159. $flag=false;
  7160. break;
  7161. }
  7162. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7163. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7164. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7165. }
  7166. if($flag){//检测可编辑
  7167. if($v[0]==$this->staff[0]['sid']){
  7168. $verifyList[$k]['status']=4;$button=4;
  7169. }
  7170. }
  7171. }
  7172. }
  7173. $receiptList[$key]['verifyList']=$verifyList;
  7174. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7175. $receiptList[$key]['button']=$button;
  7176. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7177. }
  7178. //print_r($receiptList);die;
  7179. //$data['verifyDetail']=$verifyDetail;
  7180. $mothHtml="";
  7181. for($i=1;$i<=12;$i++){
  7182. if($month==$i)
  7183. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7184. else
  7185. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7186. }
  7187. $data['mothHtml']=$mothHtml;
  7188. $data['page']=$pageinfo;
  7189. $data['receiptList']=$receiptList;
  7190. $data['receiptApprovalCount']=count($rLRes);
  7191. $data['status']=$status;
  7192. $data['year']=$year;
  7193. $data['categoryList']=$categoryList;
  7194. $data['staffList']=$staffList;
  7195. $data['cid']=$cid;
  7196. $data['sid']=$sid;
  7197. //print_r($receiptList);
  7198. $data['memu']="receipt";
  7199. $data['staff']=$this->staff;
  7200. $data['receiptMemu']='approvalExpenses';
  7201. $data['verifyId']=$this->verifyId;
  7202. $data['executeId']=$this->executeId;
  7203. $this->render ( "/admin/FALG", $data );
  7204. }
  7205. function ajaxGetReceiptOrder(){
  7206. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7207. if (!empty($receiptOrder)){
  7208. Doo::loadModel('receipt');
  7209. $receipt=new receipt();
  7210. Doo::loadModel ( 'staff' );
  7211. $staff = new staff ();
  7212. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7213. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7214. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7215. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7216. </tbody></table><table class="table table table-bordered"><tbody>';
  7217. foreach ($verifyStaff as $key=>$value){
  7218. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7219. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7220. }
  7221. $html.='</tbody></table></div></div>';
  7222. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7223. }
  7224. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7225. }
  7226. function _getMonthCollectDetail($receiptCollectList){
  7227. if(!empty($receiptCollectList)){
  7228. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7229. $html="";
  7230. $psum=0;
  7231. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7232. foreach ($item as $value){
  7233. $falg=true;
  7234. foreach ($receiptCollectList as $v){
  7235. if($v['itemCategory']=='日常相关费用'){
  7236. if($v['item']==$value){
  7237. $psum+=$v['price'];
  7238. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7239. }
  7240. }
  7241. }
  7242. if($falg)
  7243. $html.='<td class="taR">-</td>';
  7244. }
  7245. if(!empty($psum))
  7246. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7247. else
  7248. $psum='<td class="colGreen taR">-</td>';
  7249. $receiptL['日常相关费用']=$psum.$html;
  7250. /*-----------------------------------*/
  7251. $html="";
  7252. $psum=0;
  7253. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7254. foreach ($item as $value){
  7255. $falg=true;
  7256. foreach ($receiptCollectList as $v){
  7257. if($v['itemCategory']=='差旅相关费用'){
  7258. if($v['item']==$value){
  7259. $psum+=$v['price'];
  7260. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7261. }
  7262. }
  7263. }
  7264. if($falg)
  7265. $html.='<td class="taR">-</td>';
  7266. }
  7267. if(!empty($psum))
  7268. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7269. else
  7270. $psum='<td class="colGreen taR">-</td>';
  7271. $receiptL['差旅相关费用']=$psum.$html;
  7272. /*-------------------------------------*/
  7273. $html="";
  7274. $psum=0;
  7275. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7276. foreach ($item as $value){
  7277. $falg=true;
  7278. foreach ($receiptCollectList as $v){
  7279. if($v['itemCategory']=='培训班费用'){
  7280. if($v['item']==$value){
  7281. $psum+=$v['price'];
  7282. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7283. }
  7284. }
  7285. }
  7286. if($falg)
  7287. $html.='<td class="taR">-</td>';
  7288. }
  7289. if(!empty($psum))
  7290. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7291. else
  7292. $psum='<td class="colGreen taR">-</td>';
  7293. $receiptL['培训班费用']=$psum.$html;
  7294. /*-------------------------------------*/
  7295. $html="";
  7296. $psum=0;
  7297. $item=array('公关费','广告费','借款','可自加费用');
  7298. foreach ($item as $value){
  7299. $falg=true;
  7300. foreach ($receiptCollectList as $v){
  7301. if($v['itemCategory']=='其他'){
  7302. if($v['item']==$value){
  7303. $psum+=$v['price'];
  7304. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7305. }
  7306. }
  7307. }
  7308. if($falg)
  7309. $html.='<td class="taR">-</td>';
  7310. }
  7311. if(!empty($psum))
  7312. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7313. else
  7314. $psum='<td class="colGreen taR">-</td>';
  7315. $receiptL['其他']=$psum.$html;
  7316. /*-------------------------------------*/
  7317. $html="";
  7318. $psum=0;
  7319. foreach ($receiptCollectList as $v){
  7320. if($v['itemCategory']=='报销金额调整'){
  7321. if (!empty($v['price']))
  7322. $psum+=$v['price'];
  7323. }
  7324. }
  7325. if(!empty($psum))
  7326. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7327. else
  7328. $psum='<td class="taR colOrange">-</td>';
  7329. $receiptL['报销金额调整']=$psum.$html;
  7330. }else{
  7331. $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>
  7332. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7333. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7334. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7335. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7336. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7337. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7338. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7339. }
  7340. return $receiptL;
  7341. }
  7342. function eMail(){
  7343. Doo::loadModel('staff');
  7344. $staff=new staff();
  7345. Doo::loadModel('receipt');
  7346. $receipt=new receipt();
  7347. Doo::loadModel('L_category');
  7348. $Lcategory=new L_category();
  7349. Doo::loadModel("verify");
  7350. $verify=new verify();
  7351. $staffList=$staff->find(array('asArray'=>true));
  7352. foreach ($staffList as $key=>$value){
  7353. if($value['username']!='admin'){
  7354. //提交人
  7355. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7356. if(!empty($receiptList)){
  7357. $html='<br><div><style></style>
  7358. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7359. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7360. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7361. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7362. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7363. <tbody><tr>
  7364. <td style="padding: 0 40px;" align="left">
  7365. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7366. </td></tr><tr>
  7367. <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>
  7368. </tr>
  7369. </tbody> </table></td> </tr> <tr><td>
  7370. <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">
  7371. <tbody> <tr><td>
  7372. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7373. 以下报销单完成了审批,等着收款吧:</p>
  7374. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7375. foreach ($receiptList as $k=>$v){
  7376. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7377. $html.='
  7378. <tr>
  7379. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7380. <td align="left">
  7381. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7382. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7383. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7384. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7385. </tr>';
  7386. }
  7387. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7388. <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>
  7389. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7390. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7391. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7392. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7393. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7394. $receipt=new receipt();
  7395. $receipt->notice=1;
  7396. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7397. }
  7398. }
  7399. //审批人
  7400. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7401. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7402. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7403. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7404. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7405. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7406. <tbody><tr><td style="padding: 0 40px;" align="left">
  7407. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7408. </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>
  7409. </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">
  7410. <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>
  7411. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7412. foreach ($verifyList as $k=>$v){
  7413. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7414. foreach ($receiptList as $r=>$l){
  7415. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7416. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7417. $html.='
  7418. <tr>
  7419. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7420. <td align="left">
  7421. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7422. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7423. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7424. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7425. </tr>';
  7426. }
  7427. }
  7428. $html.='
  7429. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7430. <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>
  7431. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7432. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7433. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7434. // $receipt=new receipt();
  7435. // $receipt->notice=1;
  7436. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7437. }
  7438. }
  7439. }
  7440. }
  7441. function setWXMsg($rid,$type){
  7442. Doo::loadModel("receipt");
  7443. $receipt=new receipt();
  7444. $receiptDetail = $receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  7445. if(!empty($receiptDetail)){
  7446. Doo::loadModel('staff');
  7447. $staff = new staff();
  7448. $staffmsg = $staff->getStaffBySid($receiptDetail['staff']);
  7449. if(!empty($staffmsg['wxid'])){
  7450. require_once (SITE_PATH . '/protected/class/client.php');
  7451. $client = new client ('http://m.cld.smartcost.com.cn/');
  7452. $user = $staffmsg['wxid'];
  7453. $receiptName = '';
  7454. $msg = '';
  7455. switch($receiptDetail['Rtype']){
  7456. case 0:$receiptName = '报销';break;
  7457. case 1:$receiptName = '借款';break;
  7458. case 2:$receiptName = '对公汇款';break;
  7459. }
  7460. switch($type){
  7461. case 1:$msg = '太好了,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已同意支付。';break;
  7462. case 2:$msg = '注意,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被撤回,请及时处理。';break;
  7463. case 3:$msg = '很遗憾,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被终止。';break;
  7464. }
  7465. $result = $client->SendMsg($user,$msg,'text');
  7466. }
  7467. }
  7468. }
  7469. // Email发送函数
  7470. function SMail($toemail, $subject, $contents) {
  7471. Doo::loadClass('class.phpmailer');
  7472. $mail = new PHPMailer();
  7473. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7474. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7475. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7476. $mail->Password = "cDO1GjtY1seH"; //密码
  7477. $mail->CharSet = "UTF8";
  7478. $mail->SMTPAuth = true;
  7479. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7480. $mail->Mailer = "smtp";
  7481. $mail->Port = 25;
  7482. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7483. $mail->MsgHTML($contents);
  7484. $mail->AddAddress($toemail);
  7485. $mail->CharSet = "UTF-8";
  7486. return $mail->Send();
  7487. }
  7488. function swfupload(){
  7489. $POST_MAX_SIZE = ini_get('post_max_size');
  7490. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7491. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7492. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7493. header("HTTP/1.1 500 Internal Server Error");
  7494. echo "POST exceeded maximum allowed size.";
  7495. exit(0);
  7496. }
  7497. // Settings
  7498. $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)
  7499. $upload_name = "Filedata";
  7500. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7501. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7502. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7503. // Other variables
  7504. $MAX_FILENAME_LENGTH = 260;
  7505. $file_name = "";
  7506. $file_extension = "";
  7507. $uploadErrors = array(
  7508. 0=>"文件上传成功",
  7509. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7510. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7511. 3=>"上传的文件仅为部分文件",
  7512. 4=>"没有文件上传",
  7513. 6=>"缺少临时文件夹"
  7514. );
  7515. $nk= time();
  7516. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7517. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7518. echo "文件无法保存.";
  7519. exit(0);
  7520. }
  7521. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7522. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7523. exit(0);
  7524. }
  7525. function _GetFileEXT($filename) {
  7526. $pics = explode ( '.', $filename );
  7527. $num = count ( $pics );
  7528. return $pics [$num - 1];
  7529. }
  7530. /**
  7531. * 获取get或者POST值
  7532. * @param string $name 属性名称
  7533. * @return fixed 值
  7534. */
  7535. function get_args($name) {
  7536. if (isset ( $_GET [$name] )) {
  7537. if (is_array ( $_GET [$name] ))
  7538. return $_GET [$name];
  7539. else
  7540. return addslashes ( $_GET [$name] );
  7541. } elseif (isset ( $_POST [$name] )) {
  7542. if (is_array ( $_POST [$name] ))
  7543. return $_POST [$name];
  7544. else
  7545. return addslashes ( $_POST [$name] );
  7546. } else
  7547. return false;
  7548. }
  7549. function num_to_rmb($num){
  7550. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7551. $c2 = "分角元拾佰仟万拾佰仟亿";
  7552. //精确到分后面就不要了,所以只留两个小数位
  7553. $num = round($num, 2);
  7554. //将数字转化为整数
  7555. $num = $num * 100;
  7556. if (strlen($num) > 10) {
  7557. return "金额太大,请检查";
  7558. }
  7559. $i = 0;
  7560. $c = "";
  7561. while (1) {
  7562. if ($i == 0) {
  7563. //获取最后一位数字
  7564. $n = substr($num, strlen($num)-1, 1);
  7565. } else {
  7566. $n = $num % 10;
  7567. }
  7568. //每次将最后一位数字转化为中文
  7569. $p1 = substr($c1, 3 * $n, 3);
  7570. $p2 = substr($c2, 3 * $i, 3);
  7571. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7572. $c = $p1 . $p2 . $c;
  7573. } else {
  7574. $c = $p1 . $c;
  7575. }
  7576. $i = $i + 1;
  7577. //去掉数字最后一位了
  7578. $num = $num / 10;
  7579. $num = (int)$num;
  7580. //结束循环
  7581. if ($num == 0) {
  7582. break;
  7583. }
  7584. }
  7585. $j = 0;
  7586. $slen = strlen($c);
  7587. while ($j < $slen) {
  7588. //utf8一个汉字相当3个字符
  7589. $m = substr($c, $j, 6);
  7590. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7591. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7592. $left = substr($c, 0, $j);
  7593. $right = substr($c, $j + 3);
  7594. $c = $left . $right;
  7595. $j = $j-3;
  7596. $slen = $slen-3;
  7597. }
  7598. $j = $j + 3;
  7599. }
  7600. //这个是为了去掉类似23.0中最后一个“零”字
  7601. if (substr($c, strlen($c)-3, 3) == '零') {
  7602. $c = substr($c, 0, strlen($c)-3);
  7603. }
  7604. //将处理的汉字加上“整”
  7605. if (empty($c)) {
  7606. return "零元整";
  7607. }else{
  7608. return $c . "整";
  7609. }
  7610. }
  7611. /**
  7612. * 获得分页数据
  7613. * @param unknown_type $table
  7614. * @param unknown_type $condition
  7615. * @param unknown_type $on_page
  7616. * @param unknown_type $page_size
  7617. */
  7618. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7619. $page_c = "";
  7620. $page ['previous'] = $this->get_previous ( $on_page );
  7621. $page ['on_page'] = $on_page;
  7622. $total_count = $this->get_table_count ( $table, $condition );
  7623. $total = intval ( $total_count / $page_size );
  7624. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7625. $page ['total_data'] = $total_count;
  7626. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7627. $i = 1;
  7628. $page_max = 1;
  7629. $page_width=3;
  7630. if ($on_page >= $page_width) {
  7631. $page_max = intval ( $on_page / $page_width ) + 1;
  7632. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7633. }
  7634. for(; $i <= $page ['total_page']; $i ++) {
  7635. if ($i == $on_page)
  7636. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7637. else
  7638. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7639. if ($i == ($page_width * $page_max))
  7640. break;
  7641. }
  7642. $page ['page'] = $page_c;
  7643. $page ['lower'] = (-- $on_page) * $page_size;
  7644. return $page;
  7645. }
  7646. /**
  7647. * 获取总页数
  7648. * @param unknown_type $table
  7649. * @param unknown_type $condition
  7650. */
  7651. public function get_table_count($table = "", $condition = "") {
  7652. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7653. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7654. //echo $sql;die;
  7655. $query = Doo::db ()->query ( $sql );
  7656. $result = $query->fetch ();
  7657. return $result ['count'];
  7658. }
  7659. /**
  7660. * 获取上一页
  7661. * @param unknown_type $on_page
  7662. */
  7663. function get_previous($on_page = 1) {
  7664. return $on_page != 0 ? $on_page - 1 : $on_page;
  7665. }
  7666. }
  7667. ?>