ReceiptController.php 301 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. public static $NEW = 0;
  10. public static $NEW2 = 0;
  11. public $AGENCY="日常相关费用";
  12. public $TRAVEL="差旅相关费用";
  13. public $TRAIN="培训班费用";
  14. public $OTHER="其他";
  15. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  16. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  17. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  18. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  19. private function showCache($path){
  20. if(file_exists($path)){
  21. echo "<!DOCTYPE html>";
  22. include $path;die;
  23. }
  24. }
  25. private function cacheFile($path){
  26. $content = ob_get_contents();
  27. $fp = fopen($path, "w");
  28. fwrite($fp, $content);
  29. fclose($fp);
  30. }
  31. private function getExeCount(){
  32. Doo::loadModel('receipt');
  33. $receipt=new receipt();
  34. $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  35. return count($receiptList);
  36. }
  37. private function getReceiptCount(){
  38. $status=2;
  39. $year=date('Y');
  40. Doo::loadModel('receipt');
  41. $receipt=new receipt();
  42. $dateCondition=" and Year(date) =".$year;
  43. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  44. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  45. return count($receiptList);
  46. }
  47. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  48. $collectHtml="";$sumPrice=0.00;
  49. for ($i=1;$i<=12;$i++){
  50. $falg=true;
  51. foreach ($receiptCollectList as $key=>$value){
  52. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  53. $sumPrice+=$value['price'];
  54. if ($classType=="b"){
  55. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  56. }else{
  57. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  58. }
  59. }
  60. }
  61. if ($falg)
  62. $collectHtml.='<td class="taR">-</td>';
  63. }
  64. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  65. return $collectHtml;
  66. }
  67. function __construct() {
  68. if(isset($_COOKIE["staff"])){
  69. if(!empty($_COOKIE["staff"])){
  70. Doo::loadModel ( 'staff' );
  71. Doo::loadModel('verify');
  72. $verify=new verify();
  73. $staff = new staff ();
  74. Doo::loadModel("execute");
  75. $execute=new execute();
  76. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  77. $list=array();
  78. //判断角色的审批权限
  79. foreach ($verifyList as $key=>$value){
  80. $ver=json_decode($value['staff']);
  81. foreach ($ver as $k=>$v){
  82. if ($v[1]=='ROLE'){
  83. $roleList=json_decode($v[3]);
  84. foreach ($roleList as $t=>$g){
  85. $gList=explode("_", $g);
  86. array_push($list, $gList[0]);
  87. //print_r($list);
  88. }
  89. }else
  90. array_push($list, $v[0]);
  91. }
  92. }
  93. //判断执行人的审批权限
  94. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  95. $list2=array();
  96. foreach ($executeList as $key=>$value){
  97. $ver=json_decode($value['staff']);
  98. foreach ($ver as $k=>$v){
  99. array_push($list2, $v[0]);
  100. }
  101. }
  102. $eidList=file_get_contents("protected/config/execute/execute.ini");
  103. $eidList=array_filter(explode(",", $eidList));
  104. $this->executeId= array_merge($list2,$eidList);
  105. $this->verifyId=$list;
  106. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  107. self::$NEW= $this->getReceiptCount();
  108. self::$NEW2= $this->getExeCount();
  109. return "/";
  110. }
  111. }
  112. Doo::loadCore ( 'uri/DooUriRouter' );
  113. $router = new DooUriRouter ();
  114. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  115. if($routeRs['1']!="login"){
  116. header ( 'Content-Type:text/html;charset=utf-8' );
  117. @header ( "Location: /login" );
  118. }
  119. }
  120. function saeaBorad(){
  121. Doo::loadModel('receipt');
  122. Doo::loadModel('verify');
  123. $verify=new verify();
  124. $receipt=new receipt();
  125. Doo::loadModel('L_category');
  126. $lCategory=new L_category();
  127. Doo::loadModel("role");
  128. $role=new role();
  129. Doo::loadModel("receiptLog");
  130. $receiptLog=new receiptLog();
  131. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  132. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)','desc'=>'rid','asArray'=>true));
  133. foreach ($receiptDetail as $key=>$value){
  134. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  135. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  136. $v=json_decode($veList['staff']);
  137. array_push($v[0], $veList['description']);
  138. foreach ($v as $n=>$m){
  139. if ($m['1']=='ROLE'){
  140. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  141. $v[$n][1]=$roleInfo['name'];
  142. }
  143. }
  144. $receiptDetail[$key]['staff']=$v;
  145. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  146. $receiptDetail[$key]['category']=$category['title'];
  147. }
  148. //print_r($receiptLogList);
  149. $data['receiptLogList']=$receiptLogList;
  150. $data['receiptDetail']=$receiptDetail;
  151. $data['memu']="receipt";
  152. $data['staff']=$this->staff;
  153. $data['receiptMemu']='saeaBorad';
  154. $data['verifyId']=$this->verifyId;
  155. $data['executeId']=$this->executeId;
  156. $this->render ( "/admin/saeaBorad", $data );
  157. }
  158. function remitAdd(){
  159. Doo::loadModel('accountItem');
  160. Doo::loadModel('verify');
  161. Doo::loadModel('receipt');
  162. Doo::loadModel('L_category');
  163. $lCategory=new L_category();
  164. $receipt=new receipt();
  165. $verify=new verify();
  166. $accountItem=new accountItem();
  167. Doo::loadModel("role");
  168. $role=new role();
  169. $acItem=$accountItem->find(array('asArray'=>true));
  170. $veList=$verify->find(array('asArray'=>true));
  171. foreach ($veList as $key=>$value){
  172. $v=json_decode($value['staff']);
  173. $list=array();
  174. foreach ($v as $n=>$m){
  175. if ($m['1']=='ROLE'){
  176. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  177. $v[$n][1]=$roleInfo['name'];
  178. array_push($list, $roleInfo['name']);
  179. }else{
  180. array_push($list, $v[$n][1]);
  181. }
  182. }
  183. $veList[$key]['staff']=implode('>', $list);
  184. }
  185. $data['category']=$lCategory->find(array('asArray'=>true));
  186. $data['veList']=$veList;
  187. $data['acItem']=$acItem;
  188. $data['memu']="receipt";
  189. $data['staff']=$this->staff;
  190. $data['receiptMemu']='saeaBorad';
  191. $data['verifyId']=$this->verifyId;
  192. $data['executeId']=$this->executeId;
  193. $this->render ( "/admin/remitAdd", $data );
  194. }
  195. function remitAddDo(){
  196. $agency=$this->get_args('agency');
  197. $travel=$this->get_args('travel');
  198. $train=$this->get_args('train');
  199. $other=$this->get_args('other');
  200. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  201. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  202. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  203. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  204. //print_r($agency);die;
  205. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  206. Doo::loadModel('receipt');
  207. Doo::loadModel('receiptDetail');
  208. Doo::loadModel('accountItem');
  209. $accountItem=new accountItem();
  210. $receipt=new receipt();
  211. Doo::loadModel('enclosur');
  212. Doo::loadModel('execute');
  213. $execute=new execute();
  214. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  215. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  216. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  217. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  218. $ag=$tr=$ta=$ot=0;
  219. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  220. foreach ($aItem as $key=>$value){
  221. if ($value['category']==$this->AGENCY){
  222. if (isset($agency[$ag])){
  223. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  224. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  225. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  226. }
  227. }
  228. $ag++;
  229. }
  230. }
  231. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  232. //报销单
  233. $receipt->accountItem=json_encode($accountJson);
  234. $receipt->staff=$this->staff[0]['sid'];
  235. $receipt->sum=number_format($sum, 2, '.', '');
  236. $receipt->date=date("Y-m-d");
  237. $receipt->cid=$cid;
  238. $receipt->status=5;
  239. $receipt->Rtype=2;
  240. //修改审批流程加入角色
  241. $receipt->verify=$verify;
  242. $receipt->executeCopy=$executeDetail['staff'];
  243. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  244. $receipt->explanation=$explanation;
  245. $rid=$receipt->insert();
  246. //附件
  247. if (!empty($enclosurName)){
  248. $enclosurArray=explode('-', $enclosurName);
  249. foreach ($enclosurArray as $value){
  250. $enclosur=new enclosur();
  251. $enclosur->name=$value;
  252. $enclosur->rid=$rid;
  253. $enclosur->insert();
  254. }
  255. //print_r($enclosurArray);die;
  256. }
  257. //报销详情
  258. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  259. $receiptDetail=new receiptDetail();
  260. $receiptDetail->staff=$this->staff[0]['sid'];
  261. $receiptDetail->item=$value['name'];
  262. $receiptDetail->itemCategory=$this->AGENCY;
  263. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  264. $receiptDetail->date=date("Y-m-d");
  265. $receiptDetail->cid=$cid;
  266. $receiptDetail->rid=$rid;
  267. $receiptDetail->status=4;
  268. $receiptDetail->insert();
  269. }
  270. }
  271. return "/saeaBorad";
  272. }
  273. function remitEdit(){
  274. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  275. //echo $rid;
  276. Doo::loadModel('accountItem');
  277. Doo::loadModel('verify');
  278. Doo::loadModel('receipt');
  279. $receipt=new receipt();
  280. $verify=new verify();
  281. $accountItem=new accountItem();
  282. Doo::loadModel('L_category');
  283. $lCategory=new L_category();
  284. Doo::loadModel("role");
  285. $role=new role();
  286. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  287. if(empty($receiptDetail))
  288. return "/saeaCreate";
  289. $acItem=$accountItem->find(array('asArray'=>true));
  290. $veList=$verify->find(array('asArray'=>true));
  291. foreach ($veList as $key=>$value){
  292. $v=json_decode($value['staff']);
  293. $list=array();
  294. foreach ($v as $n=>$m){
  295. if ($m['1']=='ROLE'){
  296. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  297. $v[$n][1]=$roleInfo['name'];
  298. array_push($list, $roleInfo['name']);
  299. }else{
  300. array_push($list, $v[$n][1]);
  301. }
  302. }
  303. $veList[$key]['staff']=implode('>', $list);
  304. }
  305. //配置编辑信息
  306. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  307. foreach ($acItem as $key=>$value){
  308. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  309. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  310. $acItem[$key]['price']=$v['price'];
  311. }
  312. }
  313. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  314. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  315. $acItem[$key]['price']=$v['price'];
  316. }
  317. }
  318. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  319. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  320. $acItem[$key]['price']=$v['price'];
  321. }
  322. }
  323. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  324. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  325. $acItem[$key]['price']=$v['price'];
  326. }
  327. }
  328. }
  329. $data['category']=$lCategory->find(array('asArray'=>true));
  330. $data['cSum']=$accountItemList['cSum'];
  331. $data['sum']=$receiptDetail['sum'];
  332. $data['receiptDetail']=$receiptDetail;
  333. $data['veList']=$veList;
  334. $data['acItem']=$acItem;
  335. $data['memu']="receipt";
  336. $data['staff']=$this->staff;
  337. $data['receiptMemu']='saeaBorad';
  338. $data['verify']=$receiptDetail['verify'];
  339. $data['verifyId']=$this->verifyId;
  340. $data['executeId']=$this->executeId;
  341. $data['rid']=$rid;
  342. $this->render ( "/admin/remitEdit", $data );
  343. }
  344. function remitEdiDo(){
  345. $agency=$this->get_args('agency');
  346. $travel=$this->get_args('travel');
  347. $train=$this->get_args('train');
  348. $other=$this->get_args('other');
  349. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  350. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  351. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  352. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  353. if(!empty($verify)&&!empty($explanation)){
  354. Doo::loadModel('receipt');
  355. Doo::loadModel('receiptDetail');
  356. Doo::loadModel('accountItem');
  357. $accountItem=new accountItem();
  358. $receipt=new receipt();
  359. Doo::loadModel('execute');
  360. $execute=new execute();
  361. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  362. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  363. if(empty($receiptDetail))
  364. return "/saeaBorad";
  365. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  366. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  367. $ag=$tr=$ta=$ot=0;
  368. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  369. foreach ($aItem as $key=>$value){
  370. if ($value['category']==$this->AGENCY){
  371. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  372. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  373. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  374. }
  375. $ag++;
  376. }
  377. }
  378. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  379. //报销单
  380. $rid=$receipt->rid=$receiptDetail['rid'];
  381. $receipt->accountItem=json_encode($accountJson);
  382. $receipt->staff=$this->staff[0]['sid'];
  383. $receipt->sum=number_format($sum, 2, '.', '');
  384. $receipt->date=date("Y-m-d");
  385. $receipt->cid=$cid;
  386. if ($receiptDetail['Rtype']==1)
  387. $receipt->status=7;
  388. else
  389. $receipt->status=5;
  390. $receipt->verify=$verify;
  391. $receipt->executeCopy=$executeDetail['staff'];
  392. $receipt->explanation=$explanation;
  393. $receipt->update();
  394. $receiptDetail=new receiptDetail();
  395. $receiptDetail->delete(array('where'=>'rid='.$rid));
  396. //报销详情
  397. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  398. $receiptDetail=new receiptDetail();
  399. $receiptDetail->staff=$this->staff[0]['sid'];
  400. $receiptDetail->item=$value['name'];
  401. $receiptDetail->itemCategory=$this->AGENCY;
  402. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  403. $receiptDetail->date=date("Y-m-d");
  404. $receiptDetail->cid=$cid;
  405. $receiptDetail->rid=$rid;
  406. $receiptDetail->status=4;
  407. $receiptDetail->insert();
  408. }
  409. //return "/referReceipt/".$rid;
  410. }
  411. return "/saeaBorad";
  412. }
  413. function remitApproval(){
  414. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  415. $status=isset($this->params['status'])?$this->params['status']:'';
  416. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  417. $month=$this->get_args('month')?$this->get_args('month'):"";
  418. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  419. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  420. if (empty($status))
  421. $status=$this->get_args('status')?$this->get_args('status'):2;
  422. $vidList=array();
  423. $button=0;
  424. Doo::loadModel('verify');
  425. Doo::loadModel('receipt');
  426. Doo::loadModel('staff');
  427. $staff=new staff();
  428. $receipt=new receipt();
  429. $verify=new verify();
  430. Doo::loadModel('L_category');
  431. $Lcategory=new L_category();
  432. Doo::loadModel('enclosur');
  433. $enclosur=new enclosur();
  434. //user verify ID
  435. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  436. foreach ($verifyDetail as $key=>$value){
  437. array_push($vidList, $value['vid']);
  438. }
  439. $vid=implode(",", $vidList);
  440. if(empty($verifyDetail))
  441. $vid=0;
  442. $categoryList=$Lcategory->find(array('asArray'=>true));
  443. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  444. $ap="";
  445. if($status==4){
  446. $ap=4;$status=2;
  447. }
  448. //get Receipt By verifyID status 2
  449. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  450. $Locate=0;$roleId=0;
  451. if($ap==4)
  452. $status=4;
  453. foreach ($receiptList as $key=>$value){
  454. $receiptList[$key]['Locate']=$Locate;$Locate++;
  455. $receiptList[$key]['reviseDetail']=array();
  456. if (!empty($value['reviseDetail']))
  457. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  458. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  459. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  460. $receiptList[$key]['category']=$categoryDetil['title'];
  461. //检测编辑状态
  462. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  463. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  464. $verifyStaff=json_decode($value['verifyStaff'],true);
  465. Doo::loadModel('role');
  466. $role=new role();
  467. //print_r($verifyList);
  468. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  469. foreach ($verifyList as $k=>$v){
  470. //init verifyStaff
  471. if ($v[1]=='ROLE'){
  472. if (!empty($verifyStaff)){
  473. $endStaffArray=end($verifyStaff);
  474. if ($v[0]==$endStaffArray['nextStaff']){
  475. $roleId=$v[0];
  476. }
  477. }
  478. $roleVerify=json_decode($v[3],true);
  479. $roleKey=$k;$roleArray=array();
  480. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  481. foreach ($roleVerify as $o=>$p){
  482. $staffID=explode ('_',$p);
  483. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  484. //print_r($staffID);
  485. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  486. array_push($roleArray, $exp);
  487. }
  488. $roleArrayCopy[$v[0]]=$roleArray;
  489. //$verifyList[$k]['roleArray']=$roleArray;
  490. }
  491. //print_r($roleArray);
  492. $verifyList[$k]['date']="";
  493. $verifyList[$k]['opinion']="";
  494. $verifyList[$k]['status']="";
  495. if (empty($verifyStaff)){
  496. $verifyList[$k]['date']="";
  497. $verifyList[$k]['opinion']="";
  498. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  499. $verifyList[$k]['status']=4;
  500. $button=4;$flag=false;
  501. }
  502. }else{
  503. foreach ($verifyStaff as $m=>$u){
  504. if ($v[0]==$m){
  505. $verifyList[$k]['date']=$u['date'];
  506. $verifyList[$k]['opinion']=$u['opinion'];
  507. $verifyList[$k]['status']=$u['status'];
  508. $flag=false;
  509. break;
  510. }
  511. }
  512. $endStaffArray=end($verifyStaff);
  513. if (isset($endStaffArray['ROLE'])){
  514. }else{
  515. $endKey=key($verifyStaff);
  516. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  517. $button=4;
  518. $verifyList[$k]['status']=4;
  519. }
  520. }
  521. }
  522. }
  523. $rolename['name']='';
  524. if (!empty($roleId)){
  525. Doo::loadModel('role');
  526. $role=new role();
  527. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  528. }
  529. if (!empty($verifyStaff))
  530. $endStaffArray=end($verifyStaff);
  531. $KOP=false;
  532. foreach ($roleArrayCopy as $P=>$A){
  533. foreach ( $A as $MKI=>$AVL){
  534. if (!empty($verifyStaff)){
  535. //&&$rolename['rid']==$endStaffArray['nextStaff']
  536. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  537. $button=4;
  538. $roleArrayCopy[$P][$MKI]['status']=4;
  539. }
  540. foreach ($verifyStaff as $m=>$u){
  541. $AVLFK=$AVL[0].'_R';
  542. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  543. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  544. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  545. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  546. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  547. break;
  548. }
  549. }
  550. }else{
  551. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  552. $button=4;
  553. $roleArrayCopy[$P][$MKI]['status']=4;
  554. }
  555. }
  556. //$roleArray[$MKI]['rolename']=$rolename['name'];
  557. $KOP=true;
  558. }
  559. }
  560. foreach ($roleArrayCopy as $k=>$v){
  561. foreach ($verifyList as $m=>$n){
  562. if ($n[0]==$k){
  563. array_splice($verifyList,$m,1,$v);
  564. }
  565. }
  566. }
  567. $receiptList[$key]['verifyList']= $verifyList;
  568. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  569. $receiptList[$key]['button']=$button;
  570. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  571. }
  572. $mothHtml="";
  573. for($i=1;$i<=12;$i++){
  574. if($month==$i)
  575. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  576. else
  577. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  578. }
  579. //获取审批日志
  580. Doo::loadModel('receiptLog');
  581. $receiptLog=new receiptLog();
  582. $rlList=array();
  583. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  584. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  585. if (!empty($rlInfo)){
  586. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  587. }
  588. $receiptList[0]['rlList']=$rlList;
  589. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  590. $enclosurHtml='';
  591. foreach ($enclosurList as $value){
  592. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  593. }
  594. //print_r($receiptList);
  595. $data['enclosurHtml']=$enclosurHtml;
  596. $data['rolename']=$rolename['name'];
  597. $data['datetij']=$tijdate['date'];
  598. $data['mothHtml']=$mothHtml;
  599. $data['rid']=$rid;
  600. $data['receiptList']=$receiptList;
  601. $data['receiptApprovalCount']=count($receiptList);
  602. $data['status']=$status;
  603. $data['year']=$year;
  604. $data['categoryList']=$categoryList;
  605. $data['staffList']=$staffList;
  606. $data['cid']=$cid;
  607. $data['sid']=$sid;
  608. $data['ap']=$ap;
  609. $data['memu']="receipt";
  610. $data['staff']=$this->staff;
  611. $data['receiptMemu']='approvalExpenses';
  612. $data['verifyId']=$this->verifyId;
  613. $data['executeId']=$this->executeId;
  614. $this->render ( "/admin/remitApproval", $data );
  615. }
  616. function saeaLoanAdd(){
  617. Doo::loadModel('verify');
  618. $verify=new verify();
  619. Doo::loadModel("role");
  620. $role=new role();
  621. Doo::loadModel('L_category');
  622. $lCategory=new L_category();
  623. $veList=$verify->find(array('asArray'=>true));
  624. foreach ($veList as $key=>$value){
  625. $v=json_decode($value['staff']);
  626. $list=array();
  627. foreach ($v as $n=>$m){
  628. if ($m['1']=='ROLE'){
  629. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  630. $v[$n][1]=$roleInfo['name'];
  631. array_push($list, $roleInfo['name']);
  632. }else{
  633. array_push($list, $v[$n][1]);
  634. }
  635. }
  636. $veList[$key]['staff']=implode('>', $list);
  637. }
  638. $data['category']=$lCategory->find(array('asArray'=>true));
  639. $data['veList']=$veList;
  640. $data['memu']="receipt";
  641. $data['staff']=$this->staff;
  642. $data['receiptMemu']='saeaBorad';
  643. $data['verifyId']=$this->verifyId;
  644. $data['executeId']=$this->executeId;
  645. $this->render ( "/admin/saeaLoanAdd", $data );
  646. }
  647. function saeaLoanAddDo(){
  648. $agency=$this->get_args('agency');
  649. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  650. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  651. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  652. //die;
  653. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  654. Doo::loadModel('receipt');
  655. Doo::loadModel('receiptDetail');
  656. Doo::loadModel('accountItem');
  657. $accountItem=new accountItem();
  658. $receipt=new receipt();
  659. Doo::loadModel('loanReceipt');
  660. $loanReceipt=new loanReceipt();
  661. Doo::loadModel('execute');
  662. $execute=new execute();
  663. Doo::loadModel('enclosur');
  664. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  665. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  666. // if(!empty($receiptDetail))
  667. // return "/referReceipt/".$receiptDetail['rid'];
  668. $aItem=$accountItem->find(array('asArray'=>true));
  669. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  670. $ag=$tr=$ta=$ot=0;
  671. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  672. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  673. $sum+=$agency;$agencySum+=$agency;
  674. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  675. //借款数据备份
  676. $loanReceipt->loanItem=json_encode($accountJson);
  677. $loanReceipt->staff=$this->staff[0]['sid'];
  678. $loanReceipt->sum=number_format($sum, 2, '.', '');
  679. $loanReceipt->date=date("Y-m-d");
  680. $loanReceipt->cid=$cid;
  681. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  682. $loanReceipt->status=5;
  683. $loanReceipt->Rtype=1;
  684. $loanReceipt->verify=$verify;
  685. $receipt->receiptOrder=$receipt->receiptOrder;
  686. $loanReceipt->explanation=$explanation;
  687. $loanRid=$loanReceipt->insert();
  688. //报销单
  689. $receipt->loanItem=json_encode($accountJson);
  690. $receipt->staff=$this->staff[0]['sid'];
  691. $receipt->sum=number_format($sum, 2, '.', '');
  692. $receipt->date=date("Y-m-d");
  693. $receipt->cid=$cid;
  694. //特殊状态
  695. $receipt->status=5;
  696. $receipt->Rtype=1;
  697. $receipt->loanRid=$loanRid;
  698. //修改审批流程加入角色
  699. $receipt->verify=$verify;
  700. $receipt->executeCopy=$executeDetail['staff'];
  701. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  702. $receipt->explanation=$explanation;
  703. $rid=$receipt->insert();
  704. //执行数据备份
  705. // $executeCopy->rid=$rid;
  706. // $executeCopy->staff=$executeDetail['staff'];
  707. // $executeCopy->eid=$executeDetail['eid'];
  708. // $ecid=$executeCopy->insert();
  709. }
  710. return "/saeaBorad";
  711. }
  712. function saeaLoanEdi(){
  713. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  714. Doo::loadModel('verify');
  715. $verify=new verify();
  716. Doo::loadModel("role");
  717. $role=new role();
  718. Doo::loadModel('L_category');
  719. $lCategory=new L_category();
  720. Doo::loadModel('receipt');
  721. $receipt=new receipt();
  722. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  723. $veList=$verify->find(array('asArray'=>true));
  724. foreach ($veList as $key=>$value){
  725. $v=json_decode($value['staff']);
  726. $list=array();
  727. foreach ($v as $n=>$m){
  728. if ($m['1']=='ROLE'){
  729. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  730. $v[$n][1]=$roleInfo['name'];
  731. array_push($list, $roleInfo['name']);
  732. }else{
  733. array_push($list, $v[$n][1]);
  734. }
  735. }
  736. $veList[$key]['staff']=implode('>', $list);
  737. }
  738. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  739. $data['receiptInfo']=$receiptInfo;
  740. $data['category']=$lCategory->find(array('asArray'=>true));
  741. $data['veList']=$veList;
  742. $data['memu']="receipt";
  743. $data['staff']=$this->staff;
  744. $data['receiptMemu']='saeaBorad';
  745. $data['verifyId']=$this->verifyId;
  746. $data['executeId']=$this->executeId;
  747. $this->render ( "/admin/saeaLoanEdi", $data );
  748. }
  749. function saeaLoanEdiDo(){
  750. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  751. $agency=$this->get_args('agency');
  752. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  753. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  754. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  755. //die;
  756. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  757. Doo::loadModel('receipt');
  758. Doo::loadModel('receiptDetail');
  759. Doo::loadModel('accountItem');
  760. $accountItem=new accountItem();
  761. $receipt=new receipt();
  762. Doo::loadModel('loanReceipt');
  763. $loanReceipt=new loanReceipt();
  764. Doo::loadModel('enclosur');
  765. Doo::loadModel('execute');
  766. $execute=new execute();
  767. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  768. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 and rid='.$rid,'asArray'=>true));
  769. if(empty($receiptDetail))
  770. die('参数错误');
  771. $aItem=$accountItem->find(array('asArray'=>true));
  772. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  773. $ag=$tr=$ta=$ot=0;
  774. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  775. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  776. $sum+=$agency;$agencySum+=$agency;
  777. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  778. //报销单
  779. $receipt->loanItem=json_encode($accountJson);
  780. $receipt->sum=number_format($sum, 2, '.', '');
  781. $receipt->cid=$cid;
  782. //特殊状态
  783. //修改审批流程加入角色
  784. $receipt->verify=$verify;
  785. $receipt->explanation=$explanation;
  786. $receipt->update(array('where'=>'rid='.$rid));
  787. //借款数据更新
  788. $loanReceipt->loanItem=json_encode($accountJson);
  789. $loanReceipt->sum=number_format($sum, 2, '.', '');
  790. $loanReceipt->cid=$cid;
  791. $loanReceipt->verify=$verify;
  792. $loanReceipt->explanation=$explanation;
  793. $receipt->executeCopy=$executeDetail['staff'];
  794. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  795. }
  796. return "/saeaBorad";
  797. }
  798. function saeaLoanReceiptAdd(){
  799. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  800. Doo::loadModel('receipt');
  801. $receipt=new receipt();
  802. Doo::loadModel('loanReceipt');
  803. $loanReceipt=new loanReceipt();
  804. Doo::loadModel('L_category');
  805. $Lcategory=new L_category();
  806. Doo::loadModel('verify');
  807. Doo::loadModel('statistics');
  808. $statistics=new statistics();
  809. $verify=new verify();
  810. Doo::loadModel('staff');
  811. $staff=new staff();
  812. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  813. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  814. $Locate=0;$roleId=0;$button=0;
  815. foreach ($receiptList as $key=>$value){
  816. $receiptList[$key]['Locate']=$Locate;$Locate++;
  817. $receiptList[$key]['reviseDetail']=array();
  818. if (!empty($value['reviseDetail']))
  819. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  820. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  821. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  822. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  823. $receiptList[$key]['category']=$categoryDetil['title'];
  824. //检测编辑状态
  825. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  826. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  827. $verifyStaff=json_decode($value['verifyStaff'],true);
  828. Doo::loadModel('role');
  829. $role=new role();
  830. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  831. foreach ($verifyList as $k=>$v){
  832. //init verifyStaff
  833. if ($v[1]=='ROLE'){
  834. if (!empty($verifyStaff)){
  835. $endStaffArray=end($verifyStaff);
  836. // if ($v[0]==$endStaffArray['nextStaff']){
  837. // $roleId=$v[0];
  838. // }
  839. }
  840. $roleVerify=json_decode($v[3],true);
  841. $roleKey=$k;$roleArray=array();
  842. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  843. foreach ($roleVerify as $o=>$p){
  844. $staffID=explode ('_',$p);
  845. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  846. //print_r($staffID);
  847. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  848. array_push($roleArray, $exp);
  849. }
  850. $roleArrayCopy[$v[0]]=$roleArray;
  851. //$verifyList[$k]['roleArray']=$roleArray;
  852. }
  853. $verifyList[$k]['date']="";
  854. $verifyList[$k]['opinion']="";
  855. $verifyList[$k]['status']="";
  856. if (empty($verifyStaff)){
  857. $verifyList[$k]['date']="";
  858. $verifyList[$k]['opinion']="";
  859. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  860. $verifyList[$k]['status']=4;
  861. $flag=false;
  862. }
  863. }else{
  864. foreach ($verifyStaff as $m=>$u){
  865. if ($v[0]==$m){
  866. $verifyList[$k]['date']=$u['date'];
  867. $verifyList[$k]['opinion']=$u['opinion'];
  868. $verifyList[$k]['status']=$u['status'];
  869. $flag=false;
  870. break;
  871. }
  872. }
  873. $endStaffArray=end($verifyStaff);
  874. if (isset($endStaffArray['ROLE'])){
  875. }else{
  876. // $endKey=key($verifyStaff);
  877. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  878. // $button=4;
  879. // $verifyList[$k]['status']=4;
  880. // }
  881. }
  882. }
  883. }
  884. $rolename['name']='';
  885. if (!empty($roleId)){
  886. Doo::loadModel('role');
  887. $role=new role();
  888. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  889. }
  890. if (!empty($verifyStaff))
  891. $endStaffArray=end($verifyStaff);
  892. $KOP=false;
  893. foreach ($roleArrayCopy as $P=>$A){
  894. foreach ( $A as $MKI=>$AVL){
  895. if (!empty($verifyStaff)){
  896. //&&$rolename['rid']==$endStaffArray['nextStaff']
  897. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  898. $button=4;
  899. $roleArrayCopy[$P][$MKI]['status']=4;
  900. }
  901. foreach ($verifyStaff as $m=>$u){
  902. $AVLFK=$AVL[0].'_R';
  903. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  904. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  905. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  906. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  907. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  908. break;
  909. }
  910. }
  911. }else{
  912. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  913. $button=4;
  914. $roleArrayCopy[$P][$MKI]['status']=4;
  915. }
  916. }
  917. //$roleArray[$MKI]['rolename']=$rolename['name'];
  918. $KOP=true;
  919. }
  920. }
  921. foreach ($roleArrayCopy as $k=>$v){
  922. foreach ($verifyList as $m=>$n){
  923. if ($n[0]==$k){
  924. array_splice($verifyList,$m,1,$v);
  925. }
  926. }
  927. }
  928. $receiptList[$key]['verifyList']=$verifyList;
  929. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  930. $receiptList[$key]['button']=$button;
  931. //
  932. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  933. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  934. }
  935. $data['receiptList']=$receiptList;
  936. Doo::loadModel('L_category');
  937. $lCategory=new L_category();
  938. Doo::loadModel('accountItem');
  939. $accountItem=new accountItem();
  940. $acItem=$accountItem->find(array('asArray'=>true));
  941. $veList=$verify->find(array('asArray'=>true));
  942. foreach ($veList as $key=>$value){
  943. $v=json_decode($value['staff']);
  944. $list=array();
  945. foreach ($v as $n=>$m){
  946. if ($m['1']=='ROLE'){
  947. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  948. $v[$n][1]=$roleInfo['name'];
  949. array_push($list, $roleInfo['name']);
  950. }else{
  951. array_push($list, $v[$n][1]);
  952. }
  953. }
  954. $veList[$key]['staff']=implode('>', $list);
  955. }
  956. $data['rid']=$rid;
  957. $data['category']=$lCategory->find(array('asArray'=>true));
  958. $data['veList']=$veList;
  959. $data['acItem']=$acItem;
  960. $data['memu']="receipt";
  961. $data['staff']=$this->staff;
  962. $data['receiptMemu']='saeaBorad';
  963. $data['verifyId']=$this->verifyId;
  964. $data['executeId']=$this->executeId;
  965. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  966. }
  967. function saeaLoanReceiptAddDo(){
  968. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  969. $agency=$this->get_args('agency');
  970. $travel=$this->get_args('travel');
  971. $train=$this->get_args('train');
  972. $other=$this->get_args('other');
  973. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  974. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  975. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  976. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  977. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  978. Doo::loadModel('receipt');
  979. Doo::loadModel('receiptDetail');
  980. Doo::loadModel('accountItem');
  981. $accountItem=new accountItem();
  982. $receipt=new receipt();
  983. Doo::loadModel('enclosur');
  984. Doo::loadModel('execute');
  985. $execute=new execute();
  986. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  987. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  988. // if(!empty($receiptDetail))
  989. // return "/referReceipt/".$receiptDetail['rid'];
  990. $aItem=$accountItem->find(array('asArray'=>true));
  991. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  992. $ag=$tr=$ta=$ot=0;
  993. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  994. foreach ($aItem as $key=>$value){
  995. if ($value['category']==$this->AGENCY){
  996. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  997. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  998. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  999. }
  1000. $ag++;
  1001. }
  1002. if($value['category']==$this->TRAVEL){
  1003. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1004. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1005. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1006. }
  1007. $tr++;
  1008. }
  1009. if($value['category']==$this->TRAIN){
  1010. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1011. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1012. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1013. }
  1014. $ta++;
  1015. }
  1016. if($value['category']==$this->OTHER){
  1017. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1018. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1019. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1020. }
  1021. $ot++;
  1022. }
  1023. }
  1024. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1025. //报销单
  1026. $receipt->accountItem=json_encode($accountJson);
  1027. $receipt->staff=$this->staff[0]['sid'];
  1028. $receipt->loanSum=$receiptDet['sum'];
  1029. $receipt->sum=number_format($sum, 2, '.', '');
  1030. $receipt->date=date("Y-m-d");
  1031. $receipt->pastDate='';
  1032. $receipt->cid=$cid;
  1033. $receipt->status=7;
  1034. //修改审批流程加入角色
  1035. $receipt->verify=$verify;
  1036. $receipt->verifyStaff='';
  1037. $receipt->executeStaff='';
  1038. $receipt->executeCopy=$executeDetail['staff'];
  1039. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1040. $receipt->explanation=$explanation;
  1041. $receipt->update(array('where'=>'rid='.$rid));
  1042. //附件
  1043. if (!empty($enclosurName)){
  1044. $enclosurArray=explode('-', $enclosurName);
  1045. foreach ($enclosurArray as $value){
  1046. $enclosur=new enclosur();
  1047. $enclosur->name=$value;
  1048. $enclosur->rid=$rid;
  1049. $enclosur->insert();
  1050. }
  1051. //print_r($enclosurArray);die;
  1052. }
  1053. //报销详情
  1054. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1055. $receiptDetail=new receiptDetail();
  1056. $receiptDetail->staff=$this->staff[0]['sid'];
  1057. $receiptDetail->item=$value['name'];
  1058. $receiptDetail->itemCategory=$this->AGENCY;
  1059. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1060. $receiptDetail->date=date("Y-m-d");
  1061. $receiptDetail->cid=$cid;
  1062. $receiptDetail->rid=$rid;
  1063. $receiptDetail->status=4;
  1064. $receiptDetail->insert();
  1065. }
  1066. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1067. $receiptDetail=new receiptDetail();
  1068. $receiptDetail->staff=$this->staff[0]['sid'];
  1069. $receiptDetail->item=$value['name'];
  1070. $receiptDetail->itemCategory=$this->TRAVEL;
  1071. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1072. $receiptDetail->date=date("Y-m-d");
  1073. $receiptDetail->cid=$cid;
  1074. $receiptDetail->rid=$rid;
  1075. $receiptDetail->status=4;
  1076. $receiptDetail->insert();
  1077. }
  1078. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1079. $receiptDetail=new receiptDetail();
  1080. $receiptDetail->staff=$this->staff[0]['sid'];
  1081. $receiptDetail->item=$value['name'];
  1082. $receiptDetail->itemCategory=$this->TRAIN;
  1083. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1084. $receiptDetail->date=date("Y-m-d");
  1085. $receiptDetail->cid=$cid;
  1086. $receiptDetail->rid=$rid;
  1087. $receiptDetail->status=4;
  1088. $receiptDetail->insert();
  1089. }
  1090. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1091. $receiptDetail=new receiptDetail();
  1092. $receiptDetail->staff=$this->staff[0]['sid'];
  1093. $receiptDetail->item=$value['name'];
  1094. $receiptDetail->itemCategory=$this->OTHER;
  1095. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1096. $receiptDetail->date=date("Y-m-d");
  1097. $receiptDetail->cid=$cid;
  1098. $receiptDetail->rid=$rid;
  1099. $receiptDetail->status=4;
  1100. $receiptDetail->insert();
  1101. }
  1102. return "/saeaBorad";
  1103. }
  1104. return "/saeaLoanReceiptAdd/".$rid;
  1105. }
  1106. function saeaLoanReceiptEdi(){
  1107. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1108. //echo $rid;
  1109. Doo::loadModel('accountItem');
  1110. Doo::loadModel('verify');
  1111. Doo::loadModel('receipt');
  1112. $receipt=new receipt();
  1113. $verify=new verify();
  1114. $accountItem=new accountItem();
  1115. Doo::loadModel('L_category');
  1116. $Lcategory=new L_category();
  1117. Doo::loadModel("role");
  1118. $role=new role();
  1119. Doo::loadModel('loanReceipt');
  1120. $loanReceipt=new loanReceipt();
  1121. Doo::loadModel('staff');
  1122. $staff=new staff();
  1123. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1124. if(empty($receiptDetail))
  1125. return "/saeaBorad";
  1126. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1127. $Locate=0;$roleId=0;$button=0;
  1128. foreach ($receiptList as $key=>$value){
  1129. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1130. $receiptList[$key]['reviseDetail']=array();
  1131. if (!empty($value['reviseDetail']))
  1132. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1133. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1134. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1135. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1136. $receiptList[$key]['category']=$categoryDetil['title'];
  1137. //检测编辑状态
  1138. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1139. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1140. $verifyStaff=json_decode($value['verifyStaff'],true);
  1141. Doo::loadModel('role');
  1142. $role=new role();
  1143. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1144. foreach ($verifyList as $k=>$v){
  1145. //init verifyStaff
  1146. if ($v[1]=='ROLE'){
  1147. if (!empty($verifyStaff)){
  1148. $endStaffArray=end($verifyStaff);
  1149. // if ($v[0]==$endStaffArray['nextStaff']){
  1150. // $roleId=$v[0];
  1151. // }
  1152. }
  1153. $roleVerify=json_decode($v[3],true);
  1154. $roleKey=$k;$roleArray=array();
  1155. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1156. foreach ($roleVerify as $o=>$p){
  1157. $staffID=explode ('_',$p);
  1158. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1159. //print_r($staffID);
  1160. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1161. array_push($roleArray, $exp);
  1162. }
  1163. $roleArrayCopy[$v[0]]=$roleArray;
  1164. //$verifyList[$k]['roleArray']=$roleArray;
  1165. }
  1166. $verifyList[$k]['date']="";
  1167. $verifyList[$k]['opinion']="";
  1168. $verifyList[$k]['status']="";
  1169. if (empty($verifyStaff)){
  1170. $verifyList[$k]['date']="";
  1171. $verifyList[$k]['opinion']="";
  1172. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1173. $verifyList[$k]['status']=4;
  1174. $flag=false;
  1175. }
  1176. }else{
  1177. foreach ($verifyStaff as $m=>$u){
  1178. if ($v[0]==$m){
  1179. $verifyList[$k]['date']=$u['date'];
  1180. $verifyList[$k]['opinion']=$u['opinion'];
  1181. $verifyList[$k]['status']=$u['status'];
  1182. $flag=false;
  1183. break;
  1184. }
  1185. }
  1186. $endStaffArray=end($verifyStaff);
  1187. if (isset($endStaffArray['ROLE'])){
  1188. }else{
  1189. // $endKey=key($verifyStaff);
  1190. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1191. // $button=4;
  1192. // $verifyList[$k]['status']=4;
  1193. // }
  1194. }
  1195. }
  1196. }
  1197. $rolename['name']='';
  1198. if (!empty($roleId)){
  1199. Doo::loadModel('role');
  1200. $role=new role();
  1201. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1202. }
  1203. if (!empty($verifyStaff))
  1204. $endStaffArray=end($verifyStaff);
  1205. $KOP=false;
  1206. foreach ($roleArrayCopy as $P=>$A){
  1207. foreach ( $A as $MKI=>$AVL){
  1208. if (!empty($verifyStaff)){
  1209. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1210. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1211. $button=4;
  1212. $roleArrayCopy[$P][$MKI]['status']=4;
  1213. }
  1214. foreach ($verifyStaff as $m=>$u){
  1215. $AVLFK=$AVL[0].'_R';
  1216. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1217. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1218. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1219. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1220. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1221. break;
  1222. }
  1223. }
  1224. }else{
  1225. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1226. $button=4;
  1227. $roleArrayCopy[$P][$MKI]['status']=4;
  1228. }
  1229. }
  1230. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1231. $KOP=true;
  1232. }
  1233. }
  1234. foreach ($roleArrayCopy as $k=>$v){
  1235. foreach ($verifyList as $m=>$n){
  1236. if ($n[0]==$k){
  1237. array_splice($verifyList,$m,1,$v);
  1238. }
  1239. }
  1240. }
  1241. $receiptList[$key]['verifyList']=$verifyList;
  1242. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1243. $receiptList[$key]['button']=$button;
  1244. //
  1245. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1246. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1247. }
  1248. $data['receiptList']=$receiptList;
  1249. $acItem=$accountItem->find(array('asArray'=>true));
  1250. $veList=$verify->find(array('asArray'=>true));
  1251. foreach ($veList as $key=>$value){
  1252. $v=json_decode($value['staff']);
  1253. $list=array();
  1254. foreach ($v as $n=>$m){
  1255. if ($m['1']=='ROLE'){
  1256. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1257. $v[$n][1]=$roleInfo['name'];
  1258. array_push($list, $roleInfo['name']);
  1259. }else{
  1260. array_push($list, $v[$n][1]);
  1261. }
  1262. }
  1263. $veList[$key]['staff']=implode('>', $list);
  1264. }
  1265. //配置编辑信息
  1266. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1267. foreach ($acItem as $key=>$value){
  1268. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1269. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1270. $acItem[$key]['price']=$v['price'];
  1271. }
  1272. }
  1273. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1274. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1275. $acItem[$key]['price']=$v['price'];
  1276. }
  1277. }
  1278. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1279. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1280. $acItem[$key]['price']=$v['price'];
  1281. }
  1282. }
  1283. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1284. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1285. $acItem[$key]['price']=$v['price'];
  1286. }
  1287. }
  1288. }
  1289. $data['category']=$Lcategory->find(array('asArray'=>true));
  1290. $data['cSum']=$accountItemList['cSum'];
  1291. $data['sum']=$receiptDetail['sum'];
  1292. $data['receiptDetail']=$receiptDetail;
  1293. $data['veList']=$veList;
  1294. $data['acItem']=$acItem;
  1295. $data['memu']="receipt";
  1296. $data['staff']=$this->staff;
  1297. $data['receiptMemu']='saeaBorad';
  1298. $data['verify']=$receiptDetail['verify'];
  1299. $data['verifyId']=$this->verifyId;
  1300. $data['executeId']=$this->executeId;
  1301. $data['rid']=$rid;
  1302. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1303. }
  1304. function confirmation(){
  1305. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1306. Doo::loadModel('receipt');
  1307. Doo::loadModel('receiptDetail');
  1308. $receipt=new receipt();
  1309. $receiptDetail=new receiptDetail();
  1310. Doo::loadModel('statistics');
  1311. Doo::loadModel('itemStatistics');
  1312. $statistics=new statistics();
  1313. $itemStatistics=new itemStatistics();
  1314. Doo::loadModel("verify");
  1315. $verify=new verify();
  1316. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1317. if(empty($receiptDetailList))
  1318. return "/saeaBorad";
  1319. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1320. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1321. if (empty($receiptDetailList['nowStaff'])){
  1322. $nowStaff="";$nowStaffList=array();
  1323. if ($verifyDetail[0][1]=='ROLE'){
  1324. $vStaffString=json_decode($verifyDetail[0][3]);
  1325. foreach ($vStaffString as $key=>$value){
  1326. $staffK=explode("_", $value);
  1327. array_push($nowStaffList, $staffK[0]);
  1328. }
  1329. $nowStaff=implode(',', $nowStaffList);
  1330. }else{
  1331. $nowStaff=$verifyDetail[0][0];
  1332. }
  1333. $receipt->nowStaff=$nowStaff;
  1334. }
  1335. // echo $nowStaff;
  1336. // print_r($verifyDetail);die;
  1337. $receipt->rid=$receiptDetailList['rid'];
  1338. $receipt->status=2;
  1339. $receipt->update();
  1340. //操作日志
  1341. Doo::loadModel("receiptLog");
  1342. $receiptLog=new receiptLog();
  1343. $verify=new verify();
  1344. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1345. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1346. $jd=json_decode($vr['staff']);$roleId=0;
  1347. foreach ($jd as $key=>$value){
  1348. if ($value[1]=='ROLE'){
  1349. $pos = strpos($value[3], $this->staff[0]['sid']);
  1350. if ($pos !== false) {
  1351. $roleId=$value[0];
  1352. }
  1353. }
  1354. }
  1355. //审批日志
  1356. //echo $roleId;die;
  1357. if (!empty($roleId)){
  1358. Doo::loadModel("role");
  1359. $role=new role();
  1360. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1361. $receiptLog->rolename=$roleInfo['name'];
  1362. }
  1363. $receiptLog->username=$this->staff[0]['username'];
  1364. $receiptLog->uid=$this->staff[0]['sid'];
  1365. $receiptLog->date=date("Y-m-d");
  1366. $receiptLog->opinion='提交审批';
  1367. $receiptLog->img=$this->staff[0]['avatar'];
  1368. $receiptLog->status=2;
  1369. $receiptLog->rid=$rid;
  1370. $receiptLog->insert();
  1371. return "/expenses";
  1372. }
  1373. function expenses(){
  1374. $item=isset($this->params['item'])?$this->params['item']:"";
  1375. if(empty($item))
  1376. $item=$this->get_args('item')?$this->get_args('item'):"";
  1377. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1378. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1379. Doo::loadModel('receipt');
  1380. $receipt=new receipt();
  1381. Doo::loadModel('L_category');
  1382. $Lcategory=new L_category();
  1383. Doo::loadModel('verify');
  1384. Doo::loadModel('statistics');
  1385. $statistics=new statistics();
  1386. $verify=new verify();
  1387. Doo::loadModel('staff');
  1388. $staff=new staff();
  1389. $condition="";
  1390. if($item=="expenses")
  1391. $condition=" and Rtype=1 ";
  1392. elseif ($item=="receipts")
  1393. $condition=" and Rtype=0 ";
  1394. elseif ($item=="remits")
  1395. $condition=" and Rtype=2 ";
  1396. $dateCondition=" and Year(date) =".$year;
  1397. if(!empty($moth)){
  1398. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1399. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1400. }else
  1401. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1402. if(empty($stList))
  1403. $stList=array('rePrice'=>0,'agPrice'=>0);
  1404. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  1405. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  1406. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1407. $Locate=0;$roleId=0;$button=0;
  1408. foreach ($receiptList as $key=>$value){
  1409. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1410. $receiptList[$key]['reviseDetail']=array();
  1411. if (!empty($value['reviseDetail']))
  1412. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1413. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1414. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1415. $receiptList[$key]['category']=$categoryDetil['title'];
  1416. //检测编辑状态
  1417. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1418. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1419. $verifyStaff=json_decode($value['verifyStaff'],true);
  1420. Doo::loadModel('role');
  1421. $role=new role();
  1422. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1423. foreach ($verifyList as $k=>$v){
  1424. //init verifyStaff
  1425. if ($v[1]=='ROLE'){
  1426. if (!empty($verifyStaff)){
  1427. $endStaffArray=end($verifyStaff);
  1428. // if ($v[0]==$endStaffArray['nextStaff']){
  1429. // $roleId=$v[0];
  1430. // }
  1431. }
  1432. $roleVerify=json_decode($v[3],true);
  1433. $roleKey=$k;$roleArray=array();
  1434. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1435. foreach ($roleVerify as $o=>$p){
  1436. $staffID=explode ('_',$p);
  1437. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1438. //print_r($staffID);
  1439. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1440. array_push($roleArray, $exp);
  1441. }
  1442. $roleArrayCopy[$v[0]]=$roleArray;
  1443. //$verifyList[$k]['roleArray']=$roleArray;
  1444. }
  1445. $verifyList[$k]['date']="";
  1446. $verifyList[$k]['opinion']="";
  1447. $verifyList[$k]['status']="";
  1448. if (empty($verifyStaff)){
  1449. $verifyList[$k]['date']="";
  1450. $verifyList[$k]['opinion']="";
  1451. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1452. $verifyList[$k]['status']=4;
  1453. $flag=false;
  1454. }
  1455. }else{
  1456. foreach ($verifyStaff as $m=>$u){
  1457. if ($v[0]==$m){
  1458. $verifyList[$k]['date']=$u['date'];
  1459. $verifyList[$k]['opinion']=$u['opinion'];
  1460. $verifyList[$k]['status']=$u['status'];
  1461. $flag=false;
  1462. break;
  1463. }
  1464. }
  1465. $endStaffArray=end($verifyStaff);
  1466. if (isset($endStaffArray['ROLE'])){
  1467. }else{
  1468. // $endKey=key($verifyStaff);
  1469. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1470. // $button=4;
  1471. // $verifyList[$k]['status']=4;
  1472. // }
  1473. }
  1474. }
  1475. }
  1476. $rolename['name']='';
  1477. if (!empty($roleId)){
  1478. Doo::loadModel('role');
  1479. $role=new role();
  1480. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1481. }
  1482. if (!empty($verifyStaff))
  1483. $endStaffArray=end($verifyStaff);
  1484. $KOP=false;
  1485. foreach ($roleArrayCopy as $P=>$A){
  1486. foreach ( $A as $MKI=>$AVL){
  1487. if (!empty($verifyStaff)){
  1488. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1489. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1490. $button=4;
  1491. $roleArrayCopy[$P][$MKI]['status']=4;
  1492. }
  1493. foreach ($verifyStaff as $m=>$u){
  1494. $AVLFK=$AVL[0].'_R';
  1495. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1496. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1497. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1498. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1499. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1500. break;
  1501. }
  1502. }
  1503. }else{
  1504. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1505. $button=4;
  1506. $roleArrayCopy[$P][$MKI]['status']=4;
  1507. }
  1508. }
  1509. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1510. $KOP=true;
  1511. }
  1512. }
  1513. foreach ($roleArrayCopy as $k=>$v){
  1514. foreach ($verifyList as $m=>$n){
  1515. if ($n[0]==$k){
  1516. array_splice($verifyList,$m,1,$v);
  1517. }
  1518. }
  1519. }
  1520. $receiptList[$key]['verifyList']=$verifyList;
  1521. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1522. $receiptList[$key]['button']=$button;
  1523. }
  1524. //print_r($receiptList);die;
  1525. $mothHtml="";
  1526. for($i=1;$i<=12;$i++){
  1527. if($moth==$i)
  1528. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1529. else
  1530. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1531. }
  1532. $data['mothHtml']=$mothHtml;
  1533. $data['receiptList']=$receiptList;
  1534. $data['memu']="receipt";
  1535. $data['staff']=$this->staff;
  1536. $data['receiptMemu']='expenses';
  1537. $data['verifyId']=$this->verifyId;
  1538. $data['executeId']=$this->executeId;
  1539. $data['item']=$item;
  1540. $data['year']=$year;
  1541. $this->render ( "/admin/expenses", $data );
  1542. }
  1543. function expensesCollect(){
  1544. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1545. Doo::loadModel('receipt');
  1546. $receipt=new receipt();
  1547. Doo::loadModel('L_category');
  1548. $Lcategory=new L_category();
  1549. Doo::loadModel('verify');
  1550. Doo::loadModel('statistics');
  1551. $statistics=new statistics();
  1552. $verify=new verify();
  1553. Doo::loadModel('staff');
  1554. $staff=new staff();
  1555. Doo::loadModel('loanReceipt');
  1556. $loanReceipt=new loanReceipt();
  1557. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1558. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1559. $Locate=0;$roleId=0;$button=0;
  1560. foreach ($loanList as $key=>$value){
  1561. $loanList[$key]['Locate']=$Locate;$Locate++;
  1562. $loanList[$key]['reviseDetail']=array();
  1563. if (!empty($value['reviseDetail']))
  1564. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1565. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1566. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1567. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1568. $loanList[$key]['category']=$categoryDetil['title'];
  1569. //检测编辑状态
  1570. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1571. $verifyList['staff']=$value['verifyBreakup'];
  1572. else
  1573. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1574. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1575. $verifyStaff=json_decode($value['verifyStaff'],true);
  1576. Doo::loadModel('role');
  1577. $role=new role();
  1578. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1579. foreach ($verifyList as $k=>$v){
  1580. //init verifyStaff
  1581. if ($v[1]=='ROLE'){
  1582. if (!empty($verifyStaff)){
  1583. $endStaffArray=end($verifyStaff);
  1584. // if ($v[0]==$endStaffArray['nextStaff']){
  1585. // $roleId=$v[0];
  1586. // }
  1587. }
  1588. $roleVerify=json_decode($v[3],true);
  1589. $roleKey=$k;$roleArray=array();
  1590. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1591. foreach ($roleVerify as $o=>$p){
  1592. $staffID=explode ('_',$p);
  1593. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1594. //print_r($staffID);
  1595. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1596. array_push($roleArray, $exp);
  1597. }
  1598. $roleArrayCopy[$v[0]]=$roleArray;
  1599. //$verifyList[$k]['roleArray']=$roleArray;
  1600. }
  1601. $verifyList[$k]['date']="";
  1602. $verifyList[$k]['opinion']="";
  1603. $verifyList[$k]['status']="";
  1604. if (empty($verifyStaff)){
  1605. $verifyList[$k]['date']="";
  1606. $verifyList[$k]['opinion']="";
  1607. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1608. $verifyList[$k]['status']=4;
  1609. $flag=false;
  1610. }
  1611. }else{
  1612. foreach ($verifyStaff as $m=>$u){
  1613. if ($v[0]==$m){
  1614. $verifyList[$k]['date']=$u['date'];
  1615. $verifyList[$k]['opinion']=$u['opinion'];
  1616. $verifyList[$k]['status']=$u['status'];
  1617. $flag=false;
  1618. break;
  1619. }
  1620. }
  1621. $endStaffArray=end($verifyStaff);
  1622. if (isset($endStaffArray['ROLE'])){
  1623. }else{
  1624. // $endKey=key($verifyStaff);
  1625. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1626. // $button=4;
  1627. // $verifyList[$k]['status']=4;
  1628. // }
  1629. }
  1630. }
  1631. }
  1632. $rolename['name']='';
  1633. if (!empty($roleId)){
  1634. Doo::loadModel('role');
  1635. $role=new role();
  1636. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1637. }
  1638. if (!empty($verifyStaff))
  1639. $endStaffArray=end($verifyStaff);
  1640. $KOP=false;
  1641. foreach ($roleArrayCopy as $P=>$A){
  1642. foreach ( $A as $MKI=>$AVL){
  1643. if (!empty($verifyStaff)){
  1644. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1645. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1646. $button=4;
  1647. $roleArrayCopy[$P][$MKI]['status']=4;
  1648. }
  1649. foreach ($verifyStaff as $m=>$u){
  1650. $AVLFK=$AVL[0].'_R';
  1651. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1652. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1653. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1654. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1655. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1656. break;
  1657. }
  1658. }
  1659. }else{
  1660. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1661. $button=4;
  1662. $roleArrayCopy[$P][$MKI]['status']=4;
  1663. }
  1664. }
  1665. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1666. $KOP=true;
  1667. }
  1668. }
  1669. foreach ($roleArrayCopy as $k=>$v){
  1670. foreach ($verifyList as $m=>$n){
  1671. if ($n[0]==$k){
  1672. array_splice($verifyList,$m,1,$v);
  1673. }
  1674. }
  1675. }
  1676. $loanList[$key]['verifyList']=$verifyList;
  1677. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1678. $loanList[$key]['button']=$button;
  1679. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1680. }
  1681. $data['loanList']=$loanList;
  1682. $Locate=0;$roleId=0;$button=0;
  1683. foreach ($receiptList as $key=>$value){
  1684. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1685. $receiptList[$key]['reviseDetail']=array();
  1686. if (!empty($value['reviseDetail']))
  1687. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1688. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1689. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1690. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1691. $receiptList[$key]['category']=$categoryDetil['title'];
  1692. //检测编辑状态
  1693. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1694. if($value['status']==8&&$value['Rtype']==1)
  1695. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1696. else
  1697. $verifyList['staff']=$value['verifyBreakup'];
  1698. }else
  1699. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1700. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1701. $verifyStaff=json_decode($value['verifyStaff'],true);
  1702. Doo::loadModel('role');
  1703. $role=new role();
  1704. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1705. foreach ($verifyList as $k=>$v){
  1706. //init verifyStaff
  1707. if ($v[1]=='ROLE'){
  1708. if (!empty($verifyStaff)){
  1709. $endStaffArray=end($verifyStaff);
  1710. // if ($v[0]==$endStaffArray['nextStaff']){
  1711. // $roleId=$v[0];
  1712. // }
  1713. }
  1714. $roleVerify=json_decode($v[3],true);
  1715. $roleKey=$k;$roleArray=array();
  1716. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1717. foreach ($roleVerify as $o=>$p){
  1718. $staffID=explode ('_',$p);
  1719. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1720. //print_r($staffID);
  1721. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1722. array_push($roleArray, $exp);
  1723. }
  1724. $roleArrayCopy[$v[0]]=$roleArray;
  1725. //$verifyList[$k]['roleArray']=$roleArray;
  1726. }
  1727. $verifyList[$k]['date']="";
  1728. $verifyList[$k]['opinion']="";
  1729. $verifyList[$k]['status']="";
  1730. if (empty($verifyStaff)){
  1731. $verifyList[$k]['date']="";
  1732. $verifyList[$k]['opinion']="";
  1733. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1734. $verifyList[$k]['status']=4;
  1735. $flag=false;
  1736. }
  1737. }else{
  1738. foreach ($verifyStaff as $m=>$u){
  1739. if ($v[0]==$m){
  1740. $verifyList[$k]['date']=$u['date'];
  1741. $verifyList[$k]['opinion']=$u['opinion'];
  1742. $verifyList[$k]['status']=$u['status'];
  1743. $flag=false;
  1744. break;
  1745. }
  1746. }
  1747. $endStaffArray=end($verifyStaff);
  1748. if (isset($endStaffArray['ROLE'])){
  1749. }else{
  1750. // $endKey=key($verifyStaff);
  1751. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1752. // $button=4;
  1753. // $verifyList[$k]['status']=4;
  1754. // }
  1755. }
  1756. }
  1757. }
  1758. $rolename['name']='';
  1759. if (!empty($roleId)){
  1760. Doo::loadModel('role');
  1761. $role=new role();
  1762. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1763. }
  1764. if (!empty($verifyStaff))
  1765. $endStaffArray=end($verifyStaff);
  1766. $KOP=false;
  1767. foreach ($roleArrayCopy as $P=>$A){
  1768. foreach ( $A as $MKI=>$AVL){
  1769. if (!empty($verifyStaff)){
  1770. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1771. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1772. $button=4;
  1773. $roleArrayCopy[$P][$MKI]['status']=4;
  1774. }
  1775. foreach ($verifyStaff as $m=>$u){
  1776. $AVLFK=$AVL[0].'_R';
  1777. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1778. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1779. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1780. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1781. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1782. break;
  1783. }
  1784. }
  1785. }else{
  1786. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1787. $button=4;
  1788. $roleArrayCopy[$P][$MKI]['status']=4;
  1789. }
  1790. }
  1791. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1792. $KOP=true;
  1793. }
  1794. }
  1795. foreach ($roleArrayCopy as $k=>$v){
  1796. foreach ($verifyList as $m=>$n){
  1797. if ($n[0]==$k){
  1798. array_splice($verifyList,$m,1,$v);
  1799. }
  1800. }
  1801. }
  1802. $receiptList[$key]['verifyList']=$verifyList;
  1803. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1804. $receiptList[$key]['button']=$button;
  1805. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1806. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1807. $relust=$value['sum']-$value['loanSum'];
  1808. $receiptList[$key]['relust']=$relust;
  1809. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1810. }
  1811. $data['receiptList']=$receiptList;
  1812. $data['memu']="receipt";
  1813. $data['staff']=$this->staff;
  1814. $data['receiptMemu']='expenses';
  1815. $data['verifyId']=$this->verifyId;
  1816. $data['executeId']=$this->executeId;
  1817. $this->render ( "/admin/expensesCollect", $data );
  1818. }
  1819. function approvalExpenses(){
  1820. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1821. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1822. $month=$this->get_args('month')?$this->get_args('month'):"";
  1823. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1824. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1825. if (empty($status))
  1826. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1827. $page_size=12;
  1828. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1829. $vidList=array();
  1830. $button=0;
  1831. Doo::loadModel('verify');
  1832. $verify=new verify();
  1833. Doo::loadModel('receipt');
  1834. $receipt=new receipt();
  1835. Doo::loadModel('staff');
  1836. $staff=new staff();
  1837. Doo::loadModel('L_category');
  1838. $Lcategory=new L_category();
  1839. //user verify ID
  1840. $verifyDetail=$verify->find(array('where'=>' (staff not like "%\"'.$this->staff[0]['sid'].'\",\"ROLE%") and (staff like "%[\"'.$this->staff[0]['sid'].'\",%" or staff like "%\"'.$this->staff[0]['sid'].'\_%" )','asArray'=>true));
  1841. foreach ($verifyDetail as $key=>$value){
  1842. array_push($vidList, $value['vid']);
  1843. }
  1844. $vid=implode(",", $vidList);
  1845. if(empty($verifyDetail))
  1846. $vid=0;
  1847. // if ($status==0)
  1848. // $dateCondition="";
  1849. // else
  1850. $dateCondition=" and Year(date) =".$year;
  1851. if(!empty($month))
  1852. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1853. $categoryList=$Lcategory->find(array('asArray'=>true));
  1854. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1855. $cateCondition="";$staffCondition="";$approvalCondition="";
  1856. if (!empty($cid))
  1857. $cateCondition=' and cid='.$cid;
  1858. if(!empty($sid)){
  1859. $staffCondition=' and staff='.$sid;
  1860. $cateCondition="";
  1861. }
  1862. $approvalCondition=" and status=".$status;
  1863. if($status==2){
  1864. //查找角色审批人
  1865. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1866. }
  1867. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1868. $approvalCondition=' and status=2 ';
  1869. }
  1870. if($status==1){
  1871. $approvalCondition=' and (status='.$status.' or status=6) ';
  1872. }
  1873. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1874. $pageinfo['page']=array('previous'=>'');
  1875. if ($status==0){
  1876. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1877. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1878. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1879. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1880. }else
  1881. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1882. ,'desc'=>'rid','asArray'=>true));
  1883. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )'.$cateCondition.$staffCondition
  1884. ,'desc'=>'rid','asArray'=>true));
  1885. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1886. //print_r($pageinfo);
  1887. $Locate=0;
  1888. foreach ($receiptList as $key=>$value){
  1889. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1890. $receiptList[$key]['reviseDetail']=array();
  1891. if (!empty($value['reviseDetail']))
  1892. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1893. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1894. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1895. $receiptList[$key]['category']=$categoryDetil['title'];
  1896. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1897. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1898. $verifyStaff=json_decode($value['verifyStaff'],true);
  1899. foreach ($verifyList as $k=>$v){
  1900. //init verifyStaff
  1901. $verifyList[$k]['date']="";
  1902. $verifyList[$k]['opinion']="";
  1903. $verifyList[$k]['status']="";
  1904. if (empty($verifyStaff)){
  1905. $verifyList[$k]['date']="";
  1906. $verifyList[$k]['opinion']="";
  1907. if ($v[0]==$this->staff[0]['sid']){
  1908. $verifyList[$k]['status']=4;
  1909. $button=4;
  1910. }
  1911. }else{
  1912. $flag=true;
  1913. foreach ($verifyStaff as $m=>$u){
  1914. if ($v[0]==$m){
  1915. $verifyList[$k]['date']=$u['date'];
  1916. $verifyList[$k]['opinion']=$u['opinion'];
  1917. $verifyList[$k]['status']=$u['status'];
  1918. $flag=false;
  1919. break;
  1920. }
  1921. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1922. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1923. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1924. }
  1925. if($flag){//检测可编辑
  1926. if($v[0]==$this->staff[0]['sid']){
  1927. $verifyList[$k]['status']=4;$button=4;
  1928. }
  1929. }
  1930. }
  1931. }
  1932. $receiptList[$key]['verifyList']=$verifyList;
  1933. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1934. $receiptList[$key]['button']=$button;
  1935. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1936. }
  1937. //print_r($receiptList);die;
  1938. //$data['verifyDetail']=$verifyDetail;
  1939. $mothHtml="";
  1940. for($i=1;$i<=12;$i++){
  1941. if($month==$i)
  1942. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1943. else
  1944. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1945. }
  1946. $data['mothHtml']=$mothHtml;
  1947. $data['page']=$pageinfo;
  1948. $data['receiptList']=$receiptList;
  1949. $data['receiptApprovalCount']=count($rLRes);
  1950. $data['status']=$status;
  1951. $data['year']=$year;
  1952. $data['categoryList']=$categoryList;
  1953. $data['staffList']=$staffList;
  1954. $data['cid']=$cid;
  1955. $data['sid']=$sid;
  1956. //print_r($receiptList);
  1957. $data['memu']="receipt";
  1958. $data['staff']=$this->staff;
  1959. $data['receiptMemu']='approvalExpenses';
  1960. $data['verifyId']=$this->verifyId;
  1961. $data['executeId']=$this->executeId;
  1962. $this->render ( "/admin/approvalExpenses", $data );
  1963. }
  1964. function expensesDoc(){
  1965. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1966. Doo::loadModel('receipt');
  1967. $receipt=new receipt();
  1968. Doo::loadModel('L_category');
  1969. $Lcategory=new L_category();
  1970. Doo::loadModel('verify');
  1971. Doo::loadModel('statistics');
  1972. $statistics=new statistics();
  1973. $verify=new verify();
  1974. Doo::loadModel('staff');
  1975. $staff=new staff();
  1976. Doo::loadModel('loanReceipt');
  1977. $loanReceipt=new loanReceipt();
  1978. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  1979. $loanList=array();
  1980. if (!empty($receiptList))
  1981. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1982. $Locate=0;$roleId=0;$button=0;
  1983. foreach ($loanList as $key=>$value){
  1984. $loanList[$key]['Locate']=$Locate;$Locate++;
  1985. $loanList[$key]['reviseDetail']=array();
  1986. if (!empty($value['reviseDetail']))
  1987. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1988. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1989. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1990. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1991. $loanList[$key]['category']=$categoryDetil['title'];
  1992. //检测编辑状态
  1993. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1994. $verifyList['staff']=$value['verifyBreakup'];
  1995. else
  1996. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1997. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1998. $verifyStaff=json_decode($value['verifyStaff'],true);
  1999. Doo::loadModel('role');
  2000. $role=new role();
  2001. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2002. foreach ($verifyList as $k=>$v){
  2003. //init verifyStaff
  2004. if ($v[1]=='ROLE'){
  2005. if (!empty($verifyStaff)){
  2006. $endStaffArray=end($verifyStaff);
  2007. // if ($v[0]==$endStaffArray['nextStaff']){
  2008. // $roleId=$v[0];
  2009. // }
  2010. }
  2011. $roleVerify=json_decode($v[3],true);
  2012. $roleKey=$k;$roleArray=array();
  2013. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2014. foreach ($roleVerify as $o=>$p){
  2015. $staffID=explode ('_',$p);
  2016. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2017. //print_r($staffID);
  2018. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2019. array_push($roleArray, $exp);
  2020. }
  2021. $roleArrayCopy[$v[0]]=$roleArray;
  2022. //$verifyList[$k]['roleArray']=$roleArray;
  2023. }
  2024. $verifyList[$k]['date']="";
  2025. $verifyList[$k]['opinion']="";
  2026. $verifyList[$k]['status']="";
  2027. if (empty($verifyStaff)){
  2028. $verifyList[$k]['date']="";
  2029. $verifyList[$k]['opinion']="";
  2030. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2031. $verifyList[$k]['status']=4;
  2032. $flag=false;
  2033. }
  2034. }else{
  2035. foreach ($verifyStaff as $m=>$u){
  2036. if ($v[0]==$m){
  2037. $verifyList[$k]['date']=$u['date'];
  2038. $verifyList[$k]['opinion']=$u['opinion'];
  2039. $verifyList[$k]['status']=$u['status'];
  2040. $flag=false;
  2041. break;
  2042. }
  2043. }
  2044. $endStaffArray=end($verifyStaff);
  2045. if (isset($endStaffArray['ROLE'])){
  2046. }else{
  2047. // $endKey=key($verifyStaff);
  2048. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2049. // $button=4;
  2050. // $verifyList[$k]['status']=4;
  2051. // }
  2052. }
  2053. }
  2054. }
  2055. $rolename['name']='';
  2056. if (!empty($roleId)){
  2057. Doo::loadModel('role');
  2058. $role=new role();
  2059. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2060. }
  2061. if (!empty($verifyStaff))
  2062. $endStaffArray=end($verifyStaff);
  2063. $KOP=false;
  2064. foreach ($roleArrayCopy as $P=>$A){
  2065. foreach ( $A as $MKI=>$AVL){
  2066. if (!empty($verifyStaff)){
  2067. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2068. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2069. $button=4;
  2070. $roleArrayCopy[$P][$MKI]['status']=4;
  2071. }
  2072. foreach ($verifyStaff as $m=>$u){
  2073. $AVLFK=$AVL[0].'_R';
  2074. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2075. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2076. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2077. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2078. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2079. break;
  2080. }
  2081. }
  2082. }else{
  2083. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2084. $button=4;
  2085. $roleArrayCopy[$P][$MKI]['status']=4;
  2086. }
  2087. }
  2088. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2089. $KOP=true;
  2090. }
  2091. }
  2092. foreach ($roleArrayCopy as $k=>$v){
  2093. foreach ($verifyList as $m=>$n){
  2094. if ($n[0]==$k){
  2095. array_splice($verifyList,$m,1,$v);
  2096. }
  2097. }
  2098. }
  2099. $loanList[$key]['verifyList']=$verifyList;
  2100. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2101. $loanList[$key]['button']=$button;
  2102. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2103. }
  2104. $data['loanList']=$loanList;
  2105. //print_r($loanList);
  2106. $Locate=0;$roleId=0;$button=0;
  2107. foreach ($receiptList as $key=>$value){
  2108. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2109. $receiptList[$key]['reviseDetail']=array();
  2110. if (!empty($value['reviseDetail']))
  2111. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2112. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2113. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2114. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2115. $receiptList[$key]['category']=$categoryDetil['title'];
  2116. //检测编辑状态
  2117. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2118. $verifyList['staff']=$value['verifyBreakup'];
  2119. }else
  2120. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2121. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2122. $verifyStaff=json_decode($value['verifyStaff'],true);
  2123. Doo::loadModel('role');
  2124. $role=new role();
  2125. if ($verifyList==NULL)
  2126. $verifyList=array();
  2127. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2128. foreach ($verifyList as $k=>$v){
  2129. //init verifyStaff
  2130. if ($v[1]=='ROLE'){
  2131. if (!empty($verifyStaff)){
  2132. $endStaffArray=end($verifyStaff);
  2133. // if ($v[0]==$endStaffArray['nextStaff']){
  2134. // $roleId=$v[0];
  2135. // }
  2136. }
  2137. $roleVerify=json_decode($v[3],true);
  2138. $roleKey=$k;$roleArray=array();
  2139. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2140. foreach ($roleVerify as $o=>$p){
  2141. $staffID=explode ('_',$p);
  2142. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2143. //print_r($staffID);
  2144. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2145. array_push($roleArray, $exp);
  2146. }
  2147. $roleArrayCopy[$v[0]]=$roleArray;
  2148. //$verifyList[$k]['roleArray']=$roleArray;
  2149. }
  2150. $verifyList[$k]['date']="";
  2151. $verifyList[$k]['opinion']="";
  2152. $verifyList[$k]['status']="";
  2153. if (empty($verifyStaff)){
  2154. $verifyList[$k]['date']="";
  2155. $verifyList[$k]['opinion']="";
  2156. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2157. $verifyList[$k]['status']=4;
  2158. $flag=false;
  2159. }
  2160. }else{
  2161. foreach ($verifyStaff as $m=>$u){
  2162. if ($v[0]==$m){
  2163. $verifyList[$k]['date']=$u['date'];
  2164. $verifyList[$k]['opinion']=$u['opinion'];
  2165. $verifyList[$k]['status']=$u['status'];
  2166. $flag=false;
  2167. break;
  2168. }
  2169. }
  2170. $endStaffArray=end($verifyStaff);
  2171. if (isset($endStaffArray['ROLE'])){
  2172. }else{
  2173. // $endKey=key($verifyStaff);
  2174. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2175. // $button=4;
  2176. // $verifyList[$k]['status']=4;
  2177. // }
  2178. }
  2179. }
  2180. }
  2181. $rolename['name']='';
  2182. if (!empty($roleId)){
  2183. Doo::loadModel('role');
  2184. $role=new role();
  2185. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2186. }
  2187. if (!empty($verifyStaff))
  2188. $endStaffArray=end($verifyStaff);
  2189. $KOP=false;
  2190. foreach ($roleArrayCopy as $P=>$A){
  2191. foreach ( $A as $MKI=>$AVL){
  2192. if (!empty($verifyStaff)){
  2193. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2194. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2195. $button=4;
  2196. $roleArrayCopy[$P][$MKI]['status']=4;
  2197. }
  2198. foreach ($verifyStaff as $m=>$u){
  2199. $AVLFK=$AVL[0].'_R';
  2200. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2201. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2202. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2203. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2204. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2205. break;
  2206. }
  2207. }
  2208. }else{
  2209. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2210. $button=4;
  2211. $roleArrayCopy[$P][$MKI]['status']=4;
  2212. }
  2213. }
  2214. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2215. $KOP=true;
  2216. }
  2217. }
  2218. foreach ($roleArrayCopy as $k=>$v){
  2219. foreach ($verifyList as $m=>$n){
  2220. if ($n[0]==$k){
  2221. array_splice($verifyList,$m,1,$v);
  2222. }
  2223. }
  2224. }
  2225. $receiptList[$key]['verifyList']=$verifyList;
  2226. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2227. $receiptList[$key]['button']=$button;
  2228. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2229. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2230. }
  2231. //获取审批日志
  2232. Doo::loadModel('receiptLog');
  2233. $receiptLog=new receiptLog();
  2234. $rlList=array();
  2235. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2236. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2237. if (!empty($rlInfo)){
  2238. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2239. }
  2240. $receiptList[0]['rlList']=$rlList;
  2241. $data['receiptList']=$receiptList;
  2242. $data['memu']="receipt";
  2243. $data['staff']=$this->staff;
  2244. $data['receiptMemu']='approvalExpenses';
  2245. $data['verifyId']=$this->verifyId;
  2246. $data['executeId']=$this->executeId;
  2247. $this->render ( "/admin/expensesDoc", $data );
  2248. }
  2249. function expensesEdi(){
  2250. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2251. $status=isset($this->params['status'])?$this->params['status']:'';
  2252. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2253. $month=$this->get_args('month')?$this->get_args('month'):"";
  2254. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2255. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2256. if (empty($status))
  2257. $status=$this->get_args('status')?$this->get_args('status'):2;
  2258. $vidList=array();
  2259. $button=0;
  2260. Doo::loadModel('verify');
  2261. Doo::loadModel('receipt');
  2262. Doo::loadModel('staff');
  2263. $staff=new staff();
  2264. $receipt=new receipt();
  2265. $verify=new verify();
  2266. Doo::loadModel('L_category');
  2267. $Lcategory=new L_category();
  2268. Doo::loadModel('enclosur');
  2269. $enclosur=new enclosur();
  2270. //user verify ID
  2271. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2272. foreach ($verifyDetail as $key=>$value){
  2273. array_push($vidList, $value['vid']);
  2274. }
  2275. $vid=implode(",", $vidList);
  2276. if(empty($verifyDetail))
  2277. $vid=0;
  2278. $categoryList=$Lcategory->find(array('asArray'=>true));
  2279. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2280. $ap="";
  2281. if($status==4){
  2282. $ap=4;$status=2;
  2283. }
  2284. //get Receipt By verifyID status 2
  2285. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2286. $Locate=0;$roleId=0;
  2287. if($ap==4)
  2288. $status=4;
  2289. foreach ($receiptList as $key=>$value){
  2290. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2291. $receiptList[$key]['reviseDetail']=array();
  2292. if (!empty($value['reviseDetail']))
  2293. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2294. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2295. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2296. $receiptList[$key]['category']=$categoryDetil['title'];
  2297. //检测编辑状态
  2298. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2299. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2300. $verifyStaff=json_decode($value['verifyStaff'],true);
  2301. Doo::loadModel('role');
  2302. $role=new role();
  2303. //print_r($verifyList);
  2304. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2305. foreach ($verifyList as $k=>$v){
  2306. //init verifyStaff
  2307. if ($v[1]=='ROLE'){
  2308. if (!empty($verifyStaff)){
  2309. $endStaffArray=end($verifyStaff);
  2310. if ($v[0]==$endStaffArray['nextStaff']){
  2311. $roleId=$v[0];
  2312. }
  2313. }
  2314. $roleVerify=json_decode($v[3],true);
  2315. $roleKey=$k;$roleArray=array();
  2316. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2317. foreach ($roleVerify as $o=>$p){
  2318. $staffID=explode ('_',$p);
  2319. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2320. //print_r($staffID);
  2321. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2322. array_push($roleArray, $exp);
  2323. }
  2324. $roleArrayCopy[$v[0]]=$roleArray;
  2325. //$verifyList[$k]['roleArray']=$roleArray;
  2326. }
  2327. //print_r($roleArray);
  2328. $verifyList[$k]['date']="";
  2329. $verifyList[$k]['opinion']="";
  2330. $verifyList[$k]['status']="";
  2331. if (empty($verifyStaff)){
  2332. $verifyList[$k]['date']="";
  2333. $verifyList[$k]['opinion']="";
  2334. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2335. $verifyList[$k]['status']=4;
  2336. $button=4;$flag=false;
  2337. }
  2338. }else{
  2339. foreach ($verifyStaff as $m=>$u){
  2340. if ($v[0]==$m){
  2341. $verifyList[$k]['date']=$u['date'];
  2342. $verifyList[$k]['opinion']=$u['opinion'];
  2343. $verifyList[$k]['status']=$u['status'];
  2344. $flag=false;
  2345. break;
  2346. }
  2347. }
  2348. $endStaffArray=end($verifyStaff);
  2349. if (isset($endStaffArray['ROLE'])){
  2350. }else{
  2351. $endKey=key($verifyStaff);
  2352. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2353. $button=4;
  2354. $verifyList[$k]['status']=4;
  2355. }
  2356. }
  2357. }
  2358. }
  2359. $rolename['name']='';
  2360. if (!empty($roleId)){
  2361. Doo::loadModel('role');
  2362. $role=new role();
  2363. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2364. }
  2365. if (!empty($verifyStaff))
  2366. $endStaffArray=end($verifyStaff);
  2367. $KOP=false;
  2368. foreach ($roleArrayCopy as $P=>$A){
  2369. foreach ( $A as $MKI=>$AVL){
  2370. if (!empty($verifyStaff)){
  2371. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2372. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2373. $button=4;
  2374. $roleArrayCopy[$P][$MKI]['status']=4;
  2375. }
  2376. foreach ($verifyStaff as $m=>$u){
  2377. $AVLFK=$AVL[0].'_R';
  2378. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2379. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2380. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2381. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2382. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2383. break;
  2384. }
  2385. }
  2386. }else{
  2387. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2388. $button=4;
  2389. $roleArrayCopy[$P][$MKI]['status']=4;
  2390. }
  2391. }
  2392. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2393. $KOP=true;
  2394. }
  2395. }
  2396. // print_r($roleArrayCopy);
  2397. // echo $roleKey;
  2398. foreach ($roleArrayCopy as $k=>$v){
  2399. foreach ($verifyList as $m=>$n){
  2400. if ($n[0]==$k){
  2401. array_splice($verifyList,$m,1,$v);
  2402. }
  2403. }
  2404. }
  2405. $receiptList[$key]['verifyList']=$verifyList;
  2406. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2407. $receiptList[$key]['button']=$button;
  2408. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2409. }
  2410. //$data['verifyDetail']=$verifyDetail;
  2411. $mothHtml="";
  2412. for($i=1;$i<=12;$i++){
  2413. if($month==$i)
  2414. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2415. else
  2416. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2417. }
  2418. //获取审批日志
  2419. Doo::loadModel('receiptLog');
  2420. $receiptLog=new receiptLog();
  2421. $rlList=array();
  2422. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2423. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2424. if (!empty($rlInfo)){
  2425. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2426. }
  2427. $receiptList[0]['rlList']=$rlList;
  2428. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2429. $enclosurHtml='';
  2430. foreach ($enclosurList as $value){
  2431. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2432. }
  2433. //print_r($receiptList);
  2434. $data['rid']=$rid;
  2435. $data['enclosurHtml']=$enclosurHtml;
  2436. $data['rolename']=$rolename['name'];
  2437. $data['datetij']=$tijdate['date'];
  2438. $data['mothHtml']=$mothHtml;
  2439. $data['receiptList']=$receiptList;
  2440. $data['receiptApprovalCount']=count($receiptList);
  2441. $data['status']=$status;
  2442. $data['year']=$year;
  2443. $data['categoryList']=$categoryList;
  2444. $data['staffList']=$staffList;
  2445. $data['cid']=$cid;
  2446. $data['sid']=$sid;
  2447. $data['ap']=$ap;
  2448. $data['memu']="receipt";
  2449. $data['staff']=$this->staff;
  2450. $data['receiptMemu']='approvalExpenses';
  2451. $data['verifyId']=$this->verifyId;
  2452. $data['executeId']=$this->executeId;
  2453. $this->render ( "/admin/expensesEdi", $data );
  2454. }
  2455. function expensesDefray(){
  2456. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2457. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2458. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2459. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2460. if(!empty($rid)){
  2461. Doo::loadModel("verify");
  2462. $verify=new verify();
  2463. Doo::loadModel("receiptDetail");
  2464. $receiptDetailObj=new receiptDetail();
  2465. Doo::loadModel("itemStatistics");
  2466. Doo::loadModel("statistics");
  2467. $statistics=new statistics();
  2468. $itemStatistics=new itemStatistics();
  2469. Doo::loadModel("receipt");
  2470. $receipt=new receipt();
  2471. Doo::loadModel("loanReceipt");
  2472. $loanReceipt=new loanReceipt();
  2473. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2474. if (empty($receiptDetail))
  2475. return "/approval";
  2476. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2477. $verifyString=$verifyDetail['staff'];
  2478. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2479. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2480. if(empty($opinion)){
  2481. if ($status==3)
  2482. $opinion="终止";
  2483. else
  2484. $opinion="同意支付";
  2485. }
  2486. $nowStaff=0;$nowStaffList=array();
  2487. if(empty($verifyStaff)){
  2488. //还需加入是否已经进入角色审批
  2489. if ($verifyDetail[0][1]=='ROLE'){
  2490. //print_r($verifyDetail);echo "ddd";
  2491. $vStaffString=json_decode($verifyDetail[0][3]);
  2492. foreach ($vStaffString as $key=>$value){
  2493. $staffK=explode("_", $value);
  2494. if ($staffK[0]!=$this->staff[0]['sid'])
  2495. array_push($nowStaffList, $staffK[0]);
  2496. }
  2497. //print_r($verifyDetail);
  2498. //die;
  2499. $nowStaff=implode(',', $nowStaffList);
  2500. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2501. }else{
  2502. if ($verifyDetail[1][1]=='ROLE'){
  2503. $vStaffString=json_decode($verifyDetail[1][3]);
  2504. //echo "dd";
  2505. foreach ($vStaffString as $key=>$value){
  2506. $staffK=explode("_", $value);
  2507. array_push($nowStaffList, $staffK[0]);
  2508. }
  2509. $nowStaff=implode(',', $nowStaffList);
  2510. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2511. }else{
  2512. $nowStaff=$verifyDetail[1][0];
  2513. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2514. }
  2515. }
  2516. if($status==3)
  2517. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2518. $vStaffString=json_encode($verifyStaff);
  2519. $receipt->nowStaff=$nowStaff;
  2520. $receipt->verifyStaff=$vStaffString;
  2521. $loanReceipt->nowStaff=$nowStaff;
  2522. $loanReceipt->verifyStaff=$vStaffString;
  2523. }else{
  2524. $VS=end($verifyStaff);
  2525. //非角色审批
  2526. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2527. $nextStaff=0;$roleSTF=false;
  2528. foreach ($verifyDetail as $key=>$value){
  2529. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2530. if (isset($verifyDetail[$key+1])){
  2531. $nextStaff=$verifyDetail[$key+1][0];
  2532. if ($verifyDetail[$key+1][1]=='ROLE')
  2533. $roleSTF=true;
  2534. }
  2535. break;
  2536. }
  2537. }
  2538. if (!$roleSTF){
  2539. $nowStaff=$nextStaff;
  2540. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2541. }else{
  2542. //获取角色下的所有用户ID
  2543. $nowStaffList=array();
  2544. foreach ($verifyDetail as $vfk){
  2545. if ($vfk[1]=='ROLE'){
  2546. $vStaffString=json_decode($vfk[3]);
  2547. foreach ($vStaffString as $key=>$value){
  2548. $staffK=explode("_", $value);
  2549. array_push($nowStaffList, $staffK[0]);
  2550. }
  2551. }
  2552. }
  2553. $nowStaff=implode(',', $nowStaffList);
  2554. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2555. }
  2556. if($status==3){
  2557. $verifyStaff['final']=$status;
  2558. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2559. }
  2560. $vStaffString=json_encode($verifyStaff);
  2561. $receipt->nowStaff=$nowStaff;
  2562. $receipt->verifyStaff=$vStaffString;
  2563. $loanReceipt->nowStaff=$nowStaff;
  2564. $loanReceipt->verifyStaff=$vStaffString;
  2565. }
  2566. //角色审批
  2567. if (isset($VS['ROLE'])){
  2568. //找出角色人 当前审批角色组
  2569. $verifyJSStaff=array();$nowStaffList2=array();
  2570. foreach ($verifyDetail as $key=>$value){
  2571. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2572. $verifyJSStaff=json_decode($value[3]);
  2573. foreach ($verifyJSStaff as $m){
  2574. $staffK=explode("_", $m);
  2575. array_push($nowStaffList2, $staffK[0]);
  2576. }
  2577. // print_r($nowStaffList2);
  2578. }
  2579. }
  2580. $RoleVerifyStaff=array();
  2581. foreach ($verifyStaff as $key=>$value){
  2582. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2583. foreach ($nowStaffList2 as $m) {
  2584. if ($key==$m."_R")
  2585. $RoleVerifyStaff[$key]=$value;
  2586. }
  2587. }
  2588. }
  2589. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2590. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2591. //下一个审批人ID
  2592. $nextStaff=0;$falg=false;
  2593. foreach ($verifyDetail as $key=>$value){
  2594. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2595. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2596. $falg=true;
  2597. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2598. foreach ($vStaffString as $v){
  2599. $staffK=explode("_", $v);
  2600. array_push($nowStaffList, $staffK[0]);
  2601. }
  2602. $nowStaff=implode(',', $nowStaffList);
  2603. $nextStaff=$verifyDetail[$key+1][0];
  2604. }elseif(isset($verifyDetail[$key+1])){
  2605. $nextStaff=$verifyDetail[$key+1][0];
  2606. $nowStaff=$nextStaff;
  2607. }else
  2608. $nowStaff='';
  2609. break;
  2610. }
  2611. }
  2612. if ($falg)
  2613. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2614. else
  2615. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2616. // print_r($verifyStaff);
  2617. // echo $nowStaff;die;
  2618. }else{ //进入下一个角色或者审批人
  2619. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2620. //
  2621. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2622. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2623. // print_r($verifyStaff);
  2624. // die;
  2625. }
  2626. if($status==3){
  2627. $verifyStaff['final']=$status;
  2628. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2629. }
  2630. $vStaffString=json_encode($verifyStaff);
  2631. $receipt->verifyStaff=$vStaffString;
  2632. $receipt->nowStaff=$nowStaff;
  2633. $loanReceipt->nowStaff=$nowStaff;
  2634. $loanReceipt->verifyStaff=$vStaffString;
  2635. //die;
  2636. //}
  2637. // print_r($verifyStaff);
  2638. // die;
  2639. }
  2640. //print_r($verifyStaff);die;
  2641. }
  2642. //print_r($verifyDetail);
  2643. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2644. foreach ($verifyDetail as $k=>$v){
  2645. if ($v[1]=='ROLE'){
  2646. $roleId=$v[0];
  2647. $roleVerify=json_decode($v[3],true);
  2648. $roleKey=$k;$roleArray=array();
  2649. foreach ($roleVerify as $o=>$p){
  2650. $staffID=explode ('_',$p);
  2651. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2652. array_push($roleArray, $exp);
  2653. }
  2654. $verifyDetailCopy[$v[0]]=$roleArray;
  2655. }
  2656. }
  2657. //print_r($verifyDetail);
  2658. foreach ($verifyDetailCopy as $k=>$v){
  2659. foreach ($verifyDetail as $m=>$n){
  2660. if ($n[0]==$k){
  2661. array_splice($verifyDetail,$m,1,$v);
  2662. }
  2663. }
  2664. }
  2665. //审批日志
  2666. if (!isset($verifyStaff['final'])){
  2667. Doo::loadModel("receiptLog");
  2668. $receiptLog=new receiptLog();
  2669. if (!empty($roleId)){
  2670. Doo::loadModel("role");
  2671. $role=new role();
  2672. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2673. $receiptLog->rolename=$roleInfo['name'];
  2674. }
  2675. $receiptLog->username=$this->staff[0]['username'];
  2676. $receiptLog->uid=$this->staff[0]['sid'];
  2677. $receiptLog->date=date("Y-m-d");
  2678. $receiptLog->opinion=$opinion;
  2679. $receiptLog->img=$this->staff[0]['avatar'];
  2680. $receiptLog->status=1;
  2681. $receiptLog->rid=$rid;
  2682. $receiptLog->insert();
  2683. }
  2684. if (isset($verifyStaff['final'])){//rDetail
  2685. $receipt->status=3;
  2686. $receipt->verifyBreakup=$verifyString;
  2687. $receiptDetailObj->status=3;
  2688. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2689. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2690. $receipt->status=6;
  2691. $receipt->pastDate=date("Y-m-d");
  2692. $receipt->isBK=1;
  2693. $loanReceipt->verifyBreakup=$verifyString;
  2694. $loanReceipt->status=1;
  2695. $loanReceipt->pastDate=date("Y-m-d");
  2696. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2697. }
  2698. $receipt->update(array('where'=>' rid = '.$rid));
  2699. return "/approvalExpenses/2";
  2700. }
  2701. }
  2702. function implement(){
  2703. Doo::loadModel('receipt');
  2704. $receipt=new receipt();
  2705. Doo::loadModel('L_category');
  2706. $Lcategory=new L_category();
  2707. Doo::loadModel('verify');
  2708. $verify=new verify();
  2709. Doo::loadModel('staff');
  2710. $staff=new staff();
  2711. Doo::loadModel("execute");
  2712. $execute=new execute();
  2713. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2714. Doo::loadModel('loanReceipt');
  2715. $loanReceipt=new loanReceipt();
  2716. //print_r($receiptList);
  2717. $loanList=array();
  2718. if (!isset($receiptList))
  2719. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2720. $Locate=0;$roleId=0;$button=0;
  2721. foreach ($loanList as $key=>$value){
  2722. $loanList[$key]['Locate']=$Locate;$Locate++;
  2723. $loanList[$key]['reviseDetail']=array();
  2724. if (!empty($value['reviseDetail']))
  2725. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2726. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2727. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2728. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2729. $loanList[$key]['category']=$categoryDetil['title'];
  2730. //检测编辑状态
  2731. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2732. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2733. $verifyStaff=json_decode($value['verifyStaff'],true);
  2734. Doo::loadModel('role');
  2735. $role=new role();
  2736. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2737. foreach ($verifyList as $k=>$v){
  2738. //init verifyStaff
  2739. if ($v[1]=='ROLE'){
  2740. if (!empty($verifyStaff)){
  2741. $endStaffArray=end($verifyStaff);
  2742. // if ($v[0]==$endStaffArray['nextStaff']){
  2743. // $roleId=$v[0];
  2744. // }
  2745. }
  2746. $roleVerify=json_decode($v[3],true);
  2747. $roleKey=$k;$roleArray=array();
  2748. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2749. foreach ($roleVerify as $o=>$p){
  2750. $staffID=explode ('_',$p);
  2751. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2752. //print_r($staffID);
  2753. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2754. array_push($roleArray, $exp);
  2755. }
  2756. $roleArrayCopy[$v[0]]=$roleArray;
  2757. //$verifyList[$k]['roleArray']=$roleArray;
  2758. }
  2759. $verifyList[$k]['date']="";
  2760. $verifyList[$k]['opinion']="";
  2761. $verifyList[$k]['status']="";
  2762. if (empty($verifyStaff)){
  2763. $verifyList[$k]['date']="";
  2764. $verifyList[$k]['opinion']="";
  2765. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2766. $verifyList[$k]['status']=4;
  2767. $flag=false;
  2768. }
  2769. }else{
  2770. foreach ($verifyStaff as $m=>$u){
  2771. if ($v[0]==$m){
  2772. $verifyList[$k]['date']=$u['date'];
  2773. $verifyList[$k]['opinion']=$u['opinion'];
  2774. $verifyList[$k]['status']=$u['status'];
  2775. $flag=false;
  2776. break;
  2777. }
  2778. }
  2779. $endStaffArray=end($verifyStaff);
  2780. if (isset($endStaffArray['ROLE'])){
  2781. }else{
  2782. // $endKey=key($verifyStaff);
  2783. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2784. // $button=4;
  2785. // $verifyList[$k]['status']=4;
  2786. // }
  2787. }
  2788. }
  2789. }
  2790. $rolename['name']='';
  2791. if (!empty($roleId)){
  2792. Doo::loadModel('role');
  2793. $role=new role();
  2794. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2795. }
  2796. if (!empty($verifyStaff))
  2797. $endStaffArray=end($verifyStaff);
  2798. $KOP=false;
  2799. foreach ($roleArrayCopy as $P=>$A){
  2800. foreach ( $A as $MKI=>$AVL){
  2801. if (!empty($verifyStaff)){
  2802. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2803. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2804. $button=4;
  2805. $roleArrayCopy[$P][$MKI]['status']=4;
  2806. }
  2807. foreach ($verifyStaff as $m=>$u){
  2808. $AVLFK=$AVL[0].'_R';
  2809. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2810. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2811. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2812. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2813. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2814. break;
  2815. }
  2816. }
  2817. }else{
  2818. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2819. $button=4;
  2820. $roleArrayCopy[$P][$MKI]['status']=4;
  2821. }
  2822. }
  2823. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2824. $KOP=true;
  2825. }
  2826. }
  2827. foreach ($roleArrayCopy as $k=>$v){
  2828. foreach ($verifyList as $m=>$n){
  2829. if ($n[0]==$k){
  2830. array_splice($verifyList,$m,1,$v);
  2831. }
  2832. }
  2833. }
  2834. $loanList[$key]['verifyList']=$verifyList;
  2835. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2836. }
  2837. $data['loanList']=$loanList;
  2838. $Locate=0;$roleId=0;$button=0;
  2839. foreach ($receiptList as $key=>$value){
  2840. $button2=0;
  2841. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2842. $receiptList[$key]['reviseDetail']=array();
  2843. if (!empty($value['reviseDetail']))
  2844. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2845. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2846. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2847. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2848. $receiptList[$key]['category']=$categoryDetil['title'];
  2849. $executeList=json_decode($value['executeCopy'],true);
  2850. $executeStaff=array();
  2851. if (!empty($value['executeStaff'] ))
  2852. $executeStaff=json_decode($value['executeStaff'],true);
  2853. if (isset($executeList)){
  2854. foreach ($executeList as $op=>$lo){
  2855. $executeList[$op]['date']="";
  2856. $executeList[$op]['opinion']="";
  2857. $executeList[$op]['status']="";
  2858. foreach ($executeStaff as $m=>$u){
  2859. if ($lo[0]==$m){
  2860. $executeList[$op]['date']=$u['date'];
  2861. $executeList[$op]['opinion']=$u['opinion'];
  2862. $executeList[$op]['status']=$u['status'];
  2863. break;
  2864. }
  2865. }
  2866. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2867. $button2=1;
  2868. $executeList[$op]['status']=4;
  2869. }
  2870. }
  2871. }
  2872. //检测编辑状态
  2873. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2874. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2875. $verifyStaff=json_decode($value['verifyStaff'],true);
  2876. Doo::loadModel('role');
  2877. $role=new role();
  2878. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2879. foreach ($verifyList as $k=>$v){
  2880. //init verifyStaff
  2881. if ($v[1]=='ROLE'){
  2882. if (!empty($verifyStaff)){
  2883. $endStaffArray=end($verifyStaff);
  2884. // if ($v[0]==$endStaffArray['nextStaff']){
  2885. // $roleId=$v[0];
  2886. // }
  2887. }
  2888. $roleVerify=json_decode($v[3],true);
  2889. $roleKey=$k;$roleArray=array();
  2890. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2891. foreach ($roleVerify as $o=>$p){
  2892. $staffID=explode ('_',$p);
  2893. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2894. //print_r($staffID);
  2895. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2896. array_push($roleArray, $exp);
  2897. }
  2898. $roleArrayCopy[$v[0]]=$roleArray;
  2899. //$verifyList[$k]['roleArray']=$roleArray;
  2900. }
  2901. $verifyList[$k]['date']="";
  2902. $verifyList[$k]['opinion']="";
  2903. $verifyList[$k]['status']="";
  2904. if (empty($verifyStaff)){
  2905. $verifyList[$k]['date']="";
  2906. $verifyList[$k]['opinion']="";
  2907. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2908. $verifyList[$k]['status']=4;
  2909. $flag=false;
  2910. }
  2911. }else{
  2912. foreach ($verifyStaff as $m=>$u){
  2913. if ($v[0]==$m){
  2914. $verifyList[$k]['date']=$u['date'];
  2915. $verifyList[$k]['opinion']=$u['opinion'];
  2916. $verifyList[$k]['status']=$u['status'];
  2917. $flag=false;
  2918. break;
  2919. }
  2920. }
  2921. $endStaffArray=end($verifyStaff);
  2922. if (isset($endStaffArray['ROLE'])){
  2923. }else{
  2924. }
  2925. }
  2926. }
  2927. $rolename['name']='';
  2928. if (!empty($roleId)){
  2929. Doo::loadModel('role');
  2930. $role=new role();
  2931. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2932. }
  2933. if (!empty($verifyStaff))
  2934. $endStaffArray=end($verifyStaff);
  2935. $KOP=false;
  2936. foreach ($roleArrayCopy as $P=>$A){
  2937. foreach ( $A as $MKI=>$AVL){
  2938. if (!empty($verifyStaff)){
  2939. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2940. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2941. $button=4;
  2942. $roleArrayCopy[$P][$MKI]['status']=4;
  2943. }
  2944. foreach ($verifyStaff as $m=>$u){
  2945. $AVLFK=$AVL[0].'_R';
  2946. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2947. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2948. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2949. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2950. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2951. break;
  2952. }
  2953. }
  2954. }else{
  2955. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2956. $button=4;
  2957. $roleArrayCopy[$P][$MKI]['status']=4;
  2958. }
  2959. }
  2960. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2961. $KOP=true;
  2962. }
  2963. }
  2964. foreach ($roleArrayCopy as $k=>$v){
  2965. foreach ($verifyList as $m=>$n){
  2966. if ($n[0]==$k){
  2967. array_splice($verifyList,$m,1,$v);
  2968. }
  2969. }
  2970. }
  2971. $receiptList[$key]['executeList']=$executeList;
  2972. $receiptList[$key]['verifyList']=$verifyList;
  2973. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2974. $receiptList[$key]['button2']=$button2;
  2975. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2976. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2977. $relust=$value['sum']-$value['loanSum'];
  2978. $receiptList[$key]['relust']=$relust;
  2979. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  2980. }
  2981. //print_r($receiptList[$key]['executeList']);
  2982. $data['receiptList']=$receiptList;
  2983. $data['memu']="receipt";
  2984. $data['staff']=$this->staff;
  2985. $data['receiptMemu']='implement';
  2986. $data['verifyId']=$this->verifyId;
  2987. $data['executeId']=$this->executeId;
  2988. $this->render ( "/admin/implement", $data );
  2989. }
  2990. function implementDo(){
  2991. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2992. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2993. if (!empty($rid)){
  2994. Doo::loadModel('receipt');
  2995. $receipt=new receipt();
  2996. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  2997. $executeCopy=json_decode($rinfo['executeCopy'],true);
  2998. $executeStaff=json_decode($rinfo['executeStaff'],true);
  2999. if(empty($executeStaff)){
  3000. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3001. }else{
  3002. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3003. }
  3004. if (count($executeStaff)==count($executeCopy)){
  3005. $receipt->executeStaff=json_encode($executeStaff);
  3006. $receipt->status=8;
  3007. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3008. $receipt->status=9;
  3009. $receipt->executeDate= date("Y-m-d");
  3010. }else{
  3011. $receipt->executeStaff=json_encode($executeStaff);
  3012. }
  3013. $receipt->update(array('where'=>'rid='.$rid));
  3014. }
  3015. return "/implement";
  3016. }
  3017. function receiptburEdi(){
  3018. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3019. $status=isset($this->params['status'])?$this->params['status']:'';
  3020. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3021. $month=$this->get_args('month')?$this->get_args('month'):"";
  3022. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3023. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3024. if (empty($status))
  3025. $status=$this->get_args('status')?$this->get_args('status'):2;
  3026. $vidList=array();
  3027. $button=0;
  3028. Doo::loadModel('verify');
  3029. Doo::loadModel('receipt');
  3030. Doo::loadModel('staff');
  3031. $staff=new staff();
  3032. $receipt=new receipt();
  3033. $verify=new verify();
  3034. Doo::loadModel('L_category');
  3035. $Lcategory=new L_category();
  3036. Doo::loadModel('enclosur');
  3037. $enclosur=new enclosur();
  3038. Doo::loadModel('loanReceipt');
  3039. $loanReceipt=new loanReceipt();
  3040. //user verify ID
  3041. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3042. foreach ($verifyDetail as $key=>$value){
  3043. array_push($vidList, $value['vid']);
  3044. }
  3045. $vid=implode(",", $vidList);
  3046. if(empty($verifyDetail))
  3047. $vid=0;
  3048. $categoryList=$Lcategory->find(array('asArray'=>true));
  3049. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3050. $ap="";
  3051. if($status==4){
  3052. $ap=4;$status=2;
  3053. }
  3054. //get Receipt By verifyID status 2
  3055. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3056. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3057. $Locate=0;$roleId=0;$button=0;
  3058. foreach ($loanList as $key=>$value){
  3059. $loanList[$key]['Locate']=$Locate;$Locate++;
  3060. $loanList[$key]['reviseDetail']=array();
  3061. if (!empty($value['reviseDetail']))
  3062. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3063. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3064. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3065. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3066. $loanList[$key]['category']=$categoryDetil['title'];
  3067. //检测编辑状态
  3068. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3069. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3070. $verifyStaff=json_decode($value['verifyStaff'],true);
  3071. Doo::loadModel('role');
  3072. $role=new role();
  3073. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3074. foreach ($verifyList as $k=>$v){
  3075. //init verifyStaff
  3076. if ($v[1]=='ROLE'){
  3077. if (!empty($verifyStaff)){
  3078. $endStaffArray=end($verifyStaff);
  3079. }
  3080. $roleVerify=json_decode($v[3],true);
  3081. $roleKey=$k;$roleArray=array();
  3082. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3083. foreach ($roleVerify as $o=>$p){
  3084. $staffID=explode ('_',$p);
  3085. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3086. //print_r($staffID);
  3087. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3088. array_push($roleArray, $exp);
  3089. }
  3090. $roleArrayCopy[$v[0]]=$roleArray;
  3091. //$verifyList[$k]['roleArray']=$roleArray;
  3092. }
  3093. $verifyList[$k]['date']="";
  3094. $verifyList[$k]['opinion']="";
  3095. $verifyList[$k]['status']="";
  3096. if (empty($verifyStaff)){
  3097. $verifyList[$k]['date']="";
  3098. $verifyList[$k]['opinion']="";
  3099. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3100. $verifyList[$k]['status']=4;
  3101. $flag=false;
  3102. }
  3103. }else{
  3104. foreach ($verifyStaff as $m=>$u){
  3105. if ($v[0]==$m){
  3106. $verifyList[$k]['date']=$u['date'];
  3107. $verifyList[$k]['opinion']=$u['opinion'];
  3108. $verifyList[$k]['status']=$u['status'];
  3109. $flag=false;
  3110. break;
  3111. }
  3112. }
  3113. $endStaffArray=end($verifyStaff);
  3114. if (isset($endStaffArray['ROLE'])){
  3115. }else{
  3116. }
  3117. }
  3118. }
  3119. $rolename['name']='';
  3120. if (!empty($roleId)){
  3121. Doo::loadModel('role');
  3122. $role=new role();
  3123. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3124. }
  3125. if (!empty($verifyStaff))
  3126. $endStaffArray=end($verifyStaff);
  3127. $KOP=false;
  3128. foreach ($roleArrayCopy as $P=>$A){
  3129. foreach ( $A as $MKI=>$AVL){
  3130. if (!empty($verifyStaff)){
  3131. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3132. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3133. $button=4;
  3134. $roleArrayCopy[$P][$MKI]['status']=4;
  3135. }
  3136. foreach ($verifyStaff as $m=>$u){
  3137. $AVLFK=$AVL[0].'_R';
  3138. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3139. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3140. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3141. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3142. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3143. break;
  3144. }
  3145. }
  3146. }else{
  3147. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3148. $button=4;
  3149. $roleArrayCopy[$P][$MKI]['status']=4;
  3150. }
  3151. }
  3152. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3153. $KOP=true;
  3154. }
  3155. }
  3156. foreach ($roleArrayCopy as $k=>$v){
  3157. foreach ($verifyList as $m=>$n){
  3158. if ($n[0]==$k){
  3159. array_splice($verifyList,$m,1,$v);
  3160. }
  3161. }
  3162. }
  3163. $loanList[$key]['verifyList']=$verifyList;
  3164. }
  3165. $htmlLoan='';
  3166. if (isset($loanList[0])){
  3167. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3168. if ($value['status']==1)
  3169. $htmlLoan.='<li class="done" >';
  3170. elseif ($value['status']==3)
  3171. $htmlLoan.='<li class="undone" >';
  3172. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3173. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3174. if (isset($value['rolename']))
  3175. $htmlLoan.=$value['rolename'];
  3176. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3177. }
  3178. $data['loanDate']=$loanList[0]['date'];
  3179. }
  3180. $data['htmlLoan']=$htmlLoan;
  3181. //print_r($loanList);
  3182. $Locate=0;$roleId=0;$button=0;
  3183. if($ap==4)
  3184. $status=4;
  3185. foreach ($receiptList as $key=>$value){
  3186. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3187. $receiptList[$key]['reviseDetail']=array();
  3188. if (!empty($value['reviseDetail']))
  3189. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3190. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3191. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3192. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3193. $receiptList[$key]['category']=$categoryDetil['title'];
  3194. //检测编辑状态
  3195. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3196. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3197. $verifyStaff=json_decode($value['verifyStaff'],true);
  3198. Doo::loadModel('role');
  3199. $role=new role();
  3200. //print_r($verifyList);
  3201. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3202. foreach ($verifyList as $k=>$v){
  3203. //init verifyStaff
  3204. if ($v[1]=='ROLE'){
  3205. if (!empty($verifyStaff)){
  3206. $endStaffArray=end($verifyStaff);
  3207. if ($v[0]==$endStaffArray['nextStaff']){
  3208. $roleId=$v[0];
  3209. }
  3210. }
  3211. $roleVerify=json_decode($v[3],true);
  3212. $roleKey=$k;$roleArray=array();
  3213. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3214. foreach ($roleVerify as $o=>$p){
  3215. $staffID=explode ('_',$p);
  3216. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3217. //print_r($staffID);
  3218. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3219. array_push($roleArray, $exp);
  3220. }
  3221. $roleArrayCopy[$v[0]]=$roleArray;
  3222. //$verifyList[$k]['roleArray']=$roleArray;
  3223. }
  3224. //print_r($roleArray);
  3225. $verifyList[$k]['date']="";
  3226. $verifyList[$k]['opinion']="";
  3227. $verifyList[$k]['status']="";
  3228. if (empty($verifyStaff)){
  3229. $verifyList[$k]['date']="";
  3230. $verifyList[$k]['opinion']="";
  3231. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3232. $verifyList[$k]['status']=4;
  3233. $button=4;$flag=false;
  3234. }
  3235. }else{
  3236. foreach ($verifyStaff as $m=>$u){
  3237. if ($v[0]==$m){
  3238. $verifyList[$k]['date']=$u['date'];
  3239. $verifyList[$k]['opinion']=$u['opinion'];
  3240. $verifyList[$k]['status']=$u['status'];
  3241. $flag=false;
  3242. break;
  3243. }
  3244. }
  3245. $endStaffArray=end($verifyStaff);
  3246. if (isset($endStaffArray['ROLE'])){
  3247. }else{
  3248. $endKey=key($verifyStaff);
  3249. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3250. $button=4;
  3251. $verifyList[$k]['status']=4;
  3252. }
  3253. }
  3254. }
  3255. }
  3256. $rolename['name']='';
  3257. if (!empty($roleId)){
  3258. Doo::loadModel('role');
  3259. $role=new role();
  3260. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3261. }
  3262. if (!empty($verifyStaff))
  3263. $endStaffArray=end($verifyStaff);
  3264. $KOP=false;
  3265. foreach ($roleArrayCopy as $P=>$A){
  3266. foreach ( $A as $MKI=>$AVL){
  3267. if (!empty($verifyStaff)){
  3268. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3269. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3270. $button=4;
  3271. $roleArrayCopy[$P][$MKI]['status']=4;
  3272. }
  3273. foreach ($verifyStaff as $m=>$u){
  3274. $AVLFK=$AVL[0].'_R';
  3275. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3276. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3277. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3278. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3279. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3280. break;
  3281. }
  3282. }
  3283. }else{
  3284. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3285. $button=4;
  3286. $roleArrayCopy[$P][$MKI]['status']=4;
  3287. }
  3288. }
  3289. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3290. $KOP=true;
  3291. }
  3292. }
  3293. foreach ($roleArrayCopy as $k=>$v){
  3294. foreach ($verifyList as $m=>$n){
  3295. if ($n[0]==$k){
  3296. array_splice($verifyList,$m,1,$v);
  3297. }
  3298. }
  3299. }
  3300. //print_r($verifyList);
  3301. $receiptList[$key]['verifyList']=$verifyList;
  3302. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3303. $receiptList[$key]['button']=$button;
  3304. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3305. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3306. $relust=$value['sum']-$value['loanSum'];
  3307. $receiptList[$key]['relust']=$relust;
  3308. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3309. }
  3310. //print_r($receiptList);die;
  3311. //$data['verifyDetail']=$verifyDetail;
  3312. $mothHtml="";
  3313. for($i=1;$i<=12;$i++){
  3314. if($month==$i)
  3315. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3316. else
  3317. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3318. }
  3319. //获取审批日志
  3320. Doo::loadModel('receiptLog');
  3321. $receiptLog=new receiptLog();
  3322. $rlList=array();
  3323. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3324. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3325. if (!empty($rlInfo)){
  3326. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3327. }
  3328. //echo $rid;
  3329. //print_r($receiptList);
  3330. $receiptList[0]['rlList']=$rlList;
  3331. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3332. $enclosurHtml='';
  3333. foreach ($enclosurList as $value){
  3334. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3335. }
  3336. $data['enclosurHtml']=$enclosurHtml;
  3337. $data['rolename']=$rolename['name'];
  3338. // $data['datetij']=$tijdate['date'];
  3339. $data['mothHtml']=$mothHtml;
  3340. //print_r($receiptList);
  3341. $data['rid']=$rid;
  3342. $data['tijdate']=$tijdate['date'];
  3343. $data['receiptList']=$receiptList;
  3344. $data['receiptApprovalCount']=count($receiptList);
  3345. $data['status']=$status;
  3346. $data['year']=$year;
  3347. $data['categoryList']=$categoryList;
  3348. $data['staffList']=$staffList;
  3349. $data['cid']=$cid;
  3350. $data['sid']=$sid;
  3351. $data['ap']=$ap;
  3352. $data['memu']="receipt";
  3353. $data['staff']=$this->staff;
  3354. $data['receiptMemu']='approvalExpenses';
  3355. $data['verifyId']=$this->verifyId;
  3356. $data['executeId']=$this->executeId;
  3357. $this->render ( "/admin/receiptburEdi", $data );
  3358. }
  3359. function hisImplement(){
  3360. $item=isset($this->params['item'])?$this->params['item']:"";
  3361. if(empty($item))
  3362. $item=$this->get_args('item')?$this->get_args('item'):"";
  3363. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3364. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3365. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3366. $sop=$this->get_args('sop')?$this->get_args('sop'):'SOP';
  3367. Doo::loadModel('receipt');
  3368. $receipt=new receipt();
  3369. Doo::loadModel('L_category');
  3370. $Lcategory=new L_category();
  3371. Doo::loadModel('verify');
  3372. Doo::loadModel('statistics');
  3373. $statistics=new statistics();
  3374. $verify=new verify();
  3375. Doo::loadModel('staff');
  3376. $staff=new staff();
  3377. $condition="";
  3378. if($item=="expenses")
  3379. $condition=" and Rtype=1 ";
  3380. elseif ($item=="receipts")
  3381. $condition=" and Rtype=0 ";
  3382. elseif ($item=="remits")
  3383. $condition=" and Rtype=2 ";
  3384. $sopString="";
  3385. $dateCondition=" and Year(executeDate) =".$year;
  3386. if($moth!='MONTH'){
  3387. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3388. }
  3389. if($day!='DAY')
  3390. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3391. if ($sop!='SOP')
  3392. $sopString=" and staff=".$sop;
  3393. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3394. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition.$sopString,'desc'=>'rid','asArray'=>true));
  3395. //员工筛选
  3396. $receiptList2=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3397. $sopStaff=array();
  3398. foreach ($receiptList2 as $key=>$value){
  3399. $staffDetail=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3400. $sopStaff[$value['staff']]=$staffDetail['username'];
  3401. }
  3402. $Locate=0;$roleId=0;$button=0;
  3403. foreach ($receiptList as $key=>$value){
  3404. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3405. $receiptList[$key]['reviseDetail']=array();
  3406. if (!empty($value['reviseDetail']))
  3407. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3408. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3409. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3410. $receiptList[$key]['category']=$categoryDetil['title'];
  3411. //检测编辑状态
  3412. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3413. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3414. $verifyStaff=json_decode($value['verifyStaff'],true);
  3415. Doo::loadModel('role');
  3416. $role=new role();
  3417. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3418. foreach ($verifyList as $k=>$v){
  3419. //init verifyStaff
  3420. if ($v[1]=='ROLE'){
  3421. if (!empty($verifyStaff)){
  3422. $endStaffArray=end($verifyStaff);
  3423. }
  3424. $roleVerify=json_decode($v[3],true);
  3425. $roleKey=$k;$roleArray=array();
  3426. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3427. foreach ($roleVerify as $o=>$p){
  3428. $staffID=explode ('_',$p);
  3429. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3430. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3431. array_push($roleArray, $exp);
  3432. }
  3433. $roleArrayCopy[$v[0]]=$roleArray;
  3434. }
  3435. $verifyList[$k]['date']="";
  3436. $verifyList[$k]['opinion']="";
  3437. $verifyList[$k]['status']="";
  3438. if (empty($verifyStaff)){
  3439. $verifyList[$k]['date']="";
  3440. $verifyList[$k]['opinion']="";
  3441. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3442. $verifyList[$k]['status']=4;
  3443. $flag=false;
  3444. }
  3445. }else{
  3446. foreach ($verifyStaff as $m=>$u){
  3447. if ($v[0]==$m){
  3448. $verifyList[$k]['date']=$u['date'];
  3449. $verifyList[$k]['opinion']=$u['opinion'];
  3450. $verifyList[$k]['status']=$u['status'];
  3451. $flag=false;
  3452. break;
  3453. }
  3454. }
  3455. $endStaffArray=end($verifyStaff);
  3456. }
  3457. }
  3458. $rolename['name']='';
  3459. if (!empty($roleId)){
  3460. Doo::loadModel('role');
  3461. $role=new role();
  3462. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3463. }
  3464. if (!empty($verifyStaff))
  3465. $endStaffArray=end($verifyStaff);
  3466. $KOP=false;
  3467. foreach ($roleArrayCopy as $P=>$A){
  3468. foreach ( $A as $MKI=>$AVL){
  3469. if (!empty($verifyStaff)){
  3470. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3471. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3472. $button=4;
  3473. $roleArrayCopy[$P][$MKI]['status']=4;
  3474. }
  3475. foreach ($verifyStaff as $m=>$u){
  3476. $AVLFK=$AVL[0].'_R';
  3477. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3478. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3479. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3480. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3481. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3482. break;
  3483. }
  3484. }
  3485. }else{
  3486. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3487. $button=4;
  3488. $roleArrayCopy[$P][$MKI]['status']=4;
  3489. }
  3490. }
  3491. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3492. $KOP=true;
  3493. }
  3494. }
  3495. foreach ($roleArrayCopy as $k=>$v){
  3496. foreach ($verifyList as $m=>$n){
  3497. if ($n[0]==$k){
  3498. array_splice($verifyList,$m,1,$v);
  3499. }
  3500. }
  3501. }
  3502. $receiptList[$key]['verifyList']=$verifyList;
  3503. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3504. $receiptList[$key]['button']=$button;
  3505. }
  3506. //print_r($sopStaff);
  3507. $mothHtml="";
  3508. for($i=1;$i<=12;$i++){
  3509. if($moth==$i)
  3510. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3511. else
  3512. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3513. }
  3514. $dayHtml="";
  3515. if ($day!="DAY"||$moth!="MONTH"){
  3516. for($i = 1; $i <= 31; $i ++) {
  3517. if($day==$i)
  3518. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3519. else
  3520. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3521. }
  3522. }
  3523. $sopHtml="";
  3524. foreach ($sopStaff as $key=>$value){
  3525. if($sop==$key)
  3526. $sopHtml.='<option value="'.$key.'" selected >'.$value.'</option>';
  3527. else
  3528. $sopHtml.='<option value="'.$key.'" >'.$value.'</option>';
  3529. }
  3530. $data['sopHtml']=$sopHtml;
  3531. $data['dayHtml']=$dayHtml;
  3532. $data['mothHtml']=$mothHtml;
  3533. $data['receiptList']=$receiptList;
  3534. $data['memu']="receipt";
  3535. $data['staff']=$this->staff;
  3536. $data['receiptMemu']='implement';
  3537. $data['verifyId']=$this->verifyId;
  3538. $data['executeId']=$this->executeId;
  3539. $data['item']=$item;
  3540. $data['year']=$year;
  3541. $data['moth']=$moth;
  3542. $data['day']=$day;
  3543. $data['sop']=$sop;
  3544. $this->render ( "/admin/hisImplement", $data );
  3545. }
  3546. function ajaxExamine(){
  3547. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3548. Doo::loadModel('receipt');
  3549. $receipt=new receipt();
  3550. if (!empty($rid)){
  3551. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) and rid!='.$rid
  3552. ,'asArray'=>true));
  3553. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3554. }
  3555. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3556. }
  3557. function myReceipt(){
  3558. //all approval past withdraw
  3559. $item=isset($this->params['item'])?$this->params['item']:"";
  3560. if(empty($item))
  3561. $item=$this->get_args('item')?$this->get_args('item'):"";
  3562. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3563. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3564. Doo::loadModel('receipt');
  3565. $receipt=new receipt();
  3566. //pre-loaded
  3567. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3568. //have cache
  3569. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3570. if(!empty($moth))//yearPage
  3571. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3572. $this->showCache($path);
  3573. }
  3574. Doo::loadModel('L_category');
  3575. $Lcategory=new L_category();
  3576. Doo::loadModel('verify');
  3577. Doo::loadModel('statistics');
  3578. $statistics=new statistics();
  3579. $verify=new verify();
  3580. Doo::loadModel('staff');
  3581. $staff=new staff();
  3582. $condition=" and status!=0 ";
  3583. if($item=="approval")
  3584. $condition=" and status=2 ";
  3585. elseif ($item=="withdraw")
  3586. $condition=" and status=3 ";
  3587. elseif ($item=="past")
  3588. $condition=" and status=1 ";
  3589. elseif ($item=="whdw")
  3590. $condition=" and status=4 ";
  3591. $dateCondition=" and Year(date) =".$year;
  3592. if(!empty($moth)){
  3593. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3594. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3595. }else
  3596. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3597. if(empty($stList))
  3598. $stList=array('rePrice'=>0,'agPrice'=>0);
  3599. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3600. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3601. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3602. $Locate=0;$roleId=0;$button=0;
  3603. foreach ($receiptList as $key=>$value){
  3604. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3605. $receiptList[$key]['reviseDetail']=array();
  3606. if (!empty($value['reviseDetail']))
  3607. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3608. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3609. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3610. $receiptList[$key]['category']=$categoryDetil['title'];
  3611. //检测编辑状态
  3612. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3613. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3614. $verifyStaff=json_decode($value['verifyStaff'],true);
  3615. Doo::loadModel('role');
  3616. $role=new role();
  3617. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3618. foreach ($verifyList as $k=>$v){
  3619. //init verifyStaff
  3620. if ($v[1]=='ROLE'){
  3621. if (!empty($verifyStaff)){
  3622. $endStaffArray=end($verifyStaff);
  3623. // if ($v[0]==$endStaffArray['nextStaff']){
  3624. // $roleId=$v[0];
  3625. // }
  3626. }
  3627. $roleVerify=json_decode($v[3],true);
  3628. $roleKey=$k;$roleArray=array();
  3629. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3630. foreach ($roleVerify as $o=>$p){
  3631. $staffID=explode ('_',$p);
  3632. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3633. //print_r($staffID);
  3634. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3635. array_push($roleArray, $exp);
  3636. }
  3637. $roleArrayCopy[$v[0]]=$roleArray;
  3638. //$verifyList[$k]['roleArray']=$roleArray;
  3639. }
  3640. $verifyList[$k]['date']="";
  3641. $verifyList[$k]['opinion']="";
  3642. $verifyList[$k]['status']="";
  3643. if (empty($verifyStaff)){
  3644. $verifyList[$k]['date']="";
  3645. $verifyList[$k]['opinion']="";
  3646. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3647. $verifyList[$k]['status']=4;
  3648. $flag=false;
  3649. }
  3650. }else{
  3651. foreach ($verifyStaff as $m=>$u){
  3652. if ($v[0]==$m){
  3653. $verifyList[$k]['date']=$u['date'];
  3654. $verifyList[$k]['opinion']=$u['opinion'];
  3655. $verifyList[$k]['status']=$u['status'];
  3656. $flag=false;
  3657. break;
  3658. }
  3659. }
  3660. $endStaffArray=end($verifyStaff);
  3661. if (isset($endStaffArray['ROLE'])){
  3662. }else{
  3663. // $endKey=key($verifyStaff);
  3664. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3665. // $button=4;
  3666. // $verifyList[$k]['status']=4;
  3667. // }
  3668. }
  3669. }
  3670. }
  3671. $rolename['name']='';
  3672. if (!empty($roleId)){
  3673. Doo::loadModel('role');
  3674. $role=new role();
  3675. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3676. }
  3677. if (!empty($verifyStaff))
  3678. $endStaffArray=end($verifyStaff);
  3679. $KOP=false;
  3680. foreach ($roleArrayCopy as $P=>$A){
  3681. foreach ( $A as $MKI=>$AVL){
  3682. if (!empty($verifyStaff)){
  3683. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3684. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3685. $button=4;
  3686. $roleArrayCopy[$P][$MKI]['status']=4;
  3687. }
  3688. foreach ($verifyStaff as $m=>$u){
  3689. $AVLFK=$AVL[0].'_R';
  3690. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3691. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3692. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3693. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3694. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3695. break;
  3696. }
  3697. }
  3698. }else{
  3699. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3700. $button=4;
  3701. $roleArrayCopy[$P][$MKI]['status']=4;
  3702. }
  3703. }
  3704. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3705. $KOP=true;
  3706. }
  3707. }
  3708. foreach ($roleArrayCopy as $k=>$v){
  3709. foreach ($verifyList as $m=>$n){
  3710. if ($n[0]==$k){
  3711. array_splice($verifyList,$m,1,$v);
  3712. }
  3713. }
  3714. }
  3715. $receiptList[$key]['verifyList']=$verifyList;
  3716. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3717. $receiptList[$key]['button']=$button;
  3718. }
  3719. //print_r($receiptList);die;
  3720. $mothHtml="";
  3721. for($i=1;$i<=12;$i++){
  3722. if($moth==$i)
  3723. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3724. else
  3725. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3726. }
  3727. $data['mothHtml']=$mothHtml;
  3728. $data['receiptList']=$receiptList;
  3729. $data['memu']="receipt";
  3730. $data['staff']=$this->staff;
  3731. $data['receiptMemu']='receipt';
  3732. $data['verifyId']=$this->verifyId;
  3733. $data['executeId']=$this->executeId;
  3734. $data['item']=$item;
  3735. $data['year']=$year;
  3736. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3737. //sufficient condition to generate cache
  3738. if(empty($moth)&&($year<date("Y"))){
  3739. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3740. if(empty($receiptList)){ //generated files
  3741. ob_start();
  3742. $this->render ( "/admin/saea_myList", $data );
  3743. $this->cacheFile($path);die;
  3744. // $content = ob_get_contents();
  3745. // $fp = fopen($path, "w");
  3746. // fwrite($fp, $content);
  3747. // fclose($fp);
  3748. }
  3749. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3750. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$moth,'asArray'=>true));
  3751. if(empty($receiptList)){ //generated files
  3752. ob_start();
  3753. $this->render ( "/admin/saea_myList", $data );
  3754. $this->cacheFile($path);die;
  3755. }
  3756. }
  3757. }
  3758. $this->render ( "/admin/saea_myList", $data );
  3759. }
  3760. function saeaCreate(){
  3761. Doo::loadModel('accountItem');
  3762. Doo::loadModel('verify');
  3763. Doo::loadModel('receipt');
  3764. Doo::loadModel('L_category');
  3765. $lCategory=new L_category();
  3766. $receipt=new receipt();
  3767. $verify=new verify();
  3768. $accountItem=new accountItem();
  3769. Doo::loadModel("role");
  3770. $role=new role();
  3771. $acItem=$accountItem->find(array('asArray'=>true));
  3772. $veList=$verify->find(array('asArray'=>true));
  3773. foreach ($veList as $key=>$value){
  3774. $v=json_decode($value['staff']);
  3775. $list=array();
  3776. foreach ($v as $n=>$m){
  3777. if ($m['1']=='ROLE'){
  3778. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3779. $v[$n][1]=$roleInfo['name'];
  3780. array_push($list, $roleInfo['name']);
  3781. }else{
  3782. array_push($list, $v[$n][1]);
  3783. }
  3784. }
  3785. $veList[$key]['staff']=implode('>', $list);
  3786. }
  3787. $data['category']=$lCategory->find(array('asArray'=>true));
  3788. $data['veList']=$veList;
  3789. $data['acItem']=$acItem;
  3790. $data['memu']="receipt";
  3791. $data['staff']=$this->staff;
  3792. $data['receiptMemu']='saeaBorad';
  3793. $data['verifyId']=$this->verifyId;
  3794. $data['executeId']=$this->executeId;
  3795. $this->render ( "/admin/saea_create", $data );
  3796. }
  3797. function addReceipt(){
  3798. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3799. $agency=$this->get_args('agency');
  3800. $travel=$this->get_args('travel');
  3801. $train=$this->get_args('train');
  3802. $other=$this->get_args('other');
  3803. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3804. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3805. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3806. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3807. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3808. Doo::loadModel('receipt');
  3809. Doo::loadModel('receiptDetail');
  3810. Doo::loadModel('accountItem');
  3811. $accountItem=new accountItem();
  3812. $receipt=new receipt();
  3813. Doo::loadModel('enclosur');
  3814. Doo::loadModel('execute');
  3815. $execute=new execute();
  3816. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3817. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3818. // if(!empty($receiptDetail))
  3819. // return "/referReceipt/".$receiptDetail['rid'];
  3820. $aItem=$accountItem->find(array('asArray'=>true));
  3821. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3822. $ag=$tr=$ta=$ot=0;
  3823. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3824. foreach ($aItem as $key=>$value){
  3825. if ($value['category']==$this->AGENCY){
  3826. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3827. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3828. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3829. }
  3830. $ag++;
  3831. }
  3832. if($value['category']==$this->TRAVEL){
  3833. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3834. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3835. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3836. }
  3837. $tr++;
  3838. }
  3839. if($value['category']==$this->TRAIN){
  3840. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3841. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3842. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3843. }
  3844. $ta++;
  3845. }
  3846. if($value['category']==$this->OTHER){
  3847. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3848. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3849. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3850. }
  3851. $ot++;
  3852. }
  3853. }
  3854. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3855. //报销单
  3856. $receipt->accountItem=json_encode($accountJson);
  3857. $receipt->staff=$this->staff[0]['sid'];
  3858. $receipt->sum=number_format($sum, 2, '.', '');
  3859. $receipt->date=date("Y-m-d");
  3860. $receipt->cid=$cid;
  3861. $receipt->status=5;
  3862. //修改审批流程加入角色
  3863. $receipt->verify=$verify;
  3864. $receipt->executeCopy=$executeDetail['staff'];
  3865. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3866. $receipt->explanation=$explanation;
  3867. $rid=$receipt->insert();
  3868. //附件
  3869. if (!empty($enclosurName)){
  3870. $enclosurArray=explode('-', $enclosurName);
  3871. foreach ($enclosurArray as $value){
  3872. $enclosur=new enclosur();
  3873. $enclosur->name=$value;
  3874. $enclosur->rid=$rid;
  3875. $enclosur->insert();
  3876. }
  3877. //print_r($enclosurArray);die;
  3878. }
  3879. //报销详情
  3880. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3881. $receiptDetail=new receiptDetail();
  3882. $receiptDetail->staff=$this->staff[0]['sid'];
  3883. $receiptDetail->item=$value['name'];
  3884. $receiptDetail->itemCategory=$this->AGENCY;
  3885. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3886. $receiptDetail->date=date("Y-m-d");
  3887. $receiptDetail->cid=$cid;
  3888. $receiptDetail->rid=$rid;
  3889. $receiptDetail->status=4;
  3890. $receiptDetail->insert();
  3891. }
  3892. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3893. $receiptDetail=new receiptDetail();
  3894. $receiptDetail->staff=$this->staff[0]['sid'];
  3895. $receiptDetail->item=$value['name'];
  3896. $receiptDetail->itemCategory=$this->TRAVEL;
  3897. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3898. $receiptDetail->date=date("Y-m-d");
  3899. $receiptDetail->cid=$cid;
  3900. $receiptDetail->rid=$rid;
  3901. $receiptDetail->status=4;
  3902. $receiptDetail->insert();
  3903. }
  3904. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3905. $receiptDetail=new receiptDetail();
  3906. $receiptDetail->staff=$this->staff[0]['sid'];
  3907. $receiptDetail->item=$value['name'];
  3908. $receiptDetail->itemCategory=$this->TRAIN;
  3909. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3910. $receiptDetail->date=date("Y-m-d");
  3911. $receiptDetail->cid=$cid;
  3912. $receiptDetail->rid=$rid;
  3913. $receiptDetail->status=4;
  3914. $receiptDetail->insert();
  3915. }
  3916. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3917. $receiptDetail=new receiptDetail();
  3918. $receiptDetail->staff=$this->staff[0]['sid'];
  3919. $receiptDetail->item=$value['name'];
  3920. $receiptDetail->itemCategory=$this->OTHER;
  3921. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3922. $receiptDetail->date=date("Y-m-d");
  3923. $receiptDetail->cid=$cid;
  3924. $receiptDetail->rid=$rid;
  3925. $receiptDetail->status=4;
  3926. $receiptDetail->insert();
  3927. }
  3928. //return "/referReceipt/".$rid;
  3929. }
  3930. return "/saeaBorad";
  3931. }
  3932. function referReceipt(){
  3933. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3934. Doo::loadModel('receipt');
  3935. Doo::loadModel('verify');
  3936. $verify=new verify();
  3937. $receipt=new receipt();
  3938. Doo::loadModel('L_category');
  3939. $lCategory=new L_category();
  3940. Doo::loadModel("role");
  3941. $role=new role();
  3942. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  3943. if(empty($receiptDetail))
  3944. return "/addReceipt";
  3945. foreach ($receiptDetail as $key=>$value){
  3946. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  3947. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3948. $v=json_decode($veList['staff']);
  3949. array_push($v[0], $veList['description']);
  3950. foreach ($v as $n=>$m){
  3951. if ($m['1']=='ROLE'){
  3952. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3953. $v[$n][1]=$roleInfo['name'];
  3954. }
  3955. }
  3956. $receiptDetail[$key]['staff']=$v;
  3957. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3958. $receiptDetail[$key]['category']=$category['title'];
  3959. }
  3960. //print_r($receiptDetail);
  3961. $data['receiptDetail']=$receiptDetail;
  3962. $data['memu']="receipt";
  3963. $data['staff']=$this->staff;
  3964. $data['receiptMemu']='saeaCreate';
  3965. $data['verifyId']=$this->verifyId;
  3966. $data['executeId']=$this->executeId;
  3967. $this->render ( "/admin/saea_confirm", $data );
  3968. }
  3969. function editReceipt(){
  3970. //edit status 4
  3971. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3972. //echo $rid;
  3973. Doo::loadModel('accountItem');
  3974. Doo::loadModel('verify');
  3975. Doo::loadModel('receipt');
  3976. $receipt=new receipt();
  3977. $verify=new verify();
  3978. $accountItem=new accountItem();
  3979. Doo::loadModel('L_category');
  3980. $lCategory=new L_category();
  3981. Doo::loadModel("role");
  3982. $role=new role();
  3983. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  3984. if(empty($receiptDetail))
  3985. return "/saeaCreate";
  3986. $acItem=$accountItem->find(array('asArray'=>true));
  3987. $veList=$verify->find(array('asArray'=>true));
  3988. foreach ($veList as $key=>$value){
  3989. $v=json_decode($value['staff']);
  3990. $list=array();
  3991. foreach ($v as $n=>$m){
  3992. if ($m['1']=='ROLE'){
  3993. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3994. $v[$n][1]=$roleInfo['name'];
  3995. array_push($list, $roleInfo['name']);
  3996. }else{
  3997. array_push($list, $v[$n][1]);
  3998. }
  3999. }
  4000. $veList[$key]['staff']=implode('>', $list);
  4001. }
  4002. //配置编辑信息
  4003. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4004. foreach ($acItem as $key=>$value){
  4005. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4006. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4007. $acItem[$key]['price']=$v['price'];
  4008. }
  4009. }
  4010. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4011. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4012. $acItem[$key]['price']=$v['price'];
  4013. }
  4014. }
  4015. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4016. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4017. $acItem[$key]['price']=$v['price'];
  4018. }
  4019. }
  4020. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4021. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4022. $acItem[$key]['price']=$v['price'];
  4023. }
  4024. }
  4025. }
  4026. $data['category']=$lCategory->find(array('asArray'=>true));
  4027. $data['cSum']=$accountItemList['cSum'];
  4028. $data['sum']=$receiptDetail['sum'];
  4029. $data['receiptDetail']=$receiptDetail;
  4030. $data['veList']=$veList;
  4031. $data['acItem']=$acItem;
  4032. $data['memu']="receipt";
  4033. $data['staff']=$this->staff;
  4034. $data['receiptMemu']='saeaBorad';
  4035. $data['verify']=$receiptDetail['verify'];
  4036. $data['verifyId']=$this->verifyId;
  4037. $data['executeId']=$this->executeId;
  4038. $data['rid']=$rid;
  4039. $this->render ( "/admin/saea_edit", $data );
  4040. }
  4041. function updateReceipt(){
  4042. $agency=$this->get_args('agency');
  4043. $travel=$this->get_args('travel');
  4044. $train=$this->get_args('train');
  4045. $other=$this->get_args('other');
  4046. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4047. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4048. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4049. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4050. if(!empty($verify)&&!empty($explanation)){
  4051. Doo::loadModel('receipt');
  4052. Doo::loadModel('receiptDetail');
  4053. Doo::loadModel('accountItem');
  4054. $accountItem=new accountItem();
  4055. $receipt=new receipt();
  4056. Doo::loadModel('execute');
  4057. $execute=new execute();
  4058. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4059. if(empty($receiptDetail))
  4060. return "/saeaBorad";
  4061. if ($receiptDetail['Rtype']==1)
  4062. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4063. else
  4064. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4065. $aItem=$accountItem->find(array('asArray'=>true));
  4066. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4067. $ag=$tr=$ta=$ot=0;
  4068. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4069. foreach ($aItem as $key=>$value){
  4070. if ($value['category']==$this->AGENCY){
  4071. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4072. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4073. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4074. }
  4075. $ag++;
  4076. }
  4077. if($value['category']==$this->TRAVEL){
  4078. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4079. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4080. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4081. }
  4082. $tr++;
  4083. }
  4084. if($value['category']==$this->TRAIN){
  4085. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4086. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4087. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4088. }
  4089. $ta++;
  4090. }
  4091. if($value['category']==$this->OTHER){
  4092. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4093. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4094. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4095. }
  4096. $ot++;
  4097. }
  4098. }
  4099. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4100. //报销单
  4101. $rid=$receipt->rid=$receiptDetail['rid'];
  4102. $receipt->accountItem=json_encode($accountJson);
  4103. $receipt->staff=$this->staff[0]['sid'];
  4104. $receipt->sum=number_format($sum, 2, '.', '');
  4105. $receipt->date=date("Y-m-d");
  4106. $receipt->cid=$cid;
  4107. if (($receiptDetail['status']!=4)){
  4108. if ($receiptDetail['Rtype']==1)
  4109. $receipt->status=7;
  4110. else
  4111. $receipt->status=5;
  4112. }
  4113. $receipt->verify=$verify;
  4114. $receipt->executeCopy=$executeDetail['staff'];
  4115. $receipt->explanation=$explanation;
  4116. $receipt->update();
  4117. $receiptDetail=new receiptDetail();
  4118. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4119. //报销详情
  4120. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4121. $receiptDetail=new receiptDetail();
  4122. $receiptDetail->staff=$this->staff[0]['sid'];
  4123. $receiptDetail->item=$value['name'];
  4124. $receiptDetail->itemCategory=$this->AGENCY;
  4125. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4126. $receiptDetail->date=date("Y-m-d");
  4127. $receiptDetail->cid=$cid;
  4128. $receiptDetail->rid=$rid;
  4129. $receiptDetail->status=4;
  4130. $receiptDetail->insert();
  4131. }
  4132. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4133. $receiptDetail=new receiptDetail();
  4134. $receiptDetail->staff=$this->staff[0]['sid'];
  4135. $receiptDetail->item=$value['name'];
  4136. $receiptDetail->itemCategory=$this->TRAVEL;
  4137. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4138. $receiptDetail->date=date("Y-m-d");
  4139. $receiptDetail->cid=$cid;
  4140. $receiptDetail->rid=$rid;
  4141. $receiptDetail->status=4;
  4142. $receiptDetail->insert();
  4143. }
  4144. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4145. $receiptDetail=new receiptDetail();
  4146. $receiptDetail->staff=$this->staff[0]['sid'];
  4147. $receiptDetail->item=$value['name'];
  4148. $receiptDetail->itemCategory=$this->TRAIN;
  4149. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4150. $receiptDetail->date=date("Y-m-d");
  4151. $receiptDetail->cid=$cid;
  4152. $receiptDetail->rid=$rid;
  4153. $receiptDetail->status=4;
  4154. $receiptDetail->insert();
  4155. }
  4156. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4157. $receiptDetail=new receiptDetail();
  4158. $receiptDetail->staff=$this->staff[0]['sid'];
  4159. $receiptDetail->item=$value['name'];
  4160. $receiptDetail->itemCategory=$this->OTHER;
  4161. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4162. $receiptDetail->date=date("Y-m-d");
  4163. $receiptDetail->cid=$cid;
  4164. $receiptDetail->rid=$rid;
  4165. $receiptDetail->status=4;
  4166. $receiptDetail->insert();
  4167. }
  4168. //return "/referReceipt/".$rid;
  4169. }
  4170. return "/saeaBorad";
  4171. }
  4172. function approvedReceipt(){
  4173. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4174. Doo::loadModel('receipt');
  4175. Doo::loadModel('receiptDetail');
  4176. $receipt=new receipt();
  4177. $receiptDetail=new receiptDetail();
  4178. Doo::loadModel('statistics');
  4179. Doo::loadModel('itemStatistics');
  4180. $statistics=new statistics();
  4181. $itemStatistics=new itemStatistics();
  4182. Doo::loadModel("verify");
  4183. $verify=new verify();
  4184. //审批状态的判定
  4185. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4186. if(empty($receiptDetailList))
  4187. return "/saeaBorad";
  4188. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4189. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4190. if (empty($receiptDetailList['nowStaff'])){
  4191. $nowStaff="";$nowStaffList=array();
  4192. if ($verifyDetail[0][1]=='ROLE'){
  4193. $vStaffString=json_decode($verifyDetail[0][3]);
  4194. foreach ($vStaffString as $key=>$value){
  4195. $staffK=explode("_", $value);
  4196. array_push($nowStaffList, $staffK[0]);
  4197. }
  4198. $nowStaff=implode(',', $nowStaffList);
  4199. }else{
  4200. $nowStaff=$verifyDetail[0][0];
  4201. }
  4202. $receipt->nowStaff=$nowStaff;
  4203. }
  4204. // echo $nowStaff;
  4205. // print_r($verifyDetail);die;
  4206. $receipt->rid=$receiptDetailList['rid'];
  4207. $receipt->date=date("Y-m-d");
  4208. $receipt->status=2;
  4209. $receipt->update();
  4210. $receiptDetail->status=2;
  4211. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4212. Doo::loadModel("receiptLog");
  4213. $receiptLog=new receiptLog();
  4214. Doo::loadModel("verify");
  4215. $verify=new verify();
  4216. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4217. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4218. $jd=json_decode($vr['staff']);$roleId=0;
  4219. foreach ($jd as $key=>$value){
  4220. if ($value[1]=='ROLE'){
  4221. $pos = strpos($value[3], $this->staff[0]['sid']);
  4222. if ($pos !== false) {
  4223. $roleId=$value[0];
  4224. }
  4225. }
  4226. }
  4227. //审批日志
  4228. //echo $roleId;die;
  4229. if (!empty($roleId)){
  4230. Doo::loadModel("role");
  4231. $role=new role();
  4232. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4233. $receiptLog->rolename=$roleInfo['name'];
  4234. }
  4235. $receiptLog->username=$this->staff[0]['username'];
  4236. $receiptLog->uid=$this->staff[0]['sid'];
  4237. $receiptLog->date=date("Y-m-d");
  4238. $receiptLog->opinion='提交审批';
  4239. $receiptLog->img=$this->staff[0]['avatar'];
  4240. $receiptLog->status=2;
  4241. $receiptLog->rid=$rid;
  4242. $receiptLog->insert();
  4243. //statistics item
  4244. $dateArray=explode("-", $receiptDetailList['date']);
  4245. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4246. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4247. //print_r($accountItem['cSum']['agencySum']);die;
  4248. // foreach ($accountItem['cSum'] as $key=>$value){
  4249. // if($key=="agencySum"){
  4250. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4251. // if(empty($iStatistics)){
  4252. // $itemStatistics->cid=$this->staff[0]['cid'];
  4253. // $itemStatistics->staff=$this->staff[0]['sid'];
  4254. // $itemStatistics->price=$value;
  4255. // $itemStatistics->itemCategory=$this->AGENCY;
  4256. // $itemStatistics->date=date("Y-m-d");
  4257. // $itemStatistics->insert();
  4258. // }else{
  4259. // if (!empty($value)){
  4260. // $itemStatistics->price=$value+$iStatistics['price'];
  4261. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4262. // }
  4263. // }
  4264. // }elseif($key=="travelSum"){
  4265. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4266. // if(empty($iStatistics)){
  4267. // $itemStatistics->cid=$this->staff[0]['cid'];
  4268. // $itemStatistics->staff=$this->staff[0]['sid'];
  4269. // $itemStatistics->price=$value;
  4270. // $itemStatistics->itemCategory=$this->TRAVEL;
  4271. // $itemStatistics->date=date("Y-m-d");
  4272. // $itemStatistics->insert();
  4273. // }else{
  4274. // if (!empty($value)){
  4275. // $itemStatistics->price=$value+$iStatistics['price'];
  4276. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4277. // }
  4278. // }
  4279. // }elseif($key=="trainSum"){
  4280. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4281. // if(empty($iStatistics)){
  4282. // $itemStatistics->cid=$this->staff[0]['cid'];
  4283. // $itemStatistics->staff=$this->staff[0]['sid'];
  4284. // $itemStatistics->price=$value;
  4285. // $itemStatistics->itemCategory=$this->TRAIN;
  4286. // $itemStatistics->date=date("Y-m-d");
  4287. // $itemStatistics->insert();
  4288. // }else{
  4289. // if (!empty($value)){
  4290. // $itemStatistics->price=$value+$iStatistics['price'];
  4291. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4292. // }
  4293. // }
  4294. // }elseif($key=="otherSum"){
  4295. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4296. // if(empty($iStatistics)){
  4297. // $itemStatistics->cid=$this->staff[0]['cid'];
  4298. // $itemStatistics->staff=$this->staff[0]['sid'];
  4299. // $itemStatistics->price=$value;
  4300. // $itemStatistics->itemCategory=$this->OTHER;
  4301. // $itemStatistics->date=date("Y-m-d");
  4302. // $itemStatistics->insert();
  4303. // }else{
  4304. // if (!empty($value)){
  4305. // $itemStatistics->price=$value+$iStatistics['price'];
  4306. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4307. // }
  4308. // }
  4309. // }
  4310. // }
  4311. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4312. if(empty($stat)){
  4313. $statistics->date=date("Y-m-d");
  4314. $statistics->cid=$this->staff[0]['cid'];
  4315. $statistics->staff=$this->staff[0]['sid'];
  4316. $statistics->agPrice=0;
  4317. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4318. $statistics->insert();
  4319. }else{
  4320. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4321. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4322. }
  4323. return "/expenses";
  4324. }
  4325. function approval(){
  4326. $status=isset($this->params['status'])?$this->params['status']:'';
  4327. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4328. $month=$this->get_args('month')?$this->get_args('month'):"";
  4329. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4330. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4331. if (empty($status))
  4332. $status=$this->get_args('status')?$this->get_args('status'):2;
  4333. $vidList=array();
  4334. $button=0;
  4335. Doo::loadModel('verify');
  4336. $verify=new verify();
  4337. Doo::loadModel('receipt');
  4338. $receipt=new receipt();
  4339. Doo::loadModel('staff');
  4340. $staff=new staff();
  4341. Doo::loadModel('L_category');
  4342. $Lcategory=new L_category();
  4343. //user verify ID
  4344. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4345. foreach ($verifyDetail as $key=>$value){
  4346. array_push($vidList, $value['vid']);
  4347. }
  4348. $vid=implode(",", $vidList);
  4349. if(empty($verifyDetail))
  4350. $vid=0;
  4351. /*
  4352. */
  4353. $dateCondition=" and Year(date) =".$year;
  4354. if(!empty($month))
  4355. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4356. $categoryList=$Lcategory->find(array('asArray'=>true));
  4357. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4358. $cateCondition="";$staffCondition="";$approvalCondition="";
  4359. if (!empty($cid))
  4360. $cateCondition=' and cid='.$cid;
  4361. if(!empty($sid)){
  4362. $staffCondition=' and staff='.$sid;
  4363. $cateCondition="";
  4364. }
  4365. // elseif($status==1){
  4366. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4367. // }
  4368. if($status==2){
  4369. //查找角色审批人
  4370. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4371. }
  4372. $ap="";
  4373. if($status==4){
  4374. $ap=4;$status=2;
  4375. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4376. }
  4377. if($status==5){
  4378. $status=4;$ap=5;
  4379. }
  4380. //echo $vid;
  4381. //get Receipt By verifyID status 2 .$approvalCondition
  4382. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4383. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4384. ,'desc'=>'rid','asArray'=>true));
  4385. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4386. $Locate=0;
  4387. if($ap==4)
  4388. $status=4;
  4389. elseif ($ap==5)
  4390. $status=5;
  4391. foreach ($receiptList as $key=>$value){
  4392. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4393. $receiptList[$key]['reviseDetail']=array();
  4394. if (!empty($value['reviseDetail']))
  4395. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4396. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4397. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4398. $receiptList[$key]['category']=$categoryDetil['title'];
  4399. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4400. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4401. $verifyStaff=json_decode($value['verifyStaff'],true);
  4402. foreach ($verifyList as $k=>$v){
  4403. //init verifyStaff
  4404. $verifyList[$k]['date']="";
  4405. $verifyList[$k]['opinion']="";
  4406. $verifyList[$k]['status']="";
  4407. if (empty($verifyStaff)){
  4408. $verifyList[$k]['date']="";
  4409. $verifyList[$k]['opinion']="";
  4410. if ($v[0]==$this->staff[0]['sid']){
  4411. $verifyList[$k]['status']=4;
  4412. $button=4;
  4413. }
  4414. }else{
  4415. $flag=true;
  4416. foreach ($verifyStaff as $m=>$u){
  4417. if ($v[0]==$m){
  4418. $verifyList[$k]['date']=$u['date'];
  4419. $verifyList[$k]['opinion']=$u['opinion'];
  4420. $verifyList[$k]['status']=$u['status'];
  4421. $flag=false;
  4422. break;
  4423. }
  4424. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4425. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4426. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4427. }
  4428. if($flag){//检测可编辑
  4429. if($v[0]==$this->staff[0]['sid']){
  4430. $verifyList[$k]['status']=4;$button=4;
  4431. }
  4432. }
  4433. }
  4434. }
  4435. $receiptList[$key]['verifyList']=$verifyList;
  4436. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4437. $receiptList[$key]['button']=$button;
  4438. }
  4439. //print_r($receiptList);die;
  4440. //$data['verifyDetail']=$verifyDetail;
  4441. $mothHtml="";
  4442. for($i=1;$i<=12;$i++){
  4443. if($month==$i)
  4444. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4445. else
  4446. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4447. }
  4448. $data['mothHtml']=$mothHtml;
  4449. $data['receiptList']=$receiptList;
  4450. $data['receiptApprovalCount']=count($receiptList);
  4451. $data['status']=$status;
  4452. $data['year']=$year;
  4453. $data['categoryList']=$categoryList;
  4454. $data['staffList']=$staffList;
  4455. $data['cid']=$cid;
  4456. $data['sid']=$sid;
  4457. $data['ap']=$ap;
  4458. $data['memu']="receipt";
  4459. $data['staff']=$this->staff;
  4460. $data['receiptMemu']='approval';
  4461. $data['verifyId']=$this->verifyId;
  4462. $data['executeId']=$this->executeId;
  4463. $this->render ( "/admin/saea_reportList", $data );
  4464. }
  4465. function approvalDetails(){
  4466. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4467. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4468. $month=$this->get_args('month')?$this->get_args('month'):"";
  4469. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4470. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4471. Doo::loadModel('verify');
  4472. $verify=new verify();
  4473. Doo::loadModel('receipt');
  4474. $receipt=new receipt();
  4475. Doo::loadModel('staff');
  4476. $staff=new staff();
  4477. Doo::loadModel('L_category');
  4478. $Lcategory=new L_category();
  4479. Doo::loadModel('enclosur');
  4480. $enclosur=new enclosur();
  4481. $vidList=array();
  4482. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4483. foreach ($verifyDetail as $key=>$value){
  4484. array_push($vidList, $value['vid']);
  4485. }
  4486. $vid=implode(",", $vidList);
  4487. if(empty($verifyDetail))
  4488. $vid=0;
  4489. $categoryList=$Lcategory->find(array('asArray'=>true));
  4490. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4491. $ap=0;
  4492. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4493. $Locate=0;$roleId=0;$button=0;
  4494. foreach ($receiptList as $key=>$value){
  4495. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4496. $receiptList[$key]['reviseDetail']=array();
  4497. if (!empty($value['reviseDetail']))
  4498. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4499. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4500. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4501. $receiptList[$key]['category']=$categoryDetil['title'];
  4502. //检测编辑状态
  4503. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4504. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4505. $verifyStaff=json_decode($value['verifyStaff'],true);
  4506. Doo::loadModel('role');
  4507. $role=new role();
  4508. //print_r($verifyList);
  4509. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4510. foreach ($verifyList as $k=>$v){
  4511. //init verifyStaff
  4512. if ($v[1]=='ROLE'){
  4513. if (!empty($verifyStaff)){
  4514. $endStaffArray=end($verifyStaff);
  4515. if ($v[0]==$endStaffArray['nextStaff']){
  4516. $roleId=$v[0];
  4517. }
  4518. }
  4519. $roleVerify=json_decode($v[3],true);
  4520. $roleKey=$k;$roleArray=array();
  4521. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4522. foreach ($roleVerify as $o=>$p){
  4523. $staffID=explode ('_',$p);
  4524. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4525. //print_r($staffID);
  4526. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4527. array_push($roleArray, $exp);
  4528. }
  4529. $roleArrayCopy[$v[0]]=$roleArray;
  4530. //$verifyList[$k]['roleArray']=$roleArray;
  4531. }
  4532. //print_r($roleArray);
  4533. $verifyList[$k]['date']="";
  4534. $verifyList[$k]['opinion']="";
  4535. $verifyList[$k]['status']="";
  4536. if (empty($verifyStaff)){
  4537. $verifyList[$k]['date']="";
  4538. $verifyList[$k]['opinion']="";
  4539. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4540. $verifyList[$k]['status']=4;
  4541. $button=4;$flag=false;
  4542. }
  4543. }else{
  4544. foreach ($verifyStaff as $m=>$u){
  4545. if ($v[0]==$m){
  4546. $verifyList[$k]['date']=$u['date'];
  4547. $verifyList[$k]['opinion']=$u['opinion'];
  4548. $verifyList[$k]['status']=$u['status'];
  4549. $flag=false;
  4550. break;
  4551. }
  4552. }
  4553. $endStaffArray=end($verifyStaff);
  4554. if (isset($endStaffArray['ROLE'])){
  4555. }else{
  4556. $endKey=key($verifyStaff);
  4557. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4558. $button=4;
  4559. $verifyList[$k]['status']=4;
  4560. }
  4561. }
  4562. }
  4563. }
  4564. $rolename['name']='';
  4565. if (!empty($roleId)){
  4566. Doo::loadModel('role');
  4567. $role=new role();
  4568. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4569. }
  4570. if (!empty($verifyStaff))
  4571. $endStaffArray=end($verifyStaff);
  4572. $KOP=false;
  4573. foreach ($roleArrayCopy as $P=>$A){
  4574. foreach ( $A as $MKI=>$AVL){
  4575. if (!empty($verifyStaff)){
  4576. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4577. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4578. $button=4;
  4579. $roleArrayCopy[$P][$MKI]['status']=4;
  4580. }
  4581. foreach ($verifyStaff as $m=>$u){
  4582. $AVLFK=$AVL[0].'_R';
  4583. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4584. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4585. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4586. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4587. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4588. break;
  4589. }
  4590. }
  4591. }else{
  4592. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4593. $button=4;
  4594. $roleArrayCopy[$P][$MKI]['status']=4;
  4595. }
  4596. }
  4597. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4598. $KOP=true;
  4599. }
  4600. }
  4601. foreach ($roleArrayCopy as $k=>$v){
  4602. foreach ($verifyList as $m=>$n){
  4603. if ($n[0]==$k){
  4604. array_splice($verifyList,$m,1,$v);
  4605. }
  4606. }
  4607. }
  4608. $receiptList[$key]['verifyList']=$verifyList;
  4609. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4610. $receiptList[$key]['button']=$button;
  4611. }
  4612. $mothHtml="";
  4613. for($i=1;$i<=12;$i++){
  4614. if($month==$i)
  4615. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4616. else
  4617. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4618. }
  4619. //获取审批日志
  4620. Doo::loadModel('receiptLog');
  4621. $receiptLog=new receiptLog();
  4622. $rlList=array();
  4623. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4624. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4625. if (!empty($rlInfo)){
  4626. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4627. }
  4628. $receiptList[0]['rlList']=$rlList;
  4629. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4630. $enclosurHtml='';
  4631. foreach ($enclosurList as $value){
  4632. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4633. }
  4634. $data['enclosurHtml']=$enclosurHtml;
  4635. $data['rolename']=$rolename['name'];
  4636. $data['datetij']=$tijdate['date'];
  4637. $data['mothHtml']=$mothHtml;
  4638. $data['receiptList']=$receiptList;
  4639. $data['receiptApprovalCount']=count($receiptList);
  4640. $data['year']=$year;
  4641. $data['categoryList']=$categoryList;
  4642. $data['staffList']=$staffList;
  4643. $data['cid']=$cid;
  4644. $data['sid']=$sid;
  4645. $data['status']=0;
  4646. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4647. $ap=4;
  4648. }else
  4649. $data['status']=$receiptList[0]['status'];
  4650. if ($receiptList[0]['status']==4){
  4651. $data['status']=5;
  4652. $ap=0;
  4653. }
  4654. $data['ap']=$ap;
  4655. $data['memu']="receipt";
  4656. $data['staff']=$this->staff;
  4657. $data['receiptMemu']='approval';
  4658. $data['verifyId']=$this->verifyId;
  4659. $data['executeId']=$this->executeId;
  4660. $this->render ( "/admin/saeaReportListReport", $data );
  4661. }
  4662. function approvalEdi(){
  4663. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4664. $status=isset($this->params['status'])?$this->params['status']:'';
  4665. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4666. $month=$this->get_args('month')?$this->get_args('month'):"";
  4667. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4668. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4669. if (empty($status))
  4670. $status=$this->get_args('status')?$this->get_args('status'):2;
  4671. $vidList=array();
  4672. $button=0;
  4673. Doo::loadModel('verify');
  4674. Doo::loadModel('receipt');
  4675. Doo::loadModel('staff');
  4676. $staff=new staff();
  4677. $receipt=new receipt();
  4678. $verify=new verify();
  4679. Doo::loadModel('L_category');
  4680. $Lcategory=new L_category();
  4681. Doo::loadModel('enclosur');
  4682. $enclosur=new enclosur();
  4683. //user verify ID
  4684. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4685. foreach ($verifyDetail as $key=>$value){
  4686. array_push($vidList, $value['vid']);
  4687. }
  4688. $vid=implode(",", $vidList);
  4689. if(empty($verifyDetail))
  4690. $vid=0;
  4691. $categoryList=$Lcategory->find(array('asArray'=>true));
  4692. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4693. $ap="";
  4694. if($status==4){
  4695. $ap=4;$status=2;
  4696. }
  4697. //get Receipt By verifyID status 2
  4698. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4699. $Locate=0;$roleId=0;
  4700. if($ap==4)
  4701. $status=4;
  4702. foreach ($receiptList as $key=>$value){
  4703. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4704. $receiptList[$key]['reviseDetail']=array();
  4705. if (!empty($value['reviseDetail']))
  4706. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4707. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4708. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4709. $receiptList[$key]['category']=$categoryDetil['title'];
  4710. //检测编辑状态
  4711. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4712. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4713. $verifyStaff=json_decode($value['verifyStaff'],true);
  4714. // print_r($verifyList);
  4715. //
  4716. // if (empty($verifyStaff)){
  4717. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4718. // $verifyList[0]['status']=4;$button=4;
  4719. // }
  4720. //
  4721. // }else{
  4722. //
  4723. // }
  4724. // die;
  4725. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4726. // echo array_search("green",$a);
  4727. //
  4728. Doo::loadModel('role');
  4729. $role=new role();
  4730. //print_r($verifyList);
  4731. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4732. foreach ($verifyList as $k=>$v){
  4733. //init verifyStaff
  4734. if ($v[1]=='ROLE'){
  4735. if (!empty($verifyStaff)){
  4736. $endStaffArray=end($verifyStaff);
  4737. if ($v[0]==$endStaffArray['nextStaff']){
  4738. $roleId=$v[0];
  4739. }
  4740. }
  4741. $roleVerify=json_decode($v[3],true);
  4742. $roleKey=$k;$roleArray=array();
  4743. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4744. foreach ($roleVerify as $o=>$p){
  4745. $staffID=explode ('_',$p);
  4746. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4747. //print_r($staffID);
  4748. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4749. array_push($roleArray, $exp);
  4750. }
  4751. $roleArrayCopy[$v[0]]=$roleArray;
  4752. //$verifyList[$k]['roleArray']=$roleArray;
  4753. }
  4754. //print_r($roleArray);
  4755. $verifyList[$k]['date']="";
  4756. $verifyList[$k]['opinion']="";
  4757. $verifyList[$k]['status']="";
  4758. if (empty($verifyStaff)){
  4759. $verifyList[$k]['date']="";
  4760. $verifyList[$k]['opinion']="";
  4761. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4762. $verifyList[$k]['status']=4;
  4763. $button=4;$flag=false;
  4764. }
  4765. }else{
  4766. foreach ($verifyStaff as $m=>$u){
  4767. if ($v[0]==$m){
  4768. $verifyList[$k]['date']=$u['date'];
  4769. $verifyList[$k]['opinion']=$u['opinion'];
  4770. $verifyList[$k]['status']=$u['status'];
  4771. $flag=false;
  4772. break;
  4773. }
  4774. }
  4775. $endStaffArray=end($verifyStaff);
  4776. if (isset($endStaffArray['ROLE'])){
  4777. }else{
  4778. $endKey=key($verifyStaff);
  4779. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4780. $button=4;
  4781. $verifyList[$k]['status']=4;
  4782. }
  4783. }
  4784. //print_r($endStaffArray);die;
  4785. // if (empty($verifyStaff)){
  4786. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4787. // $verifyList[$k]['status']=4;$button=4;
  4788. // }
  4789. //
  4790. // }else{
  4791. //
  4792. // }
  4793. // if($flag){//检测可编辑
  4794. // if($v[0]==$this->staff[0]['sid']){
  4795. // $verifyList[$k]['status']=4;$button=4;
  4796. // }
  4797. // }
  4798. }
  4799. }
  4800. $rolename['name']='';
  4801. if (!empty($roleId)){
  4802. Doo::loadModel('role');
  4803. $role=new role();
  4804. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4805. }
  4806. if (!empty($verifyStaff))
  4807. $endStaffArray=end($verifyStaff);
  4808. $KOP=false;
  4809. foreach ($roleArrayCopy as $P=>$A){
  4810. foreach ( $A as $MKI=>$AVL){
  4811. if (!empty($verifyStaff)){
  4812. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4813. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4814. $button=4;
  4815. $roleArrayCopy[$P][$MKI]['status']=4;
  4816. }
  4817. foreach ($verifyStaff as $m=>$u){
  4818. $AVLFK=$AVL[0].'_R';
  4819. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4820. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4821. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4822. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4823. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4824. break;
  4825. }
  4826. }
  4827. }else{
  4828. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4829. $button=4;
  4830. $roleArrayCopy[$P][$MKI]['status']=4;
  4831. }
  4832. }
  4833. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4834. $KOP=true;
  4835. }
  4836. }
  4837. // print_r($roleArrayCopy);
  4838. // echo $roleKey;
  4839. foreach ($roleArrayCopy as $k=>$v){
  4840. foreach ($verifyList as $m=>$n){
  4841. if ($n[0]==$k){
  4842. array_splice($verifyList,$m,1,$v);
  4843. }
  4844. }
  4845. }
  4846. // if ($KOP)
  4847. // array_splice($verifyList,$roleKey,1,$roleArray);
  4848. //print_r($verifyList);
  4849. $receiptList[$key]['verifyList']=$verifyList;
  4850. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4851. $receiptList[$key]['button']=$button;
  4852. }
  4853. //$data['verifyDetail']=$verifyDetail;
  4854. $mothHtml="";
  4855. for($i=1;$i<=12;$i++){
  4856. if($month==$i)
  4857. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4858. else
  4859. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4860. }
  4861. //获取审批日志
  4862. Doo::loadModel('receiptLog');
  4863. $receiptLog=new receiptLog();
  4864. $rlList=array();
  4865. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4866. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4867. if (!empty($rlInfo)){
  4868. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4869. }
  4870. $receiptList[0]['rlList']=$rlList;
  4871. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4872. $enclosurHtml='';
  4873. foreach ($enclosurList as $value){
  4874. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4875. }
  4876. $data['enclosurHtml']=$enclosurHtml;
  4877. $data['rolename']=$rolename['name'];
  4878. $data['datetij']=$tijdate['date'];
  4879. $data['mothHtml']=$mothHtml;
  4880. $data['receiptList']=$receiptList;
  4881. $data['receiptApprovalCount']=count($receiptList);
  4882. $data['status']=$status;
  4883. $data['year']=$year;
  4884. $data['categoryList']=$categoryList;
  4885. $data['staffList']=$staffList;
  4886. $data['cid']=$cid;
  4887. $data['sid']=$sid;
  4888. $data['ap']=$ap;
  4889. $data['memu']="receipt";
  4890. $data['staff']=$this->staff;
  4891. $data['receiptMemu']='approval';
  4892. $data['verifyId']=$this->verifyId;
  4893. $data['executeId']=$this->executeId;
  4894. $this->render ( "/admin/saeaReportListReport", $data );
  4895. }
  4896. function remittance(){
  4897. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4898. $month=$this->get_args('month')?$this->get_args('month'):"";
  4899. Doo::loadModel('receipt');
  4900. $receipt=new receipt();
  4901. Doo::loadModel('staff');
  4902. $staff=new staff();
  4903. $dateCondition=" and Year(pastDate) =".$year;
  4904. if(!empty($month))
  4905. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4906. //get Receipt By verifyID status 1
  4907. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4908. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4909. $dataList=array();
  4910. foreach ($dateList as $d=>$a){
  4911. $dataList[$a['pastDate']]=array();$daySum=0;
  4912. foreach ($receiptList as $key=>$value){
  4913. if($a['pastDate']==$value['pastDate']){
  4914. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4915. $list=array();$html="";
  4916. foreach ($oderList as $v){
  4917. array_push($list, $v['receiptOrder']);
  4918. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4919. }
  4920. $receiptList[$key]['receiptOrder']=$html;
  4921. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4922. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4923. $receiptList[$key]['username']=$sinfo['username'];
  4924. $daySum+=$value['sum'];
  4925. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4926. }
  4927. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4928. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4929. }
  4930. }
  4931. //print_r($dataList);
  4932. $data['dataList']=$dataList;
  4933. $mothHtml="";
  4934. for($i=1;$i<=12;$i++){
  4935. if($month==$i)
  4936. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4937. else
  4938. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4939. }
  4940. $data['year']=$year;
  4941. $data['mothHtml']=$mothHtml;
  4942. $data['memu']="receipt";
  4943. $data['staff']=$this->staff;
  4944. $data['receiptMemu']='approval';
  4945. $data['verifyId']=$this->verifyId;
  4946. $data['executeId']=$this->executeId;
  4947. $this->render ( "/admin/saeaReportListPay", $data );
  4948. }
  4949. function revocationAdjustment(){
  4950. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  4951. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  4952. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4953. //echo $price;die;
  4954. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  4955. Doo::loadModel('receipt');
  4956. $receipt=new receipt();
  4957. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4958. if (empty($receiptDetail['reviseDetail']))
  4959. return "/approval";
  4960. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  4961. $RD=array();
  4962. foreach ($reviseDetail as $key=>$value){
  4963. if ($value['price']==$price&&$value['sid']==$sid)
  4964. continue;
  4965. array_push($RD, $value);
  4966. }
  4967. $reviseDetailString=json_encode($RD);
  4968. $receipt->reviseDetail=$reviseDetailString;
  4969. $receipt->sum=$receiptDetail['sum']-$price;
  4970. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  4971. $receipt->update(array('where'=>'rid='.$rid));
  4972. }
  4973. //approvalEdi/37
  4974. return "/approvalEdi/".$rid;
  4975. }
  4976. function updateApprovalReceipt(){
  4977. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  4978. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  4979. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4980. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  4981. if(!empty($rid)){
  4982. Doo::loadModel("verify");
  4983. $verify=new verify();
  4984. Doo::loadModel("receiptDetail");
  4985. $receiptDetailObj=new receiptDetail();
  4986. Doo::loadModel("itemStatistics");
  4987. Doo::loadModel("statistics");
  4988. $statistics=new statistics();
  4989. $itemStatistics=new itemStatistics();
  4990. Doo::loadModel("receipt");
  4991. $receipt=new receipt();
  4992. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  4993. if (empty($receiptDetail))
  4994. return "/approval";
  4995. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  4996. $verifyString=$verifyDetail['staff'];
  4997. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4998. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  4999. if(empty($opinion)){
  5000. if ($status==3)
  5001. $opinion="终止";
  5002. else
  5003. $opinion="同意支付";
  5004. }
  5005. $nowStaff=0;$nowStaffList=array();
  5006. if(empty($verifyStaff)){
  5007. //还需加入是否已经进入角色审批
  5008. if ($verifyDetail[0][1]=='ROLE'){
  5009. $vStaffString=json_decode($verifyDetail[0][3]);
  5010. foreach ($vStaffString as $key=>$value){
  5011. $staffK=explode("_", $value);
  5012. if ($staffK[0]!=$this->staff[0]['sid'])
  5013. array_push($nowStaffList, $staffK[0]);
  5014. }
  5015. //print_r($verifyDetail);
  5016. //die;
  5017. if (!empty($nowStaffList)){
  5018. $nowStaff=implode(',', $nowStaffList);
  5019. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5020. }else{
  5021. $nowStaff=$verifyDetail[1][0];
  5022. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5023. }
  5024. }else{
  5025. if ($verifyDetail[1][1]=='ROLE'){
  5026. $vStaffString=json_decode($verifyDetail[1][3]);
  5027. //echo "dd";
  5028. foreach ($vStaffString as $key=>$value){
  5029. $staffK=explode("_", $value);
  5030. array_push($nowStaffList, $staffK[0]);
  5031. }
  5032. $nowStaff=implode(',', $nowStaffList);
  5033. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5034. }else{
  5035. $nowStaff=$verifyDetail[1][0];
  5036. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5037. }
  5038. }
  5039. if($status==3)
  5040. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5041. $vStaffString=json_encode($verifyStaff);
  5042. $receipt->nowStaff=$nowStaff;
  5043. $receipt->verifyStaff=$vStaffString;
  5044. }else{
  5045. $VS=end($verifyStaff);
  5046. //非角色审批
  5047. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5048. $nextStaff=0;$roleSTF=false;
  5049. foreach ($verifyDetail as $key=>$value){
  5050. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5051. if (isset($verifyDetail[$key+1])){
  5052. $nextStaff=$verifyDetail[$key+1][0];
  5053. if ($verifyDetail[$key+1][1]=='ROLE')
  5054. $roleSTF=true;
  5055. }
  5056. break;
  5057. }
  5058. }
  5059. if (!$roleSTF){
  5060. $nowStaff=$nextStaff;
  5061. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5062. }else{
  5063. //获取角色下的所有用户ID
  5064. $nowStaffList=array();
  5065. foreach ($verifyDetail as $vfk){
  5066. if ($vfk[1]=='ROLE'){
  5067. $vStaffString=json_decode($vfk[3]);
  5068. foreach ($vStaffString as $key=>$value){
  5069. $staffK=explode("_", $value);
  5070. array_push($nowStaffList, $staffK[0]);
  5071. }
  5072. }
  5073. }
  5074. $nowStaff=implode(',', $nowStaffList);
  5075. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5076. }
  5077. if($status==3){
  5078. $verifyStaff['final']=$status;
  5079. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5080. }
  5081. $vStaffString=json_encode($verifyStaff);
  5082. $receipt->nowStaff=$nowStaff;
  5083. $receipt->verifyStaff=$vStaffString;
  5084. }
  5085. //角色审批
  5086. if (isset($VS['ROLE'])){
  5087. //找出角色人 当前审批角色组
  5088. $verifyJSStaff=array();$nowStaffList2=array();
  5089. foreach ($verifyDetail as $key=>$value){
  5090. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5091. $verifyJSStaff=json_decode($value[3]);
  5092. foreach ($verifyJSStaff as $m){
  5093. $staffK=explode("_", $m);
  5094. array_push($nowStaffList2, $staffK[0]);
  5095. }
  5096. // print_r($nowStaffList2);
  5097. }
  5098. }
  5099. $RoleVerifyStaff=array();
  5100. foreach ($verifyStaff as $key=>$value){
  5101. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5102. foreach ($nowStaffList2 as $m) {
  5103. if ($key==$m."_R")
  5104. $RoleVerifyStaff[$key]=$value;
  5105. }
  5106. }
  5107. }
  5108. // print_r($verifyStaff);
  5109. // print_r($nowStaffList2);
  5110. // print_r($RoleVerifyStaff);
  5111. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5112. //print_r($verifyJSStaff);
  5113. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5114. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5115. //下一个审批人ID
  5116. $nextStaff=0;$falg=false;
  5117. foreach ($verifyDetail as $key=>$value){
  5118. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5119. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5120. $falg=true;
  5121. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5122. foreach ($vStaffString as $v){
  5123. $staffK=explode("_", $v);
  5124. array_push($nowStaffList, $staffK[0]);
  5125. }
  5126. $nowStaff=implode(',', $nowStaffList);
  5127. $nextStaff=$verifyDetail[$key+1][0];
  5128. }elseif(isset($verifyDetail[$key+1])){
  5129. $nextStaff=$verifyDetail[$key+1][0];
  5130. $nowStaff=$nextStaff;
  5131. }else
  5132. $nowStaff='';
  5133. break;
  5134. }
  5135. }
  5136. if ($falg)
  5137. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5138. else
  5139. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5140. // print_r($verifyStaff);
  5141. // echo $nowStaff;die;
  5142. }else{ //进入下一个角色或者审批人
  5143. /*
  5144. */
  5145. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5146. //
  5147. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5148. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5149. // print_r($verifyStaff);
  5150. // die;
  5151. }
  5152. if($status==3){
  5153. $verifyStaff['final']=$status;
  5154. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5155. }
  5156. $vStaffString=json_encode($verifyStaff);
  5157. $receipt->verifyStaff=$vStaffString;
  5158. $receipt->nowStaff=$nowStaff;
  5159. //die;
  5160. //}
  5161. // print_r($verifyStaff);
  5162. // die;
  5163. }
  5164. //print_r($verifyStaff);die;
  5165. }
  5166. //print_r($verifyDetail);
  5167. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5168. foreach ($verifyDetail as $k=>$v){
  5169. if ($v[1]=='ROLE'){
  5170. $roleId=$v[0];
  5171. $roleVerify=json_decode($v[3],true);
  5172. $roleKey=$k;$roleArray=array();
  5173. foreach ($roleVerify as $o=>$p){
  5174. $staffID=explode ('_',$p);
  5175. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5176. array_push($roleArray, $exp);
  5177. }
  5178. $verifyDetailCopy[$v[0]]=$roleArray;
  5179. }
  5180. }
  5181. //print_r($verifyDetail);
  5182. foreach ($verifyDetailCopy as $k=>$v){
  5183. foreach ($verifyDetail as $m=>$n){
  5184. if ($n[0]==$k){
  5185. array_splice($verifyDetail,$m,1,$v);
  5186. }
  5187. }
  5188. }
  5189. // die;
  5190. // if (!empty($roleArray))
  5191. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5192. // echo $roleId;
  5193. // print_r($verifyStaff);
  5194. // print_r($verifyDetail);
  5195. // die;
  5196. Doo::loadModel("receiptLog");
  5197. $receiptLog=new receiptLog();
  5198. //审批日志
  5199. if (!isset($verifyStaff['final'])){
  5200. if (!empty($roleId)){
  5201. Doo::loadModel("role");
  5202. $role=new role();
  5203. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5204. $receiptLog->rolename=$roleInfo['name'];
  5205. }
  5206. $receiptLog->username=$this->staff[0]['username'];
  5207. $receiptLog->uid=$this->staff[0]['sid'];
  5208. $receiptLog->date=date("Y-m-d");
  5209. $receiptLog->opinion=$opinion;
  5210. $receiptLog->img=$this->staff[0]['avatar'];
  5211. $receiptLog->status=1;
  5212. $receiptLog->rid=$rid;
  5213. $receiptLog->insert();
  5214. }
  5215. if (isset($verifyStaff['final'])){//rDetail
  5216. $receipt->verifyBreakup=$verifyString;
  5217. $receipt->status=3;
  5218. $receiptDetailObj->status=3;
  5219. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5220. if (!empty($roleId)){
  5221. Doo::loadModel("role");
  5222. $role=new role();
  5223. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5224. $receiptLog->rolename=$roleInfo['name'];
  5225. }
  5226. $receiptLog->username=$this->staff[0]['username'];
  5227. $receiptLog->uid=$this->staff[0]['sid'];
  5228. $receiptLog->date=date("Y-m-d");
  5229. $receiptLog->opinion=$opinion;
  5230. $receiptLog->img=$this->staff[0]['avatar'];
  5231. $receiptLog->status=3;
  5232. $receiptLog->rid=$rid;
  5233. $receiptLog->insert();
  5234. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5235. $receipt->status=1;$reviseSum=0;
  5236. $receipt->verifyBreakup=$verifyString;
  5237. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5238. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5239. foreach ($reviseDetail as $key=>$value){
  5240. $receiptDetailObj=new receiptDetail();
  5241. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5242. $receiptDetailObj->item=$value['description'];
  5243. $receiptDetailObj->itemCategory="报销金额调整";
  5244. $receiptDetailObj->price=$value['price'];
  5245. $receiptDetailObj->date=$receiptDetail['date'];
  5246. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5247. $receiptDetailObj->rid=$rid;
  5248. $receiptDetailObj->status=1;
  5249. $receiptDetailObj->insert();
  5250. $reviseSum+=$value['price'];
  5251. }
  5252. $itemStatistics=new itemStatistics();
  5253. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5254. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5255. $itemStatistics->price=$reviseSum;
  5256. $itemStatistics->itemCategory="报销金额调整";
  5257. $itemStatistics->date=$receiptDetail['date'];
  5258. $itemStatistics->insert();
  5259. }
  5260. $receiptDetailObj=new receiptDetail();
  5261. $receiptDetailObj->status=1;
  5262. $receiptDetailObj->pastDate=date("Y-m-d");
  5263. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5264. $dateArray=explode("-", $receiptDetail['date']);
  5265. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5266. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5267. if(empty($stat)){
  5268. $statistics->date=$receiptDetail['date'];
  5269. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5270. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5271. $statistics->agPrice=$receiptDetail['sum'];
  5272. $statistics->rePrice=$reviseSum;
  5273. $statistics->insert();
  5274. }else{
  5275. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5276. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5277. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5278. }
  5279. $dateArray=explode("-", $receiptDetail['date']);
  5280. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5281. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5282. foreach ($accountItem['cSum'] as $key=>$value){
  5283. if($key=="agencySum"){
  5284. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5285. if(empty($iStatistics)){
  5286. $itemStatistics->cid=$receiptDetail['cid'];;
  5287. $itemStatistics->staff=$receiptDetail['staff'];
  5288. $itemStatistics->price=$value;
  5289. $itemStatistics->itemCategory=$this->AGENCY;
  5290. $itemStatistics->date=$receiptDetail['date'];
  5291. $itemStatistics->insert();
  5292. }else{
  5293. if (!empty($value)){
  5294. $itemStatistics->price=$value+$iStatistics['price'];
  5295. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5296. }
  5297. }
  5298. }elseif($key=="travelSum"){
  5299. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5300. if(empty($iStatistics)){
  5301. $itemStatistics->cid=$receiptDetail['cid'];
  5302. $itemStatistics->staff=$receiptDetail['staff'];
  5303. $itemStatistics->price=$value;
  5304. $itemStatistics->itemCategory=$this->TRAVEL;
  5305. $itemStatistics->date=$receiptDetail['date'];
  5306. $itemStatistics->insert();
  5307. }else{
  5308. if (!empty($value)){
  5309. $itemStatistics->price=$value+$iStatistics['price'];
  5310. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5311. }
  5312. }
  5313. }elseif($key=="trainSum"){
  5314. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5315. if(empty($iStatistics)){
  5316. $itemStatistics->cid=$receiptDetail['cid'];
  5317. $itemStatistics->staff=$receiptDetail['staff'];
  5318. $itemStatistics->price=$value;
  5319. $itemStatistics->itemCategory=$this->TRAIN;
  5320. $itemStatistics->date=$receiptDetail['date'];
  5321. $itemStatistics->insert();
  5322. }else{
  5323. if (!empty($value)){
  5324. $itemStatistics->price=$value+$iStatistics['price'];
  5325. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5326. }
  5327. }
  5328. }elseif($key=="otherSum"){
  5329. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5330. if(empty($iStatistics)){
  5331. $itemStatistics->cid=$receiptDetail['cid'];
  5332. $itemStatistics->staff=$receiptDetail['staff'];
  5333. $itemStatistics->price=$value;
  5334. $itemStatistics->itemCategory=$this->OTHER;
  5335. $itemStatistics->date=$receiptDetail['date'];
  5336. $itemStatistics->insert();
  5337. }else{
  5338. if (!empty($value)){
  5339. $itemStatistics->price=$value+$iStatistics['price'];
  5340. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5341. }
  5342. }
  5343. }
  5344. }
  5345. $receipt->pastDate=date("Y-m-d");
  5346. }
  5347. $receipt->update(array('where'=>' rid = '.$rid));
  5348. return "/approvalExpenses/2";
  5349. }
  5350. }
  5351. function expensesRetreats(){
  5352. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5353. if (!empty($rid)){
  5354. //操作记录
  5355. Doo::loadModel("receipt");
  5356. $receipt=new receipt();
  5357. Doo::loadModel("receiptLog");
  5358. $receiptLog=new receiptLog();
  5359. Doo::loadModel("verify");
  5360. $verify=new verify();
  5361. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5362. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5363. $jd=json_decode($vr['staff']);$roleId=0;
  5364. foreach ($jd as $key=>$value){
  5365. if ($value[1]=='ROLE'){
  5366. $pos = strpos($value[3], $this->staff[0]['sid']);
  5367. if ($pos !== false) {
  5368. $roleId=$value[0];
  5369. }
  5370. }
  5371. }
  5372. //审批日志
  5373. //echo $roleId;die;
  5374. if (!empty($roleId)){
  5375. Doo::loadModel("role");
  5376. $role=new role();
  5377. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5378. $receiptLog->rolename=$roleInfo['name'];
  5379. }
  5380. $receiptLog->username=$this->staff[0]['username'];
  5381. $receiptLog->uid=$this->staff[0]['sid'];
  5382. $receiptLog->date=date("Y-m-d");
  5383. $receiptLog->opinion='撤回';
  5384. $receiptLog->img=$this->staff[0]['avatar'];
  5385. $receiptLog->status=4;
  5386. $receiptLog->rid=$rid;
  5387. $receiptLog->insert();
  5388. $receipt->status=4;
  5389. $receipt->update(array('where'=>'rid='.$rid));
  5390. }
  5391. //echo "ddd";
  5392. return '/approvalExpenses';
  5393. }
  5394. function updateCheReceipt(){
  5395. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5396. if (!empty($rid)){
  5397. //操作记录
  5398. Doo::loadModel("receipt");
  5399. $receipt=new receipt();
  5400. Doo::loadModel("receiptLog");
  5401. $receiptLog=new receiptLog();
  5402. Doo::loadModel("verify");
  5403. $verify=new verify();
  5404. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5405. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5406. $jd=json_decode($vr['staff']);$roleId=0;
  5407. foreach ($jd as $key=>$value){
  5408. if ($value[1]=='ROLE'){
  5409. $pos = strpos($value[3], $this->staff[0]['sid']);
  5410. if ($pos !== false) {
  5411. $roleId=$value[0];
  5412. }
  5413. }
  5414. }
  5415. //审批日志
  5416. //echo $roleId;die;
  5417. if (!empty($roleId)){
  5418. Doo::loadModel("role");
  5419. $role=new role();
  5420. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5421. $receiptLog->rolename=$roleInfo['name'];
  5422. }
  5423. $receiptLog->username=$this->staff[0]['username'];
  5424. $receiptLog->uid=$this->staff[0]['sid'];
  5425. $receiptLog->date=date("Y-m-d");
  5426. $receiptLog->opinion='撤回';
  5427. $receiptLog->img=$this->staff[0]['avatar'];
  5428. $receiptLog->status=4;
  5429. $receiptLog->rid=$rid;
  5430. $receiptLog->insert();
  5431. $receipt->status=4;
  5432. $receipt->update(array('where'=>'rid='.$rid));
  5433. }
  5434. //echo "ddd";
  5435. return '/saeaBorad';
  5436. }
  5437. function revisePrice(){
  5438. $description=$this->get_args('description')?$this->get_args('description'):"";
  5439. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5440. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5441. //echo $price;die;
  5442. if (!empty($rid)){
  5443. Doo::loadModel("receipt");
  5444. $receipt=new receipt();
  5445. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5446. if (empty($receiptDetail))
  5447. return "/approval";
  5448. $reviseDetail=array();
  5449. if (empty($receiptDetail['reviseDetail'])){
  5450. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5451. $reviseDetailString=json_encode($reviseDetail);
  5452. $receipt->reviseDetail=$reviseDetailString;
  5453. $receipt->revisePrice=$price;
  5454. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5455. }else{
  5456. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5457. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5458. $reviseDetailString=json_encode($reviseDetail);
  5459. $receipt->reviseDetail=$reviseDetailString;
  5460. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5461. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5462. }
  5463. $receipt->update(array('where'=>'rid='.$rid));
  5464. }
  5465. return '/approvalEdi/'.$rid;
  5466. }
  5467. function personalCollect(){
  5468. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5469. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5470. $this->showCache($path);
  5471. Doo::loadModel("receiptDetail");
  5472. Doo::loadModel("itemStatistics");
  5473. Doo::loadModel('statistics');
  5474. $statistics=new statistics();
  5475. $itemStatistics=new itemStatistics();
  5476. $receiptDetail=new receiptDetail();
  5477. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5478. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5479. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5480. //create collect html
  5481. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5482. $adjustment=array();
  5483. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5484. array_push($collectArray['日常相关费用'], $collectHtml);
  5485. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5486. array_push($collectArray['差旅相关费用'], $collectHtml);
  5487. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5488. array_push($collectArray['培训班费用'], $collectHtml);
  5489. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5490. array_push($collectArray['其他'], $collectHtml);
  5491. $data['collectArray']=$collectArray;
  5492. //statistics html
  5493. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5494. if(empty($stList))
  5495. $stList=array('rePrice'=>0,'agPrice'=>0);
  5496. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5497. //Adjustment price html
  5498. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5499. array_push($adjustment, $collectHtml);
  5500. $data['adjustment']=$adjustment;
  5501. //total price html
  5502. $collectHtml="";$total=0;
  5503. for ($i=1;$i<=12;$i++){
  5504. $sumPrice=0;
  5505. foreach ($receiptCollectList as $key=>$value){
  5506. if($value['month']==$i){
  5507. $sumPrice+=$value['price'];
  5508. }
  5509. }
  5510. if ($sumPrice==0)
  5511. $collectHtml.='<td class="taR">-</td>';
  5512. else
  5513. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5514. $total+=$sumPrice;
  5515. }
  5516. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5517. $data['totalPrice']=$collectHtml;
  5518. $data['year']=$year;
  5519. $data['totalYear']=$total;
  5520. $data['memu']="receipt";
  5521. $data['staff']=$this->staff;
  5522. $data['receiptMemu']='personalCollect';
  5523. $data['verifyId']=$this->verifyId;
  5524. $data['executeId']=$this->executeId;
  5525. //year staff status 2,4
  5526. if($year<date("Y")){
  5527. Doo::loadModel('receipt');
  5528. $receipt=new receipt();
  5529. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5530. if(empty($receiptList)){
  5531. ob_start();
  5532. $this->render ( "/admin/saea_slist_collect", $data );
  5533. $this->cacheFile($path);die;
  5534. }
  5535. }
  5536. $this->render ( "/admin/saea_slist_collect", $data );
  5537. }
  5538. function personalCollectDetail(){
  5539. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5540. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5541. $this->showCache($path);
  5542. Doo::loadModel("receiptDetail");
  5543. Doo::loadModel("itemStatistics");
  5544. Doo::loadModel('statistics');
  5545. Doo::loadModel('accountItem');
  5546. $accountItem=new accountItem();
  5547. $statistics=new statistics();
  5548. $itemStatistics=new itemStatistics();
  5549. $receiptDetail=new receiptDetail();
  5550. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5551. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5552. $accountList=$accountItem->find(array('asArray'=>true));
  5553. //create CollectDetail HTML
  5554. $collectHtml=array();
  5555. foreach ($accountList as $key=>$value){
  5556. $html="";$asum=0;
  5557. for ($i=1;$i<=12;$i++){
  5558. $falg=true;
  5559. foreach ($receiptCollectList as $v) {
  5560. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5561. $asum+=$v['price'];
  5562. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5563. }
  5564. }
  5565. if($falg)
  5566. $html.='<td class="taR">-</td>';
  5567. }
  5568. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5569. $collectHtml[$value['category']][$value['name']]=$html;
  5570. }
  5571. $data['collectHtml']=$collectHtml;
  5572. //create Adjustment price html
  5573. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5574. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5575. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5576. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5577. array_push($collectArray['日常相关费用'], $collectHtml);
  5578. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5579. array_push($collectArray['差旅相关费用'], $collectHtml);
  5580. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5581. array_push($collectArray['培训班费用'], $collectHtml);
  5582. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5583. array_push($collectArray['其他'], $collectHtml);
  5584. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5585. array_push($adjustment, $collectHtml);
  5586. //total price html
  5587. $collectHtml="";$total=0;
  5588. for ($i=1;$i<=12;$i++){
  5589. $sumPrice=0;
  5590. foreach ($receiptCollectList as $key=>$value){
  5591. if($value['month']==$i){
  5592. $sumPrice+=$value['price'];
  5593. }
  5594. }
  5595. if ($sumPrice==0)
  5596. $collectHtml.='<td class="taR">-</td>';
  5597. else
  5598. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5599. $total+=$sumPrice;
  5600. }
  5601. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5602. //statistics html
  5603. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5604. if(empty($stList))
  5605. $stList=array('rePrice'=>0,'agPrice'=>0);
  5606. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5607. $data['collectArray']=$collectArray;
  5608. $data['adjustment']=$adjustment;
  5609. $data['totalPrice']=$collectHtml;
  5610. $data['totalYear']=$total;
  5611. $data['year']=$year;
  5612. $data['memu']="receipt";
  5613. $data['staff']=$this->staff;
  5614. $data['receiptMemu']='personalCollect';
  5615. $data['verifyId']=$this->verifyId;
  5616. $data['executeId']=$this->executeId;
  5617. //year staff status 2,4
  5618. if($year<date("Y")){
  5619. Doo::loadModel('receipt');
  5620. $receipt=new receipt();
  5621. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5622. if(empty($receiptList)){
  5623. ob_start();
  5624. $this->render ( "/admin/saeaCollectArticles", $data );
  5625. $this->cacheFile($path);die;
  5626. }
  5627. }
  5628. $this->render ( "/admin/saeaCollectArticles", $data );
  5629. }
  5630. function companyCategoryCollect(){
  5631. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5632. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5633. $this->showCache($path);
  5634. Doo::loadModel('L_category');
  5635. Doo::loadModel('itemStatistics');
  5636. Doo::loadModel('statistics');
  5637. $statistics=new statistics();
  5638. $Lcategory=new L_category();
  5639. $itemStatistics=new itemStatistics();
  5640. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5641. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5642. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5643. //ceatre companyCollectHtml
  5644. foreach ($LcategoryList as $value){
  5645. $html="";$asum=0;
  5646. for ($i=1;$i<=12;$i++){
  5647. $falg=true;
  5648. foreach ($itemStatisticsList as $v){
  5649. if($value['cid']==$v['cid']&&$i==$v['month']){
  5650. $asum+=$v['price'];
  5651. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5652. }
  5653. }
  5654. if($falg)
  5655. $html.='<td class="taR">-</td>';
  5656. }
  5657. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5658. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5659. }
  5660. $data['companyHtml']=$collectHtml;
  5661. //total price html
  5662. $collectHtml="";$total=0;
  5663. for ($i=1;$i<=12;$i++){
  5664. $sumPrice=0;
  5665. foreach ($itemStatisticsList as $key=>$value){
  5666. if($value['month']==$i){
  5667. $sumPrice+=$value['price'];
  5668. }
  5669. }
  5670. if ($sumPrice==0)
  5671. $collectHtml.='<td class="taR">-</td>';
  5672. else
  5673. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5674. $total+=$sumPrice;
  5675. }
  5676. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5677. $data['companyTotalHtml']=$collectHtml;
  5678. $data['total']=$total;
  5679. //statistics html
  5680. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5681. if(empty($stList))
  5682. $stList=array('rePrice'=>0,'agPrice'=>0);
  5683. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5684. $data['year']=$year;
  5685. $data['memu']="receipt";
  5686. $data['staff']=$this->staff;
  5687. $data['receiptMemu']='companyCategoryCollect';
  5688. $data['verifyId']=$this->verifyId;
  5689. $data['executeId']=$this->executeId;
  5690. //year staff status 2,4
  5691. if($year<date("Y")){
  5692. Doo::loadModel('receipt');
  5693. $receipt=new receipt();
  5694. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5695. if(empty($receiptList)){
  5696. ob_start();
  5697. $this->render ( "/admin/saeaCompanyCollect", $data );
  5698. $this->cacheFile($path);die;
  5699. }
  5700. }
  5701. $this->render ( "/admin/saeaCompanyCollect", $data );
  5702. }
  5703. function categoryCollectDetail(){
  5704. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5705. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5706. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5707. $this->showCache($path);
  5708. Doo::loadModel('statistics');
  5709. $statistics=new statistics();
  5710. Doo::loadModel("receiptDetail");
  5711. $receiptDetail=new receiptDetail();
  5712. Doo::loadModel('L_category');
  5713. $Lcategory=new L_category();
  5714. Doo::loadModel('accountItem');
  5715. $accountItem=new accountItem();
  5716. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5717. if ($cid==0){
  5718. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5719. if ($cid==0)
  5720. $cid=$LcategoryList[0]['cid'];
  5721. }
  5722. $data['LcategoryList']=$LcategoryList;
  5723. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5724. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5725. $accountList=$accountItem->find(array('asArray'=>true));
  5726. //create CollectDetail HTML
  5727. $collectHtml=array();
  5728. foreach ($accountList as $key=>$value){
  5729. $html="";$asum=0;
  5730. for ($i=1;$i<=12;$i++){
  5731. $falg=true;
  5732. foreach ($receiptCollectList as $v) {
  5733. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5734. $asum+=$v['price'];
  5735. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5736. }
  5737. }
  5738. if($falg)
  5739. $html.='<td class="taR">-</td>';
  5740. }
  5741. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5742. $collectHtml[$value['category']][$value['name']]=$html;
  5743. }
  5744. $data['collectHtml']=$collectHtml;
  5745. //create Adjustment price html
  5746. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5747. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5748. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5749. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5750. array_push($collectArray['日常相关费用'], $collectHtml);
  5751. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5752. array_push($collectArray['差旅相关费用'], $collectHtml);
  5753. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5754. array_push($collectArray['培训班费用'], $collectHtml);
  5755. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5756. array_push($collectArray['其他'], $collectHtml);
  5757. $data['collectArray']=$collectArray;
  5758. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5759. array_push($adjustment, $collectHtml);
  5760. $data['adjustment']=$adjustment;
  5761. //total price html
  5762. $collectHtml="";$total=0;
  5763. for ($i=1;$i<=12;$i++){
  5764. $sumPrice=0;
  5765. foreach ($receiptCollectList as $key=>$value){
  5766. if($value['month']==$i){
  5767. $sumPrice+=$value['price'];
  5768. }
  5769. }
  5770. if ($sumPrice==0)
  5771. $collectHtml.='<td class="taR">-</td>';
  5772. else
  5773. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5774. $total+=$sumPrice;
  5775. }
  5776. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5777. //statistics html
  5778. $stList=$statistics->statisticsByCid($year,$cid);
  5779. if(empty($stList))
  5780. $stList=array('rePrice'=>0,'agPrice'=>0);
  5781. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5782. $data['totalYear']=$total;
  5783. $data['year']=$year;
  5784. $data['cid']=$cid;
  5785. $data['memu']="receipt";
  5786. $data['staff']=$this->staff;
  5787. $data['receiptMemu']='companyCategoryCollect';
  5788. $data['verifyId']=$this->verifyId;
  5789. $data['executeId']=$this->executeId;
  5790. //year staff status 2,4
  5791. if($year<date("Y")){
  5792. Doo::loadModel('receipt');
  5793. $receipt=new receipt();
  5794. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5795. if(empty($receiptList)){
  5796. ob_start();
  5797. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5798. $this->cacheFile($path);die;
  5799. }
  5800. }
  5801. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5802. }
  5803. function staffCollect(){
  5804. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5805. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5806. //$this->showCache($path);
  5807. Doo::loadModel('statistics');
  5808. $statistics=new statistics();
  5809. Doo::loadModel("receiptDetail");
  5810. $receiptDetail=new receiptDetail();
  5811. Doo::loadModel('L_category');
  5812. $Lcategory=new L_category();
  5813. Doo::loadModel('accountItem');
  5814. $accountItem=new accountItem();
  5815. Doo::loadModel('staff');
  5816. $staff=new staff();
  5817. Doo::loadModel('itemStatistics');
  5818. $itemStatistics=new itemStatistics();
  5819. /*
  5820. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5821. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5822. if(empty($stList))
  5823. $stList=array('rePrice'=>0,'agPrice'=>0);
  5824. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5825. */
  5826. //statistics html
  5827. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5828. if(empty($stList))
  5829. $stList=array('rePrice'=>0,'agPrice'=>0);
  5830. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5831. //---
  5832. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5833. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5834. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5835. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5836. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5837. //print_r($itemStatisticsList);die;
  5838. //ceatre companyCollectHtml
  5839. foreach ($categoryList as $vlu){
  5840. $count=$vlu['count']+1;
  5841. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5842. $m1=0;$m2=0;$m3=0;$m4=0;$m5=0;$m6=0;$m7=0;$m8=0;$m9=0;$m10=0;$m11=0;$m12=0;$m13=0;
  5843. foreach ($staffList as $value){
  5844. if ($vlu['cid']==$value['cid']){
  5845. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5846. $asum=0;
  5847. for ($i=1;$i<=12;$i++){
  5848. $falg=true;
  5849. foreach ($itemStatisticsList as $v){
  5850. if($value['sid']==$v['staff']&&$i==$v['month']){
  5851. if ($v['month']==1)
  5852. $m1+=$v['price'];
  5853. if ($v['month']==2)
  5854. $m2+=$v['price'];
  5855. if ($v['month']==3)
  5856. $m3+=$v['price'];
  5857. if ($v['month']==4)
  5858. $m4+=$v['price'];
  5859. if ($v['month']==5)
  5860. $m5+=$v['price'];
  5861. if ($v['month']==6)
  5862. $m6+=$v['price'];
  5863. if ($v['month']==7)
  5864. $m7+=$v['price'];
  5865. if ($v['month']==8)
  5866. $m8+=$v['price'];
  5867. if ($v['month']==9)
  5868. $m9+=$v['price'];
  5869. if ($v['month']==10)
  5870. $m10+=$v['price'];
  5871. if ($v['month']==11)
  5872. $m11+=$v['price'];
  5873. if ($v['month']==12)
  5874. $m12+=$v['price'];
  5875. $asum+=$v['price'];
  5876. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5877. }
  5878. }
  5879. if($falg)
  5880. $html.='<td class="taR">-</td>';
  5881. }
  5882. $m13+=$asum;
  5883. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5884. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5885. $html="";
  5886. }
  5887. }
  5888. $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>
  5889. <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>
  5890. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5891. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5892. }
  5893. $data['companyHtml']=$collectHtml;
  5894. //total price html
  5895. $collectHtml="";$total=0;
  5896. for ($i=1;$i<=12;$i++){
  5897. $sumPrice=0;
  5898. foreach ($itemStatisticsList as $key=>$value){
  5899. if($value['month']==$i){
  5900. $sumPrice+=$value['price'];
  5901. }
  5902. }
  5903. if ($sumPrice==0)
  5904. $collectHtml.='<td class="taR">-</td>';
  5905. else
  5906. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5907. $total+=$sumPrice;
  5908. }
  5909. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5910. $data['companyTotalHtml']=$collectHtml;
  5911. $data['total']=$total;
  5912. $data['year']=$year;
  5913. $data['memu']="receipt";
  5914. $data['staff']=$this->staff;
  5915. $data['receiptMemu']='companyCategoryCollect';
  5916. $data['verifyId']=$this->verifyId;
  5917. $data['executeId']=$this->executeId;
  5918. if ($year<=date("Y")){
  5919. Doo::loadModel('receipt');
  5920. $receipt=new receipt();
  5921. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5922. if(empty($receiptList)){ //generated files
  5923. ob_start();
  5924. $this->render ( "/admin/saeaStaffCollectB", $data );
  5925. $this->cacheFile($path);die;
  5926. }
  5927. }
  5928. $this->render ( "/admin/saeaStaffCollectB", $data );
  5929. }
  5930. function staffCollectBak(){
  5931. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5932. $month=$this->get_args('month')?$this->get_args('month'):1;
  5933. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  5934. $this->showCache($path);
  5935. Doo::loadModel('statistics');
  5936. $statistics=new statistics();
  5937. Doo::loadModel("receiptDetail");
  5938. $receiptDetail=new receiptDetail();
  5939. Doo::loadModel('L_category');
  5940. $Lcategory=new L_category();
  5941. Doo::loadModel('accountItem');
  5942. $accountItem=new accountItem();
  5943. Doo::loadModel('staff');
  5944. $staff=new staff();
  5945. Doo::loadModel('itemStatistics');
  5946. $itemStatistics=new itemStatistics();
  5947. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5948. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  5949. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5950. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  5951. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5952. $staffList=$staff->find(array('asArray'=>true));
  5953. $htmlArray=array();
  5954. foreach ($LcategoryList as $value){
  5955. $htmlArray[$value['title']]=array();
  5956. foreach ($staffList as $v){
  5957. if($value['cid']==$v['cid']){
  5958. $html="";$falg=true;$staffSumPrice=0;
  5959. foreach ($itemStatisticsList as $a){
  5960. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  5961. if(empty($a['price'])){
  5962. $html.='<td class="taR">-</td>';$falg=false;break;
  5963. }else{
  5964. $staffSumPrice+=$a['price'];
  5965. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5966. }
  5967. }
  5968. }
  5969. if ($falg){
  5970. $html.='<td class="taR">-</td>';$falg=true;
  5971. }
  5972. $falg=true;
  5973. foreach ($itemStatisticsList as $a){
  5974. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  5975. if(empty($a['price'])){
  5976. $html.='<td class="taR">-</td>';$falg=false;break;
  5977. }else{
  5978. $staffSumPrice+=$a['price'];
  5979. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5980. }
  5981. }
  5982. }
  5983. if ($falg){
  5984. $html.='<td class="taR">-</td>';$falg=true;
  5985. }
  5986. $falg=true;
  5987. foreach ($itemStatisticsList as $a){
  5988. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  5989. if(empty($a['price'])){
  5990. $html.='<td class="taR">-</td>';$falg=false;break;
  5991. }else{
  5992. $staffSumPrice+=$a['price'];
  5993. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5994. }
  5995. }
  5996. }
  5997. if ($falg){
  5998. $html.='<td class="taR">-</td>';$falg=true;
  5999. }
  6000. $falg=true;
  6001. foreach ($itemStatisticsList as $a){
  6002. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6003. if(!empty($a['price'])){
  6004. $staffSumPrice+=$a['price'];
  6005. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6006. }else{
  6007. $html.='<td class="taR">-</td>';$falg=false;break;
  6008. }
  6009. }
  6010. }
  6011. if ($falg){
  6012. $html.='<td class="taR">-</td>';$falg=true;
  6013. }
  6014. $falg=true;
  6015. foreach ($itemStatisticsList as $a){
  6016. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6017. if(!empty($a['price'])){
  6018. $staffSumPrice+=$a['price'];
  6019. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6020. }else{
  6021. $html.='<td class="taR">-</td>';$falg=false;break;
  6022. }
  6023. }
  6024. }
  6025. if ($falg){
  6026. $html.='<td class="taR">-</td>';$falg=true;
  6027. }
  6028. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6029. $htmlArray[$value['title']][$v['username']]=$html;
  6030. }
  6031. }
  6032. /*-- ---*/
  6033. //合计费用
  6034. $cateHtml="";$catePrice=0;$cateFalg=true;
  6035. foreach ($itemCategoryList as $l){
  6036. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6037. if(empty($l['price'])){
  6038. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6039. }else{
  6040. $catePrice+=$l['price'];
  6041. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6042. }
  6043. }
  6044. }
  6045. if ($cateFalg){
  6046. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6047. }
  6048. $cateFalg=true;
  6049. foreach ($itemCategoryList as $l){
  6050. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6051. if(empty($l['price'])){
  6052. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6053. }else{
  6054. $catePrice+=$l['price'];
  6055. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6056. }
  6057. }
  6058. }
  6059. if ($cateFalg){
  6060. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6061. }
  6062. $cateFalg=true;
  6063. foreach ($itemCategoryList as $l){
  6064. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6065. if(empty($l['price'])){
  6066. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6067. }else{
  6068. $catePrice+=$l['price'];
  6069. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6070. }
  6071. }
  6072. }
  6073. if ($cateFalg){
  6074. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6075. }
  6076. $cateFalg=true;
  6077. foreach ($itemCategoryList as $l){
  6078. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6079. if(empty($l['price'])){
  6080. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6081. }else{
  6082. $catePrice+=$l['price'];
  6083. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6084. }
  6085. }
  6086. }
  6087. if ($cateFalg){
  6088. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6089. }
  6090. $cateFalg=true;
  6091. foreach ($itemCategoryList as $l){
  6092. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6093. if(empty($l['price'])){
  6094. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6095. }else{
  6096. $catePrice+=$l['price'];
  6097. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6098. }
  6099. }
  6100. }
  6101. if ($cateFalg){
  6102. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6103. }
  6104. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6105. $htmlArray[$value['title']]['合计']=$cateHtml;
  6106. /*-- ---*/
  6107. }
  6108. //print_r($htmlArray);die;
  6109. $data['htmlArray']=$htmlArray;
  6110. //statistics html
  6111. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6112. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6113. if(empty($stList))
  6114. $stList=array('rePrice'=>0,'agPrice'=>0);
  6115. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6116. $monthHtml="";
  6117. for ($i=1;$i<=12;$i++){
  6118. if ($i==$month)
  6119. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6120. else
  6121. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6122. }
  6123. $data['monthHtml']=$monthHtml;
  6124. $data['year']=$year;
  6125. $data['month']=$month;
  6126. $data['memu']="receipt";
  6127. $data['staff']=$this->staff;
  6128. $data['receiptMemu']='companyCategoryCollect';
  6129. $data['verifyId']=$this->verifyId;
  6130. $data['executeId']=$this->executeId;
  6131. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6132. Doo::loadModel('receipt');
  6133. $receipt=new receipt();
  6134. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6135. if(empty($receiptList)){ //generated files
  6136. ob_start();
  6137. $this->render ( "/admin/saeaStaffCollect", $data );
  6138. $this->cacheFile($path);die;
  6139. }
  6140. }
  6141. $this->render ( "/admin/saeaStaffCollect", $data );
  6142. }
  6143. function lyt(){
  6144. Doo::loadModel("receiptDetail");
  6145. $receiptDetail=new receiptDetail();
  6146. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6147. foreach ($receiptCollectList as $key=>$value){
  6148. $receiptDetail=new receiptDetail();
  6149. $receiptDetail->pastDate=$value['date'];
  6150. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6151. }
  6152. }
  6153. function staffCollectMonthDetail(){
  6154. $year=$this->get_args('year')?$this->get_args('year'):"";
  6155. $month=$this->get_args('month')?$this->get_args('month'):"";
  6156. if(!$year)
  6157. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6158. if(!$month)
  6159. $month=isset($this->params['month'])?$this->params['month']:1;
  6160. Doo::loadModel('staff');
  6161. $staff=new staff();
  6162. Doo::loadModel("receiptDetail");
  6163. $receiptDetail=new receiptDetail();
  6164. Doo::loadModel('accountItem');
  6165. $accountItem=new accountItem();
  6166. Doo::loadModel('statistics');
  6167. $statistics=new statistics();
  6168. Doo::loadModel('L_category');
  6169. $lCategory=new L_category();
  6170. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6171. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6172. $list=array();
  6173. foreach ($categoryList as $vlu){
  6174. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6175. $r1=0;$r2=0;$r3=0;$r4=0;$r5=0;$r6=0;$r7=0;$r8=0;$r9=0;$r10=0;$r11=0;$r12=0;$r13=0;$r14=0;$r15=0;
  6176. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6177. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6178. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6179. $s1=0;
  6180. $m1=0;
  6181. foreach ($staffList as $value){
  6182. if ($vlu['cid']==$value['cid']){
  6183. //pastDate
  6184. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6185. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6186. // if ($value['sid']==42){
  6187. // print_r($receiptCollectList);die;
  6188. // }
  6189. if(!empty($receiptCollectList)){
  6190. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6191. $html="";
  6192. $psum=0;
  6193. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6194. foreach ($item as $va){
  6195. $falg=true;
  6196. foreach ($receiptCollectList as $v){
  6197. if($v['itemCategory']=='日常相关费用'){
  6198. if($v['item']==$va){
  6199. if ($va=='市内交通费')
  6200. $r1+=$v['price'];
  6201. if ($va=='市内出租费')
  6202. $r2+=$v['price'];
  6203. if ($va=='办事处房租')
  6204. $r3+=$v['price'];
  6205. if ($va=='电话费')
  6206. $r4+=$v['price'];
  6207. if ($va=='水费')
  6208. $r5+=$v['price'];
  6209. if ($va=='电费')
  6210. $r6+=$v['price'];
  6211. if ($va=='办公费用')
  6212. $r7+=$v['price'];
  6213. if ($va=='邮寄费')
  6214. $r8+=$v['price'];
  6215. if ($va=='其他费用')
  6216. $r9+=$v['price'];
  6217. if ($va=='车辆费用')
  6218. $r10+=$v['price'];
  6219. if ($va=='广告费')
  6220. $r11+=$v['price'];
  6221. if ($va=='团队建设费')
  6222. $r13+=$v['price'];
  6223. if ($va=='物业管理费')
  6224. $r14+=$v['price'];
  6225. if ($va=='宽带费')
  6226. $r15+=$v['price'];
  6227. $psum+=$v['price'];
  6228. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6229. }
  6230. }
  6231. }
  6232. if($falg)
  6233. $html.='<td class="taR">-</td>';
  6234. }
  6235. $r12+=$psum;
  6236. if(!empty($psum))
  6237. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6238. else
  6239. $psum='<td class="colGreen taR">-</td>';
  6240. $receiptL['日常相关费用']=$psum.$html;
  6241. /*-----------------------------------*/
  6242. $html="";
  6243. $psum=0;
  6244. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6245. foreach ($item as $va){
  6246. $falg=true;
  6247. foreach ($receiptCollectList as $v){
  6248. if($v['itemCategory']=='差旅相关费用'){
  6249. if($v['item']==$va){
  6250. if ($va=='往来交通费')
  6251. $c1+=$v['price'];
  6252. if ($va=='市内交通费')
  6253. $c2+=$v['price'];
  6254. if ($va=='出差住宿费')
  6255. $c3+=$v['price'];
  6256. if ($va=='出差补助')
  6257. $c4+=$v['price'];
  6258. if ($va=='其他费用')
  6259. $c5+=$v['price'];
  6260. $psum+=$v['price'];
  6261. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6262. }
  6263. }
  6264. }
  6265. if($falg)
  6266. $html.='<td class="taR">-</td>';
  6267. }
  6268. $c6+=$psum;
  6269. if(!empty($psum))
  6270. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6271. else
  6272. $psum='<td class="colGreen taR">-</td>';
  6273. $receiptL['差旅相关费用']=$psum.$html;
  6274. /*-------------------------------------*/
  6275. $html="";
  6276. $psum=0;
  6277. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6278. foreach ($item as $va){
  6279. $falg=true;
  6280. foreach ($receiptCollectList as $v){
  6281. if($v['itemCategory']=='培训班费用'){
  6282. if($v['item']==$va){
  6283. if ($va=='场租费')
  6284. $p1+=$v['price'];
  6285. if ($va=='薪酬')
  6286. $p2+=$v['price'];
  6287. if ($va=='住宿费')
  6288. $p3+=$v['price'];
  6289. if ($va=='交通费')
  6290. $p4+=$v['price'];
  6291. if ($va=='餐饮费')
  6292. $p5+=$v['price'];
  6293. if ($va=='办公费')
  6294. $p6+=$v['price'];
  6295. if ($va=='公关费')
  6296. $p7+=$v['price'];
  6297. if ($va=='其他')
  6298. $p8+=$v['price'];
  6299. $psum+=$v['price'];
  6300. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6301. }
  6302. }
  6303. }
  6304. if($falg)
  6305. $html.='<td class="taR">-</td>';
  6306. }
  6307. $p9+=$psum;
  6308. if(!empty($psum))
  6309. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6310. else
  6311. $psum='<td class="colGreen taR">-</td>';
  6312. $receiptL['培训班费用']=$psum.$html;
  6313. /*-------------------------------------*/
  6314. $html="";
  6315. $psum=0;
  6316. $item=array('公关费','广告费','借款','可自加费用');
  6317. foreach ($item as $va){
  6318. $falg=true;
  6319. foreach ($receiptCollectList as $v){
  6320. if($v['itemCategory']=='其他'){
  6321. // if ($value['sid']==42){
  6322. //
  6323. // echo var_dump($v['item']);
  6324. // echo var_dump($va);
  6325. // echo var_dump($v['item']==" ".$va);
  6326. // echo $v['item']."==".$va."/<br/>";
  6327. // //print_r( $receiptCollectList);//echo $va;
  6328. // }
  6329. if(trim($v['item'])==$va){
  6330. if ($va=='公关费')
  6331. $t1+=$v['price'];
  6332. if ($va=='广告费'){
  6333. $t2+=$v['price'];
  6334. }
  6335. if ($va=='借款')
  6336. $t3+=$v['price'];
  6337. if ($va=='可自加费用')
  6338. $t4+=$v['price'];
  6339. $psum+=$v['price'];
  6340. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6341. }
  6342. }
  6343. }
  6344. if($falg)
  6345. $html.='<td class="taR">-</td>';
  6346. }
  6347. $t5+=$psum;
  6348. if(!empty($psum))
  6349. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6350. else
  6351. $psum='<td class="colGreen taR">-</td>';
  6352. $receiptL['其他']=$psum.$html;
  6353. /*-------------------------------------*/
  6354. $html="";
  6355. $psum=0;
  6356. foreach ($receiptCollectList as $v){
  6357. if($v['itemCategory']=='报销金额调整'){
  6358. if (!empty($v['price'])){
  6359. $psum+=$v['price'];
  6360. }
  6361. }
  6362. }
  6363. $s1+=$psum;
  6364. if(!empty($psum))
  6365. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6366. else
  6367. $psum='<td class="taR colOrange">-</td>';
  6368. $receiptL['报销金额调整']=$psum.$html;
  6369. }else{
  6370. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6371. <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>
  6372. <td class="taR">-</td><td class="taR">-</td>';
  6373. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6374. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6375. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6376. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6377. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6378. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6379. }
  6380. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6381. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6382. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6383. if(!empty($monthStaffPrice[0]['price'])){
  6384. $m1+=$monthStaffPrice[0]['price'];
  6385. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6386. }else
  6387. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6388. $list[$value['username']]=$receiptL;
  6389. }
  6390. }
  6391. $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>
  6392. <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>
  6393. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6394. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6395. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6396. $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>
  6397. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6398. $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>';
  6399. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6400. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6401. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6402. }
  6403. $data['list']=$list;
  6404. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6405. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6406. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6407. //statistics html
  6408. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6409. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6410. if(empty($stList))
  6411. $stList=array('rePrice'=>0,'agPrice'=>0);
  6412. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6413. $monthHtml="";
  6414. for ($i=1;$i<=12;$i++){
  6415. if ($i==$month)
  6416. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6417. else
  6418. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6419. }
  6420. $data['monthHtml']=$monthHtml;
  6421. $data['year']=$year;
  6422. $data['month']=$month;
  6423. $data['memu']="receipt";
  6424. $data['staff']=$this->staff;
  6425. $data['receiptMemu']='companyCategoryCollect';
  6426. $data['verifyId']=$this->verifyId;
  6427. $data['executeId']=$this->executeId;
  6428. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6429. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6430. }
  6431. function staffCollectMonthDetail2(){
  6432. $year=$this->get_args('year')?$this->get_args('year'):"";
  6433. $month=$this->get_args('month')?$this->get_args('month'):"";
  6434. if(!$year)
  6435. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6436. if(!$month)
  6437. $month=isset($this->params['month'])?$this->params['month']:1;
  6438. Doo::loadModel('staff');
  6439. $staff=new staff();
  6440. Doo::loadModel("receiptDetail");
  6441. $receiptDetail=new receiptDetail();
  6442. Doo::loadModel('accountItem');
  6443. $accountItem=new accountItem();
  6444. Doo::loadModel('statistics');
  6445. $statistics=new statistics();
  6446. Doo::loadModel('L_category');
  6447. $lCategory=new L_category();
  6448. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6449. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6450. $list=array();
  6451. foreach ($categoryList as $vlu){
  6452. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6453. $r1=0;$r2=0;$r3=0;$r4=0;$r5=0;$r6=0;$r7=0;$r8=0;$r9=0;$r10=0;$r11=0;$r12=0;$r13=0;$r14=0;$r15=0;
  6454. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6455. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6456. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6457. $s1=0;
  6458. $m1=0;
  6459. foreach ($staffList as $value){
  6460. if ($vlu['cid']==$value['cid']){
  6461. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6462. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6463. if(!empty($receiptCollectList)){
  6464. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6465. $html="";
  6466. $psum=0;
  6467. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6468. foreach ($item as $va){
  6469. $falg=true;
  6470. foreach ($receiptCollectList as $v){
  6471. if($v['itemCategory']=='日常相关费用'){
  6472. if($v['item']==$va){
  6473. if ($va=='市内交通费')
  6474. $r1+=$v['price'];
  6475. if ($va=='市内出租费')
  6476. $r2+=$v['price'];
  6477. if ($va=='办事处房租')
  6478. $r3+=$v['price'];
  6479. if ($va=='电话费')
  6480. $r4+=$v['price'];
  6481. if ($va=='水费')
  6482. $r5+=$v['price'];
  6483. if ($va=='电费')
  6484. $r6+=$v['price'];
  6485. if ($va=='办公费用')
  6486. $r7+=$v['price'];
  6487. if ($va=='邮寄费')
  6488. $r8+=$v['price'];
  6489. if ($va=='其他费用')
  6490. $r9+=$v['price'];
  6491. if ($va=='车辆费用')
  6492. $r10+=$v['price'];
  6493. if ($va=='广告费')
  6494. $r11+=$v['price'];
  6495. if ($va=='团队建设费')
  6496. $r13+=$v['price'];
  6497. if ($va=='物业管理费')
  6498. $r14+=$v['price'];
  6499. if ($va=='宽带费')
  6500. $r15+=$v['price'];
  6501. $psum+=$v['price'];
  6502. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6503. }
  6504. }
  6505. }
  6506. if($falg)
  6507. $html.='<td class="taR">-</td>';
  6508. }
  6509. $r12+=$psum;
  6510. if(!empty($psum))
  6511. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6512. else
  6513. $psum='<td class="colGreen taR">-</td>';
  6514. $receiptL['日常相关费用']=$psum.$html;
  6515. /*-----------------------------------*/
  6516. $html="";
  6517. $psum=0;
  6518. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6519. foreach ($item as $va){
  6520. $falg=true;
  6521. foreach ($receiptCollectList as $v){
  6522. if($v['itemCategory']=='差旅相关费用'){
  6523. if($v['item']==$va){
  6524. if ($va=='往来交通费')
  6525. $c1+=$v['price'];
  6526. if ($va=='市内交通费')
  6527. $c2+=$v['price'];
  6528. if ($va=='出差住宿费')
  6529. $c3+=$v['price'];
  6530. if ($va=='出差补助')
  6531. $c4+=$v['price'];
  6532. if ($va=='其他费用')
  6533. $c5+=$v['price'];
  6534. $psum+=$v['price'];
  6535. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6536. }
  6537. }
  6538. }
  6539. if($falg)
  6540. $html.='<td class="taR">-</td>';
  6541. }
  6542. $c6+=$psum;
  6543. if(!empty($psum))
  6544. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6545. else
  6546. $psum='<td class="colGreen taR">-</td>';
  6547. $receiptL['差旅相关费用']=$psum.$html;
  6548. /*-------------------------------------*/
  6549. $html="";
  6550. $psum=0;
  6551. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6552. foreach ($item as $va){
  6553. $falg=true;
  6554. foreach ($receiptCollectList as $v){
  6555. if($v['itemCategory']=='培训班费用'){
  6556. if($v['item']==$va){
  6557. if ($va=='场租费')
  6558. $p1+=$v['price'];
  6559. if ($va=='薪酬')
  6560. $p2+=$v['price'];
  6561. if ($va=='住宿费')
  6562. $p3+=$v['price'];
  6563. if ($va=='交通费')
  6564. $p4+=$v['price'];
  6565. if ($va=='餐饮费')
  6566. $p5+=$v['price'];
  6567. if ($va=='办公费')
  6568. $p6+=$v['price'];
  6569. if ($va=='公关费')
  6570. $p7+=$v['price'];
  6571. if ($va=='其他')
  6572. $p8+=$v['price'];
  6573. $psum+=$v['price'];
  6574. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6575. }
  6576. }
  6577. }
  6578. if($falg)
  6579. $html.='<td class="taR">-</td>';
  6580. }
  6581. $p9+=$psum;
  6582. if(!empty($psum))
  6583. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6584. else
  6585. $psum='<td class="colGreen taR">-</td>';
  6586. $receiptL['培训班费用']=$psum.$html;
  6587. /*-------------------------------------*/
  6588. $html="";
  6589. $psum=0;
  6590. $item=array('公关费','广告费','借款','可自加费用');
  6591. foreach ($item as $va){
  6592. $falg=true;
  6593. foreach ($receiptCollectList as $v){
  6594. if($v['itemCategory']=='其他'){
  6595. if($v['item']==$va){
  6596. if ($va=='公关费')
  6597. $t1+=$v['price'];
  6598. if ($va=='广告费')
  6599. $t2+=$v['price'];
  6600. if ($va=='借款')
  6601. $t3+=$v['price'];
  6602. if ($va=='可自加费用')
  6603. $t4+=$v['price'];
  6604. $psum+=$v['price'];
  6605. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6606. }
  6607. }
  6608. }
  6609. if($falg)
  6610. $html.='<td class="taR">-</td>';
  6611. }
  6612. $t5+=$psum;
  6613. if(!empty($psum))
  6614. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6615. else
  6616. $psum='<td class="colGreen taR">-</td>';
  6617. $receiptL['其他']=$psum.$html;
  6618. /*-------------------------------------*/
  6619. $html="";
  6620. $psum=0;
  6621. foreach ($receiptCollectList as $v){
  6622. if($v['itemCategory']=='报销金额调整'){
  6623. if (!empty($v['price'])){
  6624. $psum+=$v['price'];
  6625. }
  6626. }
  6627. }
  6628. $s1+=$psum;
  6629. if(!empty($psum))
  6630. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6631. else
  6632. $psum='<td class="taR colOrange">-</td>';
  6633. $receiptL['报销金额调整']=$psum.$html;
  6634. }else{
  6635. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6636. <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>';
  6637. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6638. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6639. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6640. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6641. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6642. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6643. }
  6644. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6645. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6646. if(!empty($monthStaffPrice[0]['price'])){
  6647. $m1+=$monthStaffPrice[0]['price'];
  6648. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6649. }else
  6650. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6651. $list[$value['username']]=$receiptL;
  6652. }
  6653. }
  6654. $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>
  6655. <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>
  6656. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6657. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6658. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6659. $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>
  6660. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6661. $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>';
  6662. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6663. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6664. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6665. }
  6666. $data['list']=$list;
  6667. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6668. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6669. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6670. //statistics html
  6671. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6672. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6673. if(empty($stList))
  6674. $stList=array('rePrice'=>0,'agPrice'=>0);
  6675. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6676. $monthHtml="";
  6677. for ($i=1;$i<=12;$i++){
  6678. if ($i==$month)
  6679. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6680. else
  6681. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6682. }
  6683. $data['monthHtml']=$monthHtml;
  6684. $data['year']=$year;
  6685. $data['month']=$month;
  6686. $data['memu']="receipt";
  6687. $data['staff']=$this->staff;
  6688. $data['receiptMemu']='companyCategoryCollect';
  6689. $data['verifyId']=$this->verifyId;
  6690. $data['executeId']=$this->executeId;
  6691. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6692. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6693. }
  6694. function companyMonthCollectDetail(){
  6695. $year=$this->get_args('year')?$this->get_args('year'):"";
  6696. $month=$this->get_args('month')?$this->get_args('month'):"";
  6697. if(!$year)
  6698. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6699. if(!$month)
  6700. $month=isset($this->params['month'])?$this->params['month']:1;
  6701. Doo::loadModel('staff');
  6702. $staff=new staff();
  6703. Doo::loadModel("receiptDetail");
  6704. $receiptDetail=new receiptDetail();
  6705. Doo::loadModel('accountItem');
  6706. $accountItem=new accountItem();
  6707. Doo::loadModel('statistics');
  6708. $statistics=new statistics();
  6709. Doo::loadModel('L_category');
  6710. $lCategory=new L_category();
  6711. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6712. $categoryList=$lCategory->find(array('asArray'=>true));
  6713. $list=array();
  6714. foreach ($categoryList as $value){
  6715. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6716. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6717. if(!empty($receiptCollectList)){
  6718. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6719. $html="";
  6720. $psum=0;
  6721. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6722. foreach ($item as $va){
  6723. $falg=true;
  6724. foreach ($receiptCollectList as $v){
  6725. if($v['itemCategory']=='日常相关费用'){
  6726. if($v['item']==$va){
  6727. $psum+=$v['price'];
  6728. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6729. }
  6730. }
  6731. }
  6732. if($falg)
  6733. $html.='<td class="taR">-</td>';
  6734. }
  6735. if(!empty($psum))
  6736. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6737. else
  6738. $psum='<td class="colGreen taR">-</td>';
  6739. $receiptL['日常相关费用']=$psum.$html;
  6740. /*-----------------------------------*/
  6741. $html="";
  6742. $psum=0;
  6743. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6744. foreach ($item as $va){
  6745. $falg=true;
  6746. foreach ($receiptCollectList as $v){
  6747. if($v['itemCategory']=='差旅相关费用'){
  6748. if($v['item']==$va){
  6749. $psum+=$v['price'];
  6750. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6751. }
  6752. }
  6753. }
  6754. if($falg)
  6755. $html.='<td class="taR">-</td>';
  6756. }
  6757. if(!empty($psum))
  6758. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6759. else
  6760. $psum='<td class="colGreen taR">-</td>';
  6761. $receiptL['差旅相关费用']=$psum.$html;
  6762. /*-------------------------------------*/
  6763. $html="";
  6764. $psum=0;
  6765. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6766. foreach ($item as $va){
  6767. $falg=true;
  6768. foreach ($receiptCollectList as $v){
  6769. if($v['itemCategory']=='培训班费用'){
  6770. if($v['item']==$va){
  6771. $psum+=$v['price'];
  6772. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6773. }
  6774. }
  6775. }
  6776. if($falg)
  6777. $html.='<td class="taR">-</td>';
  6778. }
  6779. if(!empty($psum))
  6780. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6781. else
  6782. $psum='<td class="colGreen taR">-</td>';
  6783. $receiptL['培训班费用']=$psum.$html;
  6784. /*-------------------------------------*/
  6785. $html="";
  6786. $psum=0;
  6787. $item=array('公关费','广告费','借款','可自加费用');
  6788. foreach ($item as $va){
  6789. $falg=true;
  6790. foreach ($receiptCollectList as $v){
  6791. if($v['itemCategory']=='其他'){
  6792. if($v['item']==$va){
  6793. $psum+=$v['price'];
  6794. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6795. }
  6796. }
  6797. }
  6798. if($falg)
  6799. $html.='<td class="taR">-</td>';
  6800. }
  6801. if(!empty($psum))
  6802. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6803. else
  6804. $psum='<td class="colGreen taR">-</td>';
  6805. $receiptL['其他']=$psum.$html;
  6806. /*-------------------------------------*/
  6807. $html="";
  6808. $psum=0;
  6809. foreach ($receiptCollectList as $v){
  6810. if($v['itemCategory']=='报销金额调整'){
  6811. if (!empty($v['price']))
  6812. $psum+=$v['price'];
  6813. }
  6814. }
  6815. if(!empty($psum))
  6816. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6817. else
  6818. $psum='<td class="taR colOrange">-</td>';
  6819. $receiptL['报销金额调整']=$psum.$html;
  6820. }else{
  6821. $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>
  6822. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6823. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6824. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6825. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6826. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6827. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6828. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6829. }
  6830. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6831. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6832. if(!empty($monthStaffPrice[0]['price']))
  6833. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6834. else
  6835. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6836. $list[$value['title']]=$receiptL;
  6837. }
  6838. $data['list']=$list;
  6839. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6840. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6841. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6842. //print_r($data['monthPriceHtml']);
  6843. // foreach ($data['monthPriceHtml'] as $value){
  6844. // echo $value;
  6845. // }
  6846. // die;
  6847. //statistics html
  6848. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6849. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6850. if(empty($stList))
  6851. $stList=array('rePrice'=>0,'agPrice'=>0);
  6852. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6853. $monthHtml="";
  6854. for ($i=1;$i<=12;$i++){
  6855. if ($i==$month)
  6856. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6857. else
  6858. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6859. }
  6860. $data['monthHtml']=$monthHtml;
  6861. $data['year']=$year;
  6862. $data['month']=$month;
  6863. $data['memu']="receipt";
  6864. $data['staff']=$this->staff;
  6865. $data['receiptMemu']='companyCategoryCollect';
  6866. $data['verifyId']=$this->verifyId;
  6867. $data['executeId']=$this->executeId;
  6868. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6869. }
  6870. function staffCollectDetail(){
  6871. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6872. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6873. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6874. if(!$staffname){
  6875. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6876. $staffname= urldecode($staffname);
  6877. }
  6878. Doo::loadModel('staff');
  6879. $staff=new staff();
  6880. Doo::loadModel("receiptDetail");
  6881. $receiptDetail=new receiptDetail();
  6882. Doo::loadModel('accountItem');
  6883. $accountItem=new accountItem();
  6884. Doo::loadModel('statistics');
  6885. $statistics=new statistics();
  6886. Doo::loadModel('L_category');
  6887. $lCategory=new L_category();
  6888. $staffList=$staff->find(array('asArray'=>true));
  6889. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6890. foreach ($staffList as $value){
  6891. if ($value['username']==$staffname&&$value['username']!='admin'){
  6892. $stTitle=$value['category'].'-'.$value['username'];
  6893. $staffId=$value['sid'];
  6894. $cid=$value['cid'];
  6895. $ocid=$value['cid'];
  6896. if (!empty($value['othercid']))
  6897. $cid=$value['cid'].','.$value['othercid'];
  6898. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6899. }elseif ($value['username']!='admin')
  6900. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6901. }
  6902. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6903. if(empty($pcid))
  6904. $pcid=$ocid;
  6905. $data['ocid']=$pcid;
  6906. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6907. $this->showCache($path);
  6908. //
  6909. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6910. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6911. $accountList=$accountItem->find(array('asArray'=>true));
  6912. //create CollectDetail HTML
  6913. $collectHtml=array();
  6914. foreach ($accountList as $key=>$value){
  6915. $html="";$asum=0;
  6916. for ($i=1;$i<=12;$i++){
  6917. $falg=true;
  6918. foreach ($receiptCollectList as $v) {
  6919. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  6920. $asum+=$v['price'];
  6921. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  6922. }
  6923. }
  6924. if($falg)
  6925. $html.='<td class="taR">-</td>';
  6926. }
  6927. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  6928. $collectHtml[$value['category']][$value['name']]=$html;
  6929. }
  6930. $data['collectHtml']=$collectHtml;
  6931. //create Adjustment price html
  6932. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  6933. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  6934. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6935. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  6936. array_push($collectArray['日常相关费用'], $collectHtml);
  6937. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  6938. array_push($collectArray['差旅相关费用'], $collectHtml);
  6939. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  6940. array_push($collectArray['培训班费用'], $collectHtml);
  6941. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  6942. array_push($collectArray['其他'], $collectHtml);
  6943. $data['collectArray']=$collectArray;
  6944. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  6945. array_push($adjustment, $collectHtml);
  6946. $data['adjustment']=$adjustment;
  6947. //total price html
  6948. $collectHtml="";$total=0;
  6949. for ($i=1;$i<=12;$i++){
  6950. $sumPrice=0;
  6951. foreach ($receiptCollectList as $key=>$value){
  6952. if($value['month']==$i){
  6953. $sumPrice+=$value['price'];
  6954. }
  6955. }
  6956. if ($sumPrice==0)
  6957. $collectHtml.='<td class="taR">-</td>';
  6958. else
  6959. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  6960. $total+=$sumPrice;
  6961. }
  6962. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  6963. //statistics html
  6964. $stList=$statistics->statisticsByYear($year,$staffId);
  6965. if(empty($stList))
  6966. $stList=array('rePrice'=>0,'agPrice'=>0);
  6967. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6968. $data['totalPrice']=$collectHtml;
  6969. $data['totalYear']=$total;
  6970. $data['stHtml']=$stHtml;
  6971. $data['year']=$year;
  6972. $data['stTitle']=$stTitle;
  6973. $data['memu']="receipt";
  6974. $data['staff']=$this->staff;
  6975. $data['receiptMemu']='companyCategoryCollect';
  6976. $data['verifyId']=$this->verifyId;
  6977. $data['executeId']=$this->executeId;
  6978. if ($year<date("Y")){
  6979. Doo::loadModel('receipt');
  6980. $receipt=new receipt();
  6981. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  6982. if(empty($receiptList)){ //generated files
  6983. ob_start();
  6984. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6985. $this->cacheFile($path);die;
  6986. }
  6987. }
  6988. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6989. }
  6990. function BUGFLAG(){
  6991. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  6992. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  6993. $month=$this->get_args('month')?$this->get_args('month'):"";
  6994. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  6995. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  6996. if (empty($status))
  6997. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  6998. $page_size=12;
  6999. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7000. $vidList=array();
  7001. $button=0;
  7002. Doo::loadModel('verify');
  7003. $verify=new verify();
  7004. Doo::loadModel('receipt');
  7005. $receipt=new receipt();
  7006. Doo::loadModel('staff');
  7007. $staff=new staff();
  7008. Doo::loadModel('L_category');
  7009. $Lcategory=new L_category();
  7010. $dateCondition=" and Year(date) =".$year;
  7011. if(!empty($month))
  7012. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  7013. $categoryList=$Lcategory->find(array('asArray'=>true));
  7014. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7015. $cateCondition="";$staffCondition="";$approvalCondition="";
  7016. if (!empty($cid))
  7017. $cateCondition=' and cid='.$cid;
  7018. if(!empty($sid)){
  7019. $staffCondition=' and staff='.$sid;
  7020. $cateCondition="";
  7021. }
  7022. $approvalCondition=" and status=".$status;
  7023. if($status==2){
  7024. //查找角色审批人
  7025. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7026. }
  7027. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7028. $approvalCondition=' and status=2 ';
  7029. }
  7030. if($status==1){
  7031. $approvalCondition=' and (status='.$status.' or status=6) ';
  7032. }
  7033. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7034. $pageinfo['page']=array('previous'=>'');
  7035. if ($status==0){
  7036. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7037. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7038. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7039. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7040. }else
  7041. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7042. ,'desc'=>'rid','asArray'=>true));
  7043. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )'.$cateCondition.$staffCondition
  7044. ,'desc'=>'rid','asArray'=>true));
  7045. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7046. //print_r($pageinfo);
  7047. $Locate=0;
  7048. foreach ($receiptList as $key=>$value){
  7049. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7050. $receiptList[$key]['reviseDetail']=array();
  7051. if (!empty($value['reviseDetail']))
  7052. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7053. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7054. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7055. $receiptList[$key]['category']=$categoryDetil['title'];
  7056. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7057. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7058. $verifyStaff=json_decode($value['verifyStaff'],true);
  7059. foreach ($verifyList as $k=>$v){
  7060. //init verifyStaff
  7061. $verifyList[$k]['date']="";
  7062. $verifyList[$k]['opinion']="";
  7063. $verifyList[$k]['status']="";
  7064. if (empty($verifyStaff)){
  7065. $verifyList[$k]['date']="";
  7066. $verifyList[$k]['opinion']="";
  7067. if ($v[0]==$this->staff[0]['sid']){
  7068. $verifyList[$k]['status']=4;
  7069. $button=4;
  7070. }
  7071. }else{
  7072. $flag=true;
  7073. foreach ($verifyStaff as $m=>$u){
  7074. if ($v[0]==$m){
  7075. $verifyList[$k]['date']=$u['date'];
  7076. $verifyList[$k]['opinion']=$u['opinion'];
  7077. $verifyList[$k]['status']=$u['status'];
  7078. $flag=false;
  7079. break;
  7080. }
  7081. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7082. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7083. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7084. }
  7085. if($flag){//检测可编辑
  7086. if($v[0]==$this->staff[0]['sid']){
  7087. $verifyList[$k]['status']=4;$button=4;
  7088. }
  7089. }
  7090. }
  7091. }
  7092. $receiptList[$key]['verifyList']=$verifyList;
  7093. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7094. $receiptList[$key]['button']=$button;
  7095. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7096. }
  7097. //print_r($receiptList);die;
  7098. //$data['verifyDetail']=$verifyDetail;
  7099. $mothHtml="";
  7100. for($i=1;$i<=12;$i++){
  7101. if($month==$i)
  7102. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7103. else
  7104. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7105. }
  7106. $data['mothHtml']=$mothHtml;
  7107. $data['page']=$pageinfo;
  7108. $data['receiptList']=$receiptList;
  7109. $data['receiptApprovalCount']=count($rLRes);
  7110. $data['status']=$status;
  7111. $data['year']=$year;
  7112. $data['categoryList']=$categoryList;
  7113. $data['staffList']=$staffList;
  7114. $data['cid']=$cid;
  7115. $data['sid']=$sid;
  7116. //print_r($receiptList);
  7117. $data['memu']="receipt";
  7118. $data['staff']=$this->staff;
  7119. $data['receiptMemu']='approvalExpenses';
  7120. $data['verifyId']=$this->verifyId;
  7121. $data['executeId']=$this->executeId;
  7122. $this->render ( "/admin/FALG", $data );
  7123. }
  7124. function ajaxGetReceiptOrder(){
  7125. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7126. if (!empty($receiptOrder)){
  7127. Doo::loadModel('receipt');
  7128. $receipt=new receipt();
  7129. Doo::loadModel ( 'staff' );
  7130. $staff = new staff ();
  7131. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7132. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7133. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7134. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7135. </tbody></table><table class="table table table-bordered"><tbody>';
  7136. foreach ($verifyStaff as $key=>$value){
  7137. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7138. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7139. }
  7140. $html.='</tbody></table></div></div>';
  7141. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7142. }
  7143. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7144. }
  7145. function _getMonthCollectDetail($receiptCollectList){
  7146. if(!empty($receiptCollectList)){
  7147. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7148. $html="";
  7149. $psum=0;
  7150. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7151. foreach ($item as $value){
  7152. $falg=true;
  7153. foreach ($receiptCollectList as $v){
  7154. if($v['itemCategory']=='日常相关费用'){
  7155. if($v['item']==$value){
  7156. $psum+=$v['price'];
  7157. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7158. }
  7159. }
  7160. }
  7161. if($falg)
  7162. $html.='<td class="taR">-</td>';
  7163. }
  7164. if(!empty($psum))
  7165. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7166. else
  7167. $psum='<td class="colGreen taR">-</td>';
  7168. $receiptL['日常相关费用']=$psum.$html;
  7169. /*-----------------------------------*/
  7170. $html="";
  7171. $psum=0;
  7172. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7173. foreach ($item as $value){
  7174. $falg=true;
  7175. foreach ($receiptCollectList as $v){
  7176. if($v['itemCategory']=='差旅相关费用'){
  7177. if($v['item']==$value){
  7178. $psum+=$v['price'];
  7179. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7180. }
  7181. }
  7182. }
  7183. if($falg)
  7184. $html.='<td class="taR">-</td>';
  7185. }
  7186. if(!empty($psum))
  7187. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7188. else
  7189. $psum='<td class="colGreen taR">-</td>';
  7190. $receiptL['差旅相关费用']=$psum.$html;
  7191. /*-------------------------------------*/
  7192. $html="";
  7193. $psum=0;
  7194. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7195. foreach ($item as $value){
  7196. $falg=true;
  7197. foreach ($receiptCollectList as $v){
  7198. if($v['itemCategory']=='培训班费用'){
  7199. if($v['item']==$value){
  7200. $psum+=$v['price'];
  7201. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7202. }
  7203. }
  7204. }
  7205. if($falg)
  7206. $html.='<td class="taR">-</td>';
  7207. }
  7208. if(!empty($psum))
  7209. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7210. else
  7211. $psum='<td class="colGreen taR">-</td>';
  7212. $receiptL['培训班费用']=$psum.$html;
  7213. /*-------------------------------------*/
  7214. $html="";
  7215. $psum=0;
  7216. $item=array('公关费','广告费','借款','可自加费用');
  7217. foreach ($item as $value){
  7218. $falg=true;
  7219. foreach ($receiptCollectList as $v){
  7220. if($v['itemCategory']=='其他'){
  7221. if($v['item']==$value){
  7222. $psum+=$v['price'];
  7223. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7224. }
  7225. }
  7226. }
  7227. if($falg)
  7228. $html.='<td class="taR">-</td>';
  7229. }
  7230. if(!empty($psum))
  7231. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7232. else
  7233. $psum='<td class="colGreen taR">-</td>';
  7234. $receiptL['其他']=$psum.$html;
  7235. /*-------------------------------------*/
  7236. $html="";
  7237. $psum=0;
  7238. foreach ($receiptCollectList as $v){
  7239. if($v['itemCategory']=='报销金额调整'){
  7240. if (!empty($v['price']))
  7241. $psum+=$v['price'];
  7242. }
  7243. }
  7244. if(!empty($psum))
  7245. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7246. else
  7247. $psum='<td class="taR colOrange">-</td>';
  7248. $receiptL['报销金额调整']=$psum.$html;
  7249. }else{
  7250. $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>
  7251. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7252. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7253. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7254. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7255. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7256. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7257. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7258. }
  7259. return $receiptL;
  7260. }
  7261. function eMail(){
  7262. Doo::loadModel('staff');
  7263. $staff=new staff();
  7264. Doo::loadModel('receipt');
  7265. $receipt=new receipt();
  7266. Doo::loadModel('L_category');
  7267. $Lcategory=new L_category();
  7268. Doo::loadModel("verify");
  7269. $verify=new verify();
  7270. $staffList=$staff->find(array('asArray'=>true));
  7271. foreach ($staffList as $key=>$value){
  7272. if($value['username']!='admin'){
  7273. //提交人
  7274. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7275. if(!empty($receiptList)){
  7276. $html='<br><div><style></style>
  7277. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7278. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7279. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7280. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7281. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7282. <tbody><tr>
  7283. <td style="padding: 0 40px;" align="left">
  7284. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7285. </td></tr><tr>
  7286. <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>
  7287. </tr>
  7288. </tbody> </table></td> </tr> <tr><td>
  7289. <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">
  7290. <tbody> <tr><td>
  7291. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7292. 以下报销单完成了审批,等着收款吧:</p>
  7293. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7294. foreach ($receiptList as $k=>$v){
  7295. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7296. $html.='
  7297. <tr>
  7298. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7299. <td align="left">
  7300. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7301. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7302. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7303. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7304. </tr>';
  7305. }
  7306. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7307. <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>
  7308. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7309. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7310. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7311. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7312. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7313. $receipt=new receipt();
  7314. $receipt->notice=1;
  7315. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7316. }
  7317. }
  7318. //审批人
  7319. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7320. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7321. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7322. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7323. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7324. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7325. <tbody><tr><td style="padding: 0 40px;" align="left">
  7326. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7327. </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>
  7328. </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">
  7329. <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>
  7330. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7331. foreach ($verifyList as $k=>$v){
  7332. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7333. foreach ($receiptList as $r=>$l){
  7334. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7335. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7336. $html.='
  7337. <tr>
  7338. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7339. <td align="left">
  7340. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7341. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7342. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7343. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7344. </tr>';
  7345. }
  7346. }
  7347. $html.='
  7348. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7349. <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>
  7350. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7351. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7352. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7353. // $receipt=new receipt();
  7354. // $receipt->notice=1;
  7355. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7356. }
  7357. }
  7358. }
  7359. }
  7360. // Email发送函数
  7361. function SMail($toemail, $subject, $contents) {
  7362. Doo::loadClass('class.phpmailer');
  7363. $mail = new PHPMailer();
  7364. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7365. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7366. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7367. $mail->Password = "cDO1GjtY1seH"; //密码
  7368. $mail->CharSet = "UTF8";
  7369. $mail->SMTPAuth = true;
  7370. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7371. $mail->Mailer = "smtp";
  7372. $mail->Port = 25;
  7373. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7374. $mail->MsgHTML($contents);
  7375. $mail->AddAddress($toemail);
  7376. $mail->CharSet = "UTF-8";
  7377. return $mail->Send();
  7378. }
  7379. function swfupload(){
  7380. $POST_MAX_SIZE = ini_get('post_max_size');
  7381. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7382. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7383. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7384. header("HTTP/1.1 500 Internal Server Error");
  7385. echo "POST exceeded maximum allowed size.";
  7386. exit(0);
  7387. }
  7388. // Settings
  7389. $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)
  7390. $upload_name = "Filedata";
  7391. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7392. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7393. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7394. // Other variables
  7395. $MAX_FILENAME_LENGTH = 260;
  7396. $file_name = "";
  7397. $file_extension = "";
  7398. $uploadErrors = array(
  7399. 0=>"文件上传成功",
  7400. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7401. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7402. 3=>"上传的文件仅为部分文件",
  7403. 4=>"没有文件上传",
  7404. 6=>"缺少临时文件夹"
  7405. );
  7406. $nk= time();
  7407. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7408. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7409. echo "文件无法保存.";
  7410. exit(0);
  7411. }
  7412. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7413. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7414. exit(0);
  7415. }
  7416. function _GetFileEXT($filename) {
  7417. $pics = explode ( '.', $filename );
  7418. $num = count ( $pics );
  7419. return $pics [$num - 1];
  7420. }
  7421. /**
  7422. * 获取get或者POST值
  7423. * @param string $name 属性名称
  7424. * @return fixed 值
  7425. */
  7426. function get_args($name) {
  7427. if (isset ( $_GET [$name] )) {
  7428. if (is_array ( $_GET [$name] ))
  7429. return $_GET [$name];
  7430. else
  7431. return addslashes ( $_GET [$name] );
  7432. } elseif (isset ( $_POST [$name] )) {
  7433. if (is_array ( $_POST [$name] ))
  7434. return $_POST [$name];
  7435. else
  7436. return addslashes ( $_POST [$name] );
  7437. } else
  7438. return false;
  7439. }
  7440. function num_to_rmb($num){
  7441. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7442. $c2 = "分角元拾佰仟万拾佰仟亿";
  7443. //精确到分后面就不要了,所以只留两个小数位
  7444. $num = round($num, 2);
  7445. //将数字转化为整数
  7446. $num = $num * 100;
  7447. if (strlen($num) > 10) {
  7448. return "金额太大,请检查";
  7449. }
  7450. $i = 0;
  7451. $c = "";
  7452. while (1) {
  7453. if ($i == 0) {
  7454. //获取最后一位数字
  7455. $n = substr($num, strlen($num)-1, 1);
  7456. } else {
  7457. $n = $num % 10;
  7458. }
  7459. //每次将最后一位数字转化为中文
  7460. $p1 = substr($c1, 3 * $n, 3);
  7461. $p2 = substr($c2, 3 * $i, 3);
  7462. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7463. $c = $p1 . $p2 . $c;
  7464. } else {
  7465. $c = $p1 . $c;
  7466. }
  7467. $i = $i + 1;
  7468. //去掉数字最后一位了
  7469. $num = $num / 10;
  7470. $num = (int)$num;
  7471. //结束循环
  7472. if ($num == 0) {
  7473. break;
  7474. }
  7475. }
  7476. $j = 0;
  7477. $slen = strlen($c);
  7478. while ($j < $slen) {
  7479. //utf8一个汉字相当3个字符
  7480. $m = substr($c, $j, 6);
  7481. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7482. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7483. $left = substr($c, 0, $j);
  7484. $right = substr($c, $j + 3);
  7485. $c = $left . $right;
  7486. $j = $j-3;
  7487. $slen = $slen-3;
  7488. }
  7489. $j = $j + 3;
  7490. }
  7491. //这个是为了去掉类似23.0中最后一个“零”字
  7492. if (substr($c, strlen($c)-3, 3) == '零') {
  7493. $c = substr($c, 0, strlen($c)-3);
  7494. }
  7495. //将处理的汉字加上“整”
  7496. if (empty($c)) {
  7497. return "零元整";
  7498. }else{
  7499. return $c . "整";
  7500. }
  7501. }
  7502. /**
  7503. * 获得分页数据
  7504. * @param unknown_type $table
  7505. * @param unknown_type $condition
  7506. * @param unknown_type $on_page
  7507. * @param unknown_type $page_size
  7508. */
  7509. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7510. $page_c = "";
  7511. $page ['previous'] = $this->get_previous ( $on_page );
  7512. $page ['on_page'] = $on_page;
  7513. $total_count = $this->get_table_count ( $table, $condition );
  7514. $total = intval ( $total_count / $page_size );
  7515. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7516. $page ['total_data'] = $total_count;
  7517. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7518. $i = 1;
  7519. $page_max = 1;
  7520. $page_width=3;
  7521. if ($on_page >= $page_width) {
  7522. $page_max = intval ( $on_page / $page_width ) + 1;
  7523. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7524. }
  7525. for(; $i <= $page ['total_page']; $i ++) {
  7526. if ($i == $on_page)
  7527. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7528. else
  7529. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7530. if ($i == ($page_width * $page_max))
  7531. break;
  7532. }
  7533. $page ['page'] = $page_c;
  7534. $page ['lower'] = (-- $on_page) * $page_size;
  7535. return $page;
  7536. }
  7537. /**
  7538. * 获取总页数
  7539. * @param unknown_type $table
  7540. * @param unknown_type $condition
  7541. */
  7542. public function get_table_count($table = "", $condition = "") {
  7543. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7544. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7545. //echo $sql;die;
  7546. $query = Doo::db ()->query ( $sql );
  7547. $result = $query->fetch ();
  7548. return $result ['count'];
  7549. }
  7550. /**
  7551. * 获取上一页
  7552. * @param unknown_type $on_page
  7553. */
  7554. function get_previous($on_page = 1) {
  7555. return $on_page != 0 ? $on_page - 1 : $on_page;
  7556. }
  7557. }
  7558. ?>