ReceiptController.php 349 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076
  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;
  22. die ();
  23. }
  24. }
  25. private function cacheFile($path) {
  26. $content = ob_get_contents ();
  27. $fp = fopen ( $path, "w" );
  28. fwrite ( $fp, $content );
  29. fclose ( $fp );
  30. }
  31. // private function getExeCount(){
  32. // Doo::loadModel('receipt');
  33. // $receipt=new receipt();
  34. // $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  35. // return count($receiptList);
  36. // }
  37. // private function getReceiptCount(){
  38. // $status=2;
  39. // $year=date('Y');
  40. // Doo::loadModel('receipt');
  41. // $receipt=new receipt();
  42. // $dateCondition=" and Year(date) =".$year;
  43. // $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  44. // $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  45. // return count($receiptList);
  46. // }
  47. private function collectHtml($receiptCollectList = array(), $itemCategory = "日常相关费用", $classType = "b") {
  48. $collectHtml = "";
  49. $sumPrice = 0.00;
  50. for($i = 1; $i <= 12; $i ++) {
  51. $falg = true;
  52. foreach ( $receiptCollectList as $key => $value ) {
  53. if ($value ['itemCategory'] == $itemCategory && $value ['month'] == $i) {
  54. $sumPrice += $value ['price'];
  55. if ($classType == "b") {
  56. $collectHtml .= '<td class="colGreen taR">¥' . $value ['price'] . '</td>';
  57. $falg = false;
  58. break;
  59. } else {
  60. $collectHtml .= '<td class="taR">¥' . $value ['price'] . '</td>';
  61. $falg = false;
  62. break;
  63. }
  64. }
  65. }
  66. if ($falg)
  67. $collectHtml .= '<td class="taR">-</td>';
  68. }
  69. $collectHtml .= '<td class="taR colGreen">¥' . $sumPrice . '</td>';
  70. return $collectHtml;
  71. }
  72. function __construct() {
  73. if (isset ( $_COOKIE ["staff"] )) {
  74. if (! empty ( $_COOKIE ["staff"] )) {
  75. Doo::loadModel ( 'staff' );
  76. Doo::loadModel ( 'verify' );
  77. $verify = new verify ();
  78. $staff = new staff ();
  79. Doo::loadModel ( "execute" );
  80. $execute = new execute ();
  81. $verifyList = $verify->find ( array (
  82. 'select' => 'staff',
  83. 'asArray' => true
  84. ) );
  85. $list = array ();
  86. // 判断角色的审批权限
  87. foreach ( $verifyList as $key => $value ) {
  88. $ver = json_decode ( $value ['staff'] );
  89. foreach ( $ver as $k => $v ) {
  90. if ($v [1] == 'ROLE') {
  91. $roleList = json_decode ( $v [3] );
  92. foreach ( $roleList as $t => $g ) {
  93. $gList = explode ( "_", $g );
  94. array_push ( $list, $gList [0] );
  95. // print_r($list);
  96. }
  97. } else
  98. array_push ( $list, $v [0] );
  99. }
  100. }
  101. // 判断执行人的审批权限
  102. $executeList = $execute->find ( array (
  103. 'select' => 'staff',
  104. 'asArray' => true
  105. ) );
  106. $list2 = array ();
  107. foreach ( $executeList as $key => $value ) {
  108. $ver = json_decode ( $value ['staff'] );
  109. foreach ( $ver as $k => $v ) {
  110. array_push ( $list2, $v [0] );
  111. }
  112. }
  113. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  114. $eidList = array_filter ( explode ( ",", $eidList ) );
  115. $this->executeId = array_merge ( $list2, $eidList );
  116. $this->verifyId = $list;
  117. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  118. return "/";
  119. }
  120. }
  121. Doo::loadCore ( 'uri/DooUriRouter' );
  122. $router = new DooUriRouter ();
  123. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  124. if ($routeRs ['1'] != "login") {
  125. header ( 'Content-Type:text/html;charset=utf-8' );
  126. @header ( "Location: /login" );
  127. }
  128. }
  129. function saeaBorad() {
  130. Doo::loadModel ( 'receipt' );
  131. Doo::loadModel ( 'verify' );
  132. $verify = new verify ();
  133. $receipt = new receipt ();
  134. Doo::loadModel ( 'L_category' );
  135. $lCategory = new L_category ();
  136. Doo::loadModel ( "role" );
  137. $role = new role ();
  138. Doo::loadModel ( "receiptLog" );
  139. $receiptLog = new receiptLog ();
  140. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  141. $receiptDetail = $receipt->find ( array (
  142. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  143. 'desc' => 'rid',
  144. 'asArray' => true
  145. ) );
  146. foreach ( $receiptDetail as $key => $value ) {
  147. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  148. $veList = $verify->getOne ( array (
  149. 'where' => 'vid=' . $value ['verify'],
  150. 'asArray' => true
  151. ) );
  152. $v = json_decode ( $veList ['staff'] );
  153. array_push ( $v [0], $veList ['description'] );
  154. foreach ( $v as $n => $m ) {
  155. if ($m ['1'] == 'ROLE') {
  156. $roleInfo = $role->getOne ( array (
  157. 'where' => 'rid=' . $m [0],
  158. 'asArray' => true
  159. ) );
  160. $v [$n] [1] = $roleInfo ['name'];
  161. }
  162. }
  163. $receiptDetail [$key] ['staff'] = $v;
  164. $category = $lCategory->getOne ( array (
  165. 'where' => 'cid=' . $value ['cid'],
  166. 'asArray' => true
  167. ) );
  168. $receiptDetail [$key] ['category'] = $category ['title'];
  169. }
  170. // print_r($receiptLogList);
  171. $data ['receiptLogList'] = $receiptLogList;
  172. $data ['receiptDetail'] = $receiptDetail;
  173. $data ['memu'] = "receipt";
  174. $data ['staff'] = $this->staff;
  175. $data ['receiptMemu'] = 'saeaBorad';
  176. $data ['verifyId'] = $this->verifyId;
  177. $data ['executeId'] = $this->executeId;
  178. $this->render ( "/admin/saeaBorad", $data );
  179. }
  180. function remitAdd() {
  181. Doo::loadModel ( 'accountItem' );
  182. Doo::loadModel ( 'verify' );
  183. Doo::loadModel ( 'receipt' );
  184. Doo::loadModel ( 'L_category' );
  185. $lCategory = new L_category ();
  186. $receipt = new receipt ();
  187. $verify = new verify ();
  188. $accountItem = new accountItem ();
  189. Doo::loadModel ( "role" );
  190. $role = new role ();
  191. $acItem = $accountItem->find ( array (
  192. 'asArray' => true
  193. ) );
  194. $veList = $verify->find ( array (
  195. 'asArray' => true
  196. ) );
  197. foreach ( $veList as $key => $value ) {
  198. $v = json_decode ( $value ['staff'] );
  199. $list = array ();
  200. foreach ( $v as $n => $m ) {
  201. if ($m ['1'] == 'ROLE') {
  202. $roleInfo = $role->getOne ( array (
  203. 'where' => 'rid=' . $m [0],
  204. 'asArray' => true
  205. ) );
  206. $v [$n] [1] = $roleInfo ['name'];
  207. array_push ( $list, $roleInfo ['name'] );
  208. } else {
  209. array_push ( $list, $v [$n] [1] );
  210. }
  211. }
  212. $veList [$key] ['staff'] = implode ( '>', $list );
  213. }
  214. $data ['category'] = $lCategory->find ( array (
  215. 'asArray' => true
  216. ) );
  217. $data ['veList'] = $veList;
  218. $data ['acItem'] = $acItem;
  219. $data ['memu'] = "receipt";
  220. $data ['staff'] = $this->staff;
  221. $data ['receiptMemu'] = 'saeaBorad';
  222. $data ['verifyId'] = $this->verifyId;
  223. $data ['executeId'] = $this->executeId;
  224. $this->render ( "/admin/remitAdd", $data );
  225. }
  226. function remitAddDo() {
  227. $agency = $this->get_args ( 'agency' );
  228. $travel = $this->get_args ( 'travel' );
  229. $train = $this->get_args ( 'train' );
  230. $other = $this->get_args ( 'other' );
  231. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  232. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  233. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  234. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  235. // print_r($agency);die;
  236. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation )) {
  237. Doo::loadModel ( 'receipt' );
  238. Doo::loadModel ( 'receiptDetail' );
  239. Doo::loadModel ( 'accountItem' );
  240. $accountItem = new accountItem ();
  241. $receipt = new receipt ();
  242. Doo::loadModel ( 'enclosur' );
  243. Doo::loadModel ( 'execute' );
  244. $execute = new execute ();
  245. $executeDetail = $execute->getOne ( array (
  246. 'where' => 'mold="对公汇款执行人"',
  247. 'asArray' => true
  248. ) );
  249. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  250. $aItem = $accountItem->find ( array (
  251. 'where' => 'name like "办公费用" or name like "其他费用"',
  252. 'asArray' => true
  253. ) );
  254. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  255. $ag = $tr = $ta = $ot = 0;
  256. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  257. foreach ( $aItem as $key => $value ) {
  258. if ($value ['category'] == $this->AGENCY) {
  259. if (isset ( $agency [$ag] )) {
  260. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  261. array_push ( $accountJson [$this->AGENCY], array (
  262. 'aid' => $value ['aid'],
  263. 'name' => $value ['name'],
  264. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  265. ) );
  266. $sum += $agency [$ag];
  267. $agencySum += $agency [$ag];
  268. }
  269. }
  270. $ag ++;
  271. }
  272. }
  273. $accountJson ['cSum'] = array (
  274. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  275. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  276. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  277. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  278. );
  279. // 报销单
  280. $receipt->accountItem = json_encode ( $accountJson );
  281. $receipt->staff = $this->staff [0] ['sid'];
  282. $receipt->sum = number_format ( $sum, 2, '.', '' );
  283. $receipt->date = date ( "Y-m-d" );
  284. $receipt->cid = $cid;
  285. $receipt->status = 5;
  286. $receipt->Rtype = 2;
  287. // 修改审批流程加入角色
  288. $receipt->verify = $verify;
  289. $receipt->executeCopy = $executeDetail ['staff'];
  290. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  291. $receipt->explanation = $explanation;
  292. $rid = $receipt->insert ();
  293. // 附件
  294. if (! empty ( $enclosurName )) {
  295. $enclosurArray = explode ( '-', $enclosurName );
  296. foreach ( $enclosurArray as $value ) {
  297. $enclosur = new enclosur ();
  298. $enclosur->name = $value;
  299. $enclosur->rid = $rid;
  300. $enclosur->insert ();
  301. }
  302. // print_r($enclosurArray);die;
  303. }
  304. // 报销详情
  305. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  306. $receiptDetail = new receiptDetail ();
  307. $receiptDetail->staff = $this->staff [0] ['sid'];
  308. $receiptDetail->item = $value ['name'];
  309. $receiptDetail->itemCategory = $this->AGENCY;
  310. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  311. $receiptDetail->date = date ( "Y-m-d" );
  312. $receiptDetail->cid = $cid;
  313. $receiptDetail->rid = $rid;
  314. $receiptDetail->status = 4;
  315. $receiptDetail->insert ();
  316. }
  317. }
  318. return "/saeaBorad";
  319. }
  320. function remitEdit() {
  321. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  322. // echo $rid;
  323. Doo::loadModel ( 'accountItem' );
  324. Doo::loadModel ( 'verify' );
  325. Doo::loadModel ( 'receipt' );
  326. $receipt = new receipt ();
  327. $verify = new verify ();
  328. $accountItem = new accountItem ();
  329. Doo::loadModel ( 'L_category' );
  330. $lCategory = new L_category ();
  331. Doo::loadModel ( "role" );
  332. $role = new role ();
  333. $receiptDetail = $receipt->getOne ( array (
  334. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  335. 'asArray' => true
  336. ) );
  337. if (empty ( $receiptDetail ))
  338. return "/saeaCreate";
  339. $acItem = $accountItem->find ( array (
  340. 'asArray' => true
  341. ) );
  342. $veList = $verify->find ( array (
  343. 'asArray' => true
  344. ) );
  345. foreach ( $veList as $key => $value ) {
  346. $v = json_decode ( $value ['staff'] );
  347. $list = array ();
  348. foreach ( $v as $n => $m ) {
  349. if ($m ['1'] == 'ROLE') {
  350. $roleInfo = $role->getOne ( array (
  351. 'where' => 'rid=' . $m [0],
  352. 'asArray' => true
  353. ) );
  354. $v [$n] [1] = $roleInfo ['name'];
  355. array_push ( $list, $roleInfo ['name'] );
  356. } else {
  357. array_push ( $list, $v [$n] [1] );
  358. }
  359. }
  360. $veList [$key] ['staff'] = implode ( '>', $list );
  361. }
  362. // 配置编辑信息
  363. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  364. foreach ( $acItem as $key => $value ) {
  365. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  366. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  367. $acItem [$key] ['price'] = $v ['price'];
  368. }
  369. }
  370. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  371. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  372. $acItem [$key] ['price'] = $v ['price'];
  373. }
  374. }
  375. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  376. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  377. $acItem [$key] ['price'] = $v ['price'];
  378. }
  379. }
  380. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  381. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  382. $acItem [$key] ['price'] = $v ['price'];
  383. }
  384. }
  385. }
  386. $data ['category'] = $lCategory->find ( array (
  387. 'asArray' => true
  388. ) );
  389. $data ['cSum'] = $accountItemList ['cSum'];
  390. $data ['sum'] = $receiptDetail ['sum'];
  391. $data ['receiptDetail'] = $receiptDetail;
  392. $data ['veList'] = $veList;
  393. $data ['acItem'] = $acItem;
  394. $data ['memu'] = "receipt";
  395. $data ['staff'] = $this->staff;
  396. $data ['receiptMemu'] = 'saeaBorad';
  397. $data ['verify'] = $receiptDetail ['verify'];
  398. $data ['verifyId'] = $this->verifyId;
  399. $data ['executeId'] = $this->executeId;
  400. $data ['rid'] = $rid;
  401. $this->render ( "/admin/remitEdit", $data );
  402. }
  403. function remitEdiDo() {
  404. $agency = $this->get_args ( 'agency' );
  405. $travel = $this->get_args ( 'travel' );
  406. $train = $this->get_args ( 'train' );
  407. $other = $this->get_args ( 'other' );
  408. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  409. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  410. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  411. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  412. if (! empty ( $explanation )) {
  413. Doo::loadModel ( 'receipt' );
  414. Doo::loadModel ( 'receiptDetail' );
  415. Doo::loadModel ( 'accountItem' );
  416. $accountItem = new accountItem ();
  417. $receipt = new receipt ();
  418. Doo::loadModel ( 'execute' );
  419. $execute = new execute ();
  420. $executeDetail = $execute->getOne ( array (
  421. 'where' => 'mold="对公汇款执行人"',
  422. 'asArray' => true
  423. ) );
  424. $receiptDetail = $receipt->getOne ( array (
  425. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  426. 'asArray' => true
  427. ) );
  428. if (empty ( $receiptDetail ))
  429. return "/saeaBorad";
  430. $aItem = $accountItem->find ( array (
  431. 'where' => 'name like "办公费用" or name like "其他费用"',
  432. 'asArray' => true
  433. ) );
  434. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  435. $ag = $tr = $ta = $ot = 0;
  436. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  437. foreach ( $aItem as $key => $value ) {
  438. if ($value ['category'] == $this->AGENCY) {
  439. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  440. array_push ( $accountJson [$this->AGENCY], array (
  441. 'aid' => $value ['aid'],
  442. 'name' => $value ['name'],
  443. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  444. ) );
  445. $sum += $agency [$ag];
  446. $agencySum += $agency [$ag];
  447. }
  448. $ag ++;
  449. }
  450. }
  451. $accountJson ['cSum'] = array (
  452. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  453. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  454. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  455. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  456. );
  457. // 报销单
  458. $rid = $receipt->rid = $receiptDetail ['rid'];
  459. $receipt->accountItem = json_encode ( $accountJson );
  460. $receipt->staff = $this->staff [0] ['sid'];
  461. $receipt->sum = number_format ( $sum, 2, '.', '' );
  462. $receipt->date = date ( "Y-m-d" );
  463. $receipt->cid = $cid;
  464. if ($receiptDetail ['Rtype'] == 1)
  465. $receipt->status = 7;
  466. else
  467. $receipt->status = 5;
  468. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  469. $receipt->verify = $verify;
  470. $receipt->executeCopy = $executeDetail ['staff'];
  471. $receipt->explanation = $explanation;
  472. $receipt->update ();
  473. $receiptDetail = new receiptDetail ();
  474. $receiptDetail->delete ( array (
  475. 'where' => 'rid=' . $rid
  476. ) );
  477. // 报销详情
  478. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  479. $receiptDetail = new receiptDetail ();
  480. $receiptDetail->staff = $this->staff [0] ['sid'];
  481. $receiptDetail->item = $value ['name'];
  482. $receiptDetail->itemCategory = $this->AGENCY;
  483. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  484. $receiptDetail->date = date ( "Y-m-d" );
  485. $receiptDetail->cid = $cid;
  486. $receiptDetail->rid = $rid;
  487. $receiptDetail->status = 4;
  488. $receiptDetail->insert ();
  489. }
  490. // return "/referReceipt/".$rid;
  491. }
  492. return "/saeaBorad";
  493. }
  494. function remitApproval() {
  495. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  496. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  497. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  498. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  499. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  500. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  501. if (empty ( $status ))
  502. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  503. $vidList = array ();
  504. $button = 0;
  505. Doo::loadModel ( 'verify' );
  506. Doo::loadModel ( 'receipt' );
  507. Doo::loadModel ( 'staff' );
  508. $staff = new staff ();
  509. $receipt = new receipt ();
  510. $verify = new verify ();
  511. Doo::loadModel ( 'L_category' );
  512. $Lcategory = new L_category ();
  513. Doo::loadModel ( 'enclosur' );
  514. $enclosur = new enclosur ();
  515. // user verify ID
  516. $verifyDetail = $verify->find ( array (
  517. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  518. 'asArray' => true
  519. ) );
  520. foreach ( $verifyDetail as $key => $value ) {
  521. array_push ( $vidList, $value ['vid'] );
  522. }
  523. $vid = implode ( ",", $vidList );
  524. if (empty ( $verifyDetail ))
  525. $vid = 0;
  526. $categoryList = $Lcategory->find ( array (
  527. 'asArray' => true
  528. ) );
  529. $staffList = $staff->find ( array (
  530. 'where' => 'cid=' . $cid,
  531. 'asArray' => true
  532. ) );
  533. $ap = "";
  534. if ($status == 4) {
  535. $ap = 4;
  536. $status = 2;
  537. }
  538. // get Receipt By verifyID status 2
  539. $receiptList = $receipt->find ( array (
  540. 'where' => 'rid =' . $rid,
  541. 'desc' => 'rid',
  542. 'asArray' => true
  543. ) );
  544. $Locate = 0;
  545. $roleId = 0;
  546. if ($ap == 4)
  547. $status = 4;
  548. foreach ( $receiptList as $key => $value ) {
  549. $receiptList [$key] ['Locate'] = $Locate;
  550. $Locate ++;
  551. $receiptList [$key] ['reviseDetail'] = array ();
  552. if (! empty ( $value ['reviseDetail'] ))
  553. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  554. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  555. $categoryDetil = $Lcategory->getOne ( array (
  556. 'where' => 'cid=' . $value ['cid'],
  557. 'asArray' => true
  558. ) );
  559. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  560. // 检测编辑状态
  561. $verifyList = $verify->getOne ( array (
  562. 'where' => 'vid=' . $value ['verify'],
  563. 'asArray' => true
  564. ) );
  565. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  566. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  567. Doo::loadModel ( 'role' );
  568. $role = new role ();
  569. // print_r($verifyList);
  570. $flag = true;
  571. $roleKey = 0;
  572. $endStaffArray = array ();
  573. $roleArrayCopy = array ();
  574. foreach ( $verifyList as $k => $v ) {
  575. // init verifyStaff
  576. if ($v [1] == 'ROLE') {
  577. if (! empty ( $verifyStaff )) {
  578. $endStaffArray = end ( $verifyStaff );
  579. if ($v [0] == $endStaffArray ['nextStaff']) {
  580. $roleId = $v [0];
  581. }
  582. }
  583. $roleVerify = json_decode ( $v [3], true );
  584. $roleKey = $k;
  585. $roleArray = array ();
  586. $rolename = $role->getOne ( array (
  587. 'where' => 'rid=' . $v [0],
  588. 'asArray' => true
  589. ) );
  590. foreach ( $roleVerify as $o => $p ) {
  591. $staffID = explode ( '_', $p );
  592. $staffInfo = $staff->getOne ( array (
  593. 'where' => 'sid=' . $staffID [0],
  594. 'asArray' => true
  595. ) );
  596. // print_r($staffID);
  597. $exp = array (
  598. 0 => $staffInfo ['sid'],
  599. 1 => $staffID [1],
  600. 2 => $staffInfo ['avatar'],
  601. 'date' => '',
  602. 'date' => '',
  603. 'opinion' => '',
  604. 'status' => '',
  605. 'rolename' => $rolename ['name']
  606. );
  607. array_push ( $roleArray, $exp );
  608. }
  609. $roleArrayCopy [$v [0]] = $roleArray;
  610. // $verifyList[$k]['roleArray']=$roleArray;
  611. }
  612. // print_r($roleArray);
  613. $verifyList [$k] ['date'] = "";
  614. $verifyList [$k] ['opinion'] = "";
  615. $verifyList [$k] ['status'] = "";
  616. if (empty ( $verifyStaff )) {
  617. $verifyList [$k] ['date'] = "";
  618. $verifyList [$k] ['opinion'] = "";
  619. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  620. $verifyList [$k] ['status'] = 4;
  621. $button = 4;
  622. $flag = false;
  623. }
  624. } else {
  625. foreach ( $verifyStaff as $m => $u ) {
  626. if ($v [0] == $m) {
  627. $verifyList [$k] ['date'] = $u ['date'];
  628. $verifyList [$k] ['opinion'] = $u ['opinion'];
  629. $verifyList [$k] ['status'] = $u ['status'];
  630. $flag = false;
  631. break;
  632. }
  633. }
  634. $endStaffArray = end ( $verifyStaff );
  635. if (isset ( $endStaffArray ['ROLE'] )) {
  636. } else {
  637. $endKey = key ( $verifyStaff );
  638. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  639. $button = 4;
  640. $verifyList [$k] ['status'] = 4;
  641. }
  642. }
  643. }
  644. }
  645. $rolename ['name'] = '';
  646. if (! empty ( $roleId )) {
  647. Doo::loadModel ( 'role' );
  648. $role = new role ();
  649. $rolename = $role->getOne ( array (
  650. 'where' => 'rid=' . $roleId,
  651. 'asArray' => true
  652. ) );
  653. }
  654. if (! empty ( $verifyStaff ))
  655. $endStaffArray = end ( $verifyStaff );
  656. $KOP = false;
  657. foreach ( $roleArrayCopy as $P => $A ) {
  658. foreach ( $A as $MKI => $AVL ) {
  659. if (! empty ( $verifyStaff )) {
  660. // &&$rolename['rid']==$endStaffArray['nextStaff']
  661. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  662. $button = 4;
  663. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  664. }
  665. foreach ( $verifyStaff as $m => $u ) {
  666. $AVLFK = $AVL [0] . '_R';
  667. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  668. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  669. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  670. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  671. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  672. break;
  673. }
  674. }
  675. } else {
  676. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  677. $button = 4;
  678. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  679. }
  680. }
  681. // $roleArray[$MKI]['rolename']=$rolename['name'];
  682. $KOP = true;
  683. }
  684. }
  685. foreach ( $roleArrayCopy as $k => $v ) {
  686. foreach ( $verifyList as $m => $n ) {
  687. if ($n [0] == $k) {
  688. array_splice ( $verifyList, $m, 1, $v );
  689. }
  690. }
  691. }
  692. $receiptList [$key] ['verifyList'] = $verifyList;
  693. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  694. 'where' => 'sid=' . $value ['staff'],
  695. 'asArray' => true
  696. ) );
  697. $receiptList [$key] ['button'] = $button;
  698. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  699. }
  700. $mothHtml = "";
  701. for($i = 1; $i <= 12; $i ++) {
  702. if ($month == $i)
  703. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  704. else
  705. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  706. }
  707. // 获取审批日志
  708. Doo::loadModel ( 'receiptLog' );
  709. $receiptLog = new receiptLog ();
  710. $rlList = array ();
  711. $rlInfo = $receiptLog->getOne ( array (
  712. 'where' => 'rid=' . $rid . ' and status=4',
  713. 'asArray' => true
  714. ) );
  715. $tijdate = $receiptLog->getOne ( array (
  716. 'where' => 'rid=' . $rid . ' and status=2',
  717. 'asc' => 'rlid',
  718. 'asArray' => true
  719. ) );
  720. if (! empty ( $rlInfo )) {
  721. $rlList = $receiptLog->find ( array (
  722. 'where' => 'rid=' . $rid,
  723. 'asc' => 'rlid',
  724. 'asArray' => true
  725. ) );
  726. }
  727. $receiptList [0] ['rlList'] = $rlList;
  728. $enclosurList = $enclosur->find ( array (
  729. 'where' => 'rid=' . $rid,
  730. 'asArray' => true
  731. ) );
  732. $enclosurHtml = '';
  733. foreach ( $enclosurList as $value ) {
  734. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  735. }
  736. // print_r($receiptList);
  737. $data ['enclosurHtml'] = $enclosurHtml;
  738. $data ['rolename'] = $rolename ['name'];
  739. $data ['datetij'] = $tijdate ['date'];
  740. $data ['mothHtml'] = $mothHtml;
  741. $data ['rid'] = $rid;
  742. $data ['receiptList'] = $receiptList;
  743. $data ['receiptApprovalCount'] = count ( $receiptList );
  744. $data ['status'] = $status;
  745. $data ['year'] = $year;
  746. $data ['categoryList'] = $categoryList;
  747. $data ['staffList'] = $staffList;
  748. $data ['cid'] = $cid;
  749. $data ['sid'] = $sid;
  750. $data ['ap'] = $ap;
  751. $data ['memu'] = "receipt";
  752. $data ['staff'] = $this->staff;
  753. $data ['receiptMemu'] = 'approvalExpenses';
  754. $data ['verifyId'] = $this->verifyId;
  755. $data ['executeId'] = $this->executeId;
  756. $this->render ( "/admin/remitApproval", $data );
  757. }
  758. function saeaLoanAdd() {
  759. Doo::loadModel ( 'verify' );
  760. $verify = new verify ();
  761. Doo::loadModel ( "role" );
  762. $role = new role ();
  763. Doo::loadModel ( 'L_category' );
  764. $lCategory = new L_category ();
  765. $veList = $verify->find ( array (
  766. 'asArray' => true
  767. ) );
  768. foreach ( $veList as $key => $value ) {
  769. $v = json_decode ( $value ['staff'] );
  770. $list = array ();
  771. foreach ( $v as $n => $m ) {
  772. if ($m ['1'] == 'ROLE') {
  773. $roleInfo = $role->getOne ( array (
  774. 'where' => 'rid=' . $m [0],
  775. 'asArray' => true
  776. ) );
  777. $v [$n] [1] = $roleInfo ['name'];
  778. array_push ( $list, $roleInfo ['name'] );
  779. } else {
  780. array_push ( $list, $v [$n] [1] );
  781. }
  782. }
  783. $veList [$key] ['staff'] = implode ( '>', $list );
  784. }
  785. $data ['category'] = $lCategory->find ( array (
  786. 'asArray' => true
  787. ) );
  788. $data ['veList'] = $veList;
  789. $data ['memu'] = "receipt";
  790. $data ['staff'] = $this->staff;
  791. $data ['receiptMemu'] = 'saeaBorad';
  792. $data ['verifyId'] = $this->verifyId;
  793. $data ['executeId'] = $this->executeId;
  794. $this->render ( "/admin/saeaLoanAdd", $data );
  795. }
  796. function saeaLoanAddDo() {
  797. $agency = $this->get_args ( 'agency' );
  798. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  799. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  800. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  801. // die;
  802. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation )) {
  803. Doo::loadModel ( 'receipt' );
  804. Doo::loadModel ( 'receiptDetail' );
  805. Doo::loadModel ( 'accountItem' );
  806. $accountItem = new accountItem ();
  807. $receipt = new receipt ();
  808. Doo::loadModel ( 'loanReceipt' );
  809. $loanReceipt = new loanReceipt ();
  810. Doo::loadModel ( 'execute' );
  811. $execute = new execute ();
  812. Doo::loadModel ( 'enclosur' );
  813. $executeDetail = $execute->getOne ( array (
  814. 'where' => 'mold="借款执行人"',
  815. 'asArray' => true
  816. ) );
  817. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  818. // if(!empty($receiptDetail))
  819. // return "/referReceipt/".$receiptDetail['rid'];
  820. $aItem = $accountItem->find ( array (
  821. 'asArray' => true
  822. ) );
  823. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  824. $ag = $tr = $ta = $ot = 0;
  825. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  826. array_push ( $accountJson ['借款费用'], array (
  827. 'aid' => 0,
  828. 'name' => '申请金额',
  829. 'price' => number_format ( $agency, 2, '.', '' )
  830. ) );
  831. $sum += $agency;
  832. $agencySum += $agency;
  833. $accountJson ['cSum'] = array (
  834. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  835. 'agencySum' => number_format ( 0, 2, '.', '' ),
  836. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  837. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  838. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  839. );
  840. // 借款数据备份
  841. $loanReceipt->loanItem = json_encode ( $accountJson );
  842. $loanReceipt->staff = $this->staff [0] ['sid'];
  843. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  844. $loanReceipt->date = date ( "Y-m-d" );
  845. $loanReceipt->cid = $cid;
  846. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  847. $loanReceipt->status = 5;
  848. $loanReceipt->Rtype = 1;
  849. $loanReceipt->verify = $verify;
  850. $receipt->receiptOrder = $receipt->receiptOrder;
  851. $loanReceipt->explanation = $explanation;
  852. $loanRid = $loanReceipt->insert ();
  853. // 报销单
  854. $receipt->loanItem = json_encode ( $accountJson );
  855. $receipt->staff = $this->staff [0] ['sid'];
  856. $receipt->sum = number_format ( $sum, 2, '.', '' );
  857. $receipt->date = date ( "Y-m-d" );
  858. $receipt->cid = $cid;
  859. // 特殊状态
  860. $receipt->status = 5;
  861. $receipt->Rtype = 1;
  862. $receipt->loanRid = $loanRid;
  863. // 修改审批流程加入角色
  864. $receipt->verify = $verify;
  865. $receipt->executeCopy = $executeDetail ['staff'];
  866. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  867. $receipt->explanation = $explanation;
  868. $rid = $receipt->insert ();
  869. // 执行数据备份
  870. // $executeCopy->rid=$rid;
  871. // $executeCopy->staff=$executeDetail['staff'];
  872. // $executeCopy->eid=$executeDetail['eid'];
  873. // $ecid=$executeCopy->insert();
  874. }
  875. return "/saeaBorad";
  876. }
  877. function saeaLoanEdi() {
  878. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  879. Doo::loadModel ( 'verify' );
  880. $verify = new verify ();
  881. Doo::loadModel ( "role" );
  882. $role = new role ();
  883. Doo::loadModel ( 'L_category' );
  884. $lCategory = new L_category ();
  885. Doo::loadModel ( 'receipt' );
  886. $receipt = new receipt ();
  887. $receiptInfo = $receipt->getOne ( array (
  888. 'where' => 'rid=' . $rid,
  889. 'asArray' => true
  890. ) );
  891. $veList = $verify->find ( array (
  892. 'asArray' => true
  893. ) );
  894. foreach ( $veList as $key => $value ) {
  895. $v = json_decode ( $value ['staff'] );
  896. $list = array ();
  897. foreach ( $v as $n => $m ) {
  898. if ($m ['1'] == 'ROLE') {
  899. $roleInfo = $role->getOne ( array (
  900. 'where' => 'rid=' . $m [0],
  901. 'asArray' => true
  902. ) );
  903. $v [$n] [1] = $roleInfo ['name'];
  904. array_push ( $list, $roleInfo ['name'] );
  905. } else {
  906. array_push ( $list, $v [$n] [1] );
  907. }
  908. }
  909. $veList [$key] ['staff'] = implode ( '>', $list );
  910. }
  911. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  912. $data ['receiptInfo'] = $receiptInfo;
  913. $data ['category'] = $lCategory->find ( array (
  914. 'asArray' => true
  915. ) );
  916. $data ['veList'] = $veList;
  917. $data ['memu'] = "receipt";
  918. $data ['staff'] = $this->staff;
  919. $data ['receiptMemu'] = 'saeaBorad';
  920. $data ['verifyId'] = $this->verifyId;
  921. $data ['executeId'] = $this->executeId;
  922. $this->render ( "/admin/saeaLoanEdi", $data );
  923. }
  924. function saeaLoanEdiDo() {
  925. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  926. $agency = $this->get_args ( 'agency' );
  927. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  928. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  929. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  930. // die;
  931. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid )) {
  932. Doo::loadModel ( 'receipt' );
  933. Doo::loadModel ( 'receiptDetail' );
  934. Doo::loadModel ( 'accountItem' );
  935. $accountItem = new accountItem ();
  936. $receipt = new receipt ();
  937. Doo::loadModel ( 'loanReceipt' );
  938. $loanReceipt = new loanReceipt ();
  939. Doo::loadModel ( 'enclosur' );
  940. Doo::loadModel ( 'execute' );
  941. $execute = new execute ();
  942. $executeDetail = $execute->getOne ( array (
  943. 'where' => 'mold="借款执行人"',
  944. 'asArray' => true
  945. ) );
  946. $receiptDetail = $receipt->getOne ( array (
  947. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  948. 'asArray' => true
  949. ) );
  950. if (empty ( $receiptDetail ))
  951. die ( '参数错误' );
  952. $aItem = $accountItem->find ( array (
  953. 'asArray' => true
  954. ) );
  955. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  956. $ag = $tr = $ta = $ot = 0;
  957. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  958. array_push ( $accountJson ['借款费用'], array (
  959. 'aid' => 0,
  960. 'name' => '申请金额',
  961. 'price' => number_format ( $agency, 2, '.', '' )
  962. ) );
  963. $sum += $agency;
  964. $agencySum += $agency;
  965. $accountJson ['cSum'] = array (
  966. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  967. 'agencySum' => number_format ( 0, 2, '.', '' ),
  968. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  969. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  970. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  971. );
  972. // 报销单
  973. $receipt->loanItem = json_encode ( $accountJson );
  974. $receipt->sum = number_format ( $sum, 2, '.', '' );
  975. $receipt->cid = $cid;
  976. // 特殊状态
  977. // 修改审批流程加入角色
  978. if ($receiptDetail ['status'] != 4)
  979. $receipt->verify = $verify;
  980. $receipt->explanation = $explanation;
  981. $receipt->update ( array (
  982. 'where' => 'rid=' . $rid
  983. ) );
  984. // 借款数据更新
  985. $loanReceipt->loanItem = json_encode ( $accountJson );
  986. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  987. $loanReceipt->cid = $cid;
  988. if ($receiptDetail ['status'] != 4)
  989. $loanReceipt->verify = $verify;
  990. $loanReceipt->explanation = $explanation;
  991. $receipt->executeCopy = $executeDetail ['staff'];
  992. $loanReceipt->update ( array (
  993. 'where' => 'rid=' . $receiptDetail ['loanRid']
  994. ) );
  995. }
  996. return "/saeaBorad";
  997. }
  998. function saeaLoanReceiptAdd() {
  999. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1000. Doo::loadModel ( 'receipt' );
  1001. $receipt = new receipt ();
  1002. Doo::loadModel ( 'loanReceipt' );
  1003. $loanReceipt = new loanReceipt ();
  1004. Doo::loadModel ( 'L_category' );
  1005. $Lcategory = new L_category ();
  1006. Doo::loadModel ( 'verify' );
  1007. Doo::loadModel ( 'statistics' );
  1008. $statistics = new statistics ();
  1009. $verify = new verify ();
  1010. Doo::loadModel ( 'staff' );
  1011. $staff = new staff ();
  1012. $receiptDe = $receipt->getOne ( array (
  1013. 'where' => 'rid=' . $rid,
  1014. 'desc' => 'rid',
  1015. 'asArray' => true
  1016. ) );
  1017. $receiptList = $loanReceipt->find ( array (
  1018. 'where' => 'rid=' . $receiptDe ['loanRid'],
  1019. 'desc' => 'rid',
  1020. 'asArray' => true
  1021. ) );
  1022. $Locate = 0;
  1023. $roleId = 0;
  1024. $button = 0;
  1025. foreach ( $receiptList as $key => $value ) {
  1026. $receiptList [$key] ['Locate'] = $Locate;
  1027. $Locate ++;
  1028. $receiptList [$key] ['reviseDetail'] = array ();
  1029. if (! empty ( $value ['reviseDetail'] ))
  1030. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1031. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1032. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1033. $categoryDetil = $Lcategory->getOne ( array (
  1034. 'where' => 'cid=' . $value ['cid'],
  1035. 'asArray' => true
  1036. ) );
  1037. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1038. // 检测编辑状态
  1039. $verifyList = $verify->getOne ( array (
  1040. 'where' => 'vid=' . $value ['verify'],
  1041. 'asArray' => true
  1042. ) );
  1043. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1044. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1045. Doo::loadModel ( 'role' );
  1046. $role = new role ();
  1047. $flag = true;
  1048. $roleKey = 0;
  1049. $endStaffArray = array ();
  1050. $roleArrayCopy = array ();
  1051. foreach ( $verifyList as $k => $v ) {
  1052. // init verifyStaff
  1053. if ($v [1] == 'ROLE') {
  1054. if (! empty ( $verifyStaff )) {
  1055. $endStaffArray = end ( $verifyStaff );
  1056. // if ($v[0]==$endStaffArray['nextStaff']){
  1057. // $roleId=$v[0];
  1058. // }
  1059. }
  1060. $roleVerify = json_decode ( $v [3], true );
  1061. $roleKey = $k;
  1062. $roleArray = array ();
  1063. $rolename = $role->getOne ( array (
  1064. 'where' => 'rid=' . $v [0],
  1065. 'asArray' => true
  1066. ) );
  1067. foreach ( $roleVerify as $o => $p ) {
  1068. $staffID = explode ( '_', $p );
  1069. $staffInfo = $staff->getOne ( array (
  1070. 'where' => 'sid=' . $staffID [0],
  1071. 'asArray' => true
  1072. ) );
  1073. // print_r($staffID);
  1074. $exp = array (
  1075. 0 => $staffInfo ['sid'],
  1076. 1 => $staffID [1],
  1077. 2 => $staffInfo ['avatar'],
  1078. 'date' => '',
  1079. 'date' => '',
  1080. 'opinion' => '',
  1081. 'status' => '',
  1082. 'rolename' => $rolename ['name']
  1083. );
  1084. array_push ( $roleArray, $exp );
  1085. }
  1086. $roleArrayCopy [$v [0]] = $roleArray;
  1087. // $verifyList[$k]['roleArray']=$roleArray;
  1088. }
  1089. $verifyList [$k] ['date'] = "";
  1090. $verifyList [$k] ['opinion'] = "";
  1091. $verifyList [$k] ['status'] = "";
  1092. if (empty ( $verifyStaff )) {
  1093. $verifyList [$k] ['date'] = "";
  1094. $verifyList [$k] ['opinion'] = "";
  1095. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1096. $verifyList [$k] ['status'] = 4;
  1097. $flag = false;
  1098. }
  1099. } else {
  1100. foreach ( $verifyStaff as $m => $u ) {
  1101. if ($v [0] == $m) {
  1102. $verifyList [$k] ['date'] = $u ['date'];
  1103. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1104. $verifyList [$k] ['status'] = $u ['status'];
  1105. $flag = false;
  1106. break;
  1107. }
  1108. }
  1109. $endStaffArray = end ( $verifyStaff );
  1110. if (isset ( $endStaffArray ['ROLE'] )) {
  1111. } else {
  1112. // $endKey=key($verifyStaff);
  1113. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1114. // $button=4;
  1115. // $verifyList[$k]['status']=4;
  1116. // }
  1117. }
  1118. }
  1119. }
  1120. $rolename ['name'] = '';
  1121. if (! empty ( $roleId )) {
  1122. Doo::loadModel ( 'role' );
  1123. $role = new role ();
  1124. $rolename = $role->getOne ( array (
  1125. 'where' => 'rid=' . $roleId,
  1126. 'asArray' => true
  1127. ) );
  1128. }
  1129. if (! empty ( $verifyStaff ))
  1130. $endStaffArray = end ( $verifyStaff );
  1131. $KOP = false;
  1132. foreach ( $roleArrayCopy as $P => $A ) {
  1133. foreach ( $A as $MKI => $AVL ) {
  1134. if (! empty ( $verifyStaff )) {
  1135. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1136. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1137. $button = 4;
  1138. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1139. }
  1140. foreach ( $verifyStaff as $m => $u ) {
  1141. $AVLFK = $AVL [0] . '_R';
  1142. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1143. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1144. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1145. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1146. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1147. break;
  1148. }
  1149. }
  1150. } else {
  1151. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1152. $button = 4;
  1153. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1154. }
  1155. }
  1156. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1157. $KOP = true;
  1158. }
  1159. }
  1160. foreach ( $roleArrayCopy as $k => $v ) {
  1161. foreach ( $verifyList as $m => $n ) {
  1162. if ($n [0] == $k) {
  1163. array_splice ( $verifyList, $m, 1, $v );
  1164. }
  1165. }
  1166. }
  1167. $receiptList [$key] ['verifyList'] = $verifyList;
  1168. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1169. 'where' => 'sid=' . $value ['staff'],
  1170. 'asArray' => true
  1171. ) );
  1172. $receiptList [$key] ['button'] = $button;
  1173. //
  1174. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1175. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1176. }
  1177. $data ['receiptList'] = $receiptList;
  1178. Doo::loadModel ( 'L_category' );
  1179. $lCategory = new L_category ();
  1180. Doo::loadModel ( 'accountItem' );
  1181. $accountItem = new accountItem ();
  1182. $acItem = $accountItem->find ( array (
  1183. 'asArray' => true
  1184. ) );
  1185. $veList = $verify->find ( array (
  1186. 'asArray' => true
  1187. ) );
  1188. foreach ( $veList as $key => $value ) {
  1189. $v = json_decode ( $value ['staff'] );
  1190. $list = array ();
  1191. foreach ( $v as $n => $m ) {
  1192. if ($m ['1'] == 'ROLE') {
  1193. $roleInfo = $role->getOne ( array (
  1194. 'where' => 'rid=' . $m [0],
  1195. 'asArray' => true
  1196. ) );
  1197. $v [$n] [1] = $roleInfo ['name'];
  1198. array_push ( $list, $roleInfo ['name'] );
  1199. } else {
  1200. array_push ( $list, $v [$n] [1] );
  1201. }
  1202. }
  1203. $veList [$key] ['staff'] = implode ( '>', $list );
  1204. }
  1205. $data ['rid'] = $rid;
  1206. $data ['category'] = $lCategory->find ( array (
  1207. 'asArray' => true
  1208. ) );
  1209. $data ['veList'] = $veList;
  1210. $data ['acItem'] = $acItem;
  1211. $data ['memu'] = "receipt";
  1212. $data ['staff'] = $this->staff;
  1213. $data ['receiptMemu'] = 'saeaBorad';
  1214. $data ['verifyId'] = $this->verifyId;
  1215. $data ['executeId'] = $this->executeId;
  1216. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  1217. }
  1218. function saeaLoanReceiptAddDo() {
  1219. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  1220. $agency = $this->get_args ( 'agency' );
  1221. $travel = $this->get_args ( 'travel' );
  1222. $train = $this->get_args ( 'train' );
  1223. $other = $this->get_args ( 'other' );
  1224. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1225. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1226. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1227. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1228. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid )) {
  1229. Doo::loadModel ( 'receipt' );
  1230. Doo::loadModel ( 'receiptDetail' );
  1231. Doo::loadModel ( 'accountItem' );
  1232. $accountItem = new accountItem ();
  1233. $receipt = new receipt ();
  1234. Doo::loadModel ( 'enclosur' );
  1235. Doo::loadModel ( 'execute' );
  1236. $execute = new execute ();
  1237. $executeDetail = $execute->getOne ( array (
  1238. 'where' => 'mold="借款费用执行人"',
  1239. 'asArray' => true
  1240. ) );
  1241. $receiptDet = $receipt->getOne ( array (
  1242. 'where' => 'rid=' . $rid,
  1243. 'asArray' => true
  1244. ) );
  1245. // if(!empty($receiptDetail))
  1246. // return "/referReceipt/".$receiptDetail['rid'];
  1247. $aItem = $accountItem->find ( array (
  1248. 'asArray' => true
  1249. ) );
  1250. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1251. $ag = $tr = $ta = $ot = 0;
  1252. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1253. foreach ( $aItem as $key => $value ) {
  1254. if ($value ['category'] == $this->AGENCY) {
  1255. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1256. array_push ( $accountJson [$this->AGENCY], array (
  1257. 'aid' => $value ['aid'],
  1258. 'name' => $value ['name'],
  1259. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1260. ) );
  1261. $sum += $agency [$ag];
  1262. $agencySum += $agency [$ag];
  1263. }
  1264. $ag ++;
  1265. }
  1266. if ($value ['category'] == $this->TRAVEL) {
  1267. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  1268. array_push ( $accountJson [$this->TRAVEL], array (
  1269. 'aid' => $value ['aid'],
  1270. 'name' => $value ['name'],
  1271. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  1272. ) );
  1273. $sum += $travel [$tr];
  1274. $travelSum += $travel [$tr];
  1275. }
  1276. $tr ++;
  1277. }
  1278. if ($value ['category'] == $this->TRAIN) {
  1279. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  1280. array_push ( $accountJson [$this->TRAIN], array (
  1281. 'aid' => $value ['aid'],
  1282. 'name' => $value ['name'],
  1283. 'price' => number_format ( $train [$ta], 2, '.', '' )
  1284. ) );
  1285. $sum += $train [$ta];
  1286. $trainSum += $train [$ta];
  1287. }
  1288. $ta ++;
  1289. }
  1290. if ($value ['category'] == $this->OTHER) {
  1291. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  1292. array_push ( $accountJson [$this->OTHER], array (
  1293. 'aid' => $value ['aid'],
  1294. 'name' => $value ['name'],
  1295. 'price' => number_format ( $other [$ot], 2, '.', '' )
  1296. ) );
  1297. $sum += $other [$ot];
  1298. $otherSum += $other [$ot];
  1299. }
  1300. $ot ++;
  1301. }
  1302. }
  1303. $accountJson ['cSum'] = array (
  1304. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1305. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1306. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1307. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1308. );
  1309. // 报销单
  1310. $receipt->accountItem = json_encode ( $accountJson );
  1311. $receipt->staff = $this->staff [0] ['sid'];
  1312. $receipt->loanSum = $receiptDet ['sum'];
  1313. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1314. $receipt->date = date ( "Y-m-d" );
  1315. $receipt->pastDate = '';
  1316. $receipt->cid = $cid;
  1317. $receipt->status = 7;
  1318. // 修改审批流程加入角色
  1319. $receipt->verify = $verify;
  1320. $receipt->verifyStaff = '';
  1321. $receipt->executeStaff = '';
  1322. $receipt->executeCopy = $executeDetail ['staff'];
  1323. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1324. $receipt->explanation = $explanation;
  1325. $receipt->update ( array (
  1326. 'where' => 'rid=' . $rid
  1327. ) );
  1328. // 附件
  1329. if (! empty ( $enclosurName )) {
  1330. $enclosurArray = explode ( '-', $enclosurName );
  1331. foreach ( $enclosurArray as $value ) {
  1332. $enclosur = new enclosur ();
  1333. $enclosur->name = $value;
  1334. $enclosur->rid = $rid;
  1335. $enclosur->insert ();
  1336. }
  1337. // print_r($enclosurArray);die;
  1338. }
  1339. // 报销详情
  1340. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1341. $receiptDetail = new receiptDetail ();
  1342. $receiptDetail->staff = $this->staff [0] ['sid'];
  1343. $receiptDetail->item = $value ['name'];
  1344. $receiptDetail->itemCategory = $this->AGENCY;
  1345. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1346. $receiptDetail->date = date ( "Y-m-d" );
  1347. $receiptDetail->cid = $cid;
  1348. $receiptDetail->rid = $rid;
  1349. $receiptDetail->status = 4;
  1350. $receiptDetail->insert ();
  1351. }
  1352. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1353. $receiptDetail = new receiptDetail ();
  1354. $receiptDetail->staff = $this->staff [0] ['sid'];
  1355. $receiptDetail->item = $value ['name'];
  1356. $receiptDetail->itemCategory = $this->TRAVEL;
  1357. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1358. $receiptDetail->date = date ( "Y-m-d" );
  1359. $receiptDetail->cid = $cid;
  1360. $receiptDetail->rid = $rid;
  1361. $receiptDetail->status = 4;
  1362. $receiptDetail->insert ();
  1363. }
  1364. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1365. $receiptDetail = new receiptDetail ();
  1366. $receiptDetail->staff = $this->staff [0] ['sid'];
  1367. $receiptDetail->item = $value ['name'];
  1368. $receiptDetail->itemCategory = $this->TRAIN;
  1369. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1370. $receiptDetail->date = date ( "Y-m-d" );
  1371. $receiptDetail->cid = $cid;
  1372. $receiptDetail->rid = $rid;
  1373. $receiptDetail->status = 4;
  1374. $receiptDetail->insert ();
  1375. }
  1376. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1377. $receiptDetail = new receiptDetail ();
  1378. $receiptDetail->staff = $this->staff [0] ['sid'];
  1379. $receiptDetail->item = $value ['name'];
  1380. $receiptDetail->itemCategory = $this->OTHER;
  1381. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1382. $receiptDetail->date = date ( "Y-m-d" );
  1383. $receiptDetail->cid = $cid;
  1384. $receiptDetail->rid = $rid;
  1385. $receiptDetail->status = 4;
  1386. $receiptDetail->insert ();
  1387. }
  1388. return "/saeaBorad";
  1389. }
  1390. return "/saeaLoanReceiptAdd/" . $rid;
  1391. }
  1392. function saeaLoanReceiptEdi() {
  1393. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1394. // echo $rid;
  1395. Doo::loadModel ( 'accountItem' );
  1396. Doo::loadModel ( 'verify' );
  1397. Doo::loadModel ( 'receipt' );
  1398. $receipt = new receipt ();
  1399. $verify = new verify ();
  1400. $accountItem = new accountItem ();
  1401. Doo::loadModel ( 'L_category' );
  1402. $Lcategory = new L_category ();
  1403. Doo::loadModel ( "role" );
  1404. $role = new role ();
  1405. Doo::loadModel ( 'loanReceipt' );
  1406. $loanReceipt = new loanReceipt ();
  1407. Doo::loadModel ( 'staff' );
  1408. $staff = new staff ();
  1409. $receiptDetail = $receipt->getOne ( array (
  1410. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  1411. 'asArray' => true
  1412. ) );
  1413. if (empty ( $receiptDetail ))
  1414. return "/saeaBorad";
  1415. $receiptList = $loanReceipt->find ( array (
  1416. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1417. 'desc' => 'rid',
  1418. 'asArray' => true
  1419. ) );
  1420. $Locate = 0;
  1421. $roleId = 0;
  1422. $button = 0;
  1423. foreach ( $receiptList as $key => $value ) {
  1424. $receiptList [$key] ['Locate'] = $Locate;
  1425. $Locate ++;
  1426. $receiptList [$key] ['reviseDetail'] = array ();
  1427. if (! empty ( $value ['reviseDetail'] ))
  1428. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1429. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1430. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1431. $categoryDetil = $Lcategory->getOne ( array (
  1432. 'where' => 'cid=' . $value ['cid'],
  1433. 'asArray' => true
  1434. ) );
  1435. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1436. // 检测编辑状态
  1437. $verifyList = $verify->getOne ( array (
  1438. 'where' => 'vid=' . $value ['verify'],
  1439. 'asArray' => true
  1440. ) );
  1441. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1442. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1443. Doo::loadModel ( 'role' );
  1444. $role = new role ();
  1445. $flag = true;
  1446. $roleKey = 0;
  1447. $endStaffArray = array ();
  1448. $roleArrayCopy = array ();
  1449. foreach ( $verifyList as $k => $v ) {
  1450. // init verifyStaff
  1451. if ($v [1] == 'ROLE') {
  1452. if (! empty ( $verifyStaff )) {
  1453. $endStaffArray = end ( $verifyStaff );
  1454. // if ($v[0]==$endStaffArray['nextStaff']){
  1455. // $roleId=$v[0];
  1456. // }
  1457. }
  1458. $roleVerify = json_decode ( $v [3], true );
  1459. $roleKey = $k;
  1460. $roleArray = array ();
  1461. $rolename = $role->getOne ( array (
  1462. 'where' => 'rid=' . $v [0],
  1463. 'asArray' => true
  1464. ) );
  1465. foreach ( $roleVerify as $o => $p ) {
  1466. $staffID = explode ( '_', $p );
  1467. $staffInfo = $staff->getOne ( array (
  1468. 'where' => 'sid=' . $staffID [0],
  1469. 'asArray' => true
  1470. ) );
  1471. // print_r($staffID);
  1472. $exp = array (
  1473. 0 => $staffInfo ['sid'],
  1474. 1 => $staffID [1],
  1475. 2 => $staffInfo ['avatar'],
  1476. 'date' => '',
  1477. 'date' => '',
  1478. 'opinion' => '',
  1479. 'status' => '',
  1480. 'rolename' => $rolename ['name']
  1481. );
  1482. array_push ( $roleArray, $exp );
  1483. }
  1484. $roleArrayCopy [$v [0]] = $roleArray;
  1485. // $verifyList[$k]['roleArray']=$roleArray;
  1486. }
  1487. $verifyList [$k] ['date'] = "";
  1488. $verifyList [$k] ['opinion'] = "";
  1489. $verifyList [$k] ['status'] = "";
  1490. if (empty ( $verifyStaff )) {
  1491. $verifyList [$k] ['date'] = "";
  1492. $verifyList [$k] ['opinion'] = "";
  1493. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1494. $verifyList [$k] ['status'] = 4;
  1495. $flag = false;
  1496. }
  1497. } else {
  1498. foreach ( $verifyStaff as $m => $u ) {
  1499. if ($v [0] == $m) {
  1500. $verifyList [$k] ['date'] = $u ['date'];
  1501. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1502. $verifyList [$k] ['status'] = $u ['status'];
  1503. $flag = false;
  1504. break;
  1505. }
  1506. }
  1507. $endStaffArray = end ( $verifyStaff );
  1508. if (isset ( $endStaffArray ['ROLE'] )) {
  1509. } else {
  1510. // $endKey=key($verifyStaff);
  1511. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1512. // $button=4;
  1513. // $verifyList[$k]['status']=4;
  1514. // }
  1515. }
  1516. }
  1517. }
  1518. $rolename ['name'] = '';
  1519. if (! empty ( $roleId )) {
  1520. Doo::loadModel ( 'role' );
  1521. $role = new role ();
  1522. $rolename = $role->getOne ( array (
  1523. 'where' => 'rid=' . $roleId,
  1524. 'asArray' => true
  1525. ) );
  1526. }
  1527. if (! empty ( $verifyStaff ))
  1528. $endStaffArray = end ( $verifyStaff );
  1529. $KOP = false;
  1530. foreach ( $roleArrayCopy as $P => $A ) {
  1531. foreach ( $A as $MKI => $AVL ) {
  1532. if (! empty ( $verifyStaff )) {
  1533. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1534. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1535. $button = 4;
  1536. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1537. }
  1538. foreach ( $verifyStaff as $m => $u ) {
  1539. $AVLFK = $AVL [0] . '_R';
  1540. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1541. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1542. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1543. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1544. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1545. break;
  1546. }
  1547. }
  1548. } else {
  1549. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1550. $button = 4;
  1551. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1552. }
  1553. }
  1554. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1555. $KOP = true;
  1556. }
  1557. }
  1558. foreach ( $roleArrayCopy as $k => $v ) {
  1559. foreach ( $verifyList as $m => $n ) {
  1560. if ($n [0] == $k) {
  1561. array_splice ( $verifyList, $m, 1, $v );
  1562. }
  1563. }
  1564. }
  1565. $receiptList [$key] ['verifyList'] = $verifyList;
  1566. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1567. 'where' => 'sid=' . $value ['staff'],
  1568. 'asArray' => true
  1569. ) );
  1570. $receiptList [$key] ['button'] = $button;
  1571. //
  1572. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1573. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1574. }
  1575. $data ['receiptList'] = $receiptList;
  1576. $acItem = $accountItem->find ( array (
  1577. 'asArray' => true
  1578. ) );
  1579. $veList = $verify->find ( array (
  1580. 'asArray' => true
  1581. ) );
  1582. foreach ( $veList as $key => $value ) {
  1583. $v = json_decode ( $value ['staff'] );
  1584. $list = array ();
  1585. foreach ( $v as $n => $m ) {
  1586. if ($m ['1'] == 'ROLE') {
  1587. $roleInfo = $role->getOne ( array (
  1588. 'where' => 'rid=' . $m [0],
  1589. 'asArray' => true
  1590. ) );
  1591. $v [$n] [1] = $roleInfo ['name'];
  1592. array_push ( $list, $roleInfo ['name'] );
  1593. } else {
  1594. array_push ( $list, $v [$n] [1] );
  1595. }
  1596. }
  1597. $veList [$key] ['staff'] = implode ( '>', $list );
  1598. }
  1599. // 配置编辑信息
  1600. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1601. foreach ( $acItem as $key => $value ) {
  1602. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1603. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1604. $acItem [$key] ['price'] = $v ['price'];
  1605. }
  1606. }
  1607. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1608. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1609. $acItem [$key] ['price'] = $v ['price'];
  1610. }
  1611. }
  1612. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1613. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1614. $acItem [$key] ['price'] = $v ['price'];
  1615. }
  1616. }
  1617. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1618. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1619. $acItem [$key] ['price'] = $v ['price'];
  1620. }
  1621. }
  1622. }
  1623. $data ['category'] = $Lcategory->find ( array (
  1624. 'asArray' => true
  1625. ) );
  1626. $data ['cSum'] = $accountItemList ['cSum'];
  1627. $data ['sum'] = $receiptDetail ['sum'];
  1628. $data ['receiptDetail'] = $receiptDetail;
  1629. $data ['veList'] = $veList;
  1630. $data ['acItem'] = $acItem;
  1631. $data ['memu'] = "receipt";
  1632. $data ['staff'] = $this->staff;
  1633. $data ['receiptMemu'] = 'saeaBorad';
  1634. $data ['verify'] = $receiptDetail ['verify'];
  1635. $data ['verifyId'] = $this->verifyId;
  1636. $data ['executeId'] = $this->executeId;
  1637. $data ['rid'] = $rid;
  1638. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1639. }
  1640. function confirmation() {
  1641. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1642. Doo::loadModel ( 'receipt' );
  1643. Doo::loadModel ( 'receiptDetail' );
  1644. $receipt = new receipt ();
  1645. $receiptDetail = new receiptDetail ();
  1646. Doo::loadModel ( 'statistics' );
  1647. Doo::loadModel ( 'itemStatistics' );
  1648. $statistics = new statistics ();
  1649. $itemStatistics = new itemStatistics ();
  1650. Doo::loadModel ( "verify" );
  1651. $verify = new verify ();
  1652. $receiptDetailList = $receipt->getOne ( array (
  1653. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  1654. 'asArray' => true
  1655. ) );
  1656. if (empty ( $receiptDetailList ))
  1657. return "/saeaBorad";
  1658. $verifyDetail = $verify->getOne ( array (
  1659. 'where' => ' vid =' . $receiptDetailList ['verify'],
  1660. 'asArray' => true
  1661. ) );
  1662. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  1663. if (empty ( $receiptDetailList ['nowStaff'] )) {
  1664. $nowStaff = "";
  1665. $nowStaffList = array ();
  1666. if ($verifyDetail [0] [1] == 'ROLE') {
  1667. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  1668. foreach ( $vStaffString as $key => $value ) {
  1669. $staffK = explode ( "_", $value );
  1670. array_push ( $nowStaffList, $staffK [0] );
  1671. }
  1672. $nowStaff = implode ( ',', $nowStaffList );
  1673. } else {
  1674. $nowStaff = $verifyDetail [0] [0];
  1675. }
  1676. $receipt->nowStaff = $nowStaff;
  1677. }
  1678. // echo $nowStaff;
  1679. // print_r($verifyDetail);die;
  1680. $receipt->rid = $receiptDetailList ['rid'];
  1681. $receipt->status = 2;
  1682. $receipt->update ();
  1683. // 操作日志
  1684. Doo::loadModel ( "receiptLog" );
  1685. $receiptLog = new receiptLog ();
  1686. $verify = new verify ();
  1687. $receiptInfo = $receipt->getOne ( array (
  1688. 'where' => 'rid=' . $rid,
  1689. 'asArray' => true
  1690. ) );
  1691. $vr = $verify->getOne ( array (
  1692. 'where' => 'vid=' . $receiptInfo ['verify'],
  1693. 'asArray' => true
  1694. ) );
  1695. $jd = json_decode ( $vr ['staff'] );
  1696. $roleId = 0;
  1697. foreach ( $jd as $key => $value ) {
  1698. if ($value [1] == 'ROLE') {
  1699. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  1700. if ($pos !== false) {
  1701. $roleId = $value [0];
  1702. }
  1703. }
  1704. }
  1705. // 审批日志
  1706. // echo $roleId;die;
  1707. if (! empty ( $roleId )) {
  1708. Doo::loadModel ( "role" );
  1709. $role = new role ();
  1710. $roleInfo = $role->getOne ( array (
  1711. 'where' => 'rid=' . $roleId,
  1712. 'asArray' => true
  1713. ) );
  1714. $receiptLog->rolename = $roleInfo ['name'];
  1715. }
  1716. $receiptLog->username = $this->staff [0] ['username'];
  1717. $receiptLog->uid = $this->staff [0] ['sid'];
  1718. $receiptLog->date = date ( "Y-m-d" );
  1719. $receiptLog->opinion = '提交审批';
  1720. $receiptLog->img = $this->staff [0] ['avatar'];
  1721. $receiptLog->status = 2;
  1722. $receiptLog->rid = $rid;
  1723. $receiptLog->insert ();
  1724. return "/expenses";
  1725. }
  1726. function expenses() {
  1727. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  1728. if (empty ( $item ))
  1729. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  1730. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1731. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  1732. Doo::loadModel ( 'receipt' );
  1733. $receipt = new receipt ();
  1734. Doo::loadModel ( 'L_category' );
  1735. $Lcategory = new L_category ();
  1736. Doo::loadModel ( 'verify' );
  1737. Doo::loadModel ( 'statistics' );
  1738. $statistics = new statistics ();
  1739. $verify = new verify ();
  1740. Doo::loadModel ( 'staff' );
  1741. $staff = new staff ();
  1742. $condition = "";
  1743. if ($item == "expenses")
  1744. $condition = " and Rtype=1 ";
  1745. elseif ($item == "receipts")
  1746. $condition = " and Rtype=0 ";
  1747. elseif ($item == "remits")
  1748. $condition = " and Rtype=2 ";
  1749. $dateCondition = " and Year(date) =" . $year;
  1750. if (! empty ( $moth )) {
  1751. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  1752. $stList = $statistics->getOne ( array (
  1753. 'select' => 'rePrice ,agPrice',
  1754. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  1755. 'asArray' => true
  1756. ) );
  1757. } else
  1758. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  1759. if (empty ( $stList ))
  1760. $stList = array (
  1761. 'rePrice' => 0,
  1762. 'agPrice' => 0
  1763. );
  1764. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  1765. if (! isset ( $noPassSum ['sum'] ))
  1766. $noPassSum ['sum'] = 0;
  1767. $data ['stList'] = array (
  1768. 'rePrice' => $stList ['rePrice'],
  1769. 'agPrice' => $stList ['agPrice'],
  1770. 'skPrice' => ($noPassSum ['sum'])
  1771. );
  1772. $receiptList = $receipt->find ( array (
  1773. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  1774. 'desc' => 'rid',
  1775. 'asArray' => true
  1776. ) );
  1777. $Locate = 0;
  1778. $roleId = 0;
  1779. $button = 0;
  1780. foreach ( $receiptList as $key => $value ) {
  1781. $receiptList [$key] ['Locate'] = $Locate;
  1782. $Locate ++;
  1783. $receiptList [$key] ['reviseDetail'] = array ();
  1784. if (! empty ( $value ['reviseDetail'] ))
  1785. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1786. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1787. $categoryDetil = $Lcategory->getOne ( array (
  1788. 'where' => 'cid=' . $value ['cid'],
  1789. 'asArray' => true
  1790. ) );
  1791. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1792. // 检测编辑状态
  1793. $verifyList = $verify->getOne ( array (
  1794. 'where' => 'vid=' . $value ['verify'],
  1795. 'asArray' => true
  1796. ) );
  1797. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1798. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1799. Doo::loadModel ( 'role' );
  1800. $role = new role ();
  1801. $flag = true;
  1802. $roleKey = 0;
  1803. $endStaffArray = array ();
  1804. $roleArrayCopy = array ();
  1805. foreach ( $verifyList as $k => $v ) {
  1806. // init verifyStaff
  1807. if ($v [1] == 'ROLE') {
  1808. if (! empty ( $verifyStaff )) {
  1809. $endStaffArray = end ( $verifyStaff );
  1810. // if ($v[0]==$endStaffArray['nextStaff']){
  1811. // $roleId=$v[0];
  1812. // }
  1813. }
  1814. $roleVerify = json_decode ( $v [3], true );
  1815. $roleKey = $k;
  1816. $roleArray = array ();
  1817. $rolename = $role->getOne ( array (
  1818. 'where' => 'rid=' . $v [0],
  1819. 'asArray' => true
  1820. ) );
  1821. foreach ( $roleVerify as $o => $p ) {
  1822. $staffID = explode ( '_', $p );
  1823. $staffInfo = $staff->getOne ( array (
  1824. 'where' => 'sid=' . $staffID [0],
  1825. 'asArray' => true
  1826. ) );
  1827. // print_r($staffID);
  1828. $exp = array (
  1829. 0 => $staffInfo ['sid'],
  1830. 1 => $staffID [1],
  1831. 2 => $staffInfo ['avatar'],
  1832. 'date' => '',
  1833. 'date' => '',
  1834. 'opinion' => '',
  1835. 'status' => '',
  1836. 'rolename' => $rolename ['name']
  1837. );
  1838. array_push ( $roleArray, $exp );
  1839. }
  1840. $roleArrayCopy [$v [0]] = $roleArray;
  1841. // $verifyList[$k]['roleArray']=$roleArray;
  1842. }
  1843. $verifyList [$k] ['date'] = "";
  1844. $verifyList [$k] ['opinion'] = "";
  1845. $verifyList [$k] ['status'] = "";
  1846. if (empty ( $verifyStaff )) {
  1847. $verifyList [$k] ['date'] = "";
  1848. $verifyList [$k] ['opinion'] = "";
  1849. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1850. $verifyList [$k] ['status'] = 4;
  1851. $flag = false;
  1852. }
  1853. } else {
  1854. foreach ( $verifyStaff as $m => $u ) {
  1855. if ($v [0] == $m) {
  1856. $verifyList [$k] ['date'] = $u ['date'];
  1857. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1858. $verifyList [$k] ['status'] = $u ['status'];
  1859. $flag = false;
  1860. break;
  1861. }
  1862. }
  1863. $endStaffArray = end ( $verifyStaff );
  1864. if (isset ( $endStaffArray ['ROLE'] )) {
  1865. } else {
  1866. // $endKey=key($verifyStaff);
  1867. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1868. // $button=4;
  1869. // $verifyList[$k]['status']=4;
  1870. // }
  1871. }
  1872. }
  1873. }
  1874. $rolename ['name'] = '';
  1875. if (! empty ( $roleId )) {
  1876. Doo::loadModel ( 'role' );
  1877. $role = new role ();
  1878. $rolename = $role->getOne ( array (
  1879. 'where' => 'rid=' . $roleId,
  1880. 'asArray' => true
  1881. ) );
  1882. }
  1883. if (! empty ( $verifyStaff ))
  1884. $endStaffArray = end ( $verifyStaff );
  1885. $KOP = false;
  1886. foreach ( $roleArrayCopy as $P => $A ) {
  1887. foreach ( $A as $MKI => $AVL ) {
  1888. if (! empty ( $verifyStaff )) {
  1889. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1890. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1891. $button = 4;
  1892. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1893. }
  1894. foreach ( $verifyStaff as $m => $u ) {
  1895. $AVLFK = $AVL [0] . '_R';
  1896. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1897. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1898. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1899. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1900. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1901. break;
  1902. }
  1903. }
  1904. } else {
  1905. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1906. $button = 4;
  1907. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1908. }
  1909. }
  1910. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1911. $KOP = true;
  1912. }
  1913. }
  1914. foreach ( $roleArrayCopy as $k => $v ) {
  1915. foreach ( $verifyList as $m => $n ) {
  1916. if ($n [0] == $k) {
  1917. array_splice ( $verifyList, $m, 1, $v );
  1918. }
  1919. }
  1920. }
  1921. $receiptList [$key] ['verifyList'] = $verifyList;
  1922. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1923. 'where' => 'sid=' . $value ['staff'],
  1924. 'asArray' => true
  1925. ) );
  1926. $receiptList [$key] ['button'] = $button;
  1927. }
  1928. // print_r($receiptList);die;
  1929. $mothHtml = "";
  1930. for($i = 1; $i <= 12; $i ++) {
  1931. if ($moth == $i)
  1932. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  1933. else
  1934. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  1935. }
  1936. $data ['mothHtml'] = $mothHtml;
  1937. $data ['receiptList'] = $receiptList;
  1938. $data ['memu'] = "receipt";
  1939. $data ['staff'] = $this->staff;
  1940. $data ['receiptMemu'] = 'expenses';
  1941. $data ['verifyId'] = $this->verifyId;
  1942. $data ['executeId'] = $this->executeId;
  1943. $data ['item'] = $item;
  1944. $data ['year'] = $year;
  1945. $this->render ( "/admin/expenses", $data );
  1946. }
  1947. function expensesCollect() {
  1948. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1949. Doo::loadModel ( 'receipt' );
  1950. $receipt = new receipt ();
  1951. Doo::loadModel ( 'L_category' );
  1952. $Lcategory = new L_category ();
  1953. Doo::loadModel ( 'verify' );
  1954. Doo::loadModel ( 'statistics' );
  1955. $statistics = new statistics ();
  1956. $verify = new verify ();
  1957. Doo::loadModel ( 'staff' );
  1958. $staff = new staff ();
  1959. Doo::loadModel ( 'loanReceipt' );
  1960. $loanReceipt = new loanReceipt ();
  1961. $receiptList = $receipt->find ( array (
  1962. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  1963. 'desc' => 'rid',
  1964. 'asArray' => true
  1965. ) );
  1966. $loanList = $loanReceipt->find ( array (
  1967. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  1968. 'desc' => 'rid',
  1969. 'asArray' => true
  1970. ) );
  1971. /*
  1972. * $Locate=0;$roleId=0;$button=0; foreach ($loanList as $key=>$value){ $loanList[$key]['Locate']=$Locate;$Locate++; $loanList[$key]['reviseDetail']=array(); if (!empty($value['reviseDetail'])) $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true); $loanList[$key]['accountItem']=json_decode($value['accountItem'],true); $loanList[$key]['loanItem']=json_decode($value['loanItem'],true); $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true)); $loanList[$key]['category']=$categoryDetil['title']; //检测编辑状态 if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9) $verifyList['staff']=$value['verifyBreakup']; else $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true)); $verifyList=json_decode($verifyList['staff'],true);//status opinion $verifyStaff=json_decode($value['verifyStaff'],true); Doo::loadModel('role'); $role=new role(); $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array(); foreach ($verifyList as $k=>$v){ //init verifyStaff if ($v[1]=='ROLE'){ if (!empty($verifyStaff)){ $endStaffArray=end($verifyStaff); // if ($v[0]==$endStaffArray['nextStaff']){ // $roleId=$v[0]; // } } $roleVerify=json_decode($v[3],true); $roleKey=$k;$roleArray=array(); $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true)); foreach ($roleVerify as $o=>$p){ $staffID=explode ('_',$p); $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true)); //print_r($staffID); $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']); array_push($roleArray, $exp); } $roleArrayCopy[$v[0]]=$roleArray; //$verifyList[$k]['roleArray']=$roleArray; } $verifyList[$k]['date']=""; $verifyList[$k]['opinion']=""; $verifyList[$k]['status']=""; if (empty($verifyStaff)){ $verifyList[$k]['date']=""; $verifyList[$k]['opinion']=""; if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){ $verifyList[$k]['status']=4; $flag=false; } }else{ foreach ($verifyStaff as $m=>$u){ if ($v[0]==$m){ $verifyList[$k]['date']=$u['date']; $verifyList[$k]['opinion']=$u['opinion']; $verifyList[$k]['status']=$u['status']; $flag=false; break; } } $endStaffArray=end($verifyStaff); if (isset($endStaffArray['ROLE'])){ }else{ // $endKey=key($verifyStaff); // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){ // $button=4; // $verifyList[$k]['status']=4; // } } } } $rolename['name']=''; if (!empty($roleId)){ Doo::loadModel('role'); $role=new role(); $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true)); } if (!empty($verifyStaff)) $endStaffArray=end($verifyStaff); $KOP=false; foreach ($roleArrayCopy as $P=>$A){ foreach ( $A as $MKI=>$AVL){ if (!empty($verifyStaff)){ //&&$rolename['rid']==$endStaffArray['nextStaff'] if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){ $button=4; $roleArrayCopy[$P][$MKI]['status']=4; } foreach ($verifyStaff as $m=>$u){ $AVLFK=$AVL[0].'_R'; //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>'; if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1 $roleArrayCopy[$P][$MKI]['date']=$u['date']; $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion']; $roleArrayCopy[$P][$MKI]['status']=$u['status']; break; } } }else{ if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){ $button=4; $roleArrayCopy[$P][$MKI]['status']=4; } } //$roleArray[$MKI]['rolename']=$rolename['name']; $KOP=true; } } foreach ($roleArrayCopy as $k=>$v){ foreach ($verifyList as $m=>$n){ if ($n[0]==$k){ array_splice($verifyList,$m,1,$v); } } } $loanList[$key]['verifyList']=$verifyList; $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true)); $loanList[$key]['button']=$button; //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']); } $data['loanList']=$loanList;
  1973. */
  1974. $Locate = 0;
  1975. $roleId = 0;
  1976. $button = 0;
  1977. foreach ( $receiptList as $key => $value ) {
  1978. $receiptList [$key] ['Locate'] = $Locate;
  1979. $Locate ++;
  1980. $receiptList [$key] ['reviseDetail'] = array ();
  1981. if (! empty ( $value ['reviseDetail'] ))
  1982. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1983. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1984. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1985. $categoryDetil = $Lcategory->getOne ( array (
  1986. 'where' => 'cid=' . $value ['cid'],
  1987. 'asArray' => true
  1988. ) );
  1989. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1990. // 检测编辑状态
  1991. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  1992. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  1993. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  1994. else
  1995. $verifyList ['staff'] = $value ['verifyBreakup'];
  1996. } else
  1997. $verifyList = $verify->getOne ( array (
  1998. 'where' => 'vid=' . $value ['verify'],
  1999. 'asArray' => true
  2000. ) );
  2001. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2002. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2003. Doo::loadModel ( 'role' );
  2004. $role = new role ();
  2005. $flag = true;
  2006. $roleKey = 0;
  2007. $endStaffArray = array ();
  2008. $roleArrayCopy = array ();
  2009. foreach ( $verifyList as $k => $v ) {
  2010. // init verifyStaff
  2011. if ($v [1] == 'ROLE') {
  2012. if (! empty ( $verifyStaff )) {
  2013. $endStaffArray = end ( $verifyStaff );
  2014. // if ($v[0]==$endStaffArray['nextStaff']){
  2015. // $roleId=$v[0];
  2016. // }
  2017. }
  2018. $roleVerify = json_decode ( $v [3], true );
  2019. $roleKey = $k;
  2020. $roleArray = array ();
  2021. $rolename = $role->getOne ( array (
  2022. 'where' => 'rid=' . $v [0],
  2023. 'asArray' => true
  2024. ) );
  2025. foreach ( $roleVerify as $o => $p ) {
  2026. $staffID = explode ( '_', $p );
  2027. $staffInfo = $staff->getOne ( array (
  2028. 'where' => 'sid=' . $staffID [0],
  2029. 'asArray' => true
  2030. ) );
  2031. // print_r($staffID);
  2032. $exp = array (
  2033. 0 => $staffInfo ['sid'],
  2034. 1 => $staffID [1],
  2035. 2 => $staffInfo ['avatar'],
  2036. 'date' => '',
  2037. 'date' => '',
  2038. 'opinion' => '',
  2039. 'status' => '',
  2040. 'rolename' => $rolename ['name']
  2041. );
  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 (
  2083. 'where' => 'rid=' . $roleId,
  2084. 'asArray' => true
  2085. ) );
  2086. }
  2087. if (! empty ( $verifyStaff ))
  2088. $endStaffArray = end ( $verifyStaff );
  2089. $KOP = false;
  2090. foreach ( $roleArrayCopy as $P => $A ) {
  2091. foreach ( $A as $MKI => $AVL ) {
  2092. if (! empty ( $verifyStaff )) {
  2093. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2094. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2095. $button = 4;
  2096. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2097. }
  2098. foreach ( $verifyStaff as $m => $u ) {
  2099. $AVLFK = $AVL [0] . '_R';
  2100. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2101. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2102. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2103. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2104. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2105. break;
  2106. }
  2107. }
  2108. } else {
  2109. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2110. $button = 4;
  2111. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2112. }
  2113. }
  2114. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2115. $KOP = true;
  2116. }
  2117. }
  2118. foreach ( $roleArrayCopy as $k => $v ) {
  2119. foreach ( $verifyList as $m => $n ) {
  2120. if ($n [0] == $k) {
  2121. array_splice ( $verifyList, $m, 1, $v );
  2122. }
  2123. }
  2124. }
  2125. // 费用执行人相关数据
  2126. $executeCopy = json_decode ( $value ['executeCopy'], true );
  2127. $executeStaff = json_decode ( $value ['executeStaff'], true );
  2128. foreach ( $executeCopy as $k => $v ) {
  2129. $executeCopy [$k] ['date'] = '';
  2130. $executeCopy [$k] ['opinion'] = '';
  2131. $executeCopy [$k] ['status'] = '';
  2132. if (! empty ( $executeStaff ))
  2133. foreach ( $executeStaff as $m => $u ) {
  2134. if ($v [0] == $m) {
  2135. $executeCopy [$k] ['date'] = $u ['date'];
  2136. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  2137. $executeCopy [$k] ['status'] = $u ['status'];
  2138. break;
  2139. }
  2140. }
  2141. }
  2142. $receiptList [$key] ['executeCopy'] = $executeCopy;
  2143. $receiptList [$key] ['verifyList'] = $verifyList;
  2144. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2145. 'where' => 'sid=' . $value ['staff'],
  2146. 'asArray' => true
  2147. ) );
  2148. $receiptList [$key] ['button'] = $button;
  2149. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  2150. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  2151. $relust = $value ['sum'] - $value ['loanSum'];
  2152. $receiptList [$key] ['relust'] = $relust;
  2153. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  2154. }
  2155. // print_r($receiptList);
  2156. $data ['receiptList'] = $receiptList;
  2157. $data ['memu'] = "receipt";
  2158. $data ['staff'] = $this->staff;
  2159. $data ['receiptMemu'] = 'expenses';
  2160. $data ['verifyId'] = $this->verifyId;
  2161. $data ['executeId'] = $this->executeId;
  2162. $this->render ( "/admin/expensesCollect", $data );
  2163. }
  2164. function approvalExpenses() {
  2165. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  2166. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  2167. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  2168. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2169. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  2170. if (empty ( $status ))
  2171. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2172. $page_size = 12;
  2173. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2174. $vidList = array ();
  2175. $button = 0;
  2176. Doo::loadModel ( 'verify' );
  2177. $verify = new verify ();
  2178. Doo::loadModel ( 'receipt' );
  2179. $receipt = new receipt ();
  2180. Doo::loadModel ( 'staff' );
  2181. $staff = new staff ();
  2182. Doo::loadModel ( 'L_category' );
  2183. $Lcategory = new L_category ();
  2184. // user verify ID
  2185. $verifyDetail = $verify->find ( array (
  2186. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  2187. 'asArray' => true
  2188. ) );
  2189. foreach ( $verifyDetail as $key => $value ) {
  2190. array_push ( $vidList, $value ['vid'] );
  2191. }
  2192. $vid = implode ( ",", $vidList );
  2193. if (empty ( $verifyDetail ))
  2194. $vid = 0;
  2195. // if ($status==0)
  2196. // $dateCondition="";
  2197. // else
  2198. $dateCondition = " and Year(date) =" . $year;
  2199. if (! empty ( $month ))
  2200. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  2201. $categoryList = $Lcategory->find ( array (
  2202. 'asArray' => true
  2203. ) );
  2204. $staffList = $staff->find ( array (
  2205. 'where' => 'cid=' . $cid,
  2206. 'asArray' => true
  2207. ) );
  2208. $cateCondition = "";
  2209. $staffCondition = "";
  2210. $approvalCondition = "";
  2211. if (! empty ( $cid ))
  2212. $cateCondition = ' and cid=' . $cid;
  2213. if (! empty ( $sid )) {
  2214. $staffCondition = ' and staff=' . $sid;
  2215. $cateCondition = "";
  2216. }
  2217. $approvalCondition = " and status=" . $status;
  2218. if ($status == 2) {
  2219. // 查找角色审批人
  2220. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  2221. }
  2222. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  2223. $approvalCondition = ' and status=2 ';
  2224. }
  2225. if ($status == 1) {
  2226. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  2227. }
  2228. if ($status == 8) {
  2229. $approvalCondition = ' and (status=' . $status . ' or status=9) ';
  2230. }
  2231. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  2232. $pageinfo ['page'] = array (
  2233. 'previous' => ''
  2234. );
  2235. if ($status == 0) {
  2236. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  2237. $receiptList = $receipt->find ( array (
  2238. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . ' and verify in (' . $vid . ')',
  2239. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  2240. 'desc' => 'rid',
  2241. 'asArray' => true
  2242. ) );
  2243. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  2244. } else
  2245. $receiptList = $receipt->find ( array (
  2246. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')',
  2247. 'desc' => 'rid',
  2248. 'asArray' => true
  2249. ) );
  2250. $rLRes = $receipt->find ( array (
  2251. '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,
  2252. 'desc' => 'rid',
  2253. 'asArray' => true
  2254. ) );
  2255. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  2256. // print_r($pageinfo);
  2257. $Locate = 0;
  2258. foreach ( $receiptList as $key => $value ) {
  2259. $receiptList [$key] ['Locate'] = $Locate;
  2260. $Locate ++;
  2261. $receiptList [$key] ['reviseDetail'] = array ();
  2262. if (! empty ( $value ['reviseDetail'] ))
  2263. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2264. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2265. $categoryDetil = $Lcategory->getOne ( array (
  2266. 'where' => 'cid=' . $value ['cid'],
  2267. 'asArray' => true
  2268. ) );
  2269. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2270. $verifyList = $verify->getOne ( array (
  2271. 'where' => 'vid=' . $value ['verify'],
  2272. 'asArray' => true
  2273. ) );
  2274. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2275. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2276. foreach ( $verifyList as $k => $v ) {
  2277. // init verifyStaff
  2278. $verifyList [$k] ['date'] = "";
  2279. $verifyList [$k] ['opinion'] = "";
  2280. $verifyList [$k] ['status'] = "";
  2281. if (empty ( $verifyStaff )) {
  2282. $verifyList [$k] ['date'] = "";
  2283. $verifyList [$k] ['opinion'] = "";
  2284. if ($v [0] == $this->staff [0] ['sid']) {
  2285. $verifyList [$k] ['status'] = 4;
  2286. $button = 4;
  2287. }
  2288. } else {
  2289. $flag = true;
  2290. foreach ( $verifyStaff as $m => $u ) {
  2291. if ($v [0] == $m) {
  2292. $verifyList [$k] ['date'] = $u ['date'];
  2293. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2294. $verifyList [$k] ['status'] = $u ['status'];
  2295. $flag = false;
  2296. break;
  2297. }
  2298. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  2299. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  2300. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  2301. }
  2302. if ($flag) { // 检测可编辑
  2303. if ($v [0] == $this->staff [0] ['sid']) {
  2304. $verifyList [$k] ['status'] = 4;
  2305. $button = 4;
  2306. }
  2307. }
  2308. }
  2309. }
  2310. $receiptList [$key] ['verifyList'] = $verifyList;
  2311. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2312. 'where' => 'sid=' . $value ['staff'],
  2313. 'asArray' => true
  2314. ) );
  2315. $receiptList [$key] ['button'] = $button;
  2316. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  2317. }
  2318. // print_r($receiptList);die;
  2319. // $data['verifyDetail']=$verifyDetail;
  2320. $mothHtml = "";
  2321. for($i = 1; $i <= 12; $i ++) {
  2322. if ($month == $i)
  2323. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  2324. else
  2325. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  2326. }
  2327. $data ['mothHtml'] = $mothHtml;
  2328. $data ['page'] = $pageinfo;
  2329. $data ['receiptList'] = $receiptList;
  2330. $data ['receiptApprovalCount'] = count ( $rLRes );
  2331. $data ['status'] = $status;
  2332. $data ['year'] = $year;
  2333. $data ['categoryList'] = $categoryList;
  2334. $data ['staffList'] = $staffList;
  2335. $data ['cid'] = $cid;
  2336. $data ['sid'] = $sid;
  2337. // print_r($receiptList);
  2338. $data ['memu'] = "receipt";
  2339. $data ['staff'] = $this->staff;
  2340. $data ['receiptMemu'] = 'approvalExpenses';
  2341. $data ['verifyId'] = $this->verifyId;
  2342. $data ['executeId'] = $this->executeId;
  2343. $this->render ( "/admin/approvalExpenses", $data );
  2344. }
  2345. function expensesDoc() {
  2346. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2347. Doo::loadModel ( 'receipt' );
  2348. $receipt = new receipt ();
  2349. Doo::loadModel ( 'L_category' );
  2350. $Lcategory = new L_category ();
  2351. Doo::loadModel ( 'verify' );
  2352. Doo::loadModel ( 'statistics' );
  2353. $statistics = new statistics ();
  2354. $verify = new verify ();
  2355. Doo::loadModel ( 'staff' );
  2356. $staff = new staff ();
  2357. Doo::loadModel ( 'loanReceipt' );
  2358. $loanReceipt = new loanReceipt ();
  2359. $receiptList = $receipt->find ( array (
  2360. 'where' => ' rid=' . $rid,
  2361. 'desc' => 'rid',
  2362. 'asArray' => true
  2363. ) );
  2364. $loanList = array ();
  2365. if (! empty ( $receiptList ))
  2366. $loanList = $loanReceipt->find ( array (
  2367. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  2368. 'desc' => 'rid',
  2369. 'asArray' => true
  2370. ) );
  2371. $Locate = 0;
  2372. $roleId = 0;
  2373. $button = 0;
  2374. foreach ( $loanList as $key => $value ) {
  2375. $loanList [$key] ['Locate'] = $Locate;
  2376. $Locate ++;
  2377. $loanList [$key] ['reviseDetail'] = array ();
  2378. if (! empty ( $value ['reviseDetail'] ))
  2379. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2380. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2381. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2382. $categoryDetil = $Lcategory->getOne ( array (
  2383. 'where' => 'cid=' . $value ['cid'],
  2384. 'asArray' => true
  2385. ) );
  2386. $loanList [$key] ['category'] = $categoryDetil ['title'];
  2387. // 检测编辑状态
  2388. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  2389. $verifyList ['staff'] = $value ['verifyBreakup'];
  2390. else
  2391. $verifyList = $verify->getOne ( array (
  2392. 'where' => 'vid=' . $value ['verify'],
  2393. 'asArray' => true
  2394. ) );
  2395. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2396. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2397. Doo::loadModel ( 'role' );
  2398. $role = new role ();
  2399. $flag = true;
  2400. $roleKey = 0;
  2401. $endStaffArray = array ();
  2402. $roleArrayCopy = array ();
  2403. foreach ( $verifyList as $k => $v ) {
  2404. // init verifyStaff
  2405. if ($v [1] == 'ROLE') {
  2406. if (! empty ( $verifyStaff )) {
  2407. $endStaffArray = end ( $verifyStaff );
  2408. // if ($v[0]==$endStaffArray['nextStaff']){
  2409. // $roleId=$v[0];
  2410. // }
  2411. }
  2412. $roleVerify = json_decode ( $v [3], true );
  2413. $roleKey = $k;
  2414. $roleArray = array ();
  2415. $rolename = $role->getOne ( array (
  2416. 'where' => 'rid=' . $v [0],
  2417. 'asArray' => true
  2418. ) );
  2419. foreach ( $roleVerify as $o => $p ) {
  2420. $staffID = explode ( '_', $p );
  2421. $staffInfo = $staff->getOne ( array (
  2422. 'where' => 'sid=' . $staffID [0],
  2423. 'asArray' => true
  2424. ) );
  2425. // print_r($staffID);
  2426. $exp = array (
  2427. 0 => $staffInfo ['sid'],
  2428. 1 => $staffID [1],
  2429. 2 => $staffInfo ['avatar'],
  2430. 'date' => '',
  2431. 'date' => '',
  2432. 'opinion' => '',
  2433. 'status' => '',
  2434. 'rolename' => $rolename ['name']
  2435. );
  2436. array_push ( $roleArray, $exp );
  2437. }
  2438. $roleArrayCopy [$v [0]] = $roleArray;
  2439. // $verifyList[$k]['roleArray']=$roleArray;
  2440. }
  2441. $verifyList [$k] ['date'] = "";
  2442. $verifyList [$k] ['opinion'] = "";
  2443. $verifyList [$k] ['status'] = "";
  2444. if (empty ( $verifyStaff )) {
  2445. $verifyList [$k] ['date'] = "";
  2446. $verifyList [$k] ['opinion'] = "";
  2447. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2448. $verifyList [$k] ['status'] = 4;
  2449. $flag = false;
  2450. }
  2451. } else {
  2452. foreach ( $verifyStaff as $m => $u ) {
  2453. if ($v [0] == $m) {
  2454. $verifyList [$k] ['date'] = $u ['date'];
  2455. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2456. $verifyList [$k] ['status'] = $u ['status'];
  2457. $flag = false;
  2458. break;
  2459. }
  2460. }
  2461. $endStaffArray = end ( $verifyStaff );
  2462. if (isset ( $endStaffArray ['ROLE'] )) {
  2463. } else {
  2464. // $endKey=key($verifyStaff);
  2465. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2466. // $button=4;
  2467. // $verifyList[$k]['status']=4;
  2468. // }
  2469. }
  2470. }
  2471. }
  2472. $rolename ['name'] = '';
  2473. if (! empty ( $roleId )) {
  2474. Doo::loadModel ( 'role' );
  2475. $role = new role ();
  2476. $rolename = $role->getOne ( array (
  2477. 'where' => 'rid=' . $roleId,
  2478. 'asArray' => true
  2479. ) );
  2480. }
  2481. if (! empty ( $verifyStaff ))
  2482. $endStaffArray = end ( $verifyStaff );
  2483. $KOP = false;
  2484. foreach ( $roleArrayCopy as $P => $A ) {
  2485. foreach ( $A as $MKI => $AVL ) {
  2486. if (! empty ( $verifyStaff )) {
  2487. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2488. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2489. $button = 4;
  2490. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2491. }
  2492. foreach ( $verifyStaff as $m => $u ) {
  2493. $AVLFK = $AVL [0] . '_R';
  2494. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2495. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2496. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2497. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2498. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2499. break;
  2500. }
  2501. }
  2502. } else {
  2503. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2504. $button = 4;
  2505. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2506. }
  2507. }
  2508. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2509. $KOP = true;
  2510. }
  2511. }
  2512. foreach ( $roleArrayCopy as $k => $v ) {
  2513. foreach ( $verifyList as $m => $n ) {
  2514. if ($n [0] == $k) {
  2515. array_splice ( $verifyList, $m, 1, $v );
  2516. }
  2517. }
  2518. }
  2519. $loanList [$key] ['verifyList'] = $verifyList;
  2520. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  2521. 'where' => 'sid=' . $value ['staff'],
  2522. 'asArray' => true
  2523. ) );
  2524. $loanList [$key] ['button'] = $button;
  2525. // $loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2526. }
  2527. $data ['loanList'] = $loanList;
  2528. // print_r($loanList);
  2529. $Locate = 0;
  2530. $roleId = 0;
  2531. $button = 0;
  2532. foreach ( $receiptList as $key => $value ) {
  2533. $receiptList [$key] ['Locate'] = $Locate;
  2534. $Locate ++;
  2535. $receiptList [$key] ['reviseDetail'] = array ();
  2536. if (! empty ( $value ['reviseDetail'] ))
  2537. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2538. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2539. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2540. $categoryDetil = $Lcategory->getOne ( array (
  2541. 'where' => 'cid=' . $value ['cid'],
  2542. 'asArray' => true
  2543. ) );
  2544. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2545. // 检测编辑状态
  2546. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  2547. $verifyList ['staff'] = $value ['verifyBreakup'];
  2548. } else
  2549. $verifyList = $verify->getOne ( array (
  2550. 'where' => 'vid=' . $value ['verify'],
  2551. 'asArray' => true
  2552. ) );
  2553. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2554. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2555. Doo::loadModel ( 'role' );
  2556. $role = new role ();
  2557. if ($verifyList == NULL)
  2558. $verifyList = array ();
  2559. $flag = true;
  2560. $roleKey = 0;
  2561. $endStaffArray = array ();
  2562. $roleArrayCopy = array ();
  2563. foreach ( $verifyList as $k => $v ) {
  2564. // init verifyStaff
  2565. if ($v [1] == 'ROLE') {
  2566. if (! empty ( $verifyStaff )) {
  2567. $endStaffArray = end ( $verifyStaff );
  2568. // if ($v[0]==$endStaffArray['nextStaff']){
  2569. // $roleId=$v[0];
  2570. // }
  2571. }
  2572. $roleVerify = json_decode ( $v [3], true );
  2573. $roleKey = $k;
  2574. $roleArray = array ();
  2575. $rolename = $role->getOne ( array (
  2576. 'where' => 'rid=' . $v [0],
  2577. 'asArray' => true
  2578. ) );
  2579. foreach ( $roleVerify as $o => $p ) {
  2580. $staffID = explode ( '_', $p );
  2581. $staffInfo = $staff->getOne ( array (
  2582. 'where' => 'sid=' . $staffID [0],
  2583. 'asArray' => true
  2584. ) );
  2585. // print_r($staffID);
  2586. $exp = array (
  2587. 0 => $staffInfo ['sid'],
  2588. 1 => $staffID [1],
  2589. 2 => $staffInfo ['avatar'],
  2590. 'date' => '',
  2591. 'date' => '',
  2592. 'opinion' => '',
  2593. 'status' => '',
  2594. 'rolename' => $rolename ['name']
  2595. );
  2596. array_push ( $roleArray, $exp );
  2597. }
  2598. $roleArrayCopy [$v [0]] = $roleArray;
  2599. // $verifyList[$k]['roleArray']=$roleArray;
  2600. }
  2601. $verifyList [$k] ['date'] = "";
  2602. $verifyList [$k] ['opinion'] = "";
  2603. $verifyList [$k] ['status'] = "";
  2604. if (empty ( $verifyStaff )) {
  2605. $verifyList [$k] ['date'] = "";
  2606. $verifyList [$k] ['opinion'] = "";
  2607. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2608. $verifyList [$k] ['status'] = 4;
  2609. $flag = false;
  2610. }
  2611. } else {
  2612. foreach ( $verifyStaff as $m => $u ) {
  2613. if ($v [0] == $m) {
  2614. $verifyList [$k] ['date'] = $u ['date'];
  2615. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2616. $verifyList [$k] ['status'] = $u ['status'];
  2617. $flag = false;
  2618. break;
  2619. }
  2620. }
  2621. $endStaffArray = end ( $verifyStaff );
  2622. if (isset ( $endStaffArray ['ROLE'] )) {
  2623. } else {
  2624. // $endKey=key($verifyStaff);
  2625. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2626. // $button=4;
  2627. // $verifyList[$k]['status']=4;
  2628. // }
  2629. }
  2630. }
  2631. }
  2632. $rolename ['name'] = '';
  2633. if (! empty ( $roleId )) {
  2634. Doo::loadModel ( 'role' );
  2635. $role = new role ();
  2636. $rolename = $role->getOne ( array (
  2637. 'where' => 'rid=' . $roleId,
  2638. 'asArray' => true
  2639. ) );
  2640. }
  2641. if (! empty ( $verifyStaff ))
  2642. $endStaffArray = end ( $verifyStaff );
  2643. $KOP = false;
  2644. foreach ( $roleArrayCopy as $P => $A ) {
  2645. foreach ( $A as $MKI => $AVL ) {
  2646. if (! empty ( $verifyStaff )) {
  2647. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2648. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2649. $button = 4;
  2650. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2651. }
  2652. foreach ( $verifyStaff as $m => $u ) {
  2653. $AVLFK = $AVL [0] . '_R';
  2654. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2655. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2656. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2657. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2658. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2659. break;
  2660. }
  2661. }
  2662. } else {
  2663. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2664. $button = 4;
  2665. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2666. }
  2667. }
  2668. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2669. $KOP = true;
  2670. }
  2671. }
  2672. foreach ( $roleArrayCopy as $k => $v ) {
  2673. foreach ( $verifyList as $m => $n ) {
  2674. if ($n [0] == $k) {
  2675. array_splice ( $verifyList, $m, 1, $v );
  2676. }
  2677. }
  2678. }
  2679. // 费用执行人相关数据
  2680. $executeCopy = json_decode ( $value ['executeCopy'], true );
  2681. $executeStaff = json_decode ( $value ['executeStaff'], true );
  2682. foreach ( $executeCopy as $k => $v ) {
  2683. $executeCopy [$k] ['date'] = '';
  2684. $executeCopy [$k] ['opinion'] = '';
  2685. $executeCopy [$k] ['status'] = '';
  2686. if (! empty ( $executeStaff ))
  2687. foreach ( $executeStaff as $m => $u ) {
  2688. if ($v [0] == $m) {
  2689. $executeCopy [$k] ['date'] = $u ['date'];
  2690. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  2691. $executeCopy [$k] ['status'] = $u ['status'];
  2692. break;
  2693. }
  2694. }
  2695. }
  2696. $receiptList [$key] ['executeCopy'] = $executeCopy;
  2697. $receiptList [$key] ['verifyList'] = $verifyList;
  2698. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2699. 'where' => 'sid=' . $value ['staff'],
  2700. 'asArray' => true
  2701. ) );
  2702. $receiptList [$key] ['button'] = $button;
  2703. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  2704. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  2705. }
  2706. // print_r($receiptList);
  2707. // 获取审批日志
  2708. Doo::loadModel ( 'receiptLog' );
  2709. $receiptLog = new receiptLog ();
  2710. $rlList = array ();
  2711. $rlInfo = $receiptLog->getOne ( array (
  2712. 'where' => 'rid=' . $rid . ' and status=4',
  2713. 'asArray' => true
  2714. ) );
  2715. $tijdate = $receiptLog->getOne ( array (
  2716. 'where' => 'rid=' . $rid . ' and status=2',
  2717. 'asc' => 'rlid',
  2718. 'asArray' => true
  2719. ) );
  2720. if (! empty ( $rlInfo )) {
  2721. $rlList = $receiptLog->find ( array (
  2722. 'where' => 'rid=' . $rid,
  2723. 'asc' => 'rlid',
  2724. 'asArray' => true
  2725. ) );
  2726. }
  2727. $receiptList [0] ['rlList'] = $rlList;
  2728. $data ['receiptList'] = $receiptList;
  2729. $data ['memu'] = "receipt";
  2730. $data ['staff'] = $this->staff;
  2731. $data ['receiptMemu'] = 'approvalExpenses';
  2732. $data ['verifyId'] = $this->verifyId;
  2733. $data ['executeId'] = $this->executeId;
  2734. $this->render ( "/admin/expensesDoc", $data );
  2735. }
  2736. function expensesEdi() {
  2737. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2738. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  2739. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  2740. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  2741. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2742. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  2743. if (empty ( $status ))
  2744. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  2745. $vidList = array ();
  2746. $button = 0;
  2747. Doo::loadModel ( 'verify' );
  2748. Doo::loadModel ( 'receipt' );
  2749. Doo::loadModel ( 'staff' );
  2750. $staff = new staff ();
  2751. $receipt = new receipt ();
  2752. $verify = new verify ();
  2753. Doo::loadModel ( 'L_category' );
  2754. $Lcategory = new L_category ();
  2755. Doo::loadModel ( 'enclosur' );
  2756. $enclosur = new enclosur ();
  2757. // user verify ID
  2758. $verifyDetail = $verify->find ( array (
  2759. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  2760. 'asArray' => true
  2761. ) );
  2762. foreach ( $verifyDetail as $key => $value ) {
  2763. array_push ( $vidList, $value ['vid'] );
  2764. }
  2765. $vid = implode ( ",", $vidList );
  2766. if (empty ( $verifyDetail ))
  2767. $vid = 0;
  2768. $categoryList = $Lcategory->find ( array (
  2769. 'asArray' => true
  2770. ) );
  2771. $staffList = $staff->find ( array (
  2772. 'where' => 'cid=' . $cid,
  2773. 'asArray' => true
  2774. ) );
  2775. $ap = "";
  2776. if ($status == 4) {
  2777. $ap = 4;
  2778. $status = 2;
  2779. }
  2780. // get Receipt By verifyID status 2
  2781. $receiptList = $receipt->find ( array (
  2782. 'where' => 'rid =' . $rid,
  2783. 'desc' => 'rid',
  2784. 'asArray' => true
  2785. ) );
  2786. $Locate = 0;
  2787. $roleId = 0;
  2788. if ($ap == 4)
  2789. $status = 4;
  2790. foreach ( $receiptList as $key => $value ) {
  2791. $receiptList [$key] ['Locate'] = $Locate;
  2792. $Locate ++;
  2793. $receiptList [$key] ['reviseDetail'] = array ();
  2794. if (! empty ( $value ['reviseDetail'] ))
  2795. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2796. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2797. $categoryDetil = $Lcategory->getOne ( array (
  2798. 'where' => 'cid=' . $value ['cid'],
  2799. 'asArray' => true
  2800. ) );
  2801. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2802. // 检测编辑状态
  2803. $verifyList = $verify->getOne ( array (
  2804. 'where' => 'vid=' . $value ['verify'],
  2805. 'asArray' => true
  2806. ) );
  2807. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2808. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2809. Doo::loadModel ( 'role' );
  2810. $role = new role ();
  2811. // print_r($verifyList);
  2812. $flag = true;
  2813. $roleKey = 0;
  2814. $endStaffArray = array ();
  2815. $roleArrayCopy = array ();
  2816. foreach ( $verifyList as $k => $v ) {
  2817. // init verifyStaff
  2818. if ($v [1] == 'ROLE') {
  2819. if (! empty ( $verifyStaff )) {
  2820. $endStaffArray = end ( $verifyStaff );
  2821. if ($v [0] == $endStaffArray ['nextStaff']) {
  2822. $roleId = $v [0];
  2823. }
  2824. }
  2825. $roleVerify = json_decode ( $v [3], true );
  2826. $roleKey = $k;
  2827. $roleArray = array ();
  2828. $rolename = $role->getOne ( array (
  2829. 'where' => 'rid=' . $v [0],
  2830. 'asArray' => true
  2831. ) );
  2832. foreach ( $roleVerify as $o => $p ) {
  2833. $staffID = explode ( '_', $p );
  2834. $staffInfo = $staff->getOne ( array (
  2835. 'where' => 'sid=' . $staffID [0],
  2836. 'asArray' => true
  2837. ) );
  2838. // print_r($staffID);
  2839. $exp = array (
  2840. 0 => $staffInfo ['sid'],
  2841. 1 => $staffID [1],
  2842. 2 => $staffInfo ['avatar'],
  2843. 'date' => '',
  2844. 'date' => '',
  2845. 'opinion' => '',
  2846. 'status' => '',
  2847. 'rolename' => $rolename ['name']
  2848. );
  2849. array_push ( $roleArray, $exp );
  2850. }
  2851. $roleArrayCopy [$v [0]] = $roleArray;
  2852. // $verifyList[$k]['roleArray']=$roleArray;
  2853. }
  2854. // print_r($roleArray);
  2855. $verifyList [$k] ['date'] = "";
  2856. $verifyList [$k] ['opinion'] = "";
  2857. $verifyList [$k] ['status'] = "";
  2858. if (empty ( $verifyStaff )) {
  2859. $verifyList [$k] ['date'] = "";
  2860. $verifyList [$k] ['opinion'] = "";
  2861. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2862. $verifyList [$k] ['status'] = 4;
  2863. $button = 4;
  2864. $flag = false;
  2865. }
  2866. } else {
  2867. foreach ( $verifyStaff as $m => $u ) {
  2868. if ($v [0] == $m) {
  2869. $verifyList [$k] ['date'] = $u ['date'];
  2870. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2871. $verifyList [$k] ['status'] = $u ['status'];
  2872. $flag = false;
  2873. break;
  2874. }
  2875. }
  2876. $endStaffArray = end ( $verifyStaff );
  2877. if (isset ( $endStaffArray ['ROLE'] )) {
  2878. } else {
  2879. $endKey = key ( $verifyStaff );
  2880. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  2881. $button = 4;
  2882. $verifyList [$k] ['status'] = 4;
  2883. }
  2884. }
  2885. }
  2886. }
  2887. $rolename ['name'] = '';
  2888. if (! empty ( $roleId )) {
  2889. Doo::loadModel ( 'role' );
  2890. $role = new role ();
  2891. $rolename = $role->getOne ( array (
  2892. 'where' => 'rid=' . $roleId,
  2893. 'asArray' => true
  2894. ) );
  2895. }
  2896. if (! empty ( $verifyStaff ))
  2897. $endStaffArray = end ( $verifyStaff );
  2898. $KOP = false;
  2899. foreach ( $roleArrayCopy as $P => $A ) {
  2900. foreach ( $A as $MKI => $AVL ) {
  2901. if (! empty ( $verifyStaff )) {
  2902. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2903. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2904. $button = 4;
  2905. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2906. }
  2907. foreach ( $verifyStaff as $m => $u ) {
  2908. $AVLFK = $AVL [0] . '_R';
  2909. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2910. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2911. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2912. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2913. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2914. break;
  2915. }
  2916. }
  2917. } else {
  2918. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2919. $button = 4;
  2920. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2921. }
  2922. }
  2923. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2924. $KOP = true;
  2925. }
  2926. }
  2927. // print_r($roleArrayCopy);
  2928. // echo $roleKey;
  2929. foreach ( $roleArrayCopy as $k => $v ) {
  2930. foreach ( $verifyList as $m => $n ) {
  2931. if ($n [0] == $k) {
  2932. array_splice ( $verifyList, $m, 1, $v );
  2933. }
  2934. }
  2935. }
  2936. $receiptList [$key] ['verifyList'] = $verifyList;
  2937. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2938. 'where' => 'sid=' . $value ['staff'],
  2939. 'asArray' => true
  2940. ) );
  2941. $receiptList [$key] ['button'] = $button;
  2942. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  2943. }
  2944. // $data['verifyDetail']=$verifyDetail;
  2945. $mothHtml = "";
  2946. for($i = 1; $i <= 12; $i ++) {
  2947. if ($month == $i)
  2948. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  2949. else
  2950. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  2951. }
  2952. // 获取审批日志
  2953. Doo::loadModel ( 'receiptLog' );
  2954. $receiptLog = new receiptLog ();
  2955. $rlList = array ();
  2956. $rlInfo = $receiptLog->getOne ( array (
  2957. 'where' => 'rid=' . $rid . ' and status=4',
  2958. 'asArray' => true
  2959. ) );
  2960. $tijdate = $receiptLog->getOne ( array (
  2961. 'where' => 'rid=' . $rid . ' and status=2',
  2962. 'asc' => 'rlid',
  2963. 'asArray' => true
  2964. ) );
  2965. if (! empty ( $rlInfo )) {
  2966. $rlList = $receiptLog->find ( array (
  2967. 'where' => 'rid=' . $rid,
  2968. 'asc' => 'rlid',
  2969. 'asArray' => true
  2970. ) );
  2971. }
  2972. $receiptList [0] ['rlList'] = $rlList;
  2973. $enclosurList = $enclosur->find ( array (
  2974. 'where' => 'rid=' . $rid,
  2975. 'asArray' => true
  2976. ) );
  2977. $enclosurHtml = '';
  2978. foreach ( $enclosurList as $value ) {
  2979. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  2980. }
  2981. // print_r($receiptList);
  2982. $data ['rid'] = $rid;
  2983. $data ['enclosurHtml'] = $enclosurHtml;
  2984. $data ['rolename'] = $rolename ['name'];
  2985. $data ['datetij'] = $tijdate ['date'];
  2986. $data ['mothHtml'] = $mothHtml;
  2987. $data ['receiptList'] = $receiptList;
  2988. $data ['receiptApprovalCount'] = count ( $receiptList );
  2989. $data ['status'] = $status;
  2990. $data ['year'] = $year;
  2991. $data ['categoryList'] = $categoryList;
  2992. $data ['staffList'] = $staffList;
  2993. $data ['cid'] = $cid;
  2994. $data ['sid'] = $sid;
  2995. $data ['ap'] = $ap;
  2996. $data ['memu'] = "receipt";
  2997. $data ['staff'] = $this->staff;
  2998. $data ['receiptMemu'] = 'approvalExpenses';
  2999. $data ['verifyId'] = $this->verifyId;
  3000. $data ['executeId'] = $this->executeId;
  3001. $this->render ( "/admin/expensesEdi", $data );
  3002. }
  3003. function expensesDefray() {
  3004. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  3005. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  3006. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  3007. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  3008. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  3009. if (! empty ( $rid )) {
  3010. Doo::loadModel ( "verify" );
  3011. $verify = new verify ();
  3012. Doo::loadModel ( "receiptDetail" );
  3013. $receiptDetailObj = new receiptDetail ();
  3014. Doo::loadModel ( "itemStatistics" );
  3015. Doo::loadModel ( "statistics" );
  3016. $statistics = new statistics ();
  3017. $itemStatistics = new itemStatistics ();
  3018. Doo::loadModel ( "receipt" );
  3019. $receipt = new receipt ();
  3020. Doo::loadModel ( "loanReceipt" );
  3021. $loanReceipt = new loanReceipt ();
  3022. $receiptDetail = $receipt->getOne ( array (
  3023. 'where' => 'rid=' . $rid . ' and status=2 ',
  3024. 'asArray' => true
  3025. ) );
  3026. if (empty ( $receiptDetail ))
  3027. return "/approval";
  3028. $verifyDetail = $verify->getOne ( array (
  3029. 'where' => ' vid =' . $receiptDetail ['verify'],
  3030. 'asArray' => true
  3031. ) );
  3032. $verifyString = $verifyDetail ['staff'];
  3033. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3034. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  3035. if (empty ( $opinion )) {
  3036. if ($status == 3)
  3037. $opinion = "终止";
  3038. else
  3039. $opinion = "同意支付";
  3040. }
  3041. $nowStaff = 0;
  3042. $nowStaffList = array ();
  3043. if (empty ( $verifyStaff )) {
  3044. // 还需加入是否已经进入角色审批
  3045. if ($verifyDetail [0] [1] == 'ROLE') {
  3046. // print_r($verifyDetail);echo "ddd";
  3047. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3048. foreach ( $vStaffString as $key => $value ) {
  3049. $staffK = explode ( "_", $value );
  3050. if ($staffK [0] != $this->staff [0] ['sid'])
  3051. array_push ( $nowStaffList, $staffK [0] );
  3052. }
  3053. // print_r($verifyDetail);
  3054. // die;
  3055. if (! empty ( $nowStaffList )) {
  3056. $nowStaff = implode ( ',', $nowStaffList );
  3057. $verifyStaff = array (
  3058. $this->staff [0] ['sid'] . "_R" => array (
  3059. 'date' => date ( 'Y-m-d' ),
  3060. 'opinion' => $opinion,
  3061. 'status' => $status,
  3062. 'nextStaff' => $verifyDetail [0] [0],
  3063. 'ROLE' => 1
  3064. )
  3065. );
  3066. } else {
  3067. $nowStaff = $verifyDetail [1] [0];
  3068. $verifyStaff = array (
  3069. $this->staff [0] ['sid'] . "_R" => array (
  3070. 'date' => date ( 'Y-m-d' ),
  3071. 'opinion' => $opinion,
  3072. 'status' => $status,
  3073. 'nextStaff' => $verifyDetail [1] [0]
  3074. )
  3075. );
  3076. }
  3077. } else {
  3078. if ($verifyDetail [1] [1] == 'ROLE') {
  3079. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  3080. // echo "dd";
  3081. foreach ( $vStaffString as $key => $value ) {
  3082. $staffK = explode ( "_", $value );
  3083. array_push ( $nowStaffList, $staffK [0] );
  3084. }
  3085. $nowStaff = implode ( ',', $nowStaffList );
  3086. $verifyStaff = array (
  3087. $this->staff [0] ['sid'] => array (
  3088. 'date' => date ( 'Y-m-d' ),
  3089. 'opinion' => $opinion,
  3090. 'status' => $status,
  3091. 'nextStaff' => $verifyDetail [1] [0],
  3092. 'ROLE' => 1
  3093. )
  3094. );
  3095. } else {
  3096. $nowStaff = $verifyDetail [1] [0];
  3097. $verifyStaff = array (
  3098. $this->staff [0] ['sid'] => array (
  3099. 'date' => date ( 'Y-m-d' ),
  3100. 'opinion' => $opinion,
  3101. 'status' => $status,
  3102. 'nextStaff' => $verifyDetail [1] [0]
  3103. )
  3104. );
  3105. }
  3106. }
  3107. if ($status == 3)
  3108. $verifyStaff = array (
  3109. 'final' => $status,
  3110. $this->staff [0] ['sid'] => array (
  3111. 'date' => date ( 'Y-m-d' ),
  3112. 'opinion' => $opinion,
  3113. 'status' => $status
  3114. )
  3115. );
  3116. $vStaffString = json_encode ( $verifyStaff );
  3117. $receipt->nowStaff = $nowStaff;
  3118. $receipt->verifyStaff = $vStaffString;
  3119. $loanReceipt->nowStaff = $nowStaff;
  3120. $loanReceipt->verifyStaff = $vStaffString;
  3121. } else {
  3122. $VS = end ( $verifyStaff );
  3123. // 非角色审批
  3124. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  3125. $nextStaff = 0;
  3126. $roleSTF = false;
  3127. foreach ( $verifyDetail as $key => $value ) {
  3128. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  3129. if (isset ( $verifyDetail [$key + 1] )) {
  3130. $nextStaff = $verifyDetail [$key + 1] [0];
  3131. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  3132. $roleSTF = true;
  3133. }
  3134. break;
  3135. }
  3136. }
  3137. if (! $roleSTF) {
  3138. $nowStaff = $nextStaff;
  3139. $verifyStaff [$this->staff [0] ['sid']] = array (
  3140. 'date' => date ( 'Y-m-d' ),
  3141. 'opinion' => $opinion,
  3142. 'status' => $status,
  3143. 'nextStaff' => $nextStaff
  3144. );
  3145. } else {
  3146. // 获取角色下的所有用户ID
  3147. $nowStaffList = array ();
  3148. foreach ( $verifyDetail as $vfk ) {
  3149. if ($vfk [1] == 'ROLE') {
  3150. $vStaffString = json_decode ( $vfk [3] );
  3151. foreach ( $vStaffString as $key => $value ) {
  3152. $staffK = explode ( "_", $value );
  3153. array_push ( $nowStaffList, $staffK [0] );
  3154. }
  3155. }
  3156. }
  3157. $nowStaff = implode ( ',', $nowStaffList );
  3158. $verifyStaff [$this->staff [0] ['sid']] = array (
  3159. 'date' => date ( 'Y-m-d' ),
  3160. 'opinion' => $opinion,
  3161. 'status' => $status,
  3162. 'nextStaff' => $nextStaff,
  3163. 'ROLE' => 0
  3164. );
  3165. }
  3166. if ($status == 3) {
  3167. $verifyStaff ['final'] = $status;
  3168. $verifyStaff [$this->staff [0] ['sid']] = array (
  3169. 'date' => date ( 'Y-m-d' ),
  3170. 'opinion' => $opinion,
  3171. 'status' => $status
  3172. );
  3173. }
  3174. $vStaffString = json_encode ( $verifyStaff );
  3175. $receipt->nowStaff = $nowStaff;
  3176. $receipt->verifyStaff = $vStaffString;
  3177. $loanReceipt->nowStaff = $nowStaff;
  3178. $loanReceipt->verifyStaff = $vStaffString;
  3179. }
  3180. // 角色审批
  3181. if (isset ( $VS ['ROLE'] )) {
  3182. // 找出角色人 当前审批角色组
  3183. $verifyJSStaff = array ();
  3184. $nowStaffList2 = array ();
  3185. foreach ( $verifyDetail as $key => $value ) {
  3186. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  3187. $verifyJSStaff = json_decode ( $value [3] );
  3188. foreach ( $verifyJSStaff as $m ) {
  3189. $staffK = explode ( "_", $m );
  3190. array_push ( $nowStaffList2, $staffK [0] );
  3191. }
  3192. // print_r($nowStaffList2);
  3193. }
  3194. }
  3195. $RoleVerifyStaff = array ();
  3196. foreach ( $verifyStaff as $key => $value ) {
  3197. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  3198. foreach ( $nowStaffList2 as $m ) {
  3199. if ($key == $m . "_R")
  3200. $RoleVerifyStaff [$key] = $value;
  3201. }
  3202. }
  3203. }
  3204. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  3205. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  3206. // 下一个审批人ID
  3207. $nextStaff = 0;
  3208. $falg = false;
  3209. foreach ( $verifyDetail as $key => $value ) {
  3210. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  3211. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  3212. $falg = true;
  3213. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  3214. $nowStaffList = array ();
  3215. foreach ( $vStaffString as $v ) {
  3216. $staffK = explode ( "_", $v );
  3217. array_push ( $nowStaffList, $staffK [0] );
  3218. }
  3219. $nowStaff = implode ( ',', $nowStaffList );
  3220. $nextStaff = $verifyDetail [$key + 1] [0];
  3221. } elseif (isset ( $verifyDetail [$key + 1] )) {
  3222. $nextStaff = $verifyDetail [$key + 1] [0];
  3223. $nowStaff = $nextStaff;
  3224. } else
  3225. $nowStaff = '';
  3226. break;
  3227. }
  3228. }
  3229. if ($falg)
  3230. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  3231. 'date' => date ( 'Y-m-d' ),
  3232. 'opinion' => $opinion,
  3233. 'status' => $status,
  3234. 'nextStaff' => $nextStaff,
  3235. 'ROLE' => 1
  3236. );
  3237. else
  3238. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  3239. 'date' => date ( 'Y-m-d' ),
  3240. 'opinion' => $opinion,
  3241. 'status' => $status,
  3242. 'nextStaff' => $nextStaff
  3243. );
  3244. // print_r($verifyStaff);
  3245. // echo $nowStaff;die;
  3246. } else { // 进入下一个角色或者审批人
  3247. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  3248. //
  3249. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  3250. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  3251. 'date' => date ( 'Y-m-d' ),
  3252. 'opinion' => $opinion,
  3253. 'status' => $status,
  3254. 'nextStaff' => $VS ['nextStaff'],
  3255. 'ROLE' => 1
  3256. );
  3257. // print_r($verifyStaff);
  3258. // die;
  3259. }
  3260. if ($status == 3) {
  3261. $verifyStaff ['final'] = $status;
  3262. $verifyStaff [$this->staff [0] ['sid']] = array (
  3263. 'date' => date ( 'Y-m-d' ),
  3264. 'opinion' => $opinion,
  3265. 'status' => $status
  3266. );
  3267. }
  3268. $vStaffString = json_encode ( $verifyStaff );
  3269. $receipt->verifyStaff = $vStaffString;
  3270. $receipt->nowStaff = $nowStaff;
  3271. $loanReceipt->nowStaff = $nowStaff;
  3272. $loanReceipt->verifyStaff = $vStaffString;
  3273. // die;
  3274. // }
  3275. // print_r($verifyStaff);
  3276. // die;
  3277. }
  3278. // print_r($verifyStaff);die;
  3279. }
  3280. // print_r($verifyDetail);
  3281. $roleKey = 0;
  3282. $roleId = 0;
  3283. $verifyDetailCopy = array ();
  3284. foreach ( $verifyDetail as $k => $v ) {
  3285. if ($v [1] == 'ROLE') {
  3286. $roleId = $v [0];
  3287. $roleVerify = json_decode ( $v [3], true );
  3288. $roleKey = $k;
  3289. $roleArray = array ();
  3290. foreach ( $roleVerify as $o => $p ) {
  3291. $staffID = explode ( '_', $p );
  3292. $exp = array (
  3293. 0 => $staffID [0],
  3294. 1 => $staffID [1]
  3295. );
  3296. array_push ( $roleArray, $exp );
  3297. }
  3298. $verifyDetailCopy [$v [0]] = $roleArray;
  3299. }
  3300. }
  3301. // print_r($verifyDetail);
  3302. foreach ( $verifyDetailCopy as $k => $v ) {
  3303. foreach ( $verifyDetail as $m => $n ) {
  3304. if ($n [0] == $k) {
  3305. array_splice ( $verifyDetail, $m, 1, $v );
  3306. }
  3307. }
  3308. }
  3309. // 审批日志
  3310. if (! isset ( $verifyStaff ['final'] )) {
  3311. Doo::loadModel ( "receiptLog" );
  3312. $receiptLog = new receiptLog ();
  3313. if (! empty ( $roleId )) {
  3314. Doo::loadModel ( "role" );
  3315. $role = new role ();
  3316. $roleInfo = $role->getOne ( array (
  3317. 'where' => 'rid=' . $roleId,
  3318. 'asArray' => true
  3319. ) );
  3320. $receiptLog->rolename = $roleInfo ['name'];
  3321. }
  3322. $receiptLog->username = $this->staff [0] ['username'];
  3323. $receiptLog->uid = $this->staff [0] ['sid'];
  3324. $receiptLog->date = date ( "Y-m-d" );
  3325. $receiptLog->opinion = $opinion;
  3326. $receiptLog->img = $this->staff [0] ['avatar'];
  3327. $receiptLog->status = 1;
  3328. $receiptLog->rid = $rid;
  3329. $receiptLog->insert ();
  3330. }
  3331. if (isset ( $verifyStaff ['final'] )) { // rDetail
  3332. $receipt->status = 3;
  3333. $receipt->verifyBreakup = $verifyString;
  3334. $receiptDetailObj->status = 3;
  3335. $receiptDetailObj->update ( array (
  3336. 'where' => 'rid=' . $rid
  3337. ) );
  3338. // 微信企业号通知
  3339. $this->setWXMsg ( $rid, 3 );
  3340. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  3341. $receipt->status = 6;
  3342. $receipt->pastDate = date ( "Y-m-d" );
  3343. $receipt->isBK = 1;
  3344. $loanReceipt->verifyBreakup = $verifyString;
  3345. $loanReceipt->status = 1;
  3346. $loanReceipt->pastDate = date ( "Y-m-d" );
  3347. $loanReceipt->update ( array (
  3348. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  3349. ) );
  3350. // 微信企业号通知
  3351. $this->setWXMsg ( $rid, 1 );
  3352. }
  3353. $receipt->amount = $amount;
  3354. $receipt->update ( array (
  3355. 'where' => ' rid = ' . $rid
  3356. ) );
  3357. return "/approvalExpenses/2";
  3358. }
  3359. }
  3360. function ajaxExamineExe() {
  3361. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  3362. Doo::loadModel ( 'receipt' );
  3363. $receipt = new receipt ();
  3364. Doo::loadClass ( 'XDeode' );
  3365. $XDeode = new XDeode ( 5 );
  3366. if (! empty ( $rid )) {
  3367. $rLRes = $receipt->find ( array (
  3368. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  3369. 'asArray' => true
  3370. ) );
  3371. $rLRes [0]['ridKey']=$XDeode->encode ( $rLRes [0] ['rid'] );
  3372. echo json_encode ( array (
  3373. 'status' => 1,
  3374. 'receipt' => $rLRes [0]
  3375. ) );
  3376. die ();
  3377. }
  3378. echo json_encode ( array (
  3379. 'status' => 0,
  3380. 'receipt' => array ()
  3381. ) );
  3382. die ();
  3383. }
  3384. function implement() {
  3385. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3386. Doo::loadClass ( 'XDeode' );
  3387. $XDeode = new XDeode ( 5 );
  3388. Doo::loadModel ( 'receipt' );
  3389. $receipt = new receipt ();
  3390. Doo::loadModel ( 'L_category' );
  3391. $Lcategory = new L_category ();
  3392. Doo::loadModel ( 'verify' );
  3393. $verify = new verify ();
  3394. Doo::loadModel ( 'staff' );
  3395. $staff = new staff ();
  3396. Doo::loadModel ( "execute" );
  3397. $execute = new execute ();
  3398. $rid = $XDeode->decode ( $rid );
  3399. $receiptList = $receipt->find ( array (
  3400. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  3401. 'desc' => 'rid',
  3402. 'asArray' => true
  3403. ) );
  3404. Doo::loadModel ( 'loanReceipt' );
  3405. $loanReceipt = new loanReceipt ();
  3406. // print_r($receiptList);
  3407. $loanList = array ();
  3408. if (! isset ( $receiptList ))
  3409. $loanList = $loanReceipt->find ( array (
  3410. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3411. 'desc' => 'rid',
  3412. 'asArray' => true
  3413. ) );
  3414. $Locate = 0;
  3415. $roleId = 0;
  3416. $button = 0;
  3417. foreach ( $loanList as $key => $value ) {
  3418. $loanList [$key] ['Locate'] = $Locate;
  3419. $Locate ++;
  3420. $loanList [$key] ['reviseDetail'] = array ();
  3421. if (! empty ( $value ['reviseDetail'] ))
  3422. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3423. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3424. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3425. $categoryDetil = $Lcategory->getOne ( array (
  3426. 'where' => 'cid=' . $value ['cid'],
  3427. 'asArray' => true
  3428. ) );
  3429. $loanList [$key] ['category'] = $categoryDetil ['title'];
  3430. // 检测编辑状态
  3431. $verifyList = $verify->getOne ( array (
  3432. 'where' => 'vid=' . $value ['verify'],
  3433. 'asArray' => true
  3434. ) );
  3435. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3436. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3437. Doo::loadModel ( 'role' );
  3438. $role = new role ();
  3439. $flag = true;
  3440. $roleKey = 0;
  3441. $endStaffArray = array ();
  3442. $roleArrayCopy = array ();
  3443. foreach ( $verifyList as $k => $v ) {
  3444. // init verifyStaff
  3445. if ($v [1] == 'ROLE') {
  3446. if (! empty ( $verifyStaff )) {
  3447. $endStaffArray = end ( $verifyStaff );
  3448. // if ($v[0]==$endStaffArray['nextStaff']){
  3449. // $roleId=$v[0];
  3450. // }
  3451. }
  3452. $roleVerify = json_decode ( $v [3], true );
  3453. $roleKey = $k;
  3454. $roleArray = array ();
  3455. $rolename = $role->getOne ( array (
  3456. 'where' => 'rid=' . $v [0],
  3457. 'asArray' => true
  3458. ) );
  3459. foreach ( $roleVerify as $o => $p ) {
  3460. $staffID = explode ( '_', $p );
  3461. $staffInfo = $staff->getOne ( array (
  3462. 'where' => 'sid=' . $staffID [0],
  3463. 'asArray' => true
  3464. ) );
  3465. // print_r($staffID);
  3466. $exp = array (
  3467. 0 => $staffInfo ['sid'],
  3468. 1 => $staffID [1],
  3469. 2 => $staffInfo ['avatar'],
  3470. 'date' => '',
  3471. 'date' => '',
  3472. 'opinion' => '',
  3473. 'status' => '',
  3474. 'rolename' => $rolename ['name']
  3475. );
  3476. array_push ( $roleArray, $exp );
  3477. }
  3478. $roleArrayCopy [$v [0]] = $roleArray;
  3479. // $verifyList[$k]['roleArray']=$roleArray;
  3480. }
  3481. $verifyList [$k] ['date'] = "";
  3482. $verifyList [$k] ['opinion'] = "";
  3483. $verifyList [$k] ['status'] = "";
  3484. if (empty ( $verifyStaff )) {
  3485. $verifyList [$k] ['date'] = "";
  3486. $verifyList [$k] ['opinion'] = "";
  3487. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3488. $verifyList [$k] ['status'] = 4;
  3489. $flag = false;
  3490. }
  3491. } else {
  3492. foreach ( $verifyStaff as $m => $u ) {
  3493. if ($v [0] == $m) {
  3494. $verifyList [$k] ['date'] = $u ['date'];
  3495. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3496. $verifyList [$k] ['status'] = $u ['status'];
  3497. $flag = false;
  3498. break;
  3499. }
  3500. }
  3501. $endStaffArray = end ( $verifyStaff );
  3502. if (isset ( $endStaffArray ['ROLE'] )) {
  3503. } else {
  3504. // $endKey=key($verifyStaff);
  3505. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3506. // $button=4;
  3507. // $verifyList[$k]['status']=4;
  3508. // }
  3509. }
  3510. }
  3511. }
  3512. $rolename ['name'] = '';
  3513. if (! empty ( $roleId )) {
  3514. Doo::loadModel ( 'role' );
  3515. $role = new role ();
  3516. $rolename = $role->getOne ( array (
  3517. 'where' => 'rid=' . $roleId,
  3518. 'asArray' => true
  3519. ) );
  3520. }
  3521. if (! empty ( $verifyStaff ))
  3522. $endStaffArray = end ( $verifyStaff );
  3523. $KOP = false;
  3524. foreach ( $roleArrayCopy as $P => $A ) {
  3525. foreach ( $A as $MKI => $AVL ) {
  3526. if (! empty ( $verifyStaff )) {
  3527. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3528. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3529. $button = 4;
  3530. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3531. }
  3532. foreach ( $verifyStaff as $m => $u ) {
  3533. $AVLFK = $AVL [0] . '_R';
  3534. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3535. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3536. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3537. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3538. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3539. break;
  3540. }
  3541. }
  3542. } else {
  3543. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3544. $button = 4;
  3545. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3546. }
  3547. }
  3548. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3549. $KOP = true;
  3550. }
  3551. }
  3552. foreach ( $roleArrayCopy as $k => $v ) {
  3553. foreach ( $verifyList as $m => $n ) {
  3554. if ($n [0] == $k) {
  3555. array_splice ( $verifyList, $m, 1, $v );
  3556. }
  3557. }
  3558. }
  3559. $loanList [$key] ['verifyList'] = $verifyList;
  3560. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  3561. 'where' => 'sid=' . $value ['staff'],
  3562. 'asArray' => true
  3563. ) );
  3564. }
  3565. $data ['loanList'] = $loanList;
  3566. $Locate = 0;
  3567. $roleId = 0;
  3568. $button = 0;
  3569. foreach ( $receiptList as $key => $value ) {
  3570. $button2 = 0;
  3571. $receiptList [$key] ['Locate'] = $Locate;
  3572. $Locate ++;
  3573. $receiptList [$key] ['reviseDetail'] = array ();
  3574. if (! empty ( $value ['reviseDetail'] ))
  3575. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3576. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3577. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3578. $categoryDetil = $Lcategory->getOne ( array (
  3579. 'where' => 'cid=' . $value ['cid'],
  3580. 'asArray' => true
  3581. ) );
  3582. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3583. $executeList = json_decode ( $value ['executeCopy'], true );
  3584. $executeStaff = array ();
  3585. if (! empty ( $value ['executeStaff'] ))
  3586. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3587. if (isset ( $executeList )) {
  3588. foreach ( $executeList as $op => $lo ) {
  3589. $executeList [$op] ['date'] = "";
  3590. $executeList [$op] ['opinion'] = "";
  3591. $executeList [$op] ['status'] = "";
  3592. foreach ( $executeStaff as $m => $u ) {
  3593. if ($lo [0] == $m) {
  3594. $executeList [$op] ['date'] = $u ['date'];
  3595. $executeList [$op] ['opinion'] = $u ['opinion'];
  3596. $executeList [$op] ['status'] = $u ['status'];
  3597. break;
  3598. }
  3599. }
  3600. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  3601. $button2 = 1;
  3602. $executeList [$op] ['status'] = 4;
  3603. }
  3604. }
  3605. }
  3606. // 检测编辑状态
  3607. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  3608. $verifyList ['staff'] = $value ['verifyBreakup'];
  3609. } else
  3610. $verifyList = $verify->getOne ( array (
  3611. 'where' => 'vid=' . $value ['verify'],
  3612. 'asArray' => true
  3613. ) );
  3614. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3615. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3616. Doo::loadModel ( 'role' );
  3617. $role = new role ();
  3618. if ($verifyList == NULL)
  3619. $verifyList = array ();
  3620. $flag = true;
  3621. $roleKey = 0;
  3622. $endStaffArray = array ();
  3623. $roleArrayCopy = array ();
  3624. foreach ( $verifyList as $k => $v ) {
  3625. // init verifyStaff
  3626. if ($v [1] == 'ROLE') {
  3627. if (! empty ( $verifyStaff )) {
  3628. $endStaffArray = end ( $verifyStaff );
  3629. // if ($v[0]==$endStaffArray['nextStaff']){
  3630. // $roleId=$v[0];
  3631. // }
  3632. }
  3633. $roleVerify = json_decode ( $v [3], true );
  3634. $roleKey = $k;
  3635. $roleArray = array ();
  3636. $rolename = $role->getOne ( array (
  3637. 'where' => 'rid=' . $v [0],
  3638. 'asArray' => true
  3639. ) );
  3640. foreach ( $roleVerify as $o => $p ) {
  3641. $staffID = explode ( '_', $p );
  3642. $staffInfo = $staff->getOne ( array (
  3643. 'where' => 'sid=' . $staffID [0],
  3644. 'asArray' => true
  3645. ) );
  3646. // print_r($staffID);
  3647. $exp = array (
  3648. 0 => $staffInfo ['sid'],
  3649. 1 => $staffID [1],
  3650. 2 => $staffInfo ['avatar'],
  3651. 'date' => '',
  3652. 'date' => '',
  3653. 'opinion' => '',
  3654. 'status' => '',
  3655. 'rolename' => $rolename ['name']
  3656. );
  3657. array_push ( $roleArray, $exp );
  3658. }
  3659. $roleArrayCopy [$v [0]] = $roleArray;
  3660. // $verifyList[$k]['roleArray']=$roleArray;
  3661. }
  3662. $verifyList [$k] ['date'] = "";
  3663. $verifyList [$k] ['opinion'] = "";
  3664. $verifyList [$k] ['status'] = "";
  3665. if (empty ( $verifyStaff )) {
  3666. $verifyList [$k] ['date'] = "";
  3667. $verifyList [$k] ['opinion'] = "";
  3668. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3669. $verifyList [$k] ['status'] = 4;
  3670. $flag = false;
  3671. }
  3672. } else {
  3673. foreach ( $verifyStaff as $m => $u ) {
  3674. if ($v [0] == $m) {
  3675. $verifyList [$k] ['date'] = $u ['date'];
  3676. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3677. $verifyList [$k] ['status'] = $u ['status'];
  3678. $flag = false;
  3679. break;
  3680. }
  3681. }
  3682. $endStaffArray = end ( $verifyStaff );
  3683. if (isset ( $endStaffArray ['ROLE'] )) {
  3684. } else {
  3685. // $endKey=key($verifyStaff);
  3686. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3687. // $button=4;
  3688. // $verifyList[$k]['status']=4;
  3689. // }
  3690. }
  3691. }
  3692. }
  3693. $rolename ['name'] = '';
  3694. if (! empty ( $roleId )) {
  3695. Doo::loadModel ( 'role' );
  3696. $role = new role ();
  3697. $rolename = $role->getOne ( array (
  3698. 'where' => 'rid=' . $roleId,
  3699. 'asArray' => true
  3700. ) );
  3701. }
  3702. if (! empty ( $verifyStaff ))
  3703. $endStaffArray = end ( $verifyStaff );
  3704. $KOP = false;
  3705. foreach ( $roleArrayCopy as $P => $A ) {
  3706. foreach ( $A as $MKI => $AVL ) {
  3707. if (! empty ( $verifyStaff )) {
  3708. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3709. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3710. $button = 4;
  3711. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3712. }
  3713. foreach ( $verifyStaff as $m => $u ) {
  3714. $AVLFK = $AVL [0] . '_R';
  3715. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3716. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3717. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3718. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3719. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3720. break;
  3721. }
  3722. }
  3723. } else {
  3724. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3725. $button = 4;
  3726. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3727. }
  3728. }
  3729. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3730. $KOP = true;
  3731. }
  3732. }
  3733. foreach ( $roleArrayCopy as $k => $v ) {
  3734. foreach ( $verifyList as $m => $n ) {
  3735. if ($n [0] == $k) {
  3736. array_splice ( $verifyList, $m, 1, $v );
  3737. }
  3738. }
  3739. }
  3740. $receiptList [$key] ['verifyList'] = $verifyList;
  3741. $receiptList [$key] ['executeList'] = $executeList;
  3742. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3743. 'where' => 'sid=' . $value ['staff'],
  3744. 'asArray' => true
  3745. ) );
  3746. $receiptList [$key] ['button2'] = $button2;
  3747. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  3748. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  3749. $relust = $value ['sum'] - $value ['loanSum'];
  3750. $receiptList [$key] ['relust'] = $relust;
  3751. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  3752. }
  3753. // print_r($receiptList[$key]['executeList']);
  3754. $data ['receiptList'] = $receiptList;
  3755. $data ['memu'] = "receipt";
  3756. $data ['staff'] = $this->staff;
  3757. $data ['receiptMemu'] = 'implement';
  3758. $data ['verifyId'] = $this->verifyId;
  3759. $data ['executeId'] = $this->executeId;
  3760. $this->render ( "/admin/implement", $data );
  3761. }
  3762. function implementDo() {
  3763. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  3764. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  3765. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  3766. if (! empty ( $rid )&&!empty($amount)) {
  3767. Doo::loadModel ( 'receipt' );
  3768. $receipt = new receipt ();
  3769. Doo::loadClass ( 'XDeode' );
  3770. $XDeode = new XDeode ( 5 );
  3771. $rinfo = $receipt->getOne ( array (
  3772. 'where' => 'rid=' . $rid,
  3773. 'asArray' => true
  3774. ) );
  3775. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  3776. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  3777. if (empty ( $executeStaff )) {
  3778. $executeStaff = array (
  3779. $this->staff [0] ['sid'] => array (
  3780. 'date' => date ( 'Y-m-d' ),
  3781. 'opinion' => $implementOpinions,
  3782. 'status' => 1
  3783. )
  3784. );
  3785. } else {
  3786. $executeStaff [$this->staff [0] ['sid']] = array (
  3787. 'date' => date ( 'Y-m-d' ),
  3788. 'opinion' => $implementOpinions,
  3789. 'status' => 1
  3790. );
  3791. }
  3792. if (count ( $executeStaff ) == count ( $executeCopy )) {
  3793. $receipt->executeStaff = json_encode ( $executeStaff );
  3794. $receipt->status = 8;
  3795. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  3796. $receipt->status = 9;
  3797. $receipt->executeDate = date ( "Y-m-d" );
  3798. } else {
  3799. $receipt->executeStaff = json_encode ( $executeStaff );
  3800. }
  3801. $receipt->amount=$amount;
  3802. $receipt->update ( array (
  3803. 'where' => 'rid=' . $rid
  3804. ) );
  3805. }
  3806. $ridKey = $XDeode->encode ( $rid );
  3807. return "/implement/".$ridKey.".html";
  3808. }
  3809. function receiptburEdi() {
  3810. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3811. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  3812. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  3813. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  3814. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3815. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  3816. if (empty ( $status ))
  3817. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  3818. $vidList = array ();
  3819. $button = 0;
  3820. Doo::loadModel ( 'verify' );
  3821. Doo::loadModel ( 'receipt' );
  3822. Doo::loadModel ( 'staff' );
  3823. $staff = new staff ();
  3824. $receipt = new receipt ();
  3825. $verify = new verify ();
  3826. Doo::loadModel ( 'L_category' );
  3827. $Lcategory = new L_category ();
  3828. Doo::loadModel ( 'enclosur' );
  3829. $enclosur = new enclosur ();
  3830. Doo::loadModel ( 'loanReceipt' );
  3831. $loanReceipt = new loanReceipt ();
  3832. // user verify ID
  3833. $verifyDetail = $verify->find ( array (
  3834. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  3835. 'asArray' => true
  3836. ) );
  3837. foreach ( $verifyDetail as $key => $value ) {
  3838. array_push ( $vidList, $value ['vid'] );
  3839. }
  3840. $vid = implode ( ",", $vidList );
  3841. if (empty ( $verifyDetail ))
  3842. $vid = 0;
  3843. $categoryList = $Lcategory->find ( array (
  3844. 'asArray' => true
  3845. ) );
  3846. $staffList = $staff->find ( array (
  3847. 'where' => 'cid=' . $cid,
  3848. 'asArray' => true
  3849. ) );
  3850. $ap = "";
  3851. if ($status == 4) {
  3852. $ap = 4;
  3853. $status = 2;
  3854. }
  3855. // get Receipt By verifyID status 2
  3856. $receiptList = $receipt->find ( array (
  3857. 'where' => 'rid =' . $rid,
  3858. 'desc' => 'rid',
  3859. 'asArray' => true
  3860. ) );
  3861. $loanList = $loanReceipt->find ( array (
  3862. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3863. 'desc' => 'rid',
  3864. 'asArray' => true
  3865. ) );
  3866. $Locate = 0;
  3867. $roleId = 0;
  3868. $button = 0;
  3869. foreach ( $loanList as $key => $value ) {
  3870. $loanList [$key] ['Locate'] = $Locate;
  3871. $Locate ++;
  3872. $loanList [$key] ['reviseDetail'] = array ();
  3873. if (! empty ( $value ['reviseDetail'] ))
  3874. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3875. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3876. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3877. $categoryDetil = $Lcategory->getOne ( array (
  3878. 'where' => 'cid=' . $value ['cid'],
  3879. 'asArray' => true
  3880. ) );
  3881. $loanList [$key] ['category'] = $categoryDetil ['title'];
  3882. // 检测编辑状态
  3883. $verifyList = $verify->getOne ( array (
  3884. 'where' => 'vid=' . $value ['verify'],
  3885. 'asArray' => true
  3886. ) );
  3887. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3888. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3889. Doo::loadModel ( 'role' );
  3890. $role = new role ();
  3891. $flag = true;
  3892. $roleKey = 0;
  3893. $endStaffArray = array ();
  3894. $roleArrayCopy = array ();
  3895. foreach ( $verifyList as $k => $v ) {
  3896. // init verifyStaff
  3897. if ($v [1] == 'ROLE') {
  3898. if (! empty ( $verifyStaff )) {
  3899. $endStaffArray = end ( $verifyStaff );
  3900. }
  3901. $roleVerify = json_decode ( $v [3], true );
  3902. $roleKey = $k;
  3903. $roleArray = array ();
  3904. $rolename = $role->getOne ( array (
  3905. 'where' => 'rid=' . $v [0],
  3906. 'asArray' => true
  3907. ) );
  3908. foreach ( $roleVerify as $o => $p ) {
  3909. $staffID = explode ( '_', $p );
  3910. $staffInfo = $staff->getOne ( array (
  3911. 'where' => 'sid=' . $staffID [0],
  3912. 'asArray' => true
  3913. ) );
  3914. // print_r($staffID);
  3915. $exp = array (
  3916. 0 => $staffInfo ['sid'],
  3917. 1 => $staffID [1],
  3918. 2 => $staffInfo ['avatar'],
  3919. 'date' => '',
  3920. 'date' => '',
  3921. 'opinion' => '',
  3922. 'status' => '',
  3923. 'rolename' => $rolename ['name']
  3924. );
  3925. array_push ( $roleArray, $exp );
  3926. }
  3927. $roleArrayCopy [$v [0]] = $roleArray;
  3928. // $verifyList[$k]['roleArray']=$roleArray;
  3929. }
  3930. $verifyList [$k] ['date'] = "";
  3931. $verifyList [$k] ['opinion'] = "";
  3932. $verifyList [$k] ['status'] = "";
  3933. if (empty ( $verifyStaff )) {
  3934. $verifyList [$k] ['date'] = "";
  3935. $verifyList [$k] ['opinion'] = "";
  3936. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3937. $verifyList [$k] ['status'] = 4;
  3938. $flag = false;
  3939. }
  3940. } else {
  3941. foreach ( $verifyStaff as $m => $u ) {
  3942. if ($v [0] == $m) {
  3943. $verifyList [$k] ['date'] = $u ['date'];
  3944. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3945. $verifyList [$k] ['status'] = $u ['status'];
  3946. $flag = false;
  3947. break;
  3948. }
  3949. }
  3950. $endStaffArray = end ( $verifyStaff );
  3951. if (isset ( $endStaffArray ['ROLE'] )) {
  3952. } else {
  3953. }
  3954. }
  3955. }
  3956. $rolename ['name'] = '';
  3957. if (! empty ( $roleId )) {
  3958. Doo::loadModel ( 'role' );
  3959. $role = new role ();
  3960. $rolename = $role->getOne ( array (
  3961. 'where' => 'rid=' . $roleId,
  3962. 'asArray' => true
  3963. ) );
  3964. }
  3965. if (! empty ( $verifyStaff ))
  3966. $endStaffArray = end ( $verifyStaff );
  3967. $KOP = false;
  3968. foreach ( $roleArrayCopy as $P => $A ) {
  3969. foreach ( $A as $MKI => $AVL ) {
  3970. if (! empty ( $verifyStaff )) {
  3971. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3972. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3973. $button = 4;
  3974. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3975. }
  3976. foreach ( $verifyStaff as $m => $u ) {
  3977. $AVLFK = $AVL [0] . '_R';
  3978. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3979. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3980. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3981. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3982. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3983. break;
  3984. }
  3985. }
  3986. } else {
  3987. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3988. $button = 4;
  3989. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3990. }
  3991. }
  3992. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3993. $KOP = true;
  3994. }
  3995. }
  3996. foreach ( $roleArrayCopy as $k => $v ) {
  3997. foreach ( $verifyList as $m => $n ) {
  3998. if ($n [0] == $k) {
  3999. array_splice ( $verifyList, $m, 1, $v );
  4000. }
  4001. }
  4002. }
  4003. $loanList [$key] ['verifyList'] = $verifyList;
  4004. }
  4005. $htmlLoan = '';
  4006. if (isset ( $loanList [0] )) {
  4007. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  4008. if ($value ['status'] == 1)
  4009. $htmlLoan .= '<li class="done" >';
  4010. elseif ($value ['status'] == 3)
  4011. $htmlLoan .= '<li class="undone" >';
  4012. $htmlLoan .= '<div class="avtra"><img src="' . $value [2] . '_2.jpg"></div>';
  4013. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  4014. if (isset ( $value ['rolename'] ))
  4015. $htmlLoan .= $value ['rolename'];
  4016. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  4017. }
  4018. $data ['loanDate'] = $loanList [0] ['date'];
  4019. }
  4020. $data ['htmlLoan'] = $htmlLoan;
  4021. // print_r($loanList);
  4022. $Locate = 0;
  4023. $roleId = 0;
  4024. $button = 0;
  4025. if ($ap == 4)
  4026. $status = 4;
  4027. foreach ( $receiptList as $key => $value ) {
  4028. $receiptList [$key] ['Locate'] = $Locate;
  4029. $Locate ++;
  4030. $receiptList [$key] ['reviseDetail'] = array ();
  4031. if (! empty ( $value ['reviseDetail'] ))
  4032. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4033. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4034. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4035. $categoryDetil = $Lcategory->getOne ( array (
  4036. 'where' => 'cid=' . $value ['cid'],
  4037. 'asArray' => true
  4038. ) );
  4039. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4040. // 检测编辑状态
  4041. $verifyList = $verify->getOne ( array (
  4042. 'where' => 'vid=' . $value ['verify'],
  4043. 'asArray' => true
  4044. ) );
  4045. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4046. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4047. Doo::loadModel ( 'role' );
  4048. $role = new role ();
  4049. // print_r($verifyList);
  4050. $flag = true;
  4051. $roleKey = 0;
  4052. $endStaffArray = array ();
  4053. $roleArrayCopy = array ();
  4054. foreach ( $verifyList as $k => $v ) {
  4055. // init verifyStaff
  4056. if ($v [1] == 'ROLE') {
  4057. if (! empty ( $verifyStaff )) {
  4058. $endStaffArray = end ( $verifyStaff );
  4059. if ($v [0] == $endStaffArray ['nextStaff']) {
  4060. $roleId = $v [0];
  4061. }
  4062. }
  4063. $roleVerify = json_decode ( $v [3], true );
  4064. $roleKey = $k;
  4065. $roleArray = array ();
  4066. $rolename = $role->getOne ( array (
  4067. 'where' => 'rid=' . $v [0],
  4068. 'asArray' => true
  4069. ) );
  4070. foreach ( $roleVerify as $o => $p ) {
  4071. $staffID = explode ( '_', $p );
  4072. $staffInfo = $staff->getOne ( array (
  4073. 'where' => 'sid=' . $staffID [0],
  4074. 'asArray' => true
  4075. ) );
  4076. // print_r($staffID);
  4077. $exp = array (
  4078. 0 => $staffInfo ['sid'],
  4079. 1 => $staffID [1],
  4080. 2 => $staffInfo ['avatar'],
  4081. 'date' => '',
  4082. 'date' => '',
  4083. 'opinion' => '',
  4084. 'status' => '',
  4085. 'rolename' => $rolename ['name']
  4086. );
  4087. array_push ( $roleArray, $exp );
  4088. }
  4089. $roleArrayCopy [$v [0]] = $roleArray;
  4090. // $verifyList[$k]['roleArray']=$roleArray;
  4091. }
  4092. // print_r($roleArray);
  4093. $verifyList [$k] ['date'] = "";
  4094. $verifyList [$k] ['opinion'] = "";
  4095. $verifyList [$k] ['status'] = "";
  4096. if (empty ( $verifyStaff )) {
  4097. $verifyList [$k] ['date'] = "";
  4098. $verifyList [$k] ['opinion'] = "";
  4099. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4100. $verifyList [$k] ['status'] = 4;
  4101. $button = 4;
  4102. $flag = false;
  4103. }
  4104. } else {
  4105. foreach ( $verifyStaff as $m => $u ) {
  4106. if ($v [0] == $m) {
  4107. $verifyList [$k] ['date'] = $u ['date'];
  4108. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4109. $verifyList [$k] ['status'] = $u ['status'];
  4110. $flag = false;
  4111. break;
  4112. }
  4113. }
  4114. $endStaffArray = end ( $verifyStaff );
  4115. if (isset ( $endStaffArray ['ROLE'] )) {
  4116. } else {
  4117. $endKey = key ( $verifyStaff );
  4118. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  4119. $button = 4;
  4120. $verifyList [$k] ['status'] = 4;
  4121. }
  4122. }
  4123. }
  4124. }
  4125. $rolename ['name'] = '';
  4126. if (! empty ( $roleId )) {
  4127. Doo::loadModel ( 'role' );
  4128. $role = new role ();
  4129. $rolename = $role->getOne ( array (
  4130. 'where' => 'rid=' . $roleId,
  4131. 'asArray' => true
  4132. ) );
  4133. }
  4134. if (! empty ( $verifyStaff ))
  4135. $endStaffArray = end ( $verifyStaff );
  4136. $KOP = false;
  4137. foreach ( $roleArrayCopy as $P => $A ) {
  4138. foreach ( $A as $MKI => $AVL ) {
  4139. if (! empty ( $verifyStaff )) {
  4140. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4141. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4142. $button = 4;
  4143. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4144. }
  4145. foreach ( $verifyStaff as $m => $u ) {
  4146. $AVLFK = $AVL [0] . '_R';
  4147. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4148. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4149. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4150. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4151. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4152. break;
  4153. }
  4154. }
  4155. } else {
  4156. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4157. $button = 4;
  4158. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4159. }
  4160. }
  4161. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4162. $KOP = true;
  4163. }
  4164. }
  4165. foreach ( $roleArrayCopy as $k => $v ) {
  4166. foreach ( $verifyList as $m => $n ) {
  4167. if ($n [0] == $k) {
  4168. array_splice ( $verifyList, $m, 1, $v );
  4169. }
  4170. }
  4171. }
  4172. // print_r($verifyList);
  4173. $receiptList [$key] ['verifyList'] = $verifyList;
  4174. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4175. 'where' => 'sid=' . $value ['staff'],
  4176. 'asArray' => true
  4177. ) );
  4178. $receiptList [$key] ['button'] = $button;
  4179. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4180. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4181. $relust = $value ['sum'] - $value ['loanSum'];
  4182. $receiptList [$key] ['relust'] = $relust;
  4183. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  4184. }
  4185. // print_r($receiptList);die;
  4186. // $data['verifyDetail']=$verifyDetail;
  4187. $mothHtml = "";
  4188. for($i = 1; $i <= 12; $i ++) {
  4189. if ($month == $i)
  4190. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4191. else
  4192. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4193. }
  4194. // 获取审批日志
  4195. Doo::loadModel ( 'receiptLog' );
  4196. $receiptLog = new receiptLog ();
  4197. $rlList = array ();
  4198. $rlInfo = $receiptLog->getOne ( array (
  4199. 'where' => 'rid=' . $rid . ' and status=4',
  4200. 'asArray' => true
  4201. ) );
  4202. $tijdate = $receiptLog->getOne ( array (
  4203. 'where' => 'rid=' . $rid . ' and status=2',
  4204. 'asc' => 'rlid',
  4205. 'asArray' => true
  4206. ) );
  4207. if (! empty ( $rlInfo )) {
  4208. $rlList = $receiptLog->find ( array (
  4209. 'where' => 'rid=' . $rid,
  4210. 'asc' => 'rlid',
  4211. 'asArray' => true
  4212. ) );
  4213. }
  4214. // echo $rid;
  4215. // print_r($receiptList);
  4216. $receiptList [0] ['rlList'] = $rlList;
  4217. $enclosurList = $enclosur->find ( array (
  4218. 'where' => 'rid=' . $rid,
  4219. 'asArray' => true
  4220. ) );
  4221. $enclosurHtml = '';
  4222. foreach ( $enclosurList as $value ) {
  4223. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4224. }
  4225. $data ['enclosurHtml'] = $enclosurHtml;
  4226. $data ['rolename'] = $rolename ['name'];
  4227. // $data['datetij']=$tijdate['date'];
  4228. $data ['mothHtml'] = $mothHtml;
  4229. // print_r($receiptList);
  4230. $data ['rid'] = $rid;
  4231. $data ['tijdate'] = $tijdate ['date'];
  4232. $data ['receiptList'] = $receiptList;
  4233. $data ['receiptApprovalCount'] = count ( $receiptList );
  4234. $data ['status'] = $status;
  4235. $data ['year'] = $year;
  4236. $data ['categoryList'] = $categoryList;
  4237. $data ['staffList'] = $staffList;
  4238. $data ['cid'] = $cid;
  4239. $data ['sid'] = $sid;
  4240. $data ['ap'] = $ap;
  4241. $data ['memu'] = "receipt";
  4242. $data ['staff'] = $this->staff;
  4243. $data ['receiptMemu'] = 'approvalExpenses';
  4244. $data ['verifyId'] = $this->verifyId;
  4245. $data ['executeId'] = $this->executeId;
  4246. $this->render ( "/admin/receiptburEdi", $data );
  4247. }
  4248. function hisImplement() {
  4249. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  4250. if (empty ( $item ))
  4251. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  4252. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4253. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  4254. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  4255. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  4256. Doo::loadModel ( 'receipt' );
  4257. $receipt = new receipt ();
  4258. Doo::loadModel ( 'L_category' );
  4259. $Lcategory = new L_category ();
  4260. Doo::loadModel ( 'verify' );
  4261. Doo::loadModel ( 'statistics' );
  4262. $statistics = new statistics ();
  4263. $verify = new verify ();
  4264. Doo::loadModel ( 'staff' );
  4265. $staff = new staff ();
  4266. Doo::loadClass ( 'XDeode' );
  4267. $XDeode = new XDeode ( 5 );
  4268. $condition = "";
  4269. if ($item == "expenses")
  4270. $condition = " and Rtype=1 ";
  4271. elseif ($item == "receipts")
  4272. $condition = " and Rtype=0 ";
  4273. elseif ($item == "remits")
  4274. $condition = " and Rtype=2 ";
  4275. $sopString = "";
  4276. $dateCondition = " and Year(date) =" . $year;
  4277. if ($sop != 'SOP')
  4278. $sopString = " and staff=" . $sop;
  4279. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  4280. if ($item == 'teipts') {
  4281. $statusCon = '(status=1 or status=6 )';
  4282. $dateCondition = " and Year(pastDate) =" . $year;
  4283. if ($moth != 'MONTH')
  4284. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $moth;
  4285. if ($day != 'DAY')
  4286. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $moth . " and day(pastDate)=" . $day;
  4287. } elseif ($item == 'alerpts') {
  4288. $statusCon = '(status=8 or status=9 )';
  4289. $dateCondition = " and Year(executeDate) =" . $year;
  4290. if ($moth != 'MONTH')
  4291. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  4292. if ($day != 'DAY')
  4293. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  4294. }
  4295. // $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']); and (status=1 or status=6)
  4296. $receiptList = $receipt->find ( array (
  4297. 'where' => $statusCon . $condition . $dateCondition . $sopString,
  4298. 'desc' => 'rid',
  4299. 'asArray' => true
  4300. ) );
  4301. // 员工筛选
  4302. $receiptList2 = $receipt->find ( array (
  4303. 'where' => $statusCon . $condition . $dateCondition,
  4304. 'desc' => 'rid',
  4305. 'asArray' => true
  4306. ) );
  4307. $sopStaff = array ();
  4308. foreach ( $receiptList2 as $key => $value ) {
  4309. $staffDetail = $staff->getOne ( array (
  4310. 'where' => 'sid=' . $value ['staff'],
  4311. 'asArray' => true
  4312. ) );
  4313. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  4314. }
  4315. $Locate = 0;
  4316. $roleId = 0;
  4317. $button = 0;
  4318. foreach ( $receiptList as $key => $value ) {
  4319. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  4320. $receiptList [$key] ['Texe'] = 'false';
  4321. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  4322. $receiptList [$key] ['Texe'] = 'true';
  4323. }
  4324. $receiptList [$key] ['TRexe'] = 'true';
  4325. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  4326. $receiptList [$key] ['TRexe'] = 'false';
  4327. }
  4328. $receiptList [$key] ['Locate'] = $Locate;
  4329. $Locate ++;
  4330. $receiptList [$key] ['reviseDetail'] = array ();
  4331. if (! empty ( $value ['reviseDetail'] ))
  4332. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4333. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4334. $categoryDetil = $Lcategory->getOne ( array (
  4335. 'where' => 'cid=' . $value ['cid'],
  4336. 'asArray' => true
  4337. ) );
  4338. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4339. // 检测编辑状态
  4340. $verifyList = $verify->getOne ( array (
  4341. 'where' => 'vid=' . $value ['verify'],
  4342. 'asArray' => true
  4343. ) );
  4344. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4345. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4346. Doo::loadModel ( 'role' );
  4347. $role = new role ();
  4348. $flag = true;
  4349. $roleKey = 0;
  4350. $endStaffArray = array ();
  4351. $roleArrayCopy = array ();
  4352. foreach ( $verifyList as $k => $v ) {
  4353. // init verifyStaff
  4354. if ($v [1] == 'ROLE') {
  4355. if (! empty ( $verifyStaff )) {
  4356. $endStaffArray = end ( $verifyStaff );
  4357. }
  4358. $roleVerify = json_decode ( $v [3], true );
  4359. $roleKey = $k;
  4360. $roleArray = array ();
  4361. $rolename = $role->getOne ( array (
  4362. 'where' => 'rid=' . $v [0],
  4363. 'asArray' => true
  4364. ) );
  4365. foreach ( $roleVerify as $o => $p ) {
  4366. $staffID = explode ( '_', $p );
  4367. $staffInfo = $staff->getOne ( array (
  4368. 'where' => 'sid=' . $staffID [0],
  4369. 'asArray' => true
  4370. ) );
  4371. $exp = array (
  4372. 0 => $staffInfo ['sid'],
  4373. 1 => $staffID [1],
  4374. 2 => $staffInfo ['avatar'],
  4375. 'date' => '',
  4376. 'date' => '',
  4377. 'opinion' => '',
  4378. 'status' => '',
  4379. 'rolename' => $rolename ['name']
  4380. );
  4381. array_push ( $roleArray, $exp );
  4382. }
  4383. $roleArrayCopy [$v [0]] = $roleArray;
  4384. }
  4385. $verifyList [$k] ['date'] = "";
  4386. $verifyList [$k] ['opinion'] = "";
  4387. $verifyList [$k] ['status'] = "";
  4388. if (empty ( $verifyStaff )) {
  4389. $verifyList [$k] ['date'] = "";
  4390. $verifyList [$k] ['opinion'] = "";
  4391. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4392. $verifyList [$k] ['status'] = 4;
  4393. $flag = false;
  4394. }
  4395. } else {
  4396. foreach ( $verifyStaff as $m => $u ) {
  4397. if ($v [0] == $m) {
  4398. $verifyList [$k] ['date'] = $u ['date'];
  4399. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4400. $verifyList [$k] ['status'] = $u ['status'];
  4401. $flag = false;
  4402. break;
  4403. }
  4404. }
  4405. $endStaffArray = end ( $verifyStaff );
  4406. }
  4407. }
  4408. $rolename ['name'] = '';
  4409. if (! empty ( $roleId )) {
  4410. Doo::loadModel ( 'role' );
  4411. $role = new role ();
  4412. $rolename = $role->getOne ( array (
  4413. 'where' => 'rid=' . $roleId,
  4414. 'asArray' => true
  4415. ) );
  4416. }
  4417. if (! empty ( $verifyStaff ))
  4418. $endStaffArray = end ( $verifyStaff );
  4419. $KOP = false;
  4420. foreach ( $roleArrayCopy as $P => $A ) {
  4421. foreach ( $A as $MKI => $AVL ) {
  4422. if (! empty ( $verifyStaff )) {
  4423. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4424. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4425. $button = 4;
  4426. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4427. }
  4428. foreach ( $verifyStaff as $m => $u ) {
  4429. $AVLFK = $AVL [0] . '_R';
  4430. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4431. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4432. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4433. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4434. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4435. break;
  4436. }
  4437. }
  4438. } else {
  4439. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4440. $button = 4;
  4441. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4442. }
  4443. }
  4444. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4445. $KOP = true;
  4446. }
  4447. }
  4448. foreach ( $roleArrayCopy as $k => $v ) {
  4449. foreach ( $verifyList as $m => $n ) {
  4450. if ($n [0] == $k) {
  4451. array_splice ( $verifyList, $m, 1, $v );
  4452. }
  4453. }
  4454. }
  4455. $receiptList [$key] ['verifyList'] = $verifyList;
  4456. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4457. 'where' => 'sid=' . $value ['staff'],
  4458. 'asArray' => true
  4459. ) );
  4460. $receiptList [$key] ['button'] = $button;
  4461. }
  4462. // print_r($receiptList);
  4463. $mothHtml = "";
  4464. for($i = 1; $i <= 12; $i ++) {
  4465. if ($moth == $i)
  4466. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4467. else
  4468. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4469. }
  4470. $dayHtml = "";
  4471. if ($day != "DAY" || $moth != "MONTH") {
  4472. for($i = 1; $i <= 31; $i ++) {
  4473. if ($day == $i)
  4474. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  4475. else
  4476. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  4477. }
  4478. }
  4479. $sopHtml = "";
  4480. foreach ( $sopStaff as $key => $value ) {
  4481. if ($sop == $key)
  4482. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  4483. else
  4484. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  4485. }
  4486. $data ['sopHtml'] = $sopHtml;
  4487. $data ['dayHtml'] = $dayHtml;
  4488. $data ['mothHtml'] = $mothHtml;
  4489. $data ['receiptList'] = $receiptList;
  4490. $data ['memu'] = "receipt";
  4491. $data ['staff'] = $this->staff;
  4492. $data ['receiptMemu'] = 'implement';
  4493. $data ['verifyId'] = $this->verifyId;
  4494. $data ['executeId'] = $this->executeId;
  4495. $data ['item'] = $item;
  4496. $data ['year'] = $year;
  4497. $data ['moth'] = $moth;
  4498. $data ['day'] = $day;
  4499. $data ['sop'] = $sop;
  4500. $this->render ( "/admin/hisImplement", $data );
  4501. }
  4502. function ajaxExamine() {
  4503. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4504. Doo::loadModel ( 'receipt' );
  4505. $receipt = new receipt ();
  4506. if (! empty ( $rid )) {
  4507. $rLRes = $receipt->find ( array (
  4508. '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,
  4509. 'asArray' => true
  4510. ) );
  4511. echo json_encode ( array (
  4512. 'status' => 1,
  4513. 'receipt' => $rLRes [0]
  4514. ) );
  4515. die ();
  4516. }
  4517. echo json_encode ( array (
  4518. 'status' => 0,
  4519. 'receipt' => array ()
  4520. ) );
  4521. die ();
  4522. }
  4523. /*
  4524. * 废弃
  4525. */
  4526. function myReceipt() {
  4527. // all approval past withdraw
  4528. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  4529. if (empty ( $item ))
  4530. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  4531. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4532. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  4533. Doo::loadModel ( 'receipt' );
  4534. $receipt = new receipt ();
  4535. // pre-loaded
  4536. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  4537. // have cache
  4538. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  4539. if (! empty ( $moth )) // yearPage
  4540. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  4541. $this->showCache ( $path );
  4542. }
  4543. Doo::loadModel ( 'L_category' );
  4544. $Lcategory = new L_category ();
  4545. Doo::loadModel ( 'verify' );
  4546. Doo::loadModel ( 'statistics' );
  4547. $statistics = new statistics ();
  4548. $verify = new verify ();
  4549. Doo::loadModel ( 'staff' );
  4550. $staff = new staff ();
  4551. $condition = " and status!=0 ";
  4552. if ($item == "approval")
  4553. $condition = " and status=2 ";
  4554. elseif ($item == "withdraw")
  4555. $condition = " and status=3 ";
  4556. elseif ($item == "past")
  4557. $condition = " and status=1 ";
  4558. elseif ($item == "whdw")
  4559. $condition = " and status=4 ";
  4560. $dateCondition = " and Year(date) =" . $year;
  4561. if (! empty ( $moth )) {
  4562. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  4563. $stList = $statistics->getOne ( array (
  4564. 'select' => 'rePrice ,agPrice',
  4565. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  4566. 'asArray' => true
  4567. ) );
  4568. } else
  4569. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  4570. if (empty ( $stList ))
  4571. $stList = array (
  4572. 'rePrice' => 0,
  4573. 'agPrice' => 0
  4574. );
  4575. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  4576. $data ['stList'] = array (
  4577. 'rePrice' => $stList ['rePrice'],
  4578. 'agPrice' => $stList ['agPrice'],
  4579. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  4580. );
  4581. $receiptList = $receipt->find ( array (
  4582. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  4583. 'desc' => 'rid',
  4584. 'asArray' => true
  4585. ) );
  4586. $Locate = 0;
  4587. $roleId = 0;
  4588. $button = 0;
  4589. foreach ( $receiptList as $key => $value ) {
  4590. $receiptList [$key] ['Locate'] = $Locate;
  4591. $Locate ++;
  4592. $receiptList [$key] ['reviseDetail'] = array ();
  4593. if (! empty ( $value ['reviseDetail'] ))
  4594. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4595. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4596. $categoryDetil = $Lcategory->getOne ( array (
  4597. 'where' => 'cid=' . $value ['cid'],
  4598. 'asArray' => true
  4599. ) );
  4600. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4601. // 检测编辑状态
  4602. $verifyList = $verify->getOne ( array (
  4603. 'where' => 'vid=' . $value ['verify'],
  4604. 'asArray' => true
  4605. ) );
  4606. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4607. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4608. Doo::loadModel ( 'role' );
  4609. $role = new role ();
  4610. $flag = true;
  4611. $roleKey = 0;
  4612. $endStaffArray = array ();
  4613. $roleArrayCopy = array ();
  4614. foreach ( $verifyList as $k => $v ) {
  4615. // init verifyStaff
  4616. if ($v [1] == 'ROLE') {
  4617. if (! empty ( $verifyStaff )) {
  4618. $endStaffArray = end ( $verifyStaff );
  4619. // if ($v[0]==$endStaffArray['nextStaff']){
  4620. // $roleId=$v[0];
  4621. // }
  4622. }
  4623. $roleVerify = json_decode ( $v [3], true );
  4624. $roleKey = $k;
  4625. $roleArray = array ();
  4626. $rolename = $role->getOne ( array (
  4627. 'where' => 'rid=' . $v [0],
  4628. 'asArray' => true
  4629. ) );
  4630. foreach ( $roleVerify as $o => $p ) {
  4631. $staffID = explode ( '_', $p );
  4632. $staffInfo = $staff->getOne ( array (
  4633. 'where' => 'sid=' . $staffID [0],
  4634. 'asArray' => true
  4635. ) );
  4636. // print_r($staffID);
  4637. $exp = array (
  4638. 0 => $staffInfo ['sid'],
  4639. 1 => $staffID [1],
  4640. 2 => $staffInfo ['avatar'],
  4641. 'date' => '',
  4642. 'date' => '',
  4643. 'opinion' => '',
  4644. 'status' => '',
  4645. 'rolename' => $rolename ['name']
  4646. );
  4647. array_push ( $roleArray, $exp );
  4648. }
  4649. $roleArrayCopy [$v [0]] = $roleArray;
  4650. // $verifyList[$k]['roleArray']=$roleArray;
  4651. }
  4652. $verifyList [$k] ['date'] = "";
  4653. $verifyList [$k] ['opinion'] = "";
  4654. $verifyList [$k] ['status'] = "";
  4655. if (empty ( $verifyStaff )) {
  4656. $verifyList [$k] ['date'] = "";
  4657. $verifyList [$k] ['opinion'] = "";
  4658. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4659. $verifyList [$k] ['status'] = 4;
  4660. $flag = false;
  4661. }
  4662. } else {
  4663. foreach ( $verifyStaff as $m => $u ) {
  4664. if ($v [0] == $m) {
  4665. $verifyList [$k] ['date'] = $u ['date'];
  4666. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4667. $verifyList [$k] ['status'] = $u ['status'];
  4668. $flag = false;
  4669. break;
  4670. }
  4671. }
  4672. $endStaffArray = end ( $verifyStaff );
  4673. if (isset ( $endStaffArray ['ROLE'] )) {
  4674. } else {
  4675. // $endKey=key($verifyStaff);
  4676. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4677. // $button=4;
  4678. // $verifyList[$k]['status']=4;
  4679. // }
  4680. }
  4681. }
  4682. }
  4683. $rolename ['name'] = '';
  4684. if (! empty ( $roleId )) {
  4685. Doo::loadModel ( 'role' );
  4686. $role = new role ();
  4687. $rolename = $role->getOne ( array (
  4688. 'where' => 'rid=' . $roleId,
  4689. 'asArray' => true
  4690. ) );
  4691. }
  4692. if (! empty ( $verifyStaff ))
  4693. $endStaffArray = end ( $verifyStaff );
  4694. $KOP = false;
  4695. foreach ( $roleArrayCopy as $P => $A ) {
  4696. foreach ( $A as $MKI => $AVL ) {
  4697. if (! empty ( $verifyStaff )) {
  4698. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4699. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4700. $button = 4;
  4701. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4702. }
  4703. foreach ( $verifyStaff as $m => $u ) {
  4704. $AVLFK = $AVL [0] . '_R';
  4705. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4706. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4707. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4708. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4709. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4710. break;
  4711. }
  4712. }
  4713. } else {
  4714. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4715. $button = 4;
  4716. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4717. }
  4718. }
  4719. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4720. $KOP = true;
  4721. }
  4722. }
  4723. foreach ( $roleArrayCopy as $k => $v ) {
  4724. foreach ( $verifyList as $m => $n ) {
  4725. if ($n [0] == $k) {
  4726. array_splice ( $verifyList, $m, 1, $v );
  4727. }
  4728. }
  4729. }
  4730. $receiptList [$key] ['verifyList'] = $verifyList;
  4731. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4732. 'where' => 'sid=' . $value ['staff'],
  4733. 'asArray' => true
  4734. ) );
  4735. $receiptList [$key] ['button'] = $button;
  4736. }
  4737. // print_r($receiptList);die;
  4738. $mothHtml = "";
  4739. for($i = 1; $i <= 12; $i ++) {
  4740. if ($moth == $i)
  4741. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4742. else
  4743. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4744. }
  4745. $data ['mothHtml'] = $mothHtml;
  4746. $data ['receiptList'] = $receiptList;
  4747. $data ['memu'] = "receipt";
  4748. $data ['staff'] = $this->staff;
  4749. $data ['receiptMemu'] = 'receipt';
  4750. $data ['verifyId'] = $this->verifyId;
  4751. $data ['executeId'] = $this->executeId;
  4752. $data ['item'] = $item;
  4753. $data ['year'] = $year;
  4754. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  4755. // sufficient condition to generate cache
  4756. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  4757. $receiptList = $receipt->find ( array (
  4758. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  4759. 'asArray' => true
  4760. ) );
  4761. if (empty ( $receiptList )) { // generated files
  4762. ob_start ();
  4763. $this->render ( "/admin/saea_myList", $data );
  4764. $this->cacheFile ( $path );
  4765. die ();
  4766. // $content = ob_get_contents();
  4767. // $fp = fopen($path, "w");
  4768. // fwrite($fp, $content);
  4769. // fclose($fp);
  4770. }
  4771. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  4772. $receiptList = $receipt->find ( array (
  4773. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  4774. 'asArray' => true
  4775. ) );
  4776. if (empty ( $receiptList )) { // generated files
  4777. ob_start ();
  4778. $this->render ( "/admin/saea_myList", $data );
  4779. $this->cacheFile ( $path );
  4780. die ();
  4781. }
  4782. }
  4783. }
  4784. $this->render ( "/admin/saea_myList", $data );
  4785. }
  4786. function saeaCreate() {
  4787. Doo::loadModel ( 'accountItem' );
  4788. Doo::loadModel ( 'verify' );
  4789. Doo::loadModel ( 'receipt' );
  4790. Doo::loadModel ( 'L_category' );
  4791. $lCategory = new L_category ();
  4792. $receipt = new receipt ();
  4793. $verify = new verify ();
  4794. $accountItem = new accountItem ();
  4795. Doo::loadModel ( "role" );
  4796. $role = new role ();
  4797. $acItem = $accountItem->find ( array (
  4798. 'asArray' => true
  4799. ) );
  4800. $veList = $verify->find ( array (
  4801. 'asArray' => true
  4802. ) );
  4803. foreach ( $veList as $key => $value ) {
  4804. $v = json_decode ( $value ['staff'] );
  4805. $list = array ();
  4806. foreach ( $v as $n => $m ) {
  4807. if ($m ['1'] == 'ROLE') {
  4808. $roleInfo = $role->getOne ( array (
  4809. 'where' => 'rid=' . $m [0],
  4810. 'asArray' => true
  4811. ) );
  4812. $v [$n] [1] = $roleInfo ['name'];
  4813. array_push ( $list, $roleInfo ['name'] );
  4814. } else {
  4815. array_push ( $list, $v [$n] [1] );
  4816. }
  4817. }
  4818. $veList [$key] ['staff'] = implode ( '>', $list );
  4819. }
  4820. $data ['category'] = $lCategory->find ( array (
  4821. 'asArray' => true
  4822. ) );
  4823. $data ['veList'] = $veList;
  4824. $data ['acItem'] = $acItem;
  4825. $data ['memu'] = "receipt";
  4826. $data ['staff'] = $this->staff;
  4827. $data ['receiptMemu'] = 'saeaBorad';
  4828. $data ['verifyId'] = $this->verifyId;
  4829. $data ['executeId'] = $this->executeId;
  4830. $this->render ( "/admin/saea_create", $data );
  4831. }
  4832. function addReceipt() {
  4833. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  4834. $agency = $this->get_args ( 'agency' );
  4835. $travel = $this->get_args ( 'travel' );
  4836. $train = $this->get_args ( 'train' );
  4837. $other = $this->get_args ( 'other' );
  4838. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  4839. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  4840. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  4841. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  4842. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation )) {
  4843. Doo::loadModel ( 'receipt' );
  4844. Doo::loadModel ( 'receiptDetail' );
  4845. Doo::loadModel ( 'accountItem' );
  4846. $accountItem = new accountItem ();
  4847. $receipt = new receipt ();
  4848. Doo::loadModel ( 'enclosur' );
  4849. Doo::loadModel ( 'execute' );
  4850. $execute = new execute ();
  4851. $executeDetail = $execute->getOne ( array (
  4852. 'where' => 'mold="报销单执行人"',
  4853. 'asArray' => true
  4854. ) );
  4855. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  4856. // if(!empty($receiptDetail))
  4857. // return "/referReceipt/".$receiptDetail['rid'];
  4858. $aItem = $accountItem->find ( array (
  4859. 'asArray' => true
  4860. ) );
  4861. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  4862. $ag = $tr = $ta = $ot = 0;
  4863. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  4864. foreach ( $aItem as $key => $value ) {
  4865. if ($value ['category'] == $this->AGENCY) {
  4866. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  4867. array_push ( $accountJson [$this->AGENCY], array (
  4868. 'aid' => $value ['aid'],
  4869. 'name' => $value ['name'],
  4870. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  4871. ) );
  4872. $sum += $agency [$ag];
  4873. $agencySum += $agency [$ag];
  4874. }
  4875. $ag ++;
  4876. }
  4877. if ($value ['category'] == $this->TRAVEL) {
  4878. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  4879. array_push ( $accountJson [$this->TRAVEL], array (
  4880. 'aid' => $value ['aid'],
  4881. 'name' => $value ['name'],
  4882. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  4883. ) );
  4884. $sum += $travel [$tr];
  4885. $travelSum += $travel [$tr];
  4886. }
  4887. $tr ++;
  4888. }
  4889. if ($value ['category'] == $this->TRAIN) {
  4890. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  4891. array_push ( $accountJson [$this->TRAIN], array (
  4892. 'aid' => $value ['aid'],
  4893. 'name' => $value ['name'],
  4894. 'price' => number_format ( $train [$ta], 2, '.', '' )
  4895. ) );
  4896. $sum += $train [$ta];
  4897. $trainSum += $train [$ta];
  4898. }
  4899. $ta ++;
  4900. }
  4901. if ($value ['category'] == $this->OTHER) {
  4902. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  4903. array_push ( $accountJson [$this->OTHER], array (
  4904. 'aid' => $value ['aid'],
  4905. 'name' => $value ['name'],
  4906. 'price' => number_format ( $other [$ot], 2, '.', '' )
  4907. ) );
  4908. $sum += $other [$ot];
  4909. $otherSum += $other [$ot];
  4910. }
  4911. $ot ++;
  4912. }
  4913. }
  4914. $accountJson ['cSum'] = array (
  4915. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  4916. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  4917. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  4918. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  4919. );
  4920. // 报销单
  4921. $receipt->accountItem = json_encode ( $accountJson );
  4922. $receipt->staff = $this->staff [0] ['sid'];
  4923. $receipt->sum = number_format ( $sum, 2, '.', '' );
  4924. $receipt->date = date ( "Y-m-d" );
  4925. $receipt->cid = $cid;
  4926. $receipt->status = 5;
  4927. // 修改审批流程加入角色
  4928. $receipt->verify = $verify;
  4929. $receipt->executeCopy = $executeDetail ['staff'];
  4930. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  4931. $receipt->explanation = $explanation;
  4932. $rid = $receipt->insert ();
  4933. // 附件
  4934. if (! empty ( $enclosurName )) {
  4935. $enclosurArray = explode ( '-', $enclosurName );
  4936. foreach ( $enclosurArray as $value ) {
  4937. $enclosur = new enclosur ();
  4938. $enclosur->name = $value;
  4939. $enclosur->rid = $rid;
  4940. $enclosur->insert ();
  4941. }
  4942. // print_r($enclosurArray);die;
  4943. }
  4944. // 报销详情
  4945. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  4946. $receiptDetail = new receiptDetail ();
  4947. $receiptDetail->staff = $this->staff [0] ['sid'];
  4948. $receiptDetail->item = $value ['name'];
  4949. $receiptDetail->itemCategory = $this->AGENCY;
  4950. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  4951. $receiptDetail->date = date ( "Y-m-d" );
  4952. $receiptDetail->cid = $cid;
  4953. $receiptDetail->rid = $rid;
  4954. $receiptDetail->status = 4;
  4955. $receiptDetail->insert ();
  4956. }
  4957. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  4958. $receiptDetail = new receiptDetail ();
  4959. $receiptDetail->staff = $this->staff [0] ['sid'];
  4960. $receiptDetail->item = $value ['name'];
  4961. $receiptDetail->itemCategory = $this->TRAVEL;
  4962. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  4963. $receiptDetail->date = date ( "Y-m-d" );
  4964. $receiptDetail->cid = $cid;
  4965. $receiptDetail->rid = $rid;
  4966. $receiptDetail->status = 4;
  4967. $receiptDetail->insert ();
  4968. }
  4969. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  4970. $receiptDetail = new receiptDetail ();
  4971. $receiptDetail->staff = $this->staff [0] ['sid'];
  4972. $receiptDetail->item = $value ['name'];
  4973. $receiptDetail->itemCategory = $this->TRAIN;
  4974. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  4975. $receiptDetail->date = date ( "Y-m-d" );
  4976. $receiptDetail->cid = $cid;
  4977. $receiptDetail->rid = $rid;
  4978. $receiptDetail->status = 4;
  4979. $receiptDetail->insert ();
  4980. }
  4981. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  4982. $receiptDetail = new receiptDetail ();
  4983. $receiptDetail->staff = $this->staff [0] ['sid'];
  4984. $receiptDetail->item = $value ['name'];
  4985. $receiptDetail->itemCategory = $this->OTHER;
  4986. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  4987. $receiptDetail->date = date ( "Y-m-d" );
  4988. $receiptDetail->cid = $cid;
  4989. $receiptDetail->rid = $rid;
  4990. $receiptDetail->status = 4;
  4991. $receiptDetail->insert ();
  4992. }
  4993. // return "/referReceipt/".$rid;
  4994. }
  4995. return "/saeaBorad";
  4996. }
  4997. function referReceipt() {
  4998. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4999. Doo::loadModel ( 'receipt' );
  5000. Doo::loadModel ( 'verify' );
  5001. $verify = new verify ();
  5002. $receipt = new receipt ();
  5003. Doo::loadModel ( 'L_category' );
  5004. $lCategory = new L_category ();
  5005. Doo::loadModel ( "role" );
  5006. $role = new role ();
  5007. $receiptDetail = $receipt->find ( array (
  5008. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  5009. 'asArray' => true
  5010. ) );
  5011. if (empty ( $receiptDetail ))
  5012. return "/addReceipt";
  5013. foreach ( $receiptDetail as $key => $value ) {
  5014. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5015. $veList = $verify->getOne ( array (
  5016. 'where' => 'vid=' . $value ['verify'],
  5017. 'asArray' => true
  5018. ) );
  5019. $v = json_decode ( $veList ['staff'] );
  5020. array_push ( $v [0], $veList ['description'] );
  5021. foreach ( $v as $n => $m ) {
  5022. if ($m ['1'] == 'ROLE') {
  5023. $roleInfo = $role->getOne ( array (
  5024. 'where' => 'rid=' . $m [0],
  5025. 'asArray' => true
  5026. ) );
  5027. $v [$n] [1] = $roleInfo ['name'];
  5028. }
  5029. }
  5030. $receiptDetail [$key] ['staff'] = $v;
  5031. $category = $lCategory->getOne ( array (
  5032. 'where' => 'cid=' . $value ['cid'],
  5033. 'asArray' => true
  5034. ) );
  5035. $receiptDetail [$key] ['category'] = $category ['title'];
  5036. }
  5037. // print_r($receiptDetail);
  5038. $data ['receiptDetail'] = $receiptDetail;
  5039. $data ['memu'] = "receipt";
  5040. $data ['staff'] = $this->staff;
  5041. $data ['receiptMemu'] = 'saeaCreate';
  5042. $data ['verifyId'] = $this->verifyId;
  5043. $data ['executeId'] = $this->executeId;
  5044. $this->render ( "/admin/saea_confirm", $data );
  5045. }
  5046. function editReceipt() {
  5047. // edit status 4
  5048. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5049. // echo $rid;
  5050. Doo::loadModel ( 'accountItem' );
  5051. Doo::loadModel ( 'verify' );
  5052. Doo::loadModel ( 'receipt' );
  5053. $receipt = new receipt ();
  5054. $verify = new verify ();
  5055. $accountItem = new accountItem ();
  5056. Doo::loadModel ( 'L_category' );
  5057. $lCategory = new L_category ();
  5058. Doo::loadModel ( "role" );
  5059. $role = new role ();
  5060. $receiptDetail = $receipt->getOne ( array (
  5061. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  5062. 'asArray' => true
  5063. ) );
  5064. if (empty ( $receiptDetail ))
  5065. return "/saeaCreate";
  5066. $acItem = $accountItem->find ( array (
  5067. 'asArray' => true
  5068. ) );
  5069. $veList = $verify->find ( array (
  5070. 'asArray' => true
  5071. ) );
  5072. foreach ( $veList as $key => $value ) {
  5073. $v = json_decode ( $value ['staff'] );
  5074. $list = array ();
  5075. foreach ( $v as $n => $m ) {
  5076. if ($m ['1'] == 'ROLE') {
  5077. $roleInfo = $role->getOne ( array (
  5078. 'where' => 'rid=' . $m [0],
  5079. 'asArray' => true
  5080. ) );
  5081. $v [$n] [1] = $roleInfo ['name'];
  5082. array_push ( $list, $roleInfo ['name'] );
  5083. } else {
  5084. array_push ( $list, $v [$n] [1] );
  5085. }
  5086. }
  5087. $veList [$key] ['staff'] = implode ( '>', $list );
  5088. }
  5089. // 配置编辑信息
  5090. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  5091. foreach ( $acItem as $key => $value ) {
  5092. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  5093. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  5094. $acItem [$key] ['price'] = $v ['price'];
  5095. }
  5096. }
  5097. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  5098. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  5099. $acItem [$key] ['price'] = $v ['price'];
  5100. }
  5101. }
  5102. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  5103. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  5104. $acItem [$key] ['price'] = $v ['price'];
  5105. }
  5106. }
  5107. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  5108. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  5109. $acItem [$key] ['price'] = $v ['price'];
  5110. }
  5111. }
  5112. }
  5113. $data ['category'] = $lCategory->find ( array (
  5114. 'asArray' => true
  5115. ) );
  5116. $data ['cSum'] = $accountItemList ['cSum'];
  5117. $data ['sum'] = $receiptDetail ['sum'];
  5118. $data ['receiptDetail'] = $receiptDetail;
  5119. $data ['veList'] = $veList;
  5120. $data ['acItem'] = $acItem;
  5121. $data ['memu'] = "receipt";
  5122. $data ['staff'] = $this->staff;
  5123. $data ['receiptMemu'] = 'saeaBorad';
  5124. $data ['verify'] = $receiptDetail ['verify'];
  5125. $data ['verifyId'] = $this->verifyId;
  5126. $data ['executeId'] = $this->executeId;
  5127. $data ['rid'] = $rid;
  5128. $this->render ( "/admin/saea_edit", $data );
  5129. }
  5130. function updateReceipt() {
  5131. $agency = $this->get_args ( 'agency' );
  5132. $travel = $this->get_args ( 'travel' );
  5133. $train = $this->get_args ( 'train' );
  5134. $other = $this->get_args ( 'other' );
  5135. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  5136. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  5137. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  5138. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5139. if (! empty ( $explanation )) {
  5140. Doo::loadModel ( 'receipt' );
  5141. Doo::loadModel ( 'receiptDetail' );
  5142. Doo::loadModel ( 'accountItem' );
  5143. $accountItem = new accountItem ();
  5144. $receipt = new receipt ();
  5145. Doo::loadModel ( 'execute' );
  5146. $execute = new execute ();
  5147. $receiptDetail = $receipt->getOne ( array (
  5148. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  5149. 'asArray' => true
  5150. ) );
  5151. if (empty ( $receiptDetail ))
  5152. return "/saeaBorad";
  5153. if ($receiptDetail ['Rtype'] == 1)
  5154. $executeDetail = $execute->getOne ( array (
  5155. 'where' => 'mold="借款费用执行人"',
  5156. 'asArray' => true
  5157. ) );
  5158. else
  5159. $executeDetail = $execute->getOne ( array (
  5160. 'where' => 'mold="报销单执行人"',
  5161. 'asArray' => true
  5162. ) );
  5163. $aItem = $accountItem->find ( array (
  5164. 'asArray' => true
  5165. ) );
  5166. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  5167. $ag = $tr = $ta = $ot = 0;
  5168. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  5169. foreach ( $aItem as $key => $value ) {
  5170. if ($value ['category'] == $this->AGENCY) {
  5171. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  5172. array_push ( $accountJson [$this->AGENCY], array (
  5173. 'aid' => $value ['aid'],
  5174. 'name' => $value ['name'],
  5175. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  5176. ) );
  5177. $sum += $agency [$ag];
  5178. $agencySum += $agency [$ag];
  5179. }
  5180. $ag ++;
  5181. }
  5182. if ($value ['category'] == $this->TRAVEL) {
  5183. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  5184. array_push ( $accountJson [$this->TRAVEL], array (
  5185. 'aid' => $value ['aid'],
  5186. 'name' => $value ['name'],
  5187. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  5188. ) );
  5189. $sum += $travel [$tr];
  5190. $travelSum += $travel [$tr];
  5191. }
  5192. $tr ++;
  5193. }
  5194. if ($value ['category'] == $this->TRAIN) {
  5195. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  5196. array_push ( $accountJson [$this->TRAIN], array (
  5197. 'aid' => $value ['aid'],
  5198. 'name' => $value ['name'],
  5199. 'price' => number_format ( $train [$ta], 2, '.', '' )
  5200. ) );
  5201. $sum += $train [$ta];
  5202. $trainSum += $train [$ta];
  5203. }
  5204. $ta ++;
  5205. }
  5206. if ($value ['category'] == $this->OTHER) {
  5207. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  5208. array_push ( $accountJson [$this->OTHER], array (
  5209. 'aid' => $value ['aid'],
  5210. 'name' => $value ['name'],
  5211. 'price' => number_format ( $other [$ot], 2, '.', '' )
  5212. ) );
  5213. $sum += $other [$ot];
  5214. $otherSum += $other [$ot];
  5215. }
  5216. $ot ++;
  5217. }
  5218. }
  5219. $accountJson ['cSum'] = array (
  5220. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  5221. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  5222. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  5223. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  5224. );
  5225. // 报销单
  5226. $rid = $receipt->rid = $receiptDetail ['rid'];
  5227. $receipt->accountItem = json_encode ( $accountJson );
  5228. $receipt->staff = $this->staff [0] ['sid'];
  5229. $receipt->sum = number_format ( $sum, 2, '.', '' );
  5230. $receipt->date = date ( "Y-m-d" );
  5231. $receipt->cid = $cid;
  5232. if (($receiptDetail ['status'] != 4)) {
  5233. if ($receiptDetail ['Rtype'] == 1)
  5234. $receipt->status = 7;
  5235. else
  5236. $receipt->status = 5;
  5237. }
  5238. if ($receiptDetail != 4 && ! empty ( $verify ))
  5239. $receipt->verify = $verify;
  5240. $receipt->executeCopy = $executeDetail ['staff'];
  5241. $receipt->explanation = $explanation;
  5242. $receipt->update ();
  5243. $receiptDetail = new receiptDetail ();
  5244. $receiptDetail->delete ( array (
  5245. 'where' => 'rid=' . $rid
  5246. ) );
  5247. // 报销详情
  5248. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  5249. $receiptDetail = new receiptDetail ();
  5250. $receiptDetail->staff = $this->staff [0] ['sid'];
  5251. $receiptDetail->item = $value ['name'];
  5252. $receiptDetail->itemCategory = $this->AGENCY;
  5253. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  5254. $receiptDetail->date = date ( "Y-m-d" );
  5255. $receiptDetail->cid = $cid;
  5256. $receiptDetail->rid = $rid;
  5257. $receiptDetail->status = 4;
  5258. $receiptDetail->insert ();
  5259. }
  5260. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  5261. $receiptDetail = new receiptDetail ();
  5262. $receiptDetail->staff = $this->staff [0] ['sid'];
  5263. $receiptDetail->item = $value ['name'];
  5264. $receiptDetail->itemCategory = $this->TRAVEL;
  5265. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  5266. $receiptDetail->date = date ( "Y-m-d" );
  5267. $receiptDetail->cid = $cid;
  5268. $receiptDetail->rid = $rid;
  5269. $receiptDetail->status = 4;
  5270. $receiptDetail->insert ();
  5271. }
  5272. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  5273. $receiptDetail = new receiptDetail ();
  5274. $receiptDetail->staff = $this->staff [0] ['sid'];
  5275. $receiptDetail->item = $value ['name'];
  5276. $receiptDetail->itemCategory = $this->TRAIN;
  5277. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  5278. $receiptDetail->date = date ( "Y-m-d" );
  5279. $receiptDetail->cid = $cid;
  5280. $receiptDetail->rid = $rid;
  5281. $receiptDetail->status = 4;
  5282. $receiptDetail->insert ();
  5283. }
  5284. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  5285. $receiptDetail = new receiptDetail ();
  5286. $receiptDetail->staff = $this->staff [0] ['sid'];
  5287. $receiptDetail->item = $value ['name'];
  5288. $receiptDetail->itemCategory = $this->OTHER;
  5289. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  5290. $receiptDetail->date = date ( "Y-m-d" );
  5291. $receiptDetail->cid = $cid;
  5292. $receiptDetail->rid = $rid;
  5293. $receiptDetail->status = 4;
  5294. $receiptDetail->insert ();
  5295. }
  5296. // return "/referReceipt/".$rid;
  5297. }
  5298. return "/saeaBorad";
  5299. }
  5300. function approvedReceipt() {
  5301. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5302. Doo::loadModel ( 'receipt' );
  5303. Doo::loadModel ( 'receiptDetail' );
  5304. $receipt = new receipt ();
  5305. $receiptDetail = new receiptDetail ();
  5306. Doo::loadModel ( 'statistics' );
  5307. Doo::loadModel ( 'itemStatistics' );
  5308. $statistics = new statistics ();
  5309. $itemStatistics = new itemStatistics ();
  5310. Doo::loadModel ( "verify" );
  5311. $verify = new verify ();
  5312. // 审批状态的判定
  5313. $receiptDetailList = $receipt->getOne ( array (
  5314. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  5315. 'asArray' => true
  5316. ) );
  5317. if (empty ( $receiptDetailList ))
  5318. return "/saeaBorad";
  5319. $verifyDetail = $verify->getOne ( array (
  5320. 'where' => ' vid =' . $receiptDetailList ['verify'],
  5321. 'asArray' => true
  5322. ) );
  5323. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  5324. if (empty ( $receiptDetailList ['nowStaff'] )) {
  5325. $nowStaff = "";
  5326. $nowStaffList = array ();
  5327. if ($verifyDetail [0] [1] == 'ROLE') {
  5328. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  5329. foreach ( $vStaffString as $key => $value ) {
  5330. $staffK = explode ( "_", $value );
  5331. array_push ( $nowStaffList, $staffK [0] );
  5332. }
  5333. $nowStaff = implode ( ',', $nowStaffList );
  5334. } else {
  5335. $nowStaff = $verifyDetail [0] [0];
  5336. }
  5337. $receipt->nowStaff = $nowStaff;
  5338. }
  5339. // echo $nowStaff;
  5340. // print_r($verifyDetail);die;
  5341. $receipt->rid = $receiptDetailList ['rid'];
  5342. $receipt->date = date ( "Y-m-d" );
  5343. $receipt->status = 2;
  5344. $receipt->update ();
  5345. $receiptDetail->status = 2;
  5346. $receiptDetail->update ( array (
  5347. 'where' => 'rid=' . $receiptDetailList ['rid']
  5348. ) );
  5349. Doo::loadModel ( "receiptLog" );
  5350. $receiptLog = new receiptLog ();
  5351. Doo::loadModel ( "verify" );
  5352. $verify = new verify ();
  5353. $receiptInfo = $receipt->getOne ( array (
  5354. 'where' => 'rid=' . $rid,
  5355. 'asArray' => true
  5356. ) );
  5357. $vr = $verify->getOne ( array (
  5358. 'where' => 'vid=' . $receiptInfo ['verify'],
  5359. 'asArray' => true
  5360. ) );
  5361. $jd = json_decode ( $vr ['staff'] );
  5362. $roleId = 0;
  5363. foreach ( $jd as $key => $value ) {
  5364. if ($value [1] == 'ROLE') {
  5365. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  5366. if ($pos !== false) {
  5367. $roleId = $value [0];
  5368. }
  5369. }
  5370. }
  5371. // 审批日志
  5372. // echo $roleId;die;
  5373. if (! empty ( $roleId )) {
  5374. Doo::loadModel ( "role" );
  5375. $role = new role ();
  5376. $roleInfo = $role->getOne ( array (
  5377. 'where' => 'rid=' . $roleId,
  5378. 'asArray' => true
  5379. ) );
  5380. $receiptLog->rolename = $roleInfo ['name'];
  5381. }
  5382. $receiptLog->username = $this->staff [0] ['username'];
  5383. $receiptLog->uid = $this->staff [0] ['sid'];
  5384. $receiptLog->date = date ( "Y-m-d" );
  5385. $receiptLog->opinion = '提交审批';
  5386. $receiptLog->img = $this->staff [0] ['avatar'];
  5387. $receiptLog->status = 2;
  5388. $receiptLog->rid = $rid;
  5389. $receiptLog->insert ();
  5390. // statistics item
  5391. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  5392. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  5393. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  5394. // print_r($accountItem['cSum']['agencySum']);die;
  5395. // foreach ($accountItem['cSum'] as $key=>$value){
  5396. // if($key=="agencySum"){
  5397. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5398. // if(empty($iStatistics)){
  5399. // $itemStatistics->cid=$this->staff[0]['cid'];
  5400. // $itemStatistics->staff=$this->staff[0]['sid'];
  5401. // $itemStatistics->price=$value;
  5402. // $itemStatistics->itemCategory=$this->AGENCY;
  5403. // $itemStatistics->date=date("Y-m-d");
  5404. // $itemStatistics->insert();
  5405. // }else{
  5406. // if (!empty($value)){
  5407. // $itemStatistics->price=$value+$iStatistics['price'];
  5408. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5409. // }
  5410. // }
  5411. // }elseif($key=="travelSum"){
  5412. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5413. // if(empty($iStatistics)){
  5414. // $itemStatistics->cid=$this->staff[0]['cid'];
  5415. // $itemStatistics->staff=$this->staff[0]['sid'];
  5416. // $itemStatistics->price=$value;
  5417. // $itemStatistics->itemCategory=$this->TRAVEL;
  5418. // $itemStatistics->date=date("Y-m-d");
  5419. // $itemStatistics->insert();
  5420. // }else{
  5421. // if (!empty($value)){
  5422. // $itemStatistics->price=$value+$iStatistics['price'];
  5423. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5424. // }
  5425. // }
  5426. // }elseif($key=="trainSum"){
  5427. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5428. // if(empty($iStatistics)){
  5429. // $itemStatistics->cid=$this->staff[0]['cid'];
  5430. // $itemStatistics->staff=$this->staff[0]['sid'];
  5431. // $itemStatistics->price=$value;
  5432. // $itemStatistics->itemCategory=$this->TRAIN;
  5433. // $itemStatistics->date=date("Y-m-d");
  5434. // $itemStatistics->insert();
  5435. // }else{
  5436. // if (!empty($value)){
  5437. // $itemStatistics->price=$value+$iStatistics['price'];
  5438. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5439. // }
  5440. // }
  5441. // }elseif($key=="otherSum"){
  5442. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5443. // if(empty($iStatistics)){
  5444. // $itemStatistics->cid=$this->staff[0]['cid'];
  5445. // $itemStatistics->staff=$this->staff[0]['sid'];
  5446. // $itemStatistics->price=$value;
  5447. // $itemStatistics->itemCategory=$this->OTHER;
  5448. // $itemStatistics->date=date("Y-m-d");
  5449. // $itemStatistics->insert();
  5450. // }else{
  5451. // if (!empty($value)){
  5452. // $itemStatistics->price=$value+$iStatistics['price'];
  5453. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5454. // }
  5455. // }
  5456. // }
  5457. // }
  5458. $stat = $statistics->getOne ( array (
  5459. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  5460. 'asArray' => true
  5461. ) );
  5462. if (empty ( $stat )) {
  5463. $statistics->date = date ( "Y-m-d" );
  5464. $statistics->cid = $this->staff [0] ['cid'];
  5465. $statistics->staff = $this->staff [0] ['sid'];
  5466. $statistics->agPrice = 0;
  5467. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  5468. $statistics->insert ();
  5469. } else {
  5470. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  5471. $statistics->update ( array (
  5472. 'where' => 'sid=' . $stat ['sid']
  5473. ) );
  5474. }
  5475. return "/expenses";
  5476. }
  5477. function approval() {
  5478. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5479. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5480. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5481. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5482. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5483. if (empty ( $status ))
  5484. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5485. $vidList = array ();
  5486. $button = 0;
  5487. Doo::loadModel ( 'verify' );
  5488. $verify = new verify ();
  5489. Doo::loadModel ( 'receipt' );
  5490. $receipt = new receipt ();
  5491. Doo::loadModel ( 'staff' );
  5492. $staff = new staff ();
  5493. Doo::loadModel ( 'L_category' );
  5494. $Lcategory = new L_category ();
  5495. // user verify ID
  5496. $verifyDetail = $verify->find ( array (
  5497. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5498. 'asArray' => true
  5499. ) );
  5500. foreach ( $verifyDetail as $key => $value ) {
  5501. array_push ( $vidList, $value ['vid'] );
  5502. }
  5503. $vid = implode ( ",", $vidList );
  5504. if (empty ( $verifyDetail ))
  5505. $vid = 0;
  5506. /*
  5507. */
  5508. $dateCondition = " and Year(date) =" . $year;
  5509. if (! empty ( $month ))
  5510. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  5511. $categoryList = $Lcategory->find ( array (
  5512. 'asArray' => true
  5513. ) );
  5514. $staffList = $staff->find ( array (
  5515. 'where' => 'cid=' . $cid,
  5516. 'asArray' => true
  5517. ) );
  5518. $cateCondition = "";
  5519. $staffCondition = "";
  5520. $approvalCondition = "";
  5521. if (! empty ( $cid ))
  5522. $cateCondition = ' and cid=' . $cid;
  5523. if (! empty ( $sid )) {
  5524. $staffCondition = ' and staff=' . $sid;
  5525. $cateCondition = "";
  5526. }
  5527. // elseif($status==1){
  5528. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  5529. // }
  5530. if ($status == 2) {
  5531. // 查找角色审批人
  5532. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  5533. }
  5534. $ap = "";
  5535. if ($status == 4) {
  5536. $ap = 4;
  5537. $status = 2;
  5538. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  5539. }
  5540. if ($status == 5) {
  5541. $status = 4;
  5542. $ap = 5;
  5543. }
  5544. // echo $vid;
  5545. // get Receipt By verifyID status 2 .$approvalCondition
  5546. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  5547. $receiptList = $receipt->find ( array (
  5548. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  5549. 'desc' => 'rid',
  5550. 'asArray' => true
  5551. ) );
  5552. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  5553. $Locate = 0;
  5554. if ($ap == 4)
  5555. $status = 4;
  5556. elseif ($ap == 5)
  5557. $status = 5;
  5558. foreach ( $receiptList as $key => $value ) {
  5559. $receiptList [$key] ['Locate'] = $Locate;
  5560. $Locate ++;
  5561. $receiptList [$key] ['reviseDetail'] = array ();
  5562. if (! empty ( $value ['reviseDetail'] ))
  5563. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5564. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5565. $categoryDetil = $Lcategory->getOne ( array (
  5566. 'where' => 'cid=' . $value ['cid'],
  5567. 'asArray' => true
  5568. ) );
  5569. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5570. $verifyList = $verify->getOne ( array (
  5571. 'where' => 'vid=' . $value ['verify'],
  5572. 'asArray' => true
  5573. ) );
  5574. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5575. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5576. foreach ( $verifyList as $k => $v ) {
  5577. // init verifyStaff
  5578. $verifyList [$k] ['date'] = "";
  5579. $verifyList [$k] ['opinion'] = "";
  5580. $verifyList [$k] ['status'] = "";
  5581. if (empty ( $verifyStaff )) {
  5582. $verifyList [$k] ['date'] = "";
  5583. $verifyList [$k] ['opinion'] = "";
  5584. if ($v [0] == $this->staff [0] ['sid']) {
  5585. $verifyList [$k] ['status'] = 4;
  5586. $button = 4;
  5587. }
  5588. } else {
  5589. $flag = true;
  5590. foreach ( $verifyStaff as $m => $u ) {
  5591. if ($v [0] == $m) {
  5592. $verifyList [$k] ['date'] = $u ['date'];
  5593. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5594. $verifyList [$k] ['status'] = $u ['status'];
  5595. $flag = false;
  5596. break;
  5597. }
  5598. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  5599. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  5600. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  5601. }
  5602. if ($flag) { // 检测可编辑
  5603. if ($v [0] == $this->staff [0] ['sid']) {
  5604. $verifyList [$k] ['status'] = 4;
  5605. $button = 4;
  5606. }
  5607. }
  5608. }
  5609. }
  5610. $receiptList [$key] ['verifyList'] = $verifyList;
  5611. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5612. 'where' => 'sid=' . $value ['staff'],
  5613. 'asArray' => true
  5614. ) );
  5615. $receiptList [$key] ['button'] = $button;
  5616. }
  5617. // print_r($receiptList);die;
  5618. // $data['verifyDetail']=$verifyDetail;
  5619. $mothHtml = "";
  5620. for($i = 1; $i <= 12; $i ++) {
  5621. if ($month == $i)
  5622. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5623. else
  5624. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5625. }
  5626. $data ['mothHtml'] = $mothHtml;
  5627. $data ['receiptList'] = $receiptList;
  5628. $data ['receiptApprovalCount'] = count ( $receiptList );
  5629. $data ['status'] = $status;
  5630. $data ['year'] = $year;
  5631. $data ['categoryList'] = $categoryList;
  5632. $data ['staffList'] = $staffList;
  5633. $data ['cid'] = $cid;
  5634. $data ['sid'] = $sid;
  5635. $data ['ap'] = $ap;
  5636. $data ['memu'] = "receipt";
  5637. $data ['staff'] = $this->staff;
  5638. $data ['receiptMemu'] = 'approval';
  5639. $data ['verifyId'] = $this->verifyId;
  5640. $data ['executeId'] = $this->executeId;
  5641. $this->render ( "/admin/saea_reportList", $data );
  5642. }
  5643. function approvalDetails() {
  5644. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5645. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5646. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5647. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5648. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5649. Doo::loadModel ( 'verify' );
  5650. $verify = new verify ();
  5651. Doo::loadModel ( 'receipt' );
  5652. $receipt = new receipt ();
  5653. Doo::loadModel ( 'staff' );
  5654. $staff = new staff ();
  5655. Doo::loadModel ( 'L_category' );
  5656. $Lcategory = new L_category ();
  5657. Doo::loadModel ( 'enclosur' );
  5658. $enclosur = new enclosur ();
  5659. $vidList = array ();
  5660. $verifyDetail = $verify->find ( array (
  5661. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5662. 'asArray' => true
  5663. ) );
  5664. foreach ( $verifyDetail as $key => $value ) {
  5665. array_push ( $vidList, $value ['vid'] );
  5666. }
  5667. $vid = implode ( ",", $vidList );
  5668. if (empty ( $verifyDetail ))
  5669. $vid = 0;
  5670. $categoryList = $Lcategory->find ( array (
  5671. 'asArray' => true
  5672. ) );
  5673. $staffList = $staff->find ( array (
  5674. 'where' => 'cid=' . $cid,
  5675. 'asArray' => true
  5676. ) );
  5677. $ap = 0;
  5678. $receiptList = $receipt->find ( array (
  5679. 'where' => 'rid =' . $rid,
  5680. 'desc' => 'rid',
  5681. 'asArray' => true
  5682. ) );
  5683. $Locate = 0;
  5684. $roleId = 0;
  5685. $button = 0;
  5686. foreach ( $receiptList as $key => $value ) {
  5687. $receiptList [$key] ['Locate'] = $Locate;
  5688. $Locate ++;
  5689. $receiptList [$key] ['reviseDetail'] = array ();
  5690. if (! empty ( $value ['reviseDetail'] ))
  5691. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5692. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5693. $categoryDetil = $Lcategory->getOne ( array (
  5694. 'where' => 'cid=' . $value ['cid'],
  5695. 'asArray' => true
  5696. ) );
  5697. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5698. // 检测编辑状态
  5699. $verifyList = $verify->getOne ( array (
  5700. 'where' => 'vid=' . $value ['verify'],
  5701. 'asArray' => true
  5702. ) );
  5703. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5704. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5705. Doo::loadModel ( 'role' );
  5706. $role = new role ();
  5707. // print_r($verifyList);
  5708. $flag = true;
  5709. $roleKey = 0;
  5710. $endStaffArray = array ();
  5711. $roleArrayCopy = array ();
  5712. foreach ( $verifyList as $k => $v ) {
  5713. // init verifyStaff
  5714. if ($v [1] == 'ROLE') {
  5715. if (! empty ( $verifyStaff )) {
  5716. $endStaffArray = end ( $verifyStaff );
  5717. if ($v [0] == $endStaffArray ['nextStaff']) {
  5718. $roleId = $v [0];
  5719. }
  5720. }
  5721. $roleVerify = json_decode ( $v [3], true );
  5722. $roleKey = $k;
  5723. $roleArray = array ();
  5724. $rolename = $role->getOne ( array (
  5725. 'where' => 'rid=' . $v [0],
  5726. 'asArray' => true
  5727. ) );
  5728. foreach ( $roleVerify as $o => $p ) {
  5729. $staffID = explode ( '_', $p );
  5730. $staffInfo = $staff->getOne ( array (
  5731. 'where' => 'sid=' . $staffID [0],
  5732. 'asArray' => true
  5733. ) );
  5734. // print_r($staffID);
  5735. $exp = array (
  5736. 0 => $staffInfo ['sid'],
  5737. 1 => $staffID [1],
  5738. 2 => $staffInfo ['avatar'],
  5739. 'date' => '',
  5740. 'date' => '',
  5741. 'opinion' => '',
  5742. 'status' => '',
  5743. 'rolename' => $rolename ['name']
  5744. );
  5745. array_push ( $roleArray, $exp );
  5746. }
  5747. $roleArrayCopy [$v [0]] = $roleArray;
  5748. // $verifyList[$k]['roleArray']=$roleArray;
  5749. }
  5750. // print_r($roleArray);
  5751. $verifyList [$k] ['date'] = "";
  5752. $verifyList [$k] ['opinion'] = "";
  5753. $verifyList [$k] ['status'] = "";
  5754. if (empty ( $verifyStaff )) {
  5755. $verifyList [$k] ['date'] = "";
  5756. $verifyList [$k] ['opinion'] = "";
  5757. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5758. $verifyList [$k] ['status'] = 4;
  5759. $button = 4;
  5760. $flag = false;
  5761. }
  5762. } else {
  5763. foreach ( $verifyStaff as $m => $u ) {
  5764. if ($v [0] == $m) {
  5765. $verifyList [$k] ['date'] = $u ['date'];
  5766. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5767. $verifyList [$k] ['status'] = $u ['status'];
  5768. $flag = false;
  5769. break;
  5770. }
  5771. }
  5772. $endStaffArray = end ( $verifyStaff );
  5773. if (isset ( $endStaffArray ['ROLE'] )) {
  5774. } else {
  5775. $endKey = key ( $verifyStaff );
  5776. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5777. $button = 4;
  5778. $verifyList [$k] ['status'] = 4;
  5779. }
  5780. }
  5781. }
  5782. }
  5783. $rolename ['name'] = '';
  5784. if (! empty ( $roleId )) {
  5785. Doo::loadModel ( 'role' );
  5786. $role = new role ();
  5787. $rolename = $role->getOne ( array (
  5788. 'where' => 'rid=' . $roleId,
  5789. 'asArray' => true
  5790. ) );
  5791. }
  5792. if (! empty ( $verifyStaff ))
  5793. $endStaffArray = end ( $verifyStaff );
  5794. $KOP = false;
  5795. foreach ( $roleArrayCopy as $P => $A ) {
  5796. foreach ( $A as $MKI => $AVL ) {
  5797. if (! empty ( $verifyStaff )) {
  5798. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5799. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5800. $button = 4;
  5801. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5802. }
  5803. foreach ( $verifyStaff as $m => $u ) {
  5804. $AVLFK = $AVL [0] . '_R';
  5805. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5806. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5807. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5808. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5809. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5810. break;
  5811. }
  5812. }
  5813. } else {
  5814. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5815. $button = 4;
  5816. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5817. }
  5818. }
  5819. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5820. $KOP = true;
  5821. }
  5822. }
  5823. foreach ( $roleArrayCopy as $k => $v ) {
  5824. foreach ( $verifyList as $m => $n ) {
  5825. if ($n [0] == $k) {
  5826. array_splice ( $verifyList, $m, 1, $v );
  5827. }
  5828. }
  5829. }
  5830. $receiptList [$key] ['verifyList'] = $verifyList;
  5831. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5832. 'where' => 'sid=' . $value ['staff'],
  5833. 'asArray' => true
  5834. ) );
  5835. $receiptList [$key] ['button'] = $button;
  5836. }
  5837. $mothHtml = "";
  5838. for($i = 1; $i <= 12; $i ++) {
  5839. if ($month == $i)
  5840. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5841. else
  5842. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5843. }
  5844. // 获取审批日志
  5845. Doo::loadModel ( 'receiptLog' );
  5846. $receiptLog = new receiptLog ();
  5847. $rlList = array ();
  5848. $rlInfo = $receiptLog->getOne ( array (
  5849. 'where' => 'rid=' . $rid . ' and status=4',
  5850. 'asArray' => true
  5851. ) );
  5852. $tijdate = $receiptLog->getOne ( array (
  5853. 'where' => 'rid=' . $rid . ' and status=2',
  5854. 'asc' => 'rlid',
  5855. 'asArray' => true
  5856. ) );
  5857. if (! empty ( $rlInfo )) {
  5858. $rlList = $receiptLog->find ( array (
  5859. 'where' => 'rid=' . $rid,
  5860. 'asc' => 'rlid',
  5861. 'asArray' => true
  5862. ) );
  5863. }
  5864. $receiptList [0] ['rlList'] = $rlList;
  5865. $enclosurList = $enclosur->find ( array (
  5866. 'where' => 'rid=' . $rid,
  5867. 'asArray' => true
  5868. ) );
  5869. $enclosurHtml = '';
  5870. foreach ( $enclosurList as $value ) {
  5871. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5872. }
  5873. $data ['enclosurHtml'] = $enclosurHtml;
  5874. $data ['rolename'] = $rolename ['name'];
  5875. $data ['datetij'] = $tijdate ['date'];
  5876. $data ['mothHtml'] = $mothHtml;
  5877. $data ['receiptList'] = $receiptList;
  5878. $data ['receiptApprovalCount'] = count ( $receiptList );
  5879. $data ['year'] = $year;
  5880. $data ['categoryList'] = $categoryList;
  5881. $data ['staffList'] = $staffList;
  5882. $data ['cid'] = $cid;
  5883. $data ['sid'] = $sid;
  5884. $data ['status'] = 0;
  5885. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  5886. $ap = 4;
  5887. } else
  5888. $data ['status'] = $receiptList [0] ['status'];
  5889. if ($receiptList [0] ['status'] == 4) {
  5890. $data ['status'] = 5;
  5891. $ap = 0;
  5892. }
  5893. $data ['ap'] = $ap;
  5894. $data ['memu'] = "receipt";
  5895. $data ['staff'] = $this->staff;
  5896. $data ['receiptMemu'] = 'approval';
  5897. $data ['verifyId'] = $this->verifyId;
  5898. $data ['executeId'] = $this->executeId;
  5899. $this->render ( "/admin/saeaReportListReport", $data );
  5900. }
  5901. function approvalEdi() {
  5902. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5903. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5904. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5905. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5906. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5907. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5908. if (empty ( $status ))
  5909. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5910. $vidList = array ();
  5911. $button = 0;
  5912. Doo::loadModel ( 'verify' );
  5913. Doo::loadModel ( 'receipt' );
  5914. Doo::loadModel ( 'staff' );
  5915. $staff = new staff ();
  5916. $receipt = new receipt ();
  5917. $verify = new verify ();
  5918. Doo::loadModel ( 'L_category' );
  5919. $Lcategory = new L_category ();
  5920. Doo::loadModel ( 'enclosur' );
  5921. $enclosur = new enclosur ();
  5922. // user verify ID
  5923. $verifyDetail = $verify->find ( array (
  5924. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5925. 'asArray' => true
  5926. ) );
  5927. foreach ( $verifyDetail as $key => $value ) {
  5928. array_push ( $vidList, $value ['vid'] );
  5929. }
  5930. $vid = implode ( ",", $vidList );
  5931. if (empty ( $verifyDetail ))
  5932. $vid = 0;
  5933. $categoryList = $Lcategory->find ( array (
  5934. 'asArray' => true
  5935. ) );
  5936. $staffList = $staff->find ( array (
  5937. 'where' => 'cid=' . $cid,
  5938. 'asArray' => true
  5939. ) );
  5940. $ap = "";
  5941. if ($status == 4) {
  5942. $ap = 4;
  5943. $status = 2;
  5944. }
  5945. // get Receipt By verifyID status 2
  5946. $receiptList = $receipt->find ( array (
  5947. 'where' => 'rid =' . $rid,
  5948. 'desc' => 'rid',
  5949. 'asArray' => true
  5950. ) );
  5951. $Locate = 0;
  5952. $roleId = 0;
  5953. if ($ap == 4)
  5954. $status = 4;
  5955. foreach ( $receiptList as $key => $value ) {
  5956. $receiptList [$key] ['Locate'] = $Locate;
  5957. $Locate ++;
  5958. $receiptList [$key] ['reviseDetail'] = array ();
  5959. if (! empty ( $value ['reviseDetail'] ))
  5960. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5961. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5962. $categoryDetil = $Lcategory->getOne ( array (
  5963. 'where' => 'cid=' . $value ['cid'],
  5964. 'asArray' => true
  5965. ) );
  5966. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5967. // 检测编辑状态
  5968. $verifyList = $verify->getOne ( array (
  5969. 'where' => 'vid=' . $value ['verify'],
  5970. 'asArray' => true
  5971. ) );
  5972. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5973. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5974. // print_r($verifyList);
  5975. //
  5976. // if (empty($verifyStaff)){
  5977. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  5978. // $verifyList[0]['status']=4;$button=4;
  5979. // }
  5980. //
  5981. // }else{
  5982. //
  5983. // }
  5984. // die;
  5985. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  5986. // echo array_search("green",$a);
  5987. //
  5988. Doo::loadModel ( 'role' );
  5989. $role = new role ();
  5990. // print_r($verifyList);
  5991. $flag = true;
  5992. $roleKey = 0;
  5993. $endStaffArray = array ();
  5994. $roleArrayCopy = array ();
  5995. foreach ( $verifyList as $k => $v ) {
  5996. // init verifyStaff
  5997. if ($v [1] == 'ROLE') {
  5998. if (! empty ( $verifyStaff )) {
  5999. $endStaffArray = end ( $verifyStaff );
  6000. if ($v [0] == $endStaffArray ['nextStaff']) {
  6001. $roleId = $v [0];
  6002. }
  6003. }
  6004. $roleVerify = json_decode ( $v [3], true );
  6005. $roleKey = $k;
  6006. $roleArray = array ();
  6007. $rolename = $role->getOne ( array (
  6008. 'where' => 'rid=' . $v [0],
  6009. 'asArray' => true
  6010. ) );
  6011. foreach ( $roleVerify as $o => $p ) {
  6012. $staffID = explode ( '_', $p );
  6013. $staffInfo = $staff->getOne ( array (
  6014. 'where' => 'sid=' . $staffID [0],
  6015. 'asArray' => true
  6016. ) );
  6017. // print_r($staffID);
  6018. $exp = array (
  6019. 0 => $staffInfo ['sid'],
  6020. 1 => $staffID [1],
  6021. 2 => $staffInfo ['avatar'],
  6022. 'date' => '',
  6023. 'date' => '',
  6024. 'opinion' => '',
  6025. 'status' => '',
  6026. 'rolename' => $rolename ['name']
  6027. );
  6028. array_push ( $roleArray, $exp );
  6029. }
  6030. $roleArrayCopy [$v [0]] = $roleArray;
  6031. // $verifyList[$k]['roleArray']=$roleArray;
  6032. }
  6033. // print_r($roleArray);
  6034. $verifyList [$k] ['date'] = "";
  6035. $verifyList [$k] ['opinion'] = "";
  6036. $verifyList [$k] ['status'] = "";
  6037. if (empty ( $verifyStaff )) {
  6038. $verifyList [$k] ['date'] = "";
  6039. $verifyList [$k] ['opinion'] = "";
  6040. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6041. $verifyList [$k] ['status'] = 4;
  6042. $button = 4;
  6043. $flag = false;
  6044. }
  6045. } else {
  6046. foreach ( $verifyStaff as $m => $u ) {
  6047. if ($v [0] == $m) {
  6048. $verifyList [$k] ['date'] = $u ['date'];
  6049. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6050. $verifyList [$k] ['status'] = $u ['status'];
  6051. $flag = false;
  6052. break;
  6053. }
  6054. }
  6055. $endStaffArray = end ( $verifyStaff );
  6056. if (isset ( $endStaffArray ['ROLE'] )) {
  6057. } else {
  6058. $endKey = key ( $verifyStaff );
  6059. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  6060. $button = 4;
  6061. $verifyList [$k] ['status'] = 4;
  6062. }
  6063. }
  6064. // print_r($endStaffArray);die;
  6065. // if (empty($verifyStaff)){
  6066. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  6067. // $verifyList[$k]['status']=4;$button=4;
  6068. // }
  6069. //
  6070. // }else{
  6071. //
  6072. // }
  6073. // if($flag){//检测可编辑
  6074. // if($v[0]==$this->staff[0]['sid']){
  6075. // $verifyList[$k]['status']=4;$button=4;
  6076. // }
  6077. // }
  6078. }
  6079. }
  6080. $rolename ['name'] = '';
  6081. if (! empty ( $roleId )) {
  6082. Doo::loadModel ( 'role' );
  6083. $role = new role ();
  6084. $rolename = $role->getOne ( array (
  6085. 'where' => 'rid=' . $roleId,
  6086. 'asArray' => true
  6087. ) );
  6088. }
  6089. if (! empty ( $verifyStaff ))
  6090. $endStaffArray = end ( $verifyStaff );
  6091. $KOP = false;
  6092. foreach ( $roleArrayCopy as $P => $A ) {
  6093. foreach ( $A as $MKI => $AVL ) {
  6094. if (! empty ( $verifyStaff )) {
  6095. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6096. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6097. $button = 4;
  6098. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6099. }
  6100. foreach ( $verifyStaff as $m => $u ) {
  6101. $AVLFK = $AVL [0] . '_R';
  6102. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6103. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6104. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6105. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6106. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6107. break;
  6108. }
  6109. }
  6110. } else {
  6111. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6112. $button = 4;
  6113. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6114. }
  6115. }
  6116. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6117. $KOP = true;
  6118. }
  6119. }
  6120. // print_r($roleArrayCopy);
  6121. // echo $roleKey;
  6122. foreach ( $roleArrayCopy as $k => $v ) {
  6123. foreach ( $verifyList as $m => $n ) {
  6124. if ($n [0] == $k) {
  6125. array_splice ( $verifyList, $m, 1, $v );
  6126. }
  6127. }
  6128. }
  6129. // if ($KOP)
  6130. // array_splice($verifyList,$roleKey,1,$roleArray);
  6131. // print_r($verifyList);
  6132. $receiptList [$key] ['verifyList'] = $verifyList;
  6133. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6134. 'where' => 'sid=' . $value ['staff'],
  6135. 'asArray' => true
  6136. ) );
  6137. $receiptList [$key] ['button'] = $button;
  6138. }
  6139. // $data['verifyDetail']=$verifyDetail;
  6140. $mothHtml = "";
  6141. for($i = 1; $i <= 12; $i ++) {
  6142. if ($month == $i)
  6143. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6144. else
  6145. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6146. }
  6147. // 获取审批日志
  6148. Doo::loadModel ( 'receiptLog' );
  6149. $receiptLog = new receiptLog ();
  6150. $rlList = array ();
  6151. $rlInfo = $receiptLog->getOne ( array (
  6152. 'where' => 'rid=' . $rid . ' and status=4',
  6153. 'asArray' => true
  6154. ) );
  6155. $tijdate = $receiptLog->getOne ( array (
  6156. 'where' => 'rid=' . $rid . ' and status=2',
  6157. 'asc' => 'rlid',
  6158. 'asArray' => true
  6159. ) );
  6160. if (! empty ( $rlInfo )) {
  6161. $rlList = $receiptLog->find ( array (
  6162. 'where' => 'rid=' . $rid,
  6163. 'asc' => 'rlid',
  6164. 'asArray' => true
  6165. ) );
  6166. }
  6167. $receiptList [0] ['rlList'] = $rlList;
  6168. $enclosurList = $enclosur->find ( array (
  6169. 'where' => 'rid=' . $rid,
  6170. 'asArray' => true
  6171. ) );
  6172. $enclosurHtml = '';
  6173. foreach ( $enclosurList as $value ) {
  6174. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  6175. }
  6176. $data ['enclosurHtml'] = $enclosurHtml;
  6177. $data ['rolename'] = $rolename ['name'];
  6178. $data ['datetij'] = $tijdate ['date'];
  6179. $data ['mothHtml'] = $mothHtml;
  6180. $data ['receiptList'] = $receiptList;
  6181. $data ['receiptApprovalCount'] = count ( $receiptList );
  6182. $data ['status'] = $status;
  6183. $data ['year'] = $year;
  6184. $data ['categoryList'] = $categoryList;
  6185. $data ['staffList'] = $staffList;
  6186. $data ['cid'] = $cid;
  6187. $data ['sid'] = $sid;
  6188. $data ['ap'] = $ap;
  6189. $data ['memu'] = "receipt";
  6190. $data ['staff'] = $this->staff;
  6191. $data ['receiptMemu'] = 'approval';
  6192. $data ['verifyId'] = $this->verifyId;
  6193. $data ['executeId'] = $this->executeId;
  6194. $this->render ( "/admin/saeaReportListReport", $data );
  6195. }
  6196. function remittance() {
  6197. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  6198. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  6199. Doo::loadModel ( 'receipt' );
  6200. $receipt = new receipt ();
  6201. Doo::loadModel ( 'staff' );
  6202. $staff = new staff ();
  6203. $dateCondition = " and Year(pastDate) =" . $year;
  6204. if (! empty ( $month ))
  6205. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  6206. // get Receipt By verifyID status 1
  6207. $receiptList = $receipt->find ( array (
  6208. 'select' => 'sum(sum) as sum,staff,pastDate',
  6209. 'where' => ' status=1' . $dateCondition,
  6210. 'desc' => 'pastDate',
  6211. 'groupby' => 'staff,pastDate',
  6212. 'asArray' => true
  6213. ) );
  6214. $dateList = $receipt->find ( array (
  6215. 'select' => 'pastDate,verifyStaff',
  6216. 'where' => ' status=1' . $dateCondition,
  6217. 'desc' => 'pastDate',
  6218. 'groupby' => 'pastDate',
  6219. 'asArray' => true
  6220. ) );
  6221. $dataList = array ();
  6222. foreach ( $dateList as $d => $a ) {
  6223. $dataList [$a ['pastDate']] = array ();
  6224. $daySum = 0;
  6225. foreach ( $receiptList as $key => $value ) {
  6226. if ($a ['pastDate'] == $value ['pastDate']) {
  6227. $oderList = $receipt->find ( array (
  6228. 'select' => 'receiptOrder',
  6229. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  6230. 'asArray' => true
  6231. ) );
  6232. $list = array ();
  6233. $html = "";
  6234. foreach ( $oderList as $v ) {
  6235. array_push ( $list, $v ['receiptOrder'] );
  6236. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  6237. }
  6238. $receiptList [$key] ['receiptOrder'] = $html;
  6239. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  6240. $sinfo = $staff->getOne ( array (
  6241. 'select' => 'username ',
  6242. 'where' => ' sid=' . $value ['staff'],
  6243. 'asArray' => true
  6244. ) );
  6245. $receiptList [$key] ['username'] = $sinfo ['username'];
  6246. $daySum += $value ['sum'];
  6247. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  6248. }
  6249. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  6250. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  6251. }
  6252. }
  6253. // print_r($dataList);
  6254. $data ['dataList'] = $dataList;
  6255. $mothHtml = "";
  6256. for($i = 1; $i <= 12; $i ++) {
  6257. if ($month == $i)
  6258. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6259. else
  6260. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6261. }
  6262. $data ['year'] = $year;
  6263. $data ['mothHtml'] = $mothHtml;
  6264. $data ['memu'] = "receipt";
  6265. $data ['staff'] = $this->staff;
  6266. $data ['receiptMemu'] = 'approval';
  6267. $data ['verifyId'] = $this->verifyId;
  6268. $data ['executeId'] = $this->executeId;
  6269. $this->render ( "/admin/saeaReportListPay", $data );
  6270. }
  6271. function revocationAdjustment() {
  6272. $sid = isset ( $this->params ['sid'] ) && is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  6273. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  6274. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6275. // echo $price;die;
  6276. if ((! empty ( $sid )) && ($price != - 99999) && (! empty ( $rid ))) {
  6277. Doo::loadModel ( 'receipt' );
  6278. $receipt = new receipt ();
  6279. $receiptDetail = $receipt->getOne ( array (
  6280. 'where' => 'rid=' . $rid,
  6281. 'asArray' => true
  6282. ) );
  6283. if (empty ( $receiptDetail ['reviseDetail'] ))
  6284. return "/approval";
  6285. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  6286. $RD = array ();
  6287. foreach ( $reviseDetail as $key => $value ) {
  6288. if ($value ['price'] == $price && $value ['sid'] == $sid)
  6289. continue;
  6290. array_push ( $RD, $value );
  6291. }
  6292. $reviseDetailString = json_encode ( $RD );
  6293. $receipt->reviseDetail = $reviseDetailString;
  6294. $receipt->sum = $receiptDetail ['sum'] - $price;
  6295. $receipt->revisePrice = $receiptDetail ['revisePrice'] - $price;
  6296. $receipt->update ( array (
  6297. 'where' => 'rid=' . $rid
  6298. ) );
  6299. }
  6300. // approvalEdi/37
  6301. return "/approvalEdi/" . $rid;
  6302. }
  6303. function updateApprovalReceipt() {
  6304. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  6305. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  6306. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6307. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  6308. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  6309. if (! empty ( $rid )) {
  6310. Doo::loadModel ( "verify" );
  6311. $verify = new verify ();
  6312. Doo::loadModel ( "receiptDetail" );
  6313. $receiptDetailObj = new receiptDetail ();
  6314. Doo::loadModel ( "itemStatistics" );
  6315. Doo::loadModel ( "statistics" );
  6316. $statistics = new statistics ();
  6317. $itemStatistics = new itemStatistics ();
  6318. Doo::loadModel ( "receipt" );
  6319. $receipt = new receipt ();
  6320. $receiptDetail = $receipt->getOne ( array (
  6321. 'where' => 'rid=' . $rid . ' and status=2 ',
  6322. 'asArray' => true
  6323. ) );
  6324. if (empty ( $receiptDetail ))
  6325. return "/approval";
  6326. $verifyDetail = $verify->getOne ( array (
  6327. 'where' => ' vid =' . $receiptDetail ['verify'],
  6328. 'asArray' => true
  6329. ) );
  6330. $verifyString = $verifyDetail ['staff'];
  6331. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  6332. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  6333. if (empty ( $opinion )) {
  6334. if ($status == 3)
  6335. $opinion = "终止";
  6336. else
  6337. $opinion = "同意支付";
  6338. }
  6339. $nowStaff = 0;
  6340. $nowStaffList = array ();
  6341. if (empty ( $verifyStaff )) {
  6342. // 还需加入是否已经进入角色审批
  6343. if ($verifyDetail [0] [1] == 'ROLE') {
  6344. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  6345. foreach ( $vStaffString as $key => $value ) {
  6346. $staffK = explode ( "_", $value );
  6347. if ($staffK [0] != $this->staff [0] ['sid'])
  6348. array_push ( $nowStaffList, $staffK [0] );
  6349. }
  6350. // print_r($verifyDetail);
  6351. // die;
  6352. if (! empty ( $nowStaffList )) {
  6353. $nowStaff = implode ( ',', $nowStaffList );
  6354. $verifyStaff = array (
  6355. $this->staff [0] ['sid'] . "_R" => array (
  6356. 'date' => date ( 'Y-m-d' ),
  6357. 'opinion' => $opinion,
  6358. 'status' => $status,
  6359. 'nextStaff' => $verifyDetail [0] [0],
  6360. 'ROLE' => 1
  6361. )
  6362. );
  6363. } else {
  6364. $nowStaff = $verifyDetail [1] [0];
  6365. $verifyStaff = array (
  6366. $this->staff [0] ['sid'] . "_R" => array (
  6367. 'date' => date ( 'Y-m-d' ),
  6368. 'opinion' => $opinion,
  6369. 'status' => $status,
  6370. 'nextStaff' => $verifyDetail [1] [0]
  6371. )
  6372. );
  6373. }
  6374. } else {
  6375. if ($verifyDetail [1] [1] == 'ROLE') {
  6376. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  6377. // echo "dd";
  6378. foreach ( $vStaffString as $key => $value ) {
  6379. $staffK = explode ( "_", $value );
  6380. array_push ( $nowStaffList, $staffK [0] );
  6381. }
  6382. $nowStaff = implode ( ',', $nowStaffList );
  6383. $verifyStaff = array (
  6384. $this->staff [0] ['sid'] => array (
  6385. 'date' => date ( 'Y-m-d' ),
  6386. 'opinion' => $opinion,
  6387. 'status' => $status,
  6388. 'nextStaff' => $verifyDetail [1] [0],
  6389. 'ROLE' => 1
  6390. )
  6391. );
  6392. } else {
  6393. $nowStaff = $verifyDetail [1] [0];
  6394. $verifyStaff = array (
  6395. $this->staff [0] ['sid'] => array (
  6396. 'date' => date ( 'Y-m-d' ),
  6397. 'opinion' => $opinion,
  6398. 'status' => $status,
  6399. 'nextStaff' => $verifyDetail [1] [0]
  6400. )
  6401. );
  6402. }
  6403. }
  6404. if ($status == 3)
  6405. $verifyStaff = array (
  6406. 'final' => $status,
  6407. $this->staff [0] ['sid'] => array (
  6408. 'date' => date ( 'Y-m-d' ),
  6409. 'opinion' => $opinion,
  6410. 'status' => $status
  6411. )
  6412. );
  6413. $vStaffString = json_encode ( $verifyStaff );
  6414. $receipt->nowStaff = $nowStaff;
  6415. $receipt->verifyStaff = $vStaffString;
  6416. } else {
  6417. $VS = end ( $verifyStaff );
  6418. // 非角色审批
  6419. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  6420. $nextStaff = 0;
  6421. $roleSTF = false;
  6422. foreach ( $verifyDetail as $key => $value ) {
  6423. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  6424. if (isset ( $verifyDetail [$key + 1] )) {
  6425. $nextStaff = $verifyDetail [$key + 1] [0];
  6426. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  6427. $roleSTF = true;
  6428. }
  6429. break;
  6430. }
  6431. }
  6432. if (! $roleSTF) {
  6433. $nowStaff = $nextStaff;
  6434. $verifyStaff [$this->staff [0] ['sid']] = array (
  6435. 'date' => date ( 'Y-m-d' ),
  6436. 'opinion' => $opinion,
  6437. 'status' => $status,
  6438. 'nextStaff' => $nextStaff
  6439. );
  6440. } else {
  6441. // 获取角色下的所有用户ID
  6442. $nowStaffList = array ();
  6443. foreach ( $verifyDetail as $vfk ) {
  6444. if ($vfk [1] == 'ROLE') {
  6445. $vStaffString = json_decode ( $vfk [3] );
  6446. foreach ( $vStaffString as $key => $value ) {
  6447. $staffK = explode ( "_", $value );
  6448. array_push ( $nowStaffList, $staffK [0] );
  6449. }
  6450. }
  6451. }
  6452. $nowStaff = implode ( ',', $nowStaffList );
  6453. $verifyStaff [$this->staff [0] ['sid']] = array (
  6454. 'date' => date ( 'Y-m-d' ),
  6455. 'opinion' => $opinion,
  6456. 'status' => $status,
  6457. 'nextStaff' => $nextStaff,
  6458. 'ROLE' => 0
  6459. );
  6460. }
  6461. if ($status == 3) {
  6462. $verifyStaff ['final'] = $status;
  6463. $verifyStaff [$this->staff [0] ['sid']] = array (
  6464. 'date' => date ( 'Y-m-d' ),
  6465. 'opinion' => $opinion,
  6466. 'status' => $status
  6467. );
  6468. }
  6469. $vStaffString = json_encode ( $verifyStaff );
  6470. $receipt->nowStaff = $nowStaff;
  6471. $receipt->verifyStaff = $vStaffString;
  6472. }
  6473. // 角色审批
  6474. if (isset ( $VS ['ROLE'] )) {
  6475. // 找出角色人 当前审批角色组
  6476. $verifyJSStaff = array ();
  6477. $nowStaffList2 = array ();
  6478. foreach ( $verifyDetail as $key => $value ) {
  6479. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  6480. $verifyJSStaff = json_decode ( $value [3] );
  6481. foreach ( $verifyJSStaff as $m ) {
  6482. $staffK = explode ( "_", $m );
  6483. array_push ( $nowStaffList2, $staffK [0] );
  6484. }
  6485. // print_r($nowStaffList2);
  6486. }
  6487. }
  6488. $RoleVerifyStaff = array ();
  6489. foreach ( $verifyStaff as $key => $value ) {
  6490. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  6491. foreach ( $nowStaffList2 as $m ) {
  6492. if ($key == $m . "_R")
  6493. $RoleVerifyStaff [$key] = $value;
  6494. }
  6495. }
  6496. }
  6497. // print_r($verifyStaff);
  6498. // print_r($nowStaffList2);
  6499. // print_r($RoleVerifyStaff);
  6500. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  6501. // print_r($verifyJSStaff);
  6502. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  6503. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  6504. // 下一个审批人ID
  6505. $nextStaff = 0;
  6506. $falg = false;
  6507. foreach ( $verifyDetail as $key => $value ) {
  6508. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  6509. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  6510. $falg = true;
  6511. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  6512. $nowStaffList = array ();
  6513. foreach ( $vStaffString as $v ) {
  6514. $staffK = explode ( "_", $v );
  6515. array_push ( $nowStaffList, $staffK [0] );
  6516. }
  6517. $nowStaff = implode ( ',', $nowStaffList );
  6518. $nextStaff = $verifyDetail [$key + 1] [0];
  6519. } elseif (isset ( $verifyDetail [$key + 1] )) {
  6520. $nextStaff = $verifyDetail [$key + 1] [0];
  6521. $nowStaff = $nextStaff;
  6522. } else
  6523. $nowStaff = '';
  6524. break;
  6525. }
  6526. }
  6527. if ($falg)
  6528. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  6529. 'date' => date ( 'Y-m-d' ),
  6530. 'opinion' => $opinion,
  6531. 'status' => $status,
  6532. 'nextStaff' => $nextStaff,
  6533. 'ROLE' => 1
  6534. );
  6535. else
  6536. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  6537. 'date' => date ( 'Y-m-d' ),
  6538. 'opinion' => $opinion,
  6539. 'status' => $status,
  6540. 'nextStaff' => $nextStaff
  6541. );
  6542. // print_r($verifyStaff);
  6543. // echo $nowStaff;die;
  6544. } else { // 进入下一个角色或者审批人
  6545. /*
  6546. *
  6547. */
  6548. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  6549. //
  6550. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  6551. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  6552. 'date' => date ( 'Y-m-d' ),
  6553. 'opinion' => $opinion,
  6554. 'status' => $status,
  6555. 'nextStaff' => $VS ['nextStaff'],
  6556. 'ROLE' => 1
  6557. );
  6558. // print_r($verifyStaff);
  6559. // die;
  6560. }
  6561. if ($status == 3) {
  6562. $verifyStaff ['final'] = $status;
  6563. $verifyStaff [$this->staff [0] ['sid']] = array (
  6564. 'date' => date ( 'Y-m-d' ),
  6565. 'opinion' => $opinion,
  6566. 'status' => $status
  6567. );
  6568. }
  6569. $vStaffString = json_encode ( $verifyStaff );
  6570. $receipt->verifyStaff = $vStaffString;
  6571. $receipt->nowStaff = $nowStaff;
  6572. // die;
  6573. // }
  6574. // print_r($verifyStaff);
  6575. // die;
  6576. }
  6577. // print_r($verifyStaff);die;
  6578. }
  6579. // print_r($verifyDetail);
  6580. $roleKey = 0;
  6581. $roleId = 0;
  6582. $verifyDetailCopy = array ();
  6583. foreach ( $verifyDetail as $k => $v ) {
  6584. if ($v [1] == 'ROLE') {
  6585. $roleId = $v [0];
  6586. $roleVerify = json_decode ( $v [3], true );
  6587. $roleKey = $k;
  6588. $roleArray = array ();
  6589. foreach ( $roleVerify as $o => $p ) {
  6590. $staffID = explode ( '_', $p );
  6591. $exp = array (
  6592. 0 => $staffID [0],
  6593. 1 => $staffID [1]
  6594. );
  6595. array_push ( $roleArray, $exp );
  6596. }
  6597. $verifyDetailCopy [$v [0]] = $roleArray;
  6598. }
  6599. }
  6600. // print_r($verifyDetail);
  6601. foreach ( $verifyDetailCopy as $k => $v ) {
  6602. foreach ( $verifyDetail as $m => $n ) {
  6603. if ($n [0] == $k) {
  6604. array_splice ( $verifyDetail, $m, 1, $v );
  6605. }
  6606. }
  6607. }
  6608. // die;
  6609. // if (!empty($roleArray))
  6610. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  6611. // echo $roleId;
  6612. // print_r($verifyStaff);
  6613. // print_r($verifyDetail);
  6614. // die;
  6615. Doo::loadModel ( "receiptLog" );
  6616. $receiptLog = new receiptLog ();
  6617. // 审批日志
  6618. if (! isset ( $verifyStaff ['final'] )) {
  6619. if (! empty ( $roleId )) {
  6620. Doo::loadModel ( "role" );
  6621. $role = new role ();
  6622. $roleInfo = $role->getOne ( array (
  6623. 'where' => 'rid=' . $roleId,
  6624. 'asArray' => true
  6625. ) );
  6626. $receiptLog->rolename = $roleInfo ['name'];
  6627. }
  6628. $receiptLog->username = $this->staff [0] ['username'];
  6629. $receiptLog->uid = $this->staff [0] ['sid'];
  6630. $receiptLog->date = date ( "Y-m-d" );
  6631. $receiptLog->opinion = $opinion;
  6632. $receiptLog->img = $this->staff [0] ['avatar'];
  6633. $receiptLog->status = 1;
  6634. $receiptLog->rid = $rid;
  6635. $receiptLog->insert ();
  6636. }
  6637. if (isset ( $verifyStaff ['final'] )) { // rDetail
  6638. $receipt->verifyBreakup = $verifyString;
  6639. $receipt->status = 3;
  6640. $receiptDetailObj->status = 3;
  6641. $receiptDetailObj->update ( array (
  6642. 'where' => 'rid=' . $rid
  6643. ) );
  6644. if (! empty ( $roleId )) {
  6645. Doo::loadModel ( "role" );
  6646. $role = new role ();
  6647. $roleInfo = $role->getOne ( array (
  6648. 'where' => 'rid=' . $roleId,
  6649. 'asArray' => true
  6650. ) );
  6651. $receiptLog->rolename = $roleInfo ['name'];
  6652. }
  6653. $receiptLog->username = $this->staff [0] ['username'];
  6654. $receiptLog->uid = $this->staff [0] ['sid'];
  6655. $receiptLog->date = date ( "Y-m-d" );
  6656. $receiptLog->opinion = $opinion;
  6657. $receiptLog->img = $this->staff [0] ['avatar'];
  6658. $receiptLog->status = 3;
  6659. $receiptLog->rid = $rid;
  6660. $receiptLog->insert ();
  6661. // 微信企业号通知
  6662. $this->setWXMsg ( $rid, 3 );
  6663. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  6664. $receipt->status = 1;
  6665. $reviseSum = 0;
  6666. $receipt->verifyBreakup = $verifyString;
  6667. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  6668. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  6669. foreach ( $reviseDetail as $key => $value ) {
  6670. $receiptDetailObj = new receiptDetail ();
  6671. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  6672. $receiptDetailObj->item = $value ['description'];
  6673. $receiptDetailObj->itemCategory = "报销金额调整";
  6674. $receiptDetailObj->price = $value ['price'];
  6675. $receiptDetailObj->date = $receiptDetail ['date'];
  6676. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  6677. $receiptDetailObj->rid = $rid;
  6678. $receiptDetailObj->status = 1;
  6679. $receiptDetailObj->insert ();
  6680. $reviseSum += $value ['price'];
  6681. }
  6682. $itemStatistics = new itemStatistics ();
  6683. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  6684. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  6685. $itemStatistics->price = $reviseSum;
  6686. $itemStatistics->itemCategory = "报销金额调整";
  6687. $itemStatistics->date = $receiptDetail ['date'];
  6688. $itemStatistics->insert ();
  6689. }
  6690. $receiptDetailObj = new receiptDetail ();
  6691. $receiptDetailObj->status = 1;
  6692. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  6693. $receiptDetailObj->update ( array (
  6694. 'where' => 'rid=' . $rid
  6695. ) );
  6696. $dateArray = explode ( "-", $receiptDetail ['date'] );
  6697. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  6698. $stat = $statistics->getOne ( array (
  6699. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  6700. 'asArray' => true
  6701. ) );
  6702. if (empty ( $stat )) {
  6703. $statistics->date = $receiptDetail ['date'];
  6704. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  6705. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  6706. $statistics->agPrice = $receiptDetail ['sum'];
  6707. $statistics->rePrice = $reviseSum;
  6708. $statistics->insert ();
  6709. } else {
  6710. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  6711. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  6712. $statistics->update ( array (
  6713. 'where' => 'sid=' . $stat ['sid']
  6714. ) );
  6715. }
  6716. $dateArray = explode ( "-", $receiptDetail ['date'] );
  6717. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  6718. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  6719. foreach ( $accountItem ['cSum'] as $key => $value ) {
  6720. if ($key == "agencySum") {
  6721. $iStatistics = $itemStatistics->getOne ( array (
  6722. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  6723. 'asArray' => true
  6724. ) );
  6725. if (empty ( $iStatistics )) {
  6726. $itemStatistics->cid = $receiptDetail ['cid'];
  6727. ;
  6728. $itemStatistics->staff = $receiptDetail ['staff'];
  6729. $itemStatistics->price = $value;
  6730. $itemStatistics->itemCategory = $this->AGENCY;
  6731. $itemStatistics->date = $receiptDetail ['date'];
  6732. $itemStatistics->insert ();
  6733. } else {
  6734. if (! empty ( $value )) {
  6735. $itemStatistics->price = $value + $iStatistics ['price'];
  6736. $itemStatistics->update ( array (
  6737. 'where' => 'sid=' . $iStatistics ['sid']
  6738. ) );
  6739. }
  6740. }
  6741. } elseif ($key == "travelSum") {
  6742. $iStatistics = $itemStatistics->getOne ( array (
  6743. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  6744. 'asArray' => true
  6745. ) );
  6746. if (empty ( $iStatistics )) {
  6747. $itemStatistics->cid = $receiptDetail ['cid'];
  6748. $itemStatistics->staff = $receiptDetail ['staff'];
  6749. $itemStatistics->price = $value;
  6750. $itemStatistics->itemCategory = $this->TRAVEL;
  6751. $itemStatistics->date = $receiptDetail ['date'];
  6752. $itemStatistics->insert ();
  6753. } else {
  6754. if (! empty ( $value )) {
  6755. $itemStatistics->price = $value + $iStatistics ['price'];
  6756. $itemStatistics->update ( array (
  6757. 'where' => 'sid=' . $iStatistics ['sid']
  6758. ) );
  6759. }
  6760. }
  6761. } elseif ($key == "trainSum") {
  6762. $iStatistics = $itemStatistics->getOne ( array (
  6763. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  6764. 'asArray' => true
  6765. ) );
  6766. if (empty ( $iStatistics )) {
  6767. $itemStatistics->cid = $receiptDetail ['cid'];
  6768. $itemStatistics->staff = $receiptDetail ['staff'];
  6769. $itemStatistics->price = $value;
  6770. $itemStatistics->itemCategory = $this->TRAIN;
  6771. $itemStatistics->date = $receiptDetail ['date'];
  6772. $itemStatistics->insert ();
  6773. } else {
  6774. if (! empty ( $value )) {
  6775. $itemStatistics->price = $value + $iStatistics ['price'];
  6776. $itemStatistics->update ( array (
  6777. 'where' => 'sid=' . $iStatistics ['sid']
  6778. ) );
  6779. }
  6780. }
  6781. } elseif ($key == "otherSum") {
  6782. $iStatistics = $itemStatistics->getOne ( array (
  6783. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  6784. 'asArray' => true
  6785. ) );
  6786. if (empty ( $iStatistics )) {
  6787. $itemStatistics->cid = $receiptDetail ['cid'];
  6788. $itemStatistics->staff = $receiptDetail ['staff'];
  6789. $itemStatistics->price = $value;
  6790. $itemStatistics->itemCategory = $this->OTHER;
  6791. $itemStatistics->date = $receiptDetail ['date'];
  6792. $itemStatistics->insert ();
  6793. } else {
  6794. if (! empty ( $value )) {
  6795. $itemStatistics->price = $value + $iStatistics ['price'];
  6796. $itemStatistics->update ( array (
  6797. 'where' => 'sid=' . $iStatistics ['sid']
  6798. ) );
  6799. }
  6800. }
  6801. }
  6802. }
  6803. $receipt->pastDate = date ( "Y-m-d" );
  6804. // 微信企业号通知
  6805. $this->setWXMsg ( $rid, 1 );
  6806. }
  6807. $receipt->amount=$amount;
  6808. $receipt->update ( array (
  6809. 'where' => ' rid = ' . $rid
  6810. ) );
  6811. return "/approvalExpenses/2";
  6812. }
  6813. }
  6814. function expensesRetreats() {
  6815. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6816. if (! empty ( $rid )) {
  6817. // 操作记录
  6818. Doo::loadModel ( "receipt" );
  6819. $receipt = new receipt ();
  6820. Doo::loadModel ( "receiptLog" );
  6821. $receiptLog = new receiptLog ();
  6822. Doo::loadModel ( "verify" );
  6823. $verify = new verify ();
  6824. $receiptInfo = $receipt->getOne ( array (
  6825. 'where' => 'rid=' . $rid,
  6826. 'asArray' => true
  6827. ) );
  6828. $vr = $verify->getOne ( array (
  6829. 'where' => 'vid=' . $receiptInfo ['verify'],
  6830. 'asArray' => true
  6831. ) );
  6832. $jd = json_decode ( $vr ['staff'] );
  6833. $roleId = 0;
  6834. foreach ( $jd as $key => $value ) {
  6835. if ($value [1] == 'ROLE') {
  6836. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  6837. if ($pos !== false) {
  6838. $roleId = $value [0];
  6839. }
  6840. }
  6841. }
  6842. // 审批日志
  6843. // echo $roleId;die;
  6844. if (! empty ( $roleId )) {
  6845. Doo::loadModel ( "role" );
  6846. $role = new role ();
  6847. $roleInfo = $role->getOne ( array (
  6848. 'where' => 'rid=' . $roleId,
  6849. 'asArray' => true
  6850. ) );
  6851. $receiptLog->rolename = $roleInfo ['name'];
  6852. }
  6853. $receiptLog->username = $this->staff [0] ['username'];
  6854. $receiptLog->uid = $this->staff [0] ['sid'];
  6855. $receiptLog->date = date ( "Y-m-d" );
  6856. $receiptLog->opinion = '撤回';
  6857. $receiptLog->img = $this->staff [0] ['avatar'];
  6858. $receiptLog->status = 4;
  6859. $receiptLog->rid = $rid;
  6860. $receiptLog->insert ();
  6861. $receipt->status = 4;
  6862. $receipt->update ( array (
  6863. 'where' => 'rid=' . $rid
  6864. ) );
  6865. // 微信企业号通知
  6866. $this->setWXMsg ( $rid, 2 );
  6867. }
  6868. // echo "ddd";
  6869. return '/approvalExpenses';
  6870. }
  6871. function updateCheReceipt() {
  6872. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6873. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  6874. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  6875. if (! empty ( $rid )) {
  6876. // 操作记录
  6877. Doo::loadModel ( "receipt" );
  6878. $receipt = new receipt ();
  6879. Doo::loadModel ( "receiptLog" );
  6880. $receiptLog = new receiptLog ();
  6881. Doo::loadModel ( "verify" );
  6882. $verify = new verify ();
  6883. $receiptInfo = $receipt->getOne ( array (
  6884. 'where' => 'rid=' . $rid,
  6885. 'asArray' => true
  6886. ) );
  6887. $vr = $verify->getOne ( array (
  6888. 'where' => 'vid=' . $receiptInfo ['verify'],
  6889. 'asArray' => true
  6890. ) );
  6891. $jd = json_decode ( $vr ['staff'] );
  6892. $roleId = 0;
  6893. foreach ( $jd as $key => $value ) {
  6894. if ($value [1] == 'ROLE') {
  6895. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  6896. if ($pos !== false) {
  6897. $roleId = $value [0];
  6898. }
  6899. }
  6900. }
  6901. // 审批日志
  6902. // echo $roleId;die;
  6903. if (! empty ( $roleId )) {
  6904. Doo::loadModel ( "role" );
  6905. $role = new role ();
  6906. $roleInfo = $role->getOne ( array (
  6907. 'where' => 'rid=' . $roleId,
  6908. 'asArray' => true
  6909. ) );
  6910. $receiptLog->rolename = $roleInfo ['name'];
  6911. }
  6912. $receiptLog->username = $this->staff [0] ['username'];
  6913. $receiptLog->uid = $this->staff [0] ['sid'];
  6914. $receiptLog->date = date ( "Y-m-d" );
  6915. $receiptLog->opinion = $opinion;
  6916. $receiptLog->img = $this->staff [0] ['avatar'];
  6917. $receiptLog->status = 4;
  6918. $receiptLog->rid = $rid;
  6919. $receiptLog->insert ();
  6920. $receipt->status = 4;
  6921. $receipt->update ( array (
  6922. 'where' => 'rid=' . $rid
  6923. ) );
  6924. // 微信企业号通知
  6925. $this->setWXMsg ( $rid, 2 );
  6926. echo json_encode ( array (
  6927. 'status' => 1
  6928. ) );
  6929. die ();
  6930. }
  6931. echo json_encode ( array (
  6932. 'status' => 2
  6933. ) );
  6934. die ();
  6935. // echo "ddd";
  6936. // return '/saeaBorad';
  6937. }
  6938. function revisePrice() {
  6939. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  6940. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  6941. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6942. // echo $price;die;
  6943. if (! empty ( $rid )) {
  6944. Doo::loadModel ( "receipt" );
  6945. $receipt = new receipt ();
  6946. $receiptDetail = $receipt->getOne ( array (
  6947. 'where' => 'rid=' . $rid . ' and status=2 ',
  6948. 'asArray' => true
  6949. ) );
  6950. if (empty ( $receiptDetail ))
  6951. return "/approval";
  6952. $reviseDetail = array ();
  6953. if (empty ( $receiptDetail ['reviseDetail'] )) {
  6954. array_push ( $reviseDetail, array (
  6955. 'sid' => $this->staff [0] ['sid'],
  6956. 'name' => $this->staff [0] ['username'],
  6957. 'description' => $description,
  6958. 'price' => $price
  6959. ) );
  6960. $reviseDetailString = json_encode ( $reviseDetail );
  6961. $receipt->reviseDetail = $reviseDetailString;
  6962. $receipt->revisePrice = $price;
  6963. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  6964. } else {
  6965. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  6966. array_push ( $reviseDetail, array (
  6967. 'sid' => $this->staff [0] ['sid'],
  6968. 'name' => $this->staff [0] ['username'],
  6969. 'description' => $description,
  6970. 'price' => $price
  6971. ) );
  6972. $reviseDetailString = json_encode ( $reviseDetail );
  6973. $receipt->reviseDetail = $reviseDetailString;
  6974. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  6975. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  6976. }
  6977. $receipt->update ( array (
  6978. 'where' => 'rid=' . $rid
  6979. ) );
  6980. }
  6981. return '/approvalEdi/' . $rid;
  6982. }
  6983. function personalCollect() {
  6984. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6985. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  6986. $this->showCache ( $path );
  6987. Doo::loadModel ( "receiptDetail" );
  6988. Doo::loadModel ( "itemStatistics" );
  6989. Doo::loadModel ( 'statistics' );
  6990. $statistics = new statistics ();
  6991. $itemStatistics = new itemStatistics ();
  6992. $receiptDetail = new receiptDetail ();
  6993. $receiptCollectList = $receiptDetail->find ( array (
  6994. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  6995. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  6996. 'groupby' => 'itemCategory,Month(date)',
  6997. 'asArray' => true
  6998. ) );
  6999. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  7000. 'where' => 'staff=' . $this->staff [0] ['sid'],
  7001. 'asArray' => true
  7002. ) );
  7003. // create collect html
  7004. $collectArray = array (
  7005. '日常相关费用' => array (),
  7006. '差旅相关费用' => array (),
  7007. '培训班费用' => array (),
  7008. '其他' => array ()
  7009. );
  7010. $adjustment = array ();
  7011. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  7012. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  7013. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  7014. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  7015. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  7016. array_push ( $collectArray ['培训班费用'], $collectHtml );
  7017. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  7018. array_push ( $collectArray ['其他'], $collectHtml );
  7019. $data ['collectArray'] = $collectArray;
  7020. // statistics html
  7021. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  7022. if (empty ( $stList ))
  7023. $stList = array (
  7024. 'rePrice' => 0,
  7025. 'agPrice' => 0
  7026. );
  7027. $data ['stList'] = array (
  7028. 'rePrice' => $stList ['rePrice'],
  7029. 'agPrice' => $stList ['agPrice'],
  7030. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  7031. );
  7032. // Adjustment price html
  7033. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  7034. array_push ( $adjustment, $collectHtml );
  7035. $data ['adjustment'] = $adjustment;
  7036. // total price html
  7037. $collectHtml = "";
  7038. $total = 0;
  7039. for($i = 1; $i <= 12; $i ++) {
  7040. $sumPrice = 0;
  7041. foreach ( $receiptCollectList as $key => $value ) {
  7042. if ($value ['month'] == $i) {
  7043. $sumPrice += $value ['price'];
  7044. }
  7045. }
  7046. if ($sumPrice == 0)
  7047. $collectHtml .= '<td class="taR">-</td>';
  7048. else
  7049. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  7050. $total += $sumPrice;
  7051. }
  7052. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  7053. $data ['totalPrice'] = $collectHtml;
  7054. $data ['year'] = $year;
  7055. $data ['totalYear'] = $total;
  7056. $data ['memu'] = "receipt";
  7057. $data ['staff'] = $this->staff;
  7058. $data ['receiptMemu'] = 'personalCollect';
  7059. $data ['verifyId'] = $this->verifyId;
  7060. $data ['executeId'] = $this->executeId;
  7061. // year staff status 2,4
  7062. if ($year < date ( "Y" )) {
  7063. Doo::loadModel ( 'receipt' );
  7064. $receipt = new receipt ();
  7065. $receiptList = $receipt->find ( array (
  7066. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  7067. 'asArray' => true
  7068. ) );
  7069. if (empty ( $receiptList )) {
  7070. ob_start ();
  7071. $this->render ( "/admin/saea_slist_collect", $data );
  7072. $this->cacheFile ( $path );
  7073. die ();
  7074. }
  7075. }
  7076. $this->render ( "/admin/saea_slist_collect", $data );
  7077. }
  7078. function personalCollectDetail() {
  7079. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7080. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  7081. $this->showCache ( $path );
  7082. Doo::loadModel ( "receiptDetail" );
  7083. Doo::loadModel ( "itemStatistics" );
  7084. Doo::loadModel ( 'statistics' );
  7085. Doo::loadModel ( 'accountItem' );
  7086. $accountItem = new accountItem ();
  7087. $statistics = new statistics ();
  7088. $itemStatistics = new itemStatistics ();
  7089. $receiptDetail = new receiptDetail ();
  7090. $receiptCollectList = $receiptDetail->find ( array (
  7091. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  7092. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  7093. 'groupby' => 'item,Month(date)',
  7094. 'asArray' => true
  7095. ) );
  7096. $accountList = $accountItem->find ( array (
  7097. 'asArray' => true
  7098. ) );
  7099. // create CollectDetail HTML
  7100. $collectHtml = array ();
  7101. foreach ( $accountList as $key => $value ) {
  7102. $html = "";
  7103. $asum = 0;
  7104. for($i = 1; $i <= 12; $i ++) {
  7105. $falg = true;
  7106. foreach ( $receiptCollectList as $v ) {
  7107. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  7108. $asum += $v ['price'];
  7109. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  7110. $falg = false;
  7111. break;
  7112. }
  7113. }
  7114. if ($falg)
  7115. $html .= '<td class="taR">-</td>';
  7116. }
  7117. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  7118. $collectHtml [$value ['category']] [$value ['name']] = $html;
  7119. }
  7120. $data ['collectHtml'] = $collectHtml;
  7121. // create Adjustment price html
  7122. $receiptCollectList = $receiptDetail->find ( array (
  7123. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  7124. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  7125. 'groupby' => 'itemCategory,Month(date)',
  7126. 'asArray' => true
  7127. ) );
  7128. $adjustment = array ();
  7129. $collectArray = array (
  7130. '日常相关费用' => array (),
  7131. '差旅相关费用' => array (),
  7132. '培训班费用' => array (),
  7133. '其他' => array ()
  7134. );
  7135. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  7136. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  7137. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  7138. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  7139. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  7140. array_push ( $collectArray ['培训班费用'], $collectHtml );
  7141. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  7142. array_push ( $collectArray ['其他'], $collectHtml );
  7143. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  7144. array_push ( $adjustment, $collectHtml );
  7145. // total price html
  7146. $collectHtml = "";
  7147. $total = 0;
  7148. for($i = 1; $i <= 12; $i ++) {
  7149. $sumPrice = 0;
  7150. foreach ( $receiptCollectList as $key => $value ) {
  7151. if ($value ['month'] == $i) {
  7152. $sumPrice += $value ['price'];
  7153. }
  7154. }
  7155. if ($sumPrice == 0)
  7156. $collectHtml .= '<td class="taR">-</td>';
  7157. else
  7158. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  7159. $total += $sumPrice;
  7160. }
  7161. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  7162. // statistics html
  7163. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  7164. if (empty ( $stList ))
  7165. $stList = array (
  7166. 'rePrice' => 0,
  7167. 'agPrice' => 0
  7168. );
  7169. $data ['stList'] = array (
  7170. 'rePrice' => $stList ['rePrice'],
  7171. 'agPrice' => $stList ['agPrice'],
  7172. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  7173. );
  7174. $data ['collectArray'] = $collectArray;
  7175. $data ['adjustment'] = $adjustment;
  7176. $data ['totalPrice'] = $collectHtml;
  7177. $data ['totalYear'] = $total;
  7178. $data ['year'] = $year;
  7179. $data ['memu'] = "receipt";
  7180. $data ['staff'] = $this->staff;
  7181. $data ['receiptMemu'] = 'personalCollect';
  7182. $data ['verifyId'] = $this->verifyId;
  7183. $data ['executeId'] = $this->executeId;
  7184. // year staff status 2,4
  7185. if ($year < date ( "Y" )) {
  7186. Doo::loadModel ( 'receipt' );
  7187. $receipt = new receipt ();
  7188. $receiptList = $receipt->find ( array (
  7189. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  7190. 'asArray' => true
  7191. ) );
  7192. if (empty ( $receiptList )) {
  7193. ob_start ();
  7194. $this->render ( "/admin/saeaCollectArticles", $data );
  7195. $this->cacheFile ( $path );
  7196. die ();
  7197. }
  7198. }
  7199. $this->render ( "/admin/saeaCollectArticles", $data );
  7200. }
  7201. function companyCategoryCollect() {
  7202. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7203. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  7204. $this->showCache ( $path );
  7205. Doo::loadModel ( 'L_category' );
  7206. Doo::loadModel ( 'itemStatistics' );
  7207. Doo::loadModel ( 'statistics' );
  7208. $statistics = new statistics ();
  7209. $Lcategory = new L_category ();
  7210. $itemStatistics = new itemStatistics ();
  7211. $LcategoryList = $Lcategory->find ( array (
  7212. 'asArray' => true
  7213. ) ); // 'staff='.$this->staff[0]['sid']." and
  7214. $itemStatisticsList = $itemStatistics->find ( array (
  7215. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  7216. 'where' => " Year(date)=" . $year,
  7217. 'groupby' => 'cid,Month(date)',
  7218. 'asArray' => true
  7219. ) );
  7220. // ceatre companyCollectHtml
  7221. foreach ( $LcategoryList as $value ) {
  7222. $html = "";
  7223. $asum = 0;
  7224. for($i = 1; $i <= 12; $i ++) {
  7225. $falg = true;
  7226. foreach ( $itemStatisticsList as $v ) {
  7227. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  7228. $asum += $v ['price'];
  7229. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  7230. $falg = false;
  7231. break;
  7232. }
  7233. }
  7234. if ($falg)
  7235. $html .= '<td class="taR">-</td>';
  7236. }
  7237. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  7238. $collectHtml [$value ['title']] = array (
  7239. 'html' => $html,
  7240. 'cid' => $value ['cid']
  7241. );
  7242. }
  7243. $data ['companyHtml'] = $collectHtml;
  7244. // total price html
  7245. $collectHtml = "";
  7246. $total = 0;
  7247. for($i = 1; $i <= 12; $i ++) {
  7248. $sumPrice = 0;
  7249. foreach ( $itemStatisticsList as $key => $value ) {
  7250. if ($value ['month'] == $i) {
  7251. $sumPrice += $value ['price'];
  7252. }
  7253. }
  7254. if ($sumPrice == 0)
  7255. $collectHtml .= '<td class="taR">-</td>';
  7256. else
  7257. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  7258. $total += $sumPrice;
  7259. }
  7260. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  7261. $data ['companyTotalHtml'] = $collectHtml;
  7262. $data ['total'] = $total;
  7263. // statistics html
  7264. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'] );
  7265. if (empty ( $stList ))
  7266. $stList = array (
  7267. 'rePrice' => 0,
  7268. 'agPrice' => 0
  7269. );
  7270. $data ['stList'] = array (
  7271. 'rePrice' => $stList ['rePrice'],
  7272. 'agPrice' => $stList ['agPrice'],
  7273. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  7274. );
  7275. $data ['year'] = $year;
  7276. $data ['memu'] = "receipt";
  7277. $data ['staff'] = $this->staff;
  7278. $data ['receiptMemu'] = 'companyCategoryCollect';
  7279. $data ['verifyId'] = $this->verifyId;
  7280. $data ['executeId'] = $this->executeId;
  7281. // year staff status 2,4
  7282. if ($year < date ( "Y" )) {
  7283. Doo::loadModel ( 'receipt' );
  7284. $receipt = new receipt ();
  7285. $receiptList = $receipt->find ( array (
  7286. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  7287. 'asArray' => true
  7288. ) );
  7289. if (empty ( $receiptList )) {
  7290. ob_start ();
  7291. $this->render ( "/admin/saeaCompanyCollect", $data );
  7292. $this->cacheFile ( $path );
  7293. die ();
  7294. }
  7295. }
  7296. $this->render ( "/admin/saeaCompanyCollect", $data );
  7297. }
  7298. function categoryCollectDetail() {
  7299. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7300. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  7301. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  7302. $this->showCache ( $path );
  7303. Doo::loadModel ( 'statistics' );
  7304. $statistics = new statistics ();
  7305. Doo::loadModel ( "receiptDetail" );
  7306. $receiptDetail = new receiptDetail ();
  7307. Doo::loadModel ( 'L_category' );
  7308. $Lcategory = new L_category ();
  7309. Doo::loadModel ( 'accountItem' );
  7310. $accountItem = new accountItem ();
  7311. $LcategoryList = $Lcategory->find ( array (
  7312. 'asArray' => true
  7313. ) );
  7314. if ($cid == 0) {
  7315. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7316. if ($cid == 0)
  7317. $cid = $LcategoryList [0] ['cid'];
  7318. }
  7319. $data ['LcategoryList'] = $LcategoryList;
  7320. $receiptCollectList = $receiptDetail->find ( array (
  7321. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  7322. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  7323. 'groupby' => 'item,Month(pastDate)',
  7324. 'asArray' => true
  7325. ) );
  7326. $accountList = $accountItem->find ( array (
  7327. 'asArray' => true
  7328. ) );
  7329. // create CollectDetail HTML
  7330. $collectHtml = array ();
  7331. foreach ( $accountList as $key => $value ) {
  7332. $html = "";
  7333. $asum = 0;
  7334. for($i = 1; $i <= 12; $i ++) {
  7335. $falg = true;
  7336. foreach ( $receiptCollectList as $v ) {
  7337. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  7338. $asum += $v ['price'];
  7339. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  7340. $falg = false;
  7341. break;
  7342. }
  7343. }
  7344. if ($falg)
  7345. $html .= '<td class="taR">-</td>';
  7346. }
  7347. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  7348. $collectHtml [$value ['category']] [$value ['name']] = $html;
  7349. }
  7350. $data ['collectHtml'] = $collectHtml;
  7351. // create Adjustment price html
  7352. $receiptCollectList = $receiptDetail->find ( array (
  7353. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  7354. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  7355. 'groupby' => 'itemCategory,Month(pastDate)',
  7356. 'asArray' => true
  7357. ) );
  7358. $adjustment = array ();
  7359. $collectArray = array (
  7360. '日常相关费用' => array (),
  7361. '差旅相关费用' => array (),
  7362. '培训班费用' => array (),
  7363. '其他' => array ()
  7364. );
  7365. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  7366. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  7367. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  7368. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  7369. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  7370. array_push ( $collectArray ['培训班费用'], $collectHtml );
  7371. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  7372. array_push ( $collectArray ['其他'], $collectHtml );
  7373. $data ['collectArray'] = $collectArray;
  7374. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  7375. array_push ( $adjustment, $collectHtml );
  7376. $data ['adjustment'] = $adjustment;
  7377. // total price html
  7378. $collectHtml = "";
  7379. $total = 0;
  7380. for($i = 1; $i <= 12; $i ++) {
  7381. $sumPrice = 0;
  7382. foreach ( $receiptCollectList as $key => $value ) {
  7383. if ($value ['month'] == $i) {
  7384. $sumPrice += $value ['price'];
  7385. }
  7386. }
  7387. if ($sumPrice == 0)
  7388. $collectHtml .= '<td class="taR">-</td>';
  7389. else
  7390. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  7391. $total += $sumPrice;
  7392. }
  7393. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  7394. // statistics html
  7395. $stList = $statistics->statisticsByCid ( $year, $cid );
  7396. if (empty ( $stList ))
  7397. $stList = array (
  7398. 'rePrice' => 0,
  7399. 'agPrice' => 0
  7400. );
  7401. $data ['stList'] = array (
  7402. 'rePrice' => $stList ['rePrice'],
  7403. 'agPrice' => $stList ['agPrice'],
  7404. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  7405. );
  7406. $data ['totalYear'] = $total;
  7407. $data ['year'] = $year;
  7408. $data ['cid'] = $cid;
  7409. $data ['memu'] = "receipt";
  7410. $data ['staff'] = $this->staff;
  7411. $data ['receiptMemu'] = 'companyCategoryCollect';
  7412. $data ['verifyId'] = $this->verifyId;
  7413. $data ['executeId'] = $this->executeId;
  7414. // year staff status 2,4
  7415. if ($year < date ( "Y" )) {
  7416. Doo::loadModel ( 'receipt' );
  7417. $receipt = new receipt ();
  7418. $receiptList = $receipt->find ( array (
  7419. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  7420. 'asArray' => true
  7421. ) );
  7422. if (empty ( $receiptList )) {
  7423. ob_start ();
  7424. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  7425. $this->cacheFile ( $path );
  7426. die ();
  7427. }
  7428. }
  7429. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  7430. }
  7431. function staffCollect() {
  7432. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7433. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  7434. // $this->showCache($path);
  7435. Doo::loadModel ( 'statistics' );
  7436. $statistics = new statistics ();
  7437. Doo::loadModel ( "receiptDetail" );
  7438. $receiptDetail = new receiptDetail ();
  7439. Doo::loadModel ( 'L_category' );
  7440. $Lcategory = new L_category ();
  7441. Doo::loadModel ( 'accountItem' );
  7442. $accountItem = new accountItem ();
  7443. Doo::loadModel ( 'staff' );
  7444. $staff = new staff ();
  7445. Doo::loadModel ( 'itemStatistics' );
  7446. $itemStatistics = new itemStatistics ();
  7447. /*
  7448. * $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice', 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true)); if(empty($stList)) $stList=array('rePrice'=>0,'agPrice'=>0); $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  7449. */
  7450. // statistics html
  7451. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'] );
  7452. if (empty ( $stList ))
  7453. $stList = array (
  7454. 'rePrice' => 0,
  7455. 'agPrice' => 0
  7456. );
  7457. $data ['stList'] = array (
  7458. 'rePrice' => $stList ['rePrice'],
  7459. 'agPrice' => $stList ['agPrice'],
  7460. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  7461. );
  7462. // ---
  7463. $staffList = $staff->find ( array (
  7464. 'where' => 'username !="admin"',
  7465. 'asArray' => true
  7466. ) );
  7467. $LcategoryList = $Lcategory->find ( array (
  7468. 'asArray' => true
  7469. ) ); // 'staff='.$this->staff[0]['sid']." and
  7470. $itemStatisticsList = $itemStatistics->find ( array (
  7471. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  7472. 'where' => " Year(date)=" . $year,
  7473. 'groupby' => 'staff,Month(date)',
  7474. 'asArray' => true
  7475. ) );
  7476. $categoryList = $staff->find ( array (
  7477. 'select' => 'COUNT(*) as count,cid,category',
  7478. 'where' => 'username !="admin"',
  7479. 'groupby' => 'cid',
  7480. 'asArray' => true
  7481. ) );
  7482. // print_r($itemStatisticsList);die;
  7483. // ceatre companyCollectHtml
  7484. foreach ( $categoryList as $vlu ) {
  7485. $count = $vlu ['count'] + 1;
  7486. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  7487. $m1 = 0;
  7488. $m2 = 0;
  7489. $m3 = 0;
  7490. $m4 = 0;
  7491. $m5 = 0;
  7492. $m6 = 0;
  7493. $m7 = 0;
  7494. $m8 = 0;
  7495. $m9 = 0;
  7496. $m10 = 0;
  7497. $m11 = 0;
  7498. $m12 = 0;
  7499. $m13 = 0;
  7500. foreach ( $staffList as $value ) {
  7501. if ($vlu ['cid'] == $value ['cid']) {
  7502. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  7503. $asum = 0;
  7504. for($i = 1; $i <= 12; $i ++) {
  7505. $falg = true;
  7506. foreach ( $itemStatisticsList as $v ) {
  7507. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  7508. if ($v ['month'] == 1)
  7509. $m1 += $v ['price'];
  7510. if ($v ['month'] == 2)
  7511. $m2 += $v ['price'];
  7512. if ($v ['month'] == 3)
  7513. $m3 += $v ['price'];
  7514. if ($v ['month'] == 4)
  7515. $m4 += $v ['price'];
  7516. if ($v ['month'] == 5)
  7517. $m5 += $v ['price'];
  7518. if ($v ['month'] == 6)
  7519. $m6 += $v ['price'];
  7520. if ($v ['month'] == 7)
  7521. $m7 += $v ['price'];
  7522. if ($v ['month'] == 8)
  7523. $m8 += $v ['price'];
  7524. if ($v ['month'] == 9)
  7525. $m9 += $v ['price'];
  7526. if ($v ['month'] == 10)
  7527. $m10 += $v ['price'];
  7528. if ($v ['month'] == 11)
  7529. $m11 += $v ['price'];
  7530. if ($v ['month'] == 12)
  7531. $m12 += $v ['price'];
  7532. $asum += $v ['price'];
  7533. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  7534. $falg = false;
  7535. break;
  7536. }
  7537. }
  7538. if ($falg)
  7539. $html .= '<td class="taR">-</td>';
  7540. }
  7541. $m13 += $asum;
  7542. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  7543. $collectHtml [$value ['username']] = array (
  7544. 'html' => $html,
  7545. 'sid' => $value ['sid']
  7546. );
  7547. $html = "";
  7548. }
  7549. }
  7550. $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>
  7551. <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>
  7552. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  7553. $collectHtml [$vlu ['cid']] = array (
  7554. 'html' => $hl,
  7555. 'sid' => ''
  7556. );
  7557. }
  7558. $data ['companyHtml'] = $collectHtml;
  7559. // total price html
  7560. $collectHtml = "";
  7561. $total = 0;
  7562. for($i = 1; $i <= 12; $i ++) {
  7563. $sumPrice = 0;
  7564. foreach ( $itemStatisticsList as $key => $value ) {
  7565. if ($value ['month'] == $i) {
  7566. $sumPrice += $value ['price'];
  7567. }
  7568. }
  7569. if ($sumPrice == 0)
  7570. $collectHtml .= '<td class="taR">-</td>';
  7571. else
  7572. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  7573. $total += $sumPrice;
  7574. }
  7575. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  7576. $data ['companyTotalHtml'] = $collectHtml;
  7577. $data ['total'] = $total;
  7578. $data ['year'] = $year;
  7579. $data ['memu'] = "receipt";
  7580. $data ['staff'] = $this->staff;
  7581. $data ['receiptMemu'] = 'companyCategoryCollect';
  7582. $data ['verifyId'] = $this->verifyId;
  7583. $data ['executeId'] = $this->executeId;
  7584. if ($year <= date ( "Y" )) {
  7585. Doo::loadModel ( 'receipt' );
  7586. $receipt = new receipt ();
  7587. $receiptList = $receipt->find ( array (
  7588. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  7589. 'asArray' => true
  7590. ) );
  7591. if (empty ( $receiptList )) { // generated files
  7592. ob_start ();
  7593. $this->render ( "/admin/saeaStaffCollectB", $data );
  7594. $this->cacheFile ( $path );
  7595. die ();
  7596. }
  7597. }
  7598. $this->render ( "/admin/saeaStaffCollectB", $data );
  7599. }
  7600. function staffCollectBak() {
  7601. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7602. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  7603. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  7604. $this->showCache ( $path );
  7605. Doo::loadModel ( 'statistics' );
  7606. $statistics = new statistics ();
  7607. Doo::loadModel ( "receiptDetail" );
  7608. $receiptDetail = new receiptDetail ();
  7609. Doo::loadModel ( 'L_category' );
  7610. $Lcategory = new L_category ();
  7611. Doo::loadModel ( 'accountItem' );
  7612. $accountItem = new accountItem ();
  7613. Doo::loadModel ( 'staff' );
  7614. $staff = new staff ();
  7615. Doo::loadModel ( 'itemStatistics' );
  7616. $itemStatistics = new itemStatistics ();
  7617. $itemStatisticsList = $itemStatistics->find ( array (
  7618. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  7619. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  7620. 'groupby' => 'staff,itemCategory,Month(date)',
  7621. 'asArray' => true
  7622. ) );
  7623. $itemCategoryList = $itemStatistics->find ( array (
  7624. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  7625. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  7626. 'groupby' => 'cid,itemCategory,Month(date)',
  7627. 'asArray' => true
  7628. ) );
  7629. $LcategoryList = $Lcategory->find ( array (
  7630. 'asArray' => true
  7631. ) );
  7632. $staffList = $staff->find ( array (
  7633. 'asArray' => true
  7634. ) );
  7635. $htmlArray = array ();
  7636. foreach ( $LcategoryList as $value ) {
  7637. $htmlArray [$value ['title']] = array ();
  7638. foreach ( $staffList as $v ) {
  7639. if ($value ['cid'] == $v ['cid']) {
  7640. $html = "";
  7641. $falg = true;
  7642. $staffSumPrice = 0;
  7643. foreach ( $itemStatisticsList as $a ) {
  7644. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  7645. if (empty ( $a ['price'] )) {
  7646. $html .= '<td class="taR">-</td>';
  7647. $falg = false;
  7648. break;
  7649. } else {
  7650. $staffSumPrice += $a ['price'];
  7651. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  7652. $falg = false;
  7653. break;
  7654. }
  7655. }
  7656. }
  7657. if ($falg) {
  7658. $html .= '<td class="taR">-</td>';
  7659. $falg = true;
  7660. }
  7661. $falg = true;
  7662. foreach ( $itemStatisticsList as $a ) {
  7663. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  7664. if (empty ( $a ['price'] )) {
  7665. $html .= '<td class="taR">-</td>';
  7666. $falg = false;
  7667. break;
  7668. } else {
  7669. $staffSumPrice += $a ['price'];
  7670. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  7671. $falg = false;
  7672. break;
  7673. }
  7674. }
  7675. }
  7676. if ($falg) {
  7677. $html .= '<td class="taR">-</td>';
  7678. $falg = true;
  7679. }
  7680. $falg = true;
  7681. foreach ( $itemStatisticsList as $a ) {
  7682. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  7683. if (empty ( $a ['price'] )) {
  7684. $html .= '<td class="taR">-</td>';
  7685. $falg = false;
  7686. break;
  7687. } else {
  7688. $staffSumPrice += $a ['price'];
  7689. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  7690. $falg = false;
  7691. break;
  7692. }
  7693. }
  7694. }
  7695. if ($falg) {
  7696. $html .= '<td class="taR">-</td>';
  7697. $falg = true;
  7698. }
  7699. $falg = true;
  7700. foreach ( $itemStatisticsList as $a ) {
  7701. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  7702. if (! empty ( $a ['price'] )) {
  7703. $staffSumPrice += $a ['price'];
  7704. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  7705. $falg = false;
  7706. break;
  7707. } else {
  7708. $html .= '<td class="taR">-</td>';
  7709. $falg = false;
  7710. break;
  7711. }
  7712. }
  7713. }
  7714. if ($falg) {
  7715. $html .= '<td class="taR">-</td>';
  7716. $falg = true;
  7717. }
  7718. $falg = true;
  7719. foreach ( $itemStatisticsList as $a ) {
  7720. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  7721. if (! empty ( $a ['price'] )) {
  7722. $staffSumPrice += $a ['price'];
  7723. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  7724. $falg = false;
  7725. break;
  7726. } else {
  7727. $html .= '<td class="taR">-</td>';
  7728. $falg = false;
  7729. break;
  7730. }
  7731. }
  7732. }
  7733. if ($falg) {
  7734. $html .= '<td class="taR">-</td>';
  7735. $falg = true;
  7736. }
  7737. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  7738. $htmlArray [$value ['title']] [$v ['username']] = $html;
  7739. }
  7740. }
  7741. /* -- --- */
  7742. // 合计费用
  7743. $cateHtml = "";
  7744. $catePrice = 0;
  7745. $cateFalg = true;
  7746. foreach ( $itemCategoryList as $l ) {
  7747. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  7748. if (empty ( $l ['price'] )) {
  7749. $cateHtml .= '<td class="colGreen taR">-</td>';
  7750. $cateFalg = false;
  7751. break;
  7752. } else {
  7753. $catePrice += $l ['price'];
  7754. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  7755. $cateFalg = false;
  7756. break;
  7757. }
  7758. }
  7759. }
  7760. if ($cateFalg) {
  7761. $cateHtml .= '<td class="colGreen taR">-</td>';
  7762. $cateFalg = true;
  7763. }
  7764. $cateFalg = true;
  7765. foreach ( $itemCategoryList as $l ) {
  7766. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  7767. if (empty ( $l ['price'] )) {
  7768. $cateHtml .= '<td class="colGreen taR">-</td>';
  7769. $cateFalg = false;
  7770. break;
  7771. } else {
  7772. $catePrice += $l ['price'];
  7773. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  7774. $cateFalg = false;
  7775. break;
  7776. }
  7777. }
  7778. }
  7779. if ($cateFalg) {
  7780. $cateHtml .= '<td class="colGreen taR">-</td>';
  7781. $cateFalg = true;
  7782. }
  7783. $cateFalg = true;
  7784. foreach ( $itemCategoryList as $l ) {
  7785. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  7786. if (empty ( $l ['price'] )) {
  7787. $cateHtml .= '<td class="colGreen taR">-</td>';
  7788. $cateFalg = false;
  7789. break;
  7790. } else {
  7791. $catePrice += $l ['price'];
  7792. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  7793. $cateFalg = false;
  7794. break;
  7795. }
  7796. }
  7797. }
  7798. if ($cateFalg) {
  7799. $cateHtml .= '<td class="colGreen taR">-</td>';
  7800. $cateFalg = true;
  7801. }
  7802. $cateFalg = true;
  7803. foreach ( $itemCategoryList as $l ) {
  7804. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  7805. if (empty ( $l ['price'] )) {
  7806. $cateHtml .= '<td class="colGreen taR">-</td>';
  7807. $cateFalg = false;
  7808. break;
  7809. } else {
  7810. $catePrice += $l ['price'];
  7811. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  7812. $cateFalg = false;
  7813. break;
  7814. }
  7815. }
  7816. }
  7817. if ($cateFalg) {
  7818. $cateHtml .= '<td class="colGreen taR">-</td>';
  7819. $cateFalg = true;
  7820. }
  7821. $cateFalg = true;
  7822. foreach ( $itemCategoryList as $l ) {
  7823. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  7824. if (empty ( $l ['price'] )) {
  7825. $cateHtml .= '<td class="colGreen taR">-</td>';
  7826. $cateFalg = false;
  7827. break;
  7828. } else {
  7829. $catePrice += $l ['price'];
  7830. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  7831. $cateFalg = false;
  7832. break;
  7833. }
  7834. }
  7835. }
  7836. if ($cateFalg) {
  7837. $cateHtml .= '<td class="colGreen taR">-</td>';
  7838. $cateFalg = true;
  7839. }
  7840. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  7841. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  7842. /* -- --- */
  7843. }
  7844. // print_r($htmlArray);die;
  7845. $data ['htmlArray'] = $htmlArray;
  7846. // statistics html
  7847. $stList = $statistics->getOne ( array (
  7848. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  7849. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  7850. 'groupby' => 'Month(date)',
  7851. 'asArray' => true
  7852. ) );
  7853. if (empty ( $stList ))
  7854. $stList = array (
  7855. 'rePrice' => 0,
  7856. 'agPrice' => 0
  7857. );
  7858. $data ['stList'] = array (
  7859. 'rePrice' => $stList ['rePrice'],
  7860. 'agPrice' => $stList ['agPrice'],
  7861. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  7862. );
  7863. $monthHtml = "";
  7864. for($i = 1; $i <= 12; $i ++) {
  7865. if ($i == $month)
  7866. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  7867. else
  7868. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  7869. }
  7870. $data ['monthHtml'] = $monthHtml;
  7871. $data ['year'] = $year;
  7872. $data ['month'] = $month;
  7873. $data ['memu'] = "receipt";
  7874. $data ['staff'] = $this->staff;
  7875. $data ['receiptMemu'] = 'companyCategoryCollect';
  7876. $data ['verifyId'] = $this->verifyId;
  7877. $data ['executeId'] = $this->executeId;
  7878. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  7879. Doo::loadModel ( 'receipt' );
  7880. $receipt = new receipt ();
  7881. $receiptList = $receipt->find ( array (
  7882. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  7883. 'asArray' => true
  7884. ) );
  7885. if (empty ( $receiptList )) { // generated files
  7886. ob_start ();
  7887. $this->render ( "/admin/saeaStaffCollect", $data );
  7888. $this->cacheFile ( $path );
  7889. die ();
  7890. }
  7891. }
  7892. $this->render ( "/admin/saeaStaffCollect", $data );
  7893. }
  7894. function lyt() {
  7895. Doo::loadModel ( "receiptDetail" );
  7896. $receiptDetail = new receiptDetail ();
  7897. $receiptCollectList = $receiptDetail->find ( array (
  7898. 'where' => 'status=1 ',
  7899. 'asArray' => true
  7900. ) );
  7901. foreach ( $receiptCollectList as $key => $value ) {
  7902. $receiptDetail = new receiptDetail ();
  7903. $receiptDetail->pastDate = $value ['date'];
  7904. $receiptDetail->update ( array (
  7905. 'where' => "rdid= '" . $value ['rdid'] . "'"
  7906. ) );
  7907. }
  7908. }
  7909. function staffCollectMonthDetail() {
  7910. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  7911. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7912. if (! $year)
  7913. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  7914. if (! $month)
  7915. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  7916. Doo::loadModel ( 'staff' );
  7917. $staff = new staff ();
  7918. Doo::loadModel ( "receiptDetail" );
  7919. $receiptDetail = new receiptDetail ();
  7920. Doo::loadModel ( 'accountItem' );
  7921. $accountItem = new accountItem ();
  7922. Doo::loadModel ( 'statistics' );
  7923. $statistics = new statistics ();
  7924. Doo::loadModel ( 'L_category' );
  7925. $lCategory = new L_category ();
  7926. $staffList = $staff->find ( array (
  7927. 'where' => 'username!="admin"',
  7928. 'asArray' => true
  7929. ) );
  7930. $categoryList = $staff->find ( array (
  7931. 'select' => 'COUNT(*) as count,cid,category',
  7932. 'where' => 'username !="admin"',
  7933. 'groupby' => 'cid',
  7934. 'asArray' => true
  7935. ) );
  7936. $list = array ();
  7937. foreach ( $categoryList as $vlu ) {
  7938. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  7939. $r1 = 0;
  7940. $r2 = 0;
  7941. $r3 = 0;
  7942. $r4 = 0;
  7943. $r5 = 0;
  7944. $r6 = 0;
  7945. $r7 = 0;
  7946. $r8 = 0;
  7947. $r9 = 0;
  7948. $r10 = 0;
  7949. $r11 = 0;
  7950. $r12 = 0;
  7951. $r13 = 0;
  7952. $r14 = 0;
  7953. $r15 = 0;
  7954. $c1 = 0;
  7955. $c2 = 0;
  7956. $c3 = 0;
  7957. $c4 = 0;
  7958. $c5 = 0;
  7959. $c6 = 0;
  7960. $p1 = 0;
  7961. $p2 = 0;
  7962. $p3 = 0;
  7963. $p4 = 0;
  7964. $p5 = 0;
  7965. $p6 = 0;
  7966. $p7 = 0;
  7967. $p8 = 0;
  7968. $p9 = 0;
  7969. $t1 = 0;
  7970. $t2 = 0;
  7971. $t3 = 0;
  7972. $t4 = 0;
  7973. $t5 = 0;
  7974. $s1 = 0;
  7975. $m1 = 0;
  7976. foreach ( $staffList as $value ) {
  7977. if ($vlu ['cid'] == $value ['cid']) {
  7978. // pastDate
  7979. $receiptCollectList = $receiptDetail->find ( array (
  7980. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  7981. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  7982. 'groupby' => 'item,Month(pastDate),itemCategory',
  7983. 'asArray' => true
  7984. ) );
  7985. // if ($value['sid']==42){
  7986. // print_r($receiptCollectList);die;
  7987. // }
  7988. if (! empty ( $receiptCollectList )) {
  7989. $receiptL = array (
  7990. '日常相关费用' => array (),
  7991. '差旅相关费用' => array (),
  7992. '培训班费用' => array (),
  7993. '其他' => array ()
  7994. );
  7995. $html = "";
  7996. $psum = 0;
  7997. $item = array (
  7998. '市内交通费',
  7999. '市内出租费',
  8000. '办事处房租',
  8001. '电话费',
  8002. '水费',
  8003. '电费',
  8004. '办公费用',
  8005. '邮寄费',
  8006. '其他费用',
  8007. '车辆费用',
  8008. '广告费',
  8009. '团队建设费',
  8010. '物业管理费',
  8011. '宽带费'
  8012. );
  8013. foreach ( $item as $va ) {
  8014. $falg = true;
  8015. foreach ( $receiptCollectList as $v ) {
  8016. if ($v ['itemCategory'] == '日常相关费用') {
  8017. if ($v ['item'] == $va) {
  8018. if ($va == '市内交通费')
  8019. $r1 += $v ['price'];
  8020. if ($va == '市内出租费')
  8021. $r2 += $v ['price'];
  8022. if ($va == '办事处房租')
  8023. $r3 += $v ['price'];
  8024. if ($va == '电话费')
  8025. $r4 += $v ['price'];
  8026. if ($va == '水费')
  8027. $r5 += $v ['price'];
  8028. if ($va == '电费')
  8029. $r6 += $v ['price'];
  8030. if ($va == '办公费用')
  8031. $r7 += $v ['price'];
  8032. if ($va == '邮寄费')
  8033. $r8 += $v ['price'];
  8034. if ($va == '其他费用')
  8035. $r9 += $v ['price'];
  8036. if ($va == '车辆费用')
  8037. $r10 += $v ['price'];
  8038. if ($va == '广告费')
  8039. $r11 += $v ['price'];
  8040. if ($va == '团队建设费')
  8041. $r13 += $v ['price'];
  8042. if ($va == '物业管理费')
  8043. $r14 += $v ['price'];
  8044. if ($va == '宽带费')
  8045. $r15 += $v ['price'];
  8046. $psum += $v ['price'];
  8047. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8048. $falg = false;
  8049. break;
  8050. }
  8051. }
  8052. }
  8053. if ($falg)
  8054. $html .= '<td class="taR">-</td>';
  8055. }
  8056. $r12 += $psum;
  8057. if (! empty ( $psum ))
  8058. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8059. else
  8060. $psum = '<td class="colGreen taR">-</td>';
  8061. $receiptL ['日常相关费用'] = $psum . $html;
  8062. /* ----------------------------------- */
  8063. $html = "";
  8064. $psum = 0;
  8065. $item = array (
  8066. '往来交通费',
  8067. '市内交通费',
  8068. '出差住宿费',
  8069. '出差补助',
  8070. '其他费用'
  8071. );
  8072. foreach ( $item as $va ) {
  8073. $falg = true;
  8074. foreach ( $receiptCollectList as $v ) {
  8075. if ($v ['itemCategory'] == '差旅相关费用') {
  8076. if ($v ['item'] == $va) {
  8077. if ($va == '往来交通费')
  8078. $c1 += $v ['price'];
  8079. if ($va == '市内交通费')
  8080. $c2 += $v ['price'];
  8081. if ($va == '出差住宿费')
  8082. $c3 += $v ['price'];
  8083. if ($va == '出差补助')
  8084. $c4 += $v ['price'];
  8085. if ($va == '其他费用')
  8086. $c5 += $v ['price'];
  8087. $psum += $v ['price'];
  8088. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8089. $falg = false;
  8090. break;
  8091. }
  8092. }
  8093. }
  8094. if ($falg)
  8095. $html .= '<td class="taR">-</td>';
  8096. }
  8097. $c6 += $psum;
  8098. if (! empty ( $psum ))
  8099. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8100. else
  8101. $psum = '<td class="colGreen taR">-</td>';
  8102. $receiptL ['差旅相关费用'] = $psum . $html;
  8103. /* ------------------------------------- */
  8104. $html = "";
  8105. $psum = 0;
  8106. $item = array (
  8107. '场租费',
  8108. '薪酬',
  8109. '住宿费',
  8110. '交通费',
  8111. '餐饮费',
  8112. '办公费',
  8113. '公关费',
  8114. '其他'
  8115. );
  8116. foreach ( $item as $va ) {
  8117. $falg = true;
  8118. foreach ( $receiptCollectList as $v ) {
  8119. if ($v ['itemCategory'] == '培训班费用') {
  8120. if ($v ['item'] == $va) {
  8121. if ($va == '场租费')
  8122. $p1 += $v ['price'];
  8123. if ($va == '薪酬')
  8124. $p2 += $v ['price'];
  8125. if ($va == '住宿费')
  8126. $p3 += $v ['price'];
  8127. if ($va == '交通费')
  8128. $p4 += $v ['price'];
  8129. if ($va == '餐饮费')
  8130. $p5 += $v ['price'];
  8131. if ($va == '办公费')
  8132. $p6 += $v ['price'];
  8133. if ($va == '公关费')
  8134. $p7 += $v ['price'];
  8135. if ($va == '其他')
  8136. $p8 += $v ['price'];
  8137. $psum += $v ['price'];
  8138. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8139. $falg = false;
  8140. break;
  8141. }
  8142. }
  8143. }
  8144. if ($falg)
  8145. $html .= '<td class="taR">-</td>';
  8146. }
  8147. $p9 += $psum;
  8148. if (! empty ( $psum ))
  8149. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8150. else
  8151. $psum = '<td class="colGreen taR">-</td>';
  8152. $receiptL ['培训班费用'] = $psum . $html;
  8153. /* ------------------------------------- */
  8154. $html = "";
  8155. $psum = 0;
  8156. $item = array (
  8157. '公关费',
  8158. '广告费',
  8159. '借款',
  8160. '可自加费用'
  8161. );
  8162. foreach ( $item as $va ) {
  8163. $falg = true;
  8164. foreach ( $receiptCollectList as $v ) {
  8165. if ($v ['itemCategory'] == '其他') {
  8166. // if ($value['sid']==42){
  8167. //
  8168. // echo var_dump($v['item']);
  8169. // echo var_dump($va);
  8170. // echo var_dump($v['item']==" ".$va);
  8171. // echo $v['item']."==".$va."/<br/>";
  8172. // //print_r( $receiptCollectList);//echo $va;
  8173. // }
  8174. if (trim ( $v ['item'] ) == $va) {
  8175. if ($va == '公关费')
  8176. $t1 += $v ['price'];
  8177. if ($va == '广告费') {
  8178. $t2 += $v ['price'];
  8179. }
  8180. if ($va == '借款')
  8181. $t3 += $v ['price'];
  8182. if ($va == '可自加费用')
  8183. $t4 += $v ['price'];
  8184. $psum += $v ['price'];
  8185. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8186. $falg = false;
  8187. break;
  8188. }
  8189. }
  8190. }
  8191. if ($falg)
  8192. $html .= '<td class="taR">-</td>';
  8193. }
  8194. $t5 += $psum;
  8195. if (! empty ( $psum ))
  8196. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8197. else
  8198. $psum = '<td class="colGreen taR">-</td>';
  8199. $receiptL ['其他'] = $psum . $html;
  8200. /* ------------------------------------- */
  8201. $html = "";
  8202. $psum = 0;
  8203. foreach ( $receiptCollectList as $v ) {
  8204. if ($v ['itemCategory'] == '报销金额调整') {
  8205. if (! empty ( $v ['price'] )) {
  8206. $psum += $v ['price'];
  8207. }
  8208. }
  8209. }
  8210. $s1 += $psum;
  8211. if (! empty ( $psum ))
  8212. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  8213. else
  8214. $psum = '<td class="taR colOrange">-</td>';
  8215. $receiptL ['报销金额调整'] = $psum . $html;
  8216. } else {
  8217. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  8218. <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>
  8219. <td class="taR">-</td><td class="taR">-</td>';
  8220. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  8221. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  8222. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  8223. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  8224. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  8225. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  8226. }
  8227. $monthStaffPrice = $receiptDetail->find ( array (
  8228. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  8229. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  8230. 'groupby' => 'Month(pastDate)',
  8231. 'asArray' => true
  8232. ) );
  8233. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  8234. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  8235. $m1 += $monthStaffPrice [0] ['price'];
  8236. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  8237. } else
  8238. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  8239. $list [$value ['username']] = $receiptL;
  8240. }
  8241. }
  8242. $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>
  8243. <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>
  8244. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  8245. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  8246. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  8247. $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>
  8248. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  8249. $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>';
  8250. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  8251. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  8252. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  8253. }
  8254. $data ['list'] = $list;
  8255. $receiptCollectList = $receiptDetail->find ( array (
  8256. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  8257. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  8258. 'groupby' => 'item,Month(pastDate),itemCategory',
  8259. 'asArray' => true
  8260. ) );
  8261. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  8262. // statistics html
  8263. $stList = $statistics->getOne ( array (
  8264. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  8265. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  8266. 'groupby' => 'Month(date)',
  8267. 'asArray' => true
  8268. ) );
  8269. if (empty ( $stList ))
  8270. $stList = array (
  8271. 'rePrice' => 0,
  8272. 'agPrice' => 0
  8273. );
  8274. $data ['stList'] = array (
  8275. 'rePrice' => $stList ['rePrice'],
  8276. 'agPrice' => $stList ['agPrice'],
  8277. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  8278. );
  8279. $monthHtml = "";
  8280. for($i = 1; $i <= 12; $i ++) {
  8281. if ($i == $month)
  8282. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  8283. else
  8284. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  8285. }
  8286. $data ['monthHtml'] = $monthHtml;
  8287. $data ['year'] = $year;
  8288. $data ['month'] = $month;
  8289. $data ['memu'] = "receipt";
  8290. $data ['staff'] = $this->staff;
  8291. $data ['receiptMemu'] = 'companyCategoryCollect';
  8292. $data ['verifyId'] = $this->verifyId;
  8293. $data ['executeId'] = $this->executeId;
  8294. $this->render ( "/admin/staffCollectMonthDetail", $data );
  8295. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  8296. }
  8297. function staffCollectMonthDetail2() {
  8298. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  8299. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8300. if (! $year)
  8301. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  8302. if (! $month)
  8303. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  8304. Doo::loadModel ( 'staff' );
  8305. $staff = new staff ();
  8306. Doo::loadModel ( "receiptDetail" );
  8307. $receiptDetail = new receiptDetail ();
  8308. Doo::loadModel ( 'accountItem' );
  8309. $accountItem = new accountItem ();
  8310. Doo::loadModel ( 'statistics' );
  8311. $statistics = new statistics ();
  8312. Doo::loadModel ( 'L_category' );
  8313. $lCategory = new L_category ();
  8314. $staffList = $staff->find ( array (
  8315. 'where' => 'username!="admin"',
  8316. 'asArray' => true
  8317. ) );
  8318. $categoryList = $staff->find ( array (
  8319. 'select' => 'COUNT(*) as count,cid,category',
  8320. 'where' => 'username !="admin"',
  8321. 'groupby' => 'cid',
  8322. 'asArray' => true
  8323. ) );
  8324. $list = array ();
  8325. foreach ( $categoryList as $vlu ) {
  8326. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  8327. $r1 = 0;
  8328. $r2 = 0;
  8329. $r3 = 0;
  8330. $r4 = 0;
  8331. $r5 = 0;
  8332. $r6 = 0;
  8333. $r7 = 0;
  8334. $r8 = 0;
  8335. $r9 = 0;
  8336. $r10 = 0;
  8337. $r11 = 0;
  8338. $r12 = 0;
  8339. $r13 = 0;
  8340. $r14 = 0;
  8341. $r15 = 0;
  8342. $c1 = 0;
  8343. $c2 = 0;
  8344. $c3 = 0;
  8345. $c4 = 0;
  8346. $c5 = 0;
  8347. $c6 = 0;
  8348. $p1 = 0;
  8349. $p2 = 0;
  8350. $p3 = 0;
  8351. $p4 = 0;
  8352. $p5 = 0;
  8353. $p6 = 0;
  8354. $p7 = 0;
  8355. $p8 = 0;
  8356. $p9 = 0;
  8357. $t1 = 0;
  8358. $t2 = 0;
  8359. $t3 = 0;
  8360. $t4 = 0;
  8361. $t5 = 0;
  8362. $s1 = 0;
  8363. $m1 = 0;
  8364. foreach ( $staffList as $value ) {
  8365. if ($vlu ['cid'] == $value ['cid']) {
  8366. $receiptCollectList = $receiptDetail->find ( array (
  8367. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  8368. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  8369. 'groupby' => 'item,Month(date),itemCategory',
  8370. 'asArray' => true
  8371. ) );
  8372. if (! empty ( $receiptCollectList )) {
  8373. $receiptL = array (
  8374. '日常相关费用' => array (),
  8375. '差旅相关费用' => array (),
  8376. '培训班费用' => array (),
  8377. '其他' => array ()
  8378. );
  8379. $html = "";
  8380. $psum = 0;
  8381. $item = array (
  8382. '市内交通费',
  8383. '市内出租费',
  8384. '办事处房租',
  8385. '电话费',
  8386. '水费',
  8387. '电费',
  8388. '办公费用',
  8389. '邮寄费',
  8390. '其他费用',
  8391. '车辆费用',
  8392. '广告费',
  8393. '团队建设费',
  8394. '物业管理费',
  8395. '宽带费'
  8396. );
  8397. foreach ( $item as $va ) {
  8398. $falg = true;
  8399. foreach ( $receiptCollectList as $v ) {
  8400. if ($v ['itemCategory'] == '日常相关费用') {
  8401. if ($v ['item'] == $va) {
  8402. if ($va == '市内交通费')
  8403. $r1 += $v ['price'];
  8404. if ($va == '市内出租费')
  8405. $r2 += $v ['price'];
  8406. if ($va == '办事处房租')
  8407. $r3 += $v ['price'];
  8408. if ($va == '电话费')
  8409. $r4 += $v ['price'];
  8410. if ($va == '水费')
  8411. $r5 += $v ['price'];
  8412. if ($va == '电费')
  8413. $r6 += $v ['price'];
  8414. if ($va == '办公费用')
  8415. $r7 += $v ['price'];
  8416. if ($va == '邮寄费')
  8417. $r8 += $v ['price'];
  8418. if ($va == '其他费用')
  8419. $r9 += $v ['price'];
  8420. if ($va == '车辆费用')
  8421. $r10 += $v ['price'];
  8422. if ($va == '广告费')
  8423. $r11 += $v ['price'];
  8424. if ($va == '团队建设费')
  8425. $r13 += $v ['price'];
  8426. if ($va == '物业管理费')
  8427. $r14 += $v ['price'];
  8428. if ($va == '宽带费')
  8429. $r15 += $v ['price'];
  8430. $psum += $v ['price'];
  8431. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8432. $falg = false;
  8433. break;
  8434. }
  8435. }
  8436. }
  8437. if ($falg)
  8438. $html .= '<td class="taR">-</td>';
  8439. }
  8440. $r12 += $psum;
  8441. if (! empty ( $psum ))
  8442. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8443. else
  8444. $psum = '<td class="colGreen taR">-</td>';
  8445. $receiptL ['日常相关费用'] = $psum . $html;
  8446. /* ----------------------------------- */
  8447. $html = "";
  8448. $psum = 0;
  8449. $item = array (
  8450. '往来交通费',
  8451. '市内交通费',
  8452. '出差住宿费',
  8453. '出差补助',
  8454. '其他费用'
  8455. );
  8456. foreach ( $item as $va ) {
  8457. $falg = true;
  8458. foreach ( $receiptCollectList as $v ) {
  8459. if ($v ['itemCategory'] == '差旅相关费用') {
  8460. if ($v ['item'] == $va) {
  8461. if ($va == '往来交通费')
  8462. $c1 += $v ['price'];
  8463. if ($va == '市内交通费')
  8464. $c2 += $v ['price'];
  8465. if ($va == '出差住宿费')
  8466. $c3 += $v ['price'];
  8467. if ($va == '出差补助')
  8468. $c4 += $v ['price'];
  8469. if ($va == '其他费用')
  8470. $c5 += $v ['price'];
  8471. $psum += $v ['price'];
  8472. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8473. $falg = false;
  8474. break;
  8475. }
  8476. }
  8477. }
  8478. if ($falg)
  8479. $html .= '<td class="taR">-</td>';
  8480. }
  8481. $c6 += $psum;
  8482. if (! empty ( $psum ))
  8483. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8484. else
  8485. $psum = '<td class="colGreen taR">-</td>';
  8486. $receiptL ['差旅相关费用'] = $psum . $html;
  8487. /* ------------------------------------- */
  8488. $html = "";
  8489. $psum = 0;
  8490. $item = array (
  8491. '场租费',
  8492. '薪酬',
  8493. '住宿费',
  8494. '交通费',
  8495. '餐饮费',
  8496. '办公费',
  8497. '公关费',
  8498. '其他'
  8499. );
  8500. foreach ( $item as $va ) {
  8501. $falg = true;
  8502. foreach ( $receiptCollectList as $v ) {
  8503. if ($v ['itemCategory'] == '培训班费用') {
  8504. if ($v ['item'] == $va) {
  8505. if ($va == '场租费')
  8506. $p1 += $v ['price'];
  8507. if ($va == '薪酬')
  8508. $p2 += $v ['price'];
  8509. if ($va == '住宿费')
  8510. $p3 += $v ['price'];
  8511. if ($va == '交通费')
  8512. $p4 += $v ['price'];
  8513. if ($va == '餐饮费')
  8514. $p5 += $v ['price'];
  8515. if ($va == '办公费')
  8516. $p6 += $v ['price'];
  8517. if ($va == '公关费')
  8518. $p7 += $v ['price'];
  8519. if ($va == '其他')
  8520. $p8 += $v ['price'];
  8521. $psum += $v ['price'];
  8522. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8523. $falg = false;
  8524. break;
  8525. }
  8526. }
  8527. }
  8528. if ($falg)
  8529. $html .= '<td class="taR">-</td>';
  8530. }
  8531. $p9 += $psum;
  8532. if (! empty ( $psum ))
  8533. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8534. else
  8535. $psum = '<td class="colGreen taR">-</td>';
  8536. $receiptL ['培训班费用'] = $psum . $html;
  8537. /* ------------------------------------- */
  8538. $html = "";
  8539. $psum = 0;
  8540. $item = array (
  8541. '公关费',
  8542. '广告费',
  8543. '借款',
  8544. '可自加费用'
  8545. );
  8546. foreach ( $item as $va ) {
  8547. $falg = true;
  8548. foreach ( $receiptCollectList as $v ) {
  8549. if ($v ['itemCategory'] == '其他') {
  8550. if ($v ['item'] == $va) {
  8551. if ($va == '公关费')
  8552. $t1 += $v ['price'];
  8553. if ($va == '广告费')
  8554. $t2 += $v ['price'];
  8555. if ($va == '借款')
  8556. $t3 += $v ['price'];
  8557. if ($va == '可自加费用')
  8558. $t4 += $v ['price'];
  8559. $psum += $v ['price'];
  8560. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8561. $falg = false;
  8562. break;
  8563. }
  8564. }
  8565. }
  8566. if ($falg)
  8567. $html .= '<td class="taR">-</td>';
  8568. }
  8569. $t5 += $psum;
  8570. if (! empty ( $psum ))
  8571. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8572. else
  8573. $psum = '<td class="colGreen taR">-</td>';
  8574. $receiptL ['其他'] = $psum . $html;
  8575. /* ------------------------------------- */
  8576. $html = "";
  8577. $psum = 0;
  8578. foreach ( $receiptCollectList as $v ) {
  8579. if ($v ['itemCategory'] == '报销金额调整') {
  8580. if (! empty ( $v ['price'] )) {
  8581. $psum += $v ['price'];
  8582. }
  8583. }
  8584. }
  8585. $s1 += $psum;
  8586. if (! empty ( $psum ))
  8587. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  8588. else
  8589. $psum = '<td class="taR colOrange">-</td>';
  8590. $receiptL ['报销金额调整'] = $psum . $html;
  8591. } else {
  8592. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  8593. <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>';
  8594. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  8595. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  8596. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  8597. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  8598. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  8599. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  8600. }
  8601. $monthStaffPrice = $receiptDetail->find ( array (
  8602. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  8603. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  8604. 'asArray' => true
  8605. ) );
  8606. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  8607. $m1 += $monthStaffPrice [0] ['price'];
  8608. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  8609. } else
  8610. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  8611. $list [$value ['username']] = $receiptL;
  8612. }
  8613. }
  8614. $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>
  8615. <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>
  8616. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  8617. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  8618. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  8619. $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>
  8620. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  8621. $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>';
  8622. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  8623. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  8624. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  8625. }
  8626. $data ['list'] = $list;
  8627. $receiptCollectList = $receiptDetail->find ( array (
  8628. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  8629. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  8630. 'groupby' => 'item,Month(date),itemCategory',
  8631. 'asArray' => true
  8632. ) );
  8633. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  8634. // statistics html
  8635. $stList = $statistics->getOne ( array (
  8636. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  8637. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  8638. 'groupby' => 'Month(date)',
  8639. 'asArray' => true
  8640. ) );
  8641. if (empty ( $stList ))
  8642. $stList = array (
  8643. 'rePrice' => 0,
  8644. 'agPrice' => 0
  8645. );
  8646. $data ['stList'] = array (
  8647. 'rePrice' => $stList ['rePrice'],
  8648. 'agPrice' => $stList ['agPrice'],
  8649. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  8650. );
  8651. $monthHtml = "";
  8652. for($i = 1; $i <= 12; $i ++) {
  8653. if ($i == $month)
  8654. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  8655. else
  8656. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  8657. }
  8658. $data ['monthHtml'] = $monthHtml;
  8659. $data ['year'] = $year;
  8660. $data ['month'] = $month;
  8661. $data ['memu'] = "receipt";
  8662. $data ['staff'] = $this->staff;
  8663. $data ['receiptMemu'] = 'companyCategoryCollect';
  8664. $data ['verifyId'] = $this->verifyId;
  8665. $data ['executeId'] = $this->executeId;
  8666. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  8667. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  8668. }
  8669. function companyMonthCollectDetail() {
  8670. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  8671. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8672. if (! $year)
  8673. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  8674. if (! $month)
  8675. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  8676. Doo::loadModel ( 'staff' );
  8677. $staff = new staff ();
  8678. Doo::loadModel ( "receiptDetail" );
  8679. $receiptDetail = new receiptDetail ();
  8680. Doo::loadModel ( 'accountItem' );
  8681. $accountItem = new accountItem ();
  8682. Doo::loadModel ( 'statistics' );
  8683. $statistics = new statistics ();
  8684. Doo::loadModel ( 'L_category' );
  8685. $lCategory = new L_category ();
  8686. $staffList = $staff->find ( array (
  8687. 'where' => 'username!="admin"',
  8688. 'asArray' => true
  8689. ) );
  8690. $categoryList = $lCategory->find ( array (
  8691. 'asArray' => true
  8692. ) );
  8693. $list = array ();
  8694. foreach ( $categoryList as $value ) {
  8695. $receiptCollectList = $receiptDetail->find ( array (
  8696. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  8697. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  8698. 'groupby' => 'item,Month(pastDate),itemCategory',
  8699. 'asArray' => true
  8700. ) );
  8701. if (! empty ( $receiptCollectList )) {
  8702. $receiptL = array (
  8703. '日常相关费用' => array (),
  8704. '差旅相关费用' => array (),
  8705. '培训班费用' => array (),
  8706. '其他' => array ()
  8707. );
  8708. $html = "";
  8709. $psum = 0;
  8710. $item = array (
  8711. '市内交通费',
  8712. '市内出租费',
  8713. '办事处房租',
  8714. '电话费',
  8715. '水费',
  8716. '电费',
  8717. '办公费用',
  8718. '邮寄费',
  8719. '其他费用',
  8720. '车辆费用',
  8721. '广告费',
  8722. '团队建设费'
  8723. );
  8724. foreach ( $item as $va ) {
  8725. $falg = true;
  8726. foreach ( $receiptCollectList as $v ) {
  8727. if ($v ['itemCategory'] == '日常相关费用') {
  8728. if ($v ['item'] == $va) {
  8729. $psum += $v ['price'];
  8730. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8731. $falg = false;
  8732. break;
  8733. }
  8734. }
  8735. }
  8736. if ($falg)
  8737. $html .= '<td class="taR">-</td>';
  8738. }
  8739. if (! empty ( $psum ))
  8740. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8741. else
  8742. $psum = '<td class="colGreen taR">-</td>';
  8743. $receiptL ['日常相关费用'] = $psum . $html;
  8744. /* ----------------------------------- */
  8745. $html = "";
  8746. $psum = 0;
  8747. $item = array (
  8748. '往来交通费',
  8749. '市内交通费',
  8750. '出差住宿费',
  8751. '出差补助',
  8752. '其他费用'
  8753. );
  8754. foreach ( $item as $va ) {
  8755. $falg = true;
  8756. foreach ( $receiptCollectList as $v ) {
  8757. if ($v ['itemCategory'] == '差旅相关费用') {
  8758. if ($v ['item'] == $va) {
  8759. $psum += $v ['price'];
  8760. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8761. $falg = false;
  8762. break;
  8763. }
  8764. }
  8765. }
  8766. if ($falg)
  8767. $html .= '<td class="taR">-</td>';
  8768. }
  8769. if (! empty ( $psum ))
  8770. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8771. else
  8772. $psum = '<td class="colGreen taR">-</td>';
  8773. $receiptL ['差旅相关费用'] = $psum . $html;
  8774. /* ------------------------------------- */
  8775. $html = "";
  8776. $psum = 0;
  8777. $item = array (
  8778. '场租费',
  8779. '薪酬',
  8780. '住宿费',
  8781. '交通费',
  8782. '餐饮费',
  8783. '办公费',
  8784. '公关费',
  8785. '其他'
  8786. );
  8787. foreach ( $item as $va ) {
  8788. $falg = true;
  8789. foreach ( $receiptCollectList as $v ) {
  8790. if ($v ['itemCategory'] == '培训班费用') {
  8791. if ($v ['item'] == $va) {
  8792. $psum += $v ['price'];
  8793. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8794. $falg = false;
  8795. break;
  8796. }
  8797. }
  8798. }
  8799. if ($falg)
  8800. $html .= '<td class="taR">-</td>';
  8801. }
  8802. if (! empty ( $psum ))
  8803. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8804. else
  8805. $psum = '<td class="colGreen taR">-</td>';
  8806. $receiptL ['培训班费用'] = $psum . $html;
  8807. /* ------------------------------------- */
  8808. $html = "";
  8809. $psum = 0;
  8810. $item = array (
  8811. '公关费',
  8812. '广告费',
  8813. '借款',
  8814. '可自加费用'
  8815. );
  8816. foreach ( $item as $va ) {
  8817. $falg = true;
  8818. foreach ( $receiptCollectList as $v ) {
  8819. if ($v ['itemCategory'] == '其他') {
  8820. if ($v ['item'] == $va) {
  8821. $psum += $v ['price'];
  8822. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  8823. $falg = false;
  8824. break;
  8825. }
  8826. }
  8827. }
  8828. if ($falg)
  8829. $html .= '<td class="taR">-</td>';
  8830. }
  8831. if (! empty ( $psum ))
  8832. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  8833. else
  8834. $psum = '<td class="colGreen taR">-</td>';
  8835. $receiptL ['其他'] = $psum . $html;
  8836. /* ------------------------------------- */
  8837. $html = "";
  8838. $psum = 0;
  8839. foreach ( $receiptCollectList as $v ) {
  8840. if ($v ['itemCategory'] == '报销金额调整') {
  8841. if (! empty ( $v ['price'] ))
  8842. $psum += $v ['price'];
  8843. }
  8844. }
  8845. if (! empty ( $psum ))
  8846. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  8847. else
  8848. $psum = '<td class="taR colOrange">-</td>';
  8849. $receiptL ['报销金额调整'] = $psum . $html;
  8850. } else {
  8851. $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>
  8852. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  8853. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  8854. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  8855. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  8856. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  8857. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  8858. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  8859. }
  8860. $monthStaffPrice = $receiptDetail->find ( array (
  8861. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  8862. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  8863. 'asArray' => true
  8864. ) );
  8865. if (! empty ( $monthStaffPrice [0] ['price'] ))
  8866. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  8867. else
  8868. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  8869. $list [$value ['title']] = $receiptL;
  8870. }
  8871. $data ['list'] = $list;
  8872. $receiptCollectList = $receiptDetail->find ( array (
  8873. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  8874. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  8875. 'groupby' => 'item,Month(pastDate),itemCategory',
  8876. 'asArray' => true
  8877. ) );
  8878. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  8879. // print_r($data['monthPriceHtml']);
  8880. // foreach ($data['monthPriceHtml'] as $value){
  8881. // echo $value;
  8882. // }
  8883. // die;
  8884. // statistics html
  8885. $stList = $statistics->getOne ( array (
  8886. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  8887. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  8888. 'groupby' => 'Month(date)',
  8889. 'asArray' => true
  8890. ) );
  8891. if (empty ( $stList ))
  8892. $stList = array (
  8893. 'rePrice' => 0,
  8894. 'agPrice' => 0
  8895. );
  8896. $data ['stList'] = array (
  8897. 'rePrice' => $stList ['rePrice'],
  8898. 'agPrice' => $stList ['agPrice'],
  8899. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  8900. );
  8901. $monthHtml = "";
  8902. for($i = 1; $i <= 12; $i ++) {
  8903. if ($i == $month)
  8904. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  8905. else
  8906. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  8907. }
  8908. $data ['monthHtml'] = $monthHtml;
  8909. $data ['year'] = $year;
  8910. $data ['month'] = $month;
  8911. $data ['memu'] = "receipt";
  8912. $data ['staff'] = $this->staff;
  8913. $data ['receiptMemu'] = 'companyCategoryCollect';
  8914. $data ['verifyId'] = $this->verifyId;
  8915. $data ['executeId'] = $this->executeId;
  8916. $this->render ( "/admin/companyMonthCollectDetail", $data );
  8917. }
  8918. function staffCollectDetail() {
  8919. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  8920. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  8921. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  8922. if (! $staffname) {
  8923. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  8924. $staffname = urldecode ( $staffname );
  8925. }
  8926. Doo::loadModel ( 'staff' );
  8927. $staff = new staff ();
  8928. Doo::loadModel ( "receiptDetail" );
  8929. $receiptDetail = new receiptDetail ();
  8930. Doo::loadModel ( 'accountItem' );
  8931. $accountItem = new accountItem ();
  8932. Doo::loadModel ( 'statistics' );
  8933. $statistics = new statistics ();
  8934. Doo::loadModel ( 'L_category' );
  8935. $lCategory = new L_category ();
  8936. $staffList = $staff->find ( array (
  8937. 'asArray' => true
  8938. ) );
  8939. $stHtml = '';
  8940. $stTitle = "";
  8941. $staffId = 0;
  8942. $cid = 0;
  8943. $ocid = 0;
  8944. foreach ( $staffList as $value ) {
  8945. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  8946. $stTitle = $value ['category'] . '-' . $value ['username'];
  8947. $staffId = $value ['sid'];
  8948. $cid = $value ['cid'];
  8949. $ocid = $value ['cid'];
  8950. if (! empty ( $value ['othercid'] ))
  8951. $cid = $value ['cid'] . ',' . $value ['othercid'];
  8952. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  8953. } elseif ($value ['username'] != 'admin')
  8954. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  8955. }
  8956. $data ['lCategoryHtml'] = $lCategory->find ( array (
  8957. 'where' => 'cid in(' . $cid . ')',
  8958. 'asArray' => true
  8959. ) );
  8960. if (empty ( $pcid ))
  8961. $pcid = $ocid;
  8962. $data ['ocid'] = $pcid;
  8963. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  8964. $this->showCache ( $path );
  8965. //
  8966. $receiptCollectList = $receiptDetail->find ( array (
  8967. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  8968. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  8969. 'groupby' => 'item,Month(pastDate),itemCategory',
  8970. 'asArray' => true
  8971. ) );
  8972. $accountList = $accountItem->find ( array (
  8973. 'asArray' => true
  8974. ) );
  8975. // create CollectDetail HTML
  8976. $collectHtml = array ();
  8977. foreach ( $accountList as $key => $value ) {
  8978. $html = "";
  8979. $asum = 0;
  8980. for($i = 1; $i <= 12; $i ++) {
  8981. $falg = true;
  8982. foreach ( $receiptCollectList as $v ) {
  8983. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  8984. $asum += $v ['price'];
  8985. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  8986. $falg = false;
  8987. break;
  8988. }
  8989. }
  8990. if ($falg)
  8991. $html .= '<td class="taR">-</td>';
  8992. }
  8993. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  8994. $collectHtml [$value ['category']] [$value ['name']] = $html;
  8995. }
  8996. $data ['collectHtml'] = $collectHtml;
  8997. // create Adjustment price html
  8998. $receiptCollectList = $receiptDetail->find ( array (
  8999. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9000. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  9001. 'groupby' => 'itemCategory,Month(pastDate)',
  9002. 'asArray' => true
  9003. ) );
  9004. $adjustment = array ();
  9005. $collectArray = array (
  9006. '日常相关费用' => array (),
  9007. '差旅相关费用' => array (),
  9008. '培训班费用' => array (),
  9009. '其他' => array ()
  9010. );
  9011. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9012. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9013. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9014. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9015. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9016. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9017. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9018. array_push ( $collectArray ['其他'], $collectHtml );
  9019. $data ['collectArray'] = $collectArray;
  9020. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9021. array_push ( $adjustment, $collectHtml );
  9022. $data ['adjustment'] = $adjustment;
  9023. // total price html
  9024. $collectHtml = "";
  9025. $total = 0;
  9026. for($i = 1; $i <= 12; $i ++) {
  9027. $sumPrice = 0;
  9028. foreach ( $receiptCollectList as $key => $value ) {
  9029. if ($value ['month'] == $i) {
  9030. $sumPrice += $value ['price'];
  9031. }
  9032. }
  9033. if ($sumPrice == 0)
  9034. $collectHtml .= '<td class="taR">-</td>';
  9035. else
  9036. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9037. $total += $sumPrice;
  9038. }
  9039. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9040. // statistics html
  9041. $stList = $statistics->statisticsByYear ( $year, $staffId );
  9042. if (empty ( $stList ))
  9043. $stList = array (
  9044. 'rePrice' => 0,
  9045. 'agPrice' => 0
  9046. );
  9047. $data ['stList'] = array (
  9048. 'rePrice' => $stList ['rePrice'],
  9049. 'agPrice' => $stList ['agPrice'],
  9050. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9051. );
  9052. $data ['totalPrice'] = $collectHtml;
  9053. $data ['totalYear'] = $total;
  9054. $data ['stHtml'] = $stHtml;
  9055. $data ['year'] = $year;
  9056. $data ['stTitle'] = $stTitle;
  9057. $data ['memu'] = "receipt";
  9058. $data ['staff'] = $this->staff;
  9059. $data ['receiptMemu'] = 'companyCategoryCollect';
  9060. $data ['verifyId'] = $this->verifyId;
  9061. $data ['executeId'] = $this->executeId;
  9062. if ($year < date ( "Y" )) {
  9063. Doo::loadModel ( 'receipt' );
  9064. $receipt = new receipt ();
  9065. $receiptList = $receipt->find ( array (
  9066. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  9067. 'asArray' => true
  9068. ) );
  9069. if (empty ( $receiptList )) { // generated files
  9070. ob_start ();
  9071. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  9072. $this->cacheFile ( $path );
  9073. die ();
  9074. }
  9075. }
  9076. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  9077. }
  9078. function BUGFLAG() {
  9079. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  9080. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  9081. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  9082. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9083. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  9084. if (empty ( $status ))
  9085. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  9086. $page_size = 12;
  9087. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  9088. $vidList = array ();
  9089. $button = 0;
  9090. Doo::loadModel ( 'verify' );
  9091. $verify = new verify ();
  9092. Doo::loadModel ( 'receipt' );
  9093. $receipt = new receipt ();
  9094. Doo::loadModel ( 'staff' );
  9095. $staff = new staff ();
  9096. Doo::loadModel ( 'L_category' );
  9097. $Lcategory = new L_category ();
  9098. $dateCondition = " and Year(date) =" . $year;
  9099. if (! empty ( $month ))
  9100. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  9101. $categoryList = $Lcategory->find ( array (
  9102. 'asArray' => true
  9103. ) );
  9104. $staffList = $staff->find ( array (
  9105. 'where' => 'cid=' . $cid,
  9106. 'asArray' => true
  9107. ) );
  9108. $cateCondition = "";
  9109. $staffCondition = "";
  9110. $approvalCondition = "";
  9111. if (! empty ( $cid ))
  9112. $cateCondition = ' and cid=' . $cid;
  9113. if (! empty ( $sid )) {
  9114. $staffCondition = ' and staff=' . $sid;
  9115. $cateCondition = "";
  9116. }
  9117. $approvalCondition = " and status=" . $status;
  9118. if ($status == 2) {
  9119. // 查找角色审批人
  9120. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  9121. }
  9122. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  9123. $approvalCondition = ' and status=2 ';
  9124. }
  9125. if ($status == 1) {
  9126. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  9127. }
  9128. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  9129. $pageinfo ['page'] = array (
  9130. 'previous' => ''
  9131. );
  9132. if ($status == 0) {
  9133. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  9134. $receiptList = $receipt->find ( array (
  9135. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  9136. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  9137. 'desc' => 'rid',
  9138. 'asArray' => true
  9139. ) );
  9140. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  9141. } else
  9142. $receiptList = $receipt->find ( array (
  9143. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  9144. 'desc' => 'rid',
  9145. 'asArray' => true
  9146. ) );
  9147. $rLRes = $receipt->find ( array (
  9148. '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,
  9149. 'desc' => 'rid',
  9150. 'asArray' => true
  9151. ) );
  9152. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  9153. // print_r($pageinfo);
  9154. $Locate = 0;
  9155. foreach ( $receiptList as $key => $value ) {
  9156. $receiptList [$key] ['Locate'] = $Locate;
  9157. $Locate ++;
  9158. $receiptList [$key] ['reviseDetail'] = array ();
  9159. if (! empty ( $value ['reviseDetail'] ))
  9160. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  9161. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  9162. $categoryDetil = $Lcategory->getOne ( array (
  9163. 'where' => 'cid=' . $value ['cid'],
  9164. 'asArray' => true
  9165. ) );
  9166. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  9167. $verifyList = $verify->getOne ( array (
  9168. 'where' => 'vid=' . $value ['verify'],
  9169. 'asArray' => true
  9170. ) );
  9171. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  9172. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  9173. foreach ( $verifyList as $k => $v ) {
  9174. // init verifyStaff
  9175. $verifyList [$k] ['date'] = "";
  9176. $verifyList [$k] ['opinion'] = "";
  9177. $verifyList [$k] ['status'] = "";
  9178. if (empty ( $verifyStaff )) {
  9179. $verifyList [$k] ['date'] = "";
  9180. $verifyList [$k] ['opinion'] = "";
  9181. if ($v [0] == $this->staff [0] ['sid']) {
  9182. $verifyList [$k] ['status'] = 4;
  9183. $button = 4;
  9184. }
  9185. } else {
  9186. $flag = true;
  9187. foreach ( $verifyStaff as $m => $u ) {
  9188. if ($v [0] == $m) {
  9189. $verifyList [$k] ['date'] = $u ['date'];
  9190. $verifyList [$k] ['opinion'] = $u ['opinion'];
  9191. $verifyList [$k] ['status'] = $u ['status'];
  9192. $flag = false;
  9193. break;
  9194. }
  9195. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  9196. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  9197. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  9198. }
  9199. if ($flag) { // 检测可编辑
  9200. if ($v [0] == $this->staff [0] ['sid']) {
  9201. $verifyList [$k] ['status'] = 4;
  9202. $button = 4;
  9203. }
  9204. }
  9205. }
  9206. }
  9207. $receiptList [$key] ['verifyList'] = $verifyList;
  9208. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  9209. 'where' => 'sid=' . $value ['staff'],
  9210. 'asArray' => true
  9211. ) );
  9212. $receiptList [$key] ['button'] = $button;
  9213. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  9214. }
  9215. // print_r($receiptList);die;
  9216. // $data['verifyDetail']=$verifyDetail;
  9217. $mothHtml = "";
  9218. for($i = 1; $i <= 12; $i ++) {
  9219. if ($month == $i)
  9220. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  9221. else
  9222. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  9223. }
  9224. $data ['mothHtml'] = $mothHtml;
  9225. $data ['page'] = $pageinfo;
  9226. $data ['receiptList'] = $receiptList;
  9227. $data ['receiptApprovalCount'] = count ( $rLRes );
  9228. $data ['status'] = $status;
  9229. $data ['year'] = $year;
  9230. $data ['categoryList'] = $categoryList;
  9231. $data ['staffList'] = $staffList;
  9232. $data ['cid'] = $cid;
  9233. $data ['sid'] = $sid;
  9234. // print_r($receiptList);
  9235. $data ['memu'] = "receipt";
  9236. $data ['staff'] = $this->staff;
  9237. $data ['receiptMemu'] = 'approvalExpenses';
  9238. $data ['verifyId'] = $this->verifyId;
  9239. $data ['executeId'] = $this->executeId;
  9240. $this->render ( "/admin/FALG", $data );
  9241. }
  9242. function ajaxGetReceiptOrder() {
  9243. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  9244. if (! empty ( $receiptOrder )) {
  9245. Doo::loadModel ( 'receipt' );
  9246. $receipt = new receipt ();
  9247. Doo::loadModel ( 'staff' );
  9248. $staff = new staff ();
  9249. $receiptInfo = $receipt->getOne ( array (
  9250. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  9251. 'asArray' => true
  9252. ) );
  9253. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  9254. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  9255. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  9256. </tbody></table><table class="table table table-bordered"><tbody>';
  9257. foreach ( $verifyStaff as $key => $value ) {
  9258. $staffInfo = $staff->getOne ( array (
  9259. 'select' => 'username',
  9260. 'where' => ' sid="' . $key . '"',
  9261. 'asArray' => true
  9262. ) );
  9263. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  9264. }
  9265. $html .= '</tbody></table></div></div>';
  9266. echo json_encode ( array (
  9267. 'status' => 1,
  9268. 'receiptHtml' => $html
  9269. ) );
  9270. die ();
  9271. }
  9272. echo json_encode ( array (
  9273. 'status' => 2,
  9274. 'receiptHtml' => ''
  9275. ) );
  9276. die ();
  9277. }
  9278. function _getMonthCollectDetail($receiptCollectList) {
  9279. if (! empty ( $receiptCollectList )) {
  9280. $receiptL = array (
  9281. '日常相关费用' => array (),
  9282. '差旅相关费用' => array (),
  9283. '培训班费用' => array (),
  9284. '其他' => array ()
  9285. );
  9286. $html = "";
  9287. $psum = 0;
  9288. $item = array (
  9289. '市内交通费',
  9290. '市内出租费',
  9291. '办事处房租',
  9292. '电话费',
  9293. '水费',
  9294. '电费',
  9295. '办公费用',
  9296. '邮寄费',
  9297. '其他费用',
  9298. '车辆费用',
  9299. '广告费',
  9300. '团队建设费',
  9301. '物业管理费',
  9302. '宽带费'
  9303. );
  9304. foreach ( $item as $value ) {
  9305. $falg = true;
  9306. foreach ( $receiptCollectList as $v ) {
  9307. if ($v ['itemCategory'] == '日常相关费用') {
  9308. if ($v ['item'] == $value) {
  9309. $psum += $v ['price'];
  9310. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  9311. $falg = false;
  9312. break;
  9313. }
  9314. }
  9315. }
  9316. if ($falg)
  9317. $html .= '<td class="taR">-</td>';
  9318. }
  9319. if (! empty ( $psum ))
  9320. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  9321. else
  9322. $psum = '<td class="colGreen taR">-</td>';
  9323. $receiptL ['日常相关费用'] = $psum . $html;
  9324. /* ----------------------------------- */
  9325. $html = "";
  9326. $psum = 0;
  9327. $item = array (
  9328. '往来交通费',
  9329. '市内交通费',
  9330. '出差住宿费',
  9331. '出差补助',
  9332. '其他费用'
  9333. );
  9334. foreach ( $item as $value ) {
  9335. $falg = true;
  9336. foreach ( $receiptCollectList as $v ) {
  9337. if ($v ['itemCategory'] == '差旅相关费用') {
  9338. if ($v ['item'] == $value) {
  9339. $psum += $v ['price'];
  9340. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  9341. $falg = false;
  9342. break;
  9343. }
  9344. }
  9345. }
  9346. if ($falg)
  9347. $html .= '<td class="taR">-</td>';
  9348. }
  9349. if (! empty ( $psum ))
  9350. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  9351. else
  9352. $psum = '<td class="colGreen taR">-</td>';
  9353. $receiptL ['差旅相关费用'] = $psum . $html;
  9354. /* ------------------------------------- */
  9355. $html = "";
  9356. $psum = 0;
  9357. $item = array (
  9358. '场租费',
  9359. '薪酬',
  9360. '住宿费',
  9361. '交通费',
  9362. '餐饮费',
  9363. '办公费',
  9364. '公关费',
  9365. '其他'
  9366. );
  9367. foreach ( $item as $value ) {
  9368. $falg = true;
  9369. foreach ( $receiptCollectList as $v ) {
  9370. if ($v ['itemCategory'] == '培训班费用') {
  9371. if ($v ['item'] == $value) {
  9372. $psum += $v ['price'];
  9373. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  9374. $falg = false;
  9375. break;
  9376. }
  9377. }
  9378. }
  9379. if ($falg)
  9380. $html .= '<td class="taR">-</td>';
  9381. }
  9382. if (! empty ( $psum ))
  9383. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  9384. else
  9385. $psum = '<td class="colGreen taR">-</td>';
  9386. $receiptL ['培训班费用'] = $psum . $html;
  9387. /* ------------------------------------- */
  9388. $html = "";
  9389. $psum = 0;
  9390. $item = array (
  9391. '公关费',
  9392. '广告费',
  9393. '借款',
  9394. '可自加费用'
  9395. );
  9396. foreach ( $item as $value ) {
  9397. $falg = true;
  9398. foreach ( $receiptCollectList as $v ) {
  9399. if ($v ['itemCategory'] == '其他') {
  9400. if ($v ['item'] == $value) {
  9401. $psum += $v ['price'];
  9402. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  9403. $falg = false;
  9404. break;
  9405. }
  9406. }
  9407. }
  9408. if ($falg)
  9409. $html .= '<td class="taR">-</td>';
  9410. }
  9411. if (! empty ( $psum ))
  9412. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  9413. else
  9414. $psum = '<td class="colGreen taR">-</td>';
  9415. $receiptL ['其他'] = $psum . $html;
  9416. /* ------------------------------------- */
  9417. $html = "";
  9418. $psum = 0;
  9419. foreach ( $receiptCollectList as $v ) {
  9420. if ($v ['itemCategory'] == '报销金额调整') {
  9421. if (! empty ( $v ['price'] ))
  9422. $psum += $v ['price'];
  9423. }
  9424. }
  9425. if (! empty ( $psum ))
  9426. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  9427. else
  9428. $psum = '<td class="taR colOrange">-</td>';
  9429. $receiptL ['报销金额调整'] = $psum . $html;
  9430. } else {
  9431. $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>
  9432. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  9433. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  9434. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  9435. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  9436. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  9437. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  9438. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  9439. }
  9440. return $receiptL;
  9441. }
  9442. function eMail() {
  9443. Doo::loadModel ( 'staff' );
  9444. $staff = new staff ();
  9445. Doo::loadModel ( 'receipt' );
  9446. $receipt = new receipt ();
  9447. Doo::loadModel ( 'L_category' );
  9448. $Lcategory = new L_category ();
  9449. Doo::loadModel ( "verify" );
  9450. $verify = new verify ();
  9451. $staffList = $staff->find ( array (
  9452. 'asArray' => true
  9453. ) );
  9454. foreach ( $staffList as $key => $value ) {
  9455. if ($value ['username'] != 'admin') {
  9456. // 提交人
  9457. $receiptList = $receipt->find ( array (
  9458. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  9459. 'asArray' => true
  9460. ) );
  9461. if (! empty ( $receiptList )) {
  9462. $html = '<br><div><style></style>
  9463. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  9464. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  9465. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  9466. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  9467. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  9468. <tbody><tr>
  9469. <td style="padding: 0 40px;" align="left">
  9470. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  9471. </td></tr><tr>
  9472. <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>
  9473. </tr>
  9474. </tbody> </table></td> </tr> <tr><td>
  9475. <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">
  9476. <tbody> <tr><td>
  9477. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  9478. 以下报销单完成了审批,等着收款吧:</p>
  9479. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  9480. foreach ( $receiptList as $k => $v ) {
  9481. $category = $Lcategory->getOne ( array (
  9482. 'where' => 'cid=' . $v ['cid'],
  9483. 'asArray' => true
  9484. ) );
  9485. $html .= '
  9486. <tr>
  9487. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  9488. <td align="left">
  9489. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  9490. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  9491. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  9492. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  9493. </tr>';
  9494. }
  9495. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  9496. <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>
  9497. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  9498. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  9499. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  9500. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  9501. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  9502. $receipt = new receipt ();
  9503. $receipt->notice = 1;
  9504. $receipt->update ( array (
  9505. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  9506. ) );
  9507. }
  9508. }
  9509. // 审批人
  9510. $verifyList = $verify->find ( array (
  9511. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  9512. 'asArray' => true
  9513. ) );
  9514. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  9515. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  9516. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  9517. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  9518. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  9519. <tbody><tr><td style="padding: 0 40px;" align="left">
  9520. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  9521. </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>
  9522. </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">
  9523. <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>
  9524. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  9525. foreach ( $verifyList as $k => $v ) {
  9526. $receiptList = $receipt->find ( array (
  9527. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  9528. 'asArray' => true
  9529. ) );
  9530. foreach ( $receiptList as $r => $l ) {
  9531. $category = $Lcategory->getOne ( array (
  9532. 'where' => 'cid=' . $l ['cid'],
  9533. 'asArray' => true
  9534. ) );
  9535. $staffDetile = $staff->getOne ( array (
  9536. 'where' => 'sid=' . $l ['staff'],
  9537. 'asArray' => true
  9538. ) );
  9539. $html .= '
  9540. <tr>
  9541. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  9542. <td align="left">
  9543. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  9544. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  9545. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  9546. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  9547. </tr>';
  9548. }
  9549. }
  9550. $html .= '
  9551. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  9552. <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>
  9553. </tr></tbody></table></td></tr></tbody></table></div><br>';
  9554. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  9555. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  9556. // $receipt=new receipt();
  9557. // $receipt->notice=1;
  9558. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  9559. }
  9560. }
  9561. }
  9562. }
  9563. function setWXMsg($rid, $type) {
  9564. Doo::loadModel ( "receipt" );
  9565. $receipt = new receipt ();
  9566. $receiptDetail = $receipt->getOne ( array (
  9567. 'where' => 'rid=' . $rid,
  9568. 'asArray' => true
  9569. ) );
  9570. if (! empty ( $receiptDetail )) {
  9571. Doo::loadModel ( 'staff' );
  9572. $staff = new staff ();
  9573. $staffmsg = $staff->getStaffBySid ( $receiptDetail ['staff'] );
  9574. if (! empty ( $staffmsg ['wxid'] )) {
  9575. require_once (SITE_PATH . '/protected/class/client.php');
  9576. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  9577. $user = $staffmsg ['wxid'];
  9578. $receiptName = '';
  9579. $msg = '';
  9580. switch ($receiptDetail ['Rtype']) {
  9581. case 0 :
  9582. $receiptName = '报销';
  9583. break;
  9584. case 1 :
  9585. $receiptName = '借款';
  9586. break;
  9587. case 2 :
  9588. $receiptName = '对公汇款';
  9589. break;
  9590. }
  9591. switch ($type) {
  9592. case 1 :
  9593. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  9594. break;
  9595. case 2 :
  9596. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  9597. break;
  9598. case 3 :
  9599. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  9600. break;
  9601. }
  9602. $result = $client->SendMsg ( $user, $msg, 'text' );
  9603. }
  9604. }
  9605. }
  9606. // Email发送函数
  9607. function SMail($toemail, $subject, $contents) {
  9608. Doo::loadClass ( 'class.phpmailer' );
  9609. $mail = new PHPMailer ();
  9610. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  9611. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  9612. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  9613. $mail->Password = "cDO1GjtY1seH"; // 密码
  9614. $mail->CharSet = "UTF8";
  9615. $mail->SMTPAuth = true;
  9616. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  9617. $mail->Mailer = "smtp";
  9618. $mail->Port = 25;
  9619. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  9620. $mail->MsgHTML ( $contents );
  9621. $mail->AddAddress ( $toemail );
  9622. $mail->CharSet = "UTF-8";
  9623. return $mail->Send ();
  9624. }
  9625. function swfupload() {
  9626. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  9627. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  9628. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  9629. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  9630. header ( "HTTP/1.1 500 Internal Server Error" );
  9631. echo "POST exceeded maximum allowed size.";
  9632. exit ( 0 );
  9633. }
  9634. // Settings
  9635. $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)
  9636. $upload_name = "Filedata";
  9637. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  9638. $extension_whitelist = array (
  9639. "doc",
  9640. "txt",
  9641. "jpg",
  9642. "gif",
  9643. "png"
  9644. ); // Allowed file extensions
  9645. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  9646. // Other variables
  9647. $MAX_FILENAME_LENGTH = 260;
  9648. $file_name = "";
  9649. $file_extension = "";
  9650. $uploadErrors = array (
  9651. 0 => "文件上传成功",
  9652. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  9653. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  9654. 3 => "上传的文件仅为部分文件",
  9655. 4 => "没有文件上传",
  9656. 6 => "缺少临时文件夹"
  9657. );
  9658. $nk = time ();
  9659. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  9660. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  9661. echo "文件无法保存.";
  9662. exit ( 0 );
  9663. }
  9664. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  9665. echo json_encode ( array (
  9666. 'filename' => $file_name,
  9667. 'id' => $nk
  9668. ) );
  9669. exit ( 0 );
  9670. }
  9671. function _GetFileEXT($filename) {
  9672. $pics = explode ( '.', $filename );
  9673. $num = count ( $pics );
  9674. return $pics [$num - 1];
  9675. }
  9676. /**
  9677. * 获取get或者POST值
  9678. * @param string $name 属性名称
  9679. * @return fixed 值
  9680. */
  9681. function get_args($name) {
  9682. if (isset ( $_GET [$name] )) {
  9683. if (is_array ( $_GET [$name] ))
  9684. return $_GET [$name];
  9685. else
  9686. return addslashes ( $_GET [$name] );
  9687. } elseif (isset ( $_POST [$name] )) {
  9688. if (is_array ( $_POST [$name] ))
  9689. return $_POST [$name];
  9690. else
  9691. return addslashes ( $_POST [$name] );
  9692. } else
  9693. return false;
  9694. }
  9695. function num_to_rmb($num) {
  9696. $c1 = "零壹贰叁肆伍陆柒捌玖";
  9697. $c2 = "分角元拾佰仟万拾佰仟亿";
  9698. // 精确到分后面就不要了,所以只留两个小数位
  9699. $num = round ( $num, 2 );
  9700. // 将数字转化为整数
  9701. $num = $num * 100;
  9702. if (strlen ( $num ) > 10) {
  9703. return "金额太大,请检查";
  9704. }
  9705. $i = 0;
  9706. $c = "";
  9707. while ( 1 ) {
  9708. if ($i == 0) {
  9709. // 获取最后一位数字
  9710. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  9711. } else {
  9712. $n = $num % 10;
  9713. }
  9714. // 每次将最后一位数字转化为中文
  9715. $p1 = substr ( $c1, 3 * $n, 3 );
  9716. $p2 = substr ( $c2, 3 * $i, 3 );
  9717. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  9718. $c = $p1 . $p2 . $c;
  9719. } else {
  9720. $c = $p1 . $c;
  9721. }
  9722. $i = $i + 1;
  9723. // 去掉数字最后一位了
  9724. $num = $num / 10;
  9725. $num = ( int ) $num;
  9726. // 结束循环
  9727. if ($num == 0) {
  9728. break;
  9729. }
  9730. }
  9731. $j = 0;
  9732. $slen = strlen ( $c );
  9733. while ( $j < $slen ) {
  9734. // utf8一个汉字相当3个字符
  9735. $m = substr ( $c, $j, 6 );
  9736. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  9737. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  9738. $left = substr ( $c, 0, $j );
  9739. $right = substr ( $c, $j + 3 );
  9740. $c = $left . $right;
  9741. $j = $j - 3;
  9742. $slen = $slen - 3;
  9743. }
  9744. $j = $j + 3;
  9745. }
  9746. // 这个是为了去掉类似23.0中最后一个“零”字
  9747. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  9748. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  9749. }
  9750. // 将处理的汉字加上“整”
  9751. if (empty ( $c )) {
  9752. return "零元整";
  9753. } else {
  9754. return $c . "整";
  9755. }
  9756. }
  9757. /**
  9758. * 获得分页数据
  9759. * @param unknown_type $table
  9760. * @param unknown_type $condition
  9761. * @param unknown_type $on_page
  9762. * @param unknown_type $page_size
  9763. */
  9764. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  9765. $page_c = "";
  9766. $page ['previous'] = $this->get_previous ( $on_page );
  9767. $page ['on_page'] = $on_page;
  9768. $total_count = $this->get_table_count ( $table, $condition );
  9769. $total = intval ( $total_count / $page_size );
  9770. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  9771. $page ['total_data'] = $total_count;
  9772. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  9773. $i = 1;
  9774. $page_max = 1;
  9775. $page_width = 3;
  9776. if ($on_page >= $page_width) {
  9777. $page_max = intval ( $on_page / $page_width ) + 1;
  9778. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  9779. }
  9780. for(; $i <= $page ['total_page']; $i ++) {
  9781. if ($i == $on_page)
  9782. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  9783. else
  9784. $page_c .= '<li><a href="/' . $action . '/0/' . $i . $get . '">' . $i . '</a></li>';
  9785. if ($i == ($page_width * $page_max))
  9786. break;
  9787. }
  9788. $page ['page'] = $page_c;
  9789. $page ['lower'] = (-- $on_page) * $page_size;
  9790. return $page;
  9791. }
  9792. /**
  9793. * 获取总页数
  9794. * @param unknown_type $table
  9795. * @param unknown_type $condition
  9796. */
  9797. public function get_table_count($table = "", $condition = "") {
  9798. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  9799. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  9800. // echo $sql;die;
  9801. $query = Doo::db ()->query ( $sql );
  9802. $result = $query->fetch ();
  9803. return $result ['count'];
  9804. }
  9805. /**
  9806. * 获取上一页
  9807. * @param unknown_type $on_page
  9808. */
  9809. function get_previous($on_page = 1) {
  9810. return $on_page != 0 ? $on_page - 1 : $on_page;
  9811. }
  9812. }
  9813. ?>