ReceiptController.php 295 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038
  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. Doo::loadModel('verify');
  43. // $verify=new verify();
  44. //
  45. // //user verify ID
  46. // $vidList=array();
  47. // $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'\"%"','asArray'=>true));
  48. // foreach ($verifyDetail as $key=>$value){
  49. // array_push($vidList, $value['vid']);
  50. // }
  51. // $vid=implode(",", $vidList);
  52. // if(empty($verifyDetail))
  53. // $vid=0;
  54. $dateCondition=" and Year(date) =".$year;
  55. //$approvalCondition=' and verifyStaff not like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  56. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  57. $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  58. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  59. return count($receiptList);
  60. }
  61. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  62. $collectHtml="";$sumPrice=0.00;
  63. for ($i=1;$i<=12;$i++){
  64. $falg=true;
  65. foreach ($receiptCollectList as $key=>$value){
  66. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  67. $sumPrice+=$value['price'];
  68. if ($classType=="b"){
  69. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  70. }else{
  71. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  72. }
  73. }
  74. }
  75. if ($falg)
  76. $collectHtml.='<td class="taR">-</td>';
  77. }
  78. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  79. return $collectHtml;
  80. }
  81. function __construct() {
  82. if(isset($_COOKIE["staff"])){
  83. if(!empty($_COOKIE["staff"])){
  84. Doo::loadModel ( 'staff' );
  85. Doo::loadModel('verify');
  86. $verify=new verify();
  87. $staff = new staff ();
  88. Doo::loadModel("execute");
  89. $execute=new execute();
  90. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  91. $list=array();
  92. //判断角色的审批权限
  93. foreach ($verifyList as $key=>$value){
  94. $ver=json_decode($value['staff']);
  95. foreach ($ver as $k=>$v){
  96. if ($v[1]=='ROLE'){
  97. $roleList=json_decode($v[3]);
  98. foreach ($roleList as $t=>$g){
  99. $gList=explode("_", $g);
  100. array_push($list, $gList[0]);
  101. //print_r($list);
  102. }
  103. }else
  104. array_push($list, $v[0]);
  105. }
  106. }
  107. //判断执行人的审批权限
  108. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  109. $list2=array();
  110. foreach ($executeList as $key=>$value){
  111. $ver=json_decode($value['staff']);
  112. foreach ($ver as $k=>$v){
  113. array_push($list2, $v[0]);
  114. }
  115. }
  116. $eidList=file_get_contents("protected/config/execute/execute.ini");
  117. $eidList=array_filter(explode(",", $eidList));
  118. $this->executeId= array_merge($list2,$eidList);
  119. $this->verifyId=$list;
  120. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  121. self::$NEW= $this->getReceiptCount();
  122. self::$NEW2= $this->getExeCount();
  123. return "/";
  124. }
  125. }
  126. Doo::loadCore ( 'uri/DooUriRouter' );
  127. $router = new DooUriRouter ();
  128. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  129. if($routeRs['1']!="login"){
  130. header ( 'Content-Type:text/html;charset=utf-8' );
  131. @header ( "Location: /login" );
  132. }
  133. }
  134. function saeaBorad(){
  135. Doo::loadModel('receipt');
  136. Doo::loadModel('verify');
  137. $verify=new verify();
  138. $receipt=new receipt();
  139. Doo::loadModel('L_category');
  140. $lCategory=new L_category();
  141. Doo::loadModel("role");
  142. $role=new role();
  143. Doo::loadModel("receiptLog");
  144. $receiptLog=new receiptLog();
  145. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  146. $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));
  147. foreach ($receiptDetail as $key=>$value){
  148. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  149. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  150. $v=json_decode($veList['staff']);
  151. array_push($v[0], $veList['description']);
  152. foreach ($v as $n=>$m){
  153. if ($m['1']=='ROLE'){
  154. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  155. $v[$n][1]=$roleInfo['name'];
  156. }
  157. }
  158. $receiptDetail[$key]['staff']=$v;
  159. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  160. $receiptDetail[$key]['category']=$category['title'];
  161. }
  162. //print_r($receiptLogList);
  163. $data['receiptLogList']=$receiptLogList;
  164. $data['receiptDetail']=$receiptDetail;
  165. $data['memu']="receipt";
  166. $data['staff']=$this->staff;
  167. $data['receiptMemu']='saeaBorad';
  168. $data['verifyId']=$this->verifyId;
  169. $data['executeId']=$this->executeId;
  170. $this->render ( "/admin/saeaBorad", $data );
  171. }
  172. function remitAdd(){
  173. Doo::loadModel('accountItem');
  174. Doo::loadModel('verify');
  175. Doo::loadModel('receipt');
  176. Doo::loadModel('L_category');
  177. $lCategory=new L_category();
  178. $receipt=new receipt();
  179. $verify=new verify();
  180. $accountItem=new accountItem();
  181. Doo::loadModel("role");
  182. $role=new role();
  183. $acItem=$accountItem->find(array('asArray'=>true));
  184. $veList=$verify->find(array('asArray'=>true));
  185. foreach ($veList as $key=>$value){
  186. $v=json_decode($value['staff']);
  187. $list=array();
  188. foreach ($v as $n=>$m){
  189. if ($m['1']=='ROLE'){
  190. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  191. $v[$n][1]=$roleInfo['name'];
  192. array_push($list, $roleInfo['name']);
  193. }else{
  194. array_push($list, $v[$n][1]);
  195. }
  196. }
  197. $veList[$key]['staff']=implode('>', $list);
  198. }
  199. $data['category']=$lCategory->find(array('asArray'=>true));
  200. $data['veList']=$veList;
  201. $data['acItem']=$acItem;
  202. $data['memu']="receipt";
  203. $data['staff']=$this->staff;
  204. $data['receiptMemu']='saeaBorad';
  205. $data['verifyId']=$this->verifyId;
  206. $data['executeId']=$this->executeId;
  207. $this->render ( "/admin/remitAdd", $data );
  208. }
  209. function remitAddDo(){
  210. $agency=$this->get_args('agency');
  211. $travel=$this->get_args('travel');
  212. $train=$this->get_args('train');
  213. $other=$this->get_args('other');
  214. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  215. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  216. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  217. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  218. //print_r($agency);die;
  219. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  220. Doo::loadModel('receipt');
  221. Doo::loadModel('receiptDetail');
  222. Doo::loadModel('accountItem');
  223. $accountItem=new accountItem();
  224. $receipt=new receipt();
  225. Doo::loadModel('enclosur');
  226. Doo::loadModel('execute');
  227. $execute=new execute();
  228. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  229. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  230. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  231. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  232. $ag=$tr=$ta=$ot=0;
  233. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  234. foreach ($aItem as $key=>$value){
  235. if ($value['category']==$this->AGENCY){
  236. if (isset($agency[$ag])){
  237. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  238. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  239. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  240. }
  241. }
  242. $ag++;
  243. }
  244. }
  245. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  246. //报销单
  247. $receipt->accountItem=json_encode($accountJson);
  248. $receipt->staff=$this->staff[0]['sid'];
  249. $receipt->sum=number_format($sum, 2, '.', '');
  250. $receipt->date=date("Y-m-d");
  251. $receipt->cid=$cid;
  252. $receipt->status=5;
  253. $receipt->Rtype=2;
  254. //修改审批流程加入角色
  255. $receipt->verify=$verify;
  256. $receipt->executeCopy=$executeDetail['staff'];
  257. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  258. $receipt->explanation=$explanation;
  259. $rid=$receipt->insert();
  260. //附件
  261. if (!empty($enclosurName)){
  262. $enclosurArray=explode('-', $enclosurName);
  263. foreach ($enclosurArray as $value){
  264. $enclosur=new enclosur();
  265. $enclosur->name=$value;
  266. $enclosur->rid=$rid;
  267. $enclosur->insert();
  268. }
  269. //print_r($enclosurArray);die;
  270. }
  271. //报销详情
  272. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  273. $receiptDetail=new receiptDetail();
  274. $receiptDetail->staff=$this->staff[0]['sid'];
  275. $receiptDetail->item=$value['name'];
  276. $receiptDetail->itemCategory=$this->AGENCY;
  277. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  278. $receiptDetail->date=date("Y-m-d");
  279. $receiptDetail->cid=$cid;
  280. $receiptDetail->rid=$rid;
  281. $receiptDetail->status=4;
  282. $receiptDetail->insert();
  283. }
  284. }
  285. return "/saeaBorad";
  286. }
  287. function remitEdit(){
  288. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  289. //echo $rid;
  290. Doo::loadModel('accountItem');
  291. Doo::loadModel('verify');
  292. Doo::loadModel('receipt');
  293. $receipt=new receipt();
  294. $verify=new verify();
  295. $accountItem=new accountItem();
  296. Doo::loadModel('L_category');
  297. $lCategory=new L_category();
  298. Doo::loadModel("role");
  299. $role=new role();
  300. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  301. if(empty($receiptDetail))
  302. return "/saeaCreate";
  303. $acItem=$accountItem->find(array('asArray'=>true));
  304. $veList=$verify->find(array('asArray'=>true));
  305. foreach ($veList as $key=>$value){
  306. $v=json_decode($value['staff']);
  307. $list=array();
  308. foreach ($v as $n=>$m){
  309. if ($m['1']=='ROLE'){
  310. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  311. $v[$n][1]=$roleInfo['name'];
  312. array_push($list, $roleInfo['name']);
  313. }else{
  314. array_push($list, $v[$n][1]);
  315. }
  316. }
  317. $veList[$key]['staff']=implode('>', $list);
  318. }
  319. //配置编辑信息
  320. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  321. foreach ($acItem as $key=>$value){
  322. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  323. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  324. $acItem[$key]['price']=$v['price'];
  325. }
  326. }
  327. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  328. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  329. $acItem[$key]['price']=$v['price'];
  330. }
  331. }
  332. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  333. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  334. $acItem[$key]['price']=$v['price'];
  335. }
  336. }
  337. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  338. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  339. $acItem[$key]['price']=$v['price'];
  340. }
  341. }
  342. }
  343. $data['category']=$lCategory->find(array('asArray'=>true));
  344. $data['cSum']=$accountItemList['cSum'];
  345. $data['sum']=$receiptDetail['sum'];
  346. $data['receiptDetail']=$receiptDetail;
  347. $data['veList']=$veList;
  348. $data['acItem']=$acItem;
  349. $data['memu']="receipt";
  350. $data['staff']=$this->staff;
  351. $data['receiptMemu']='saeaBorad';
  352. $data['verify']=$receiptDetail['verify'];
  353. $data['verifyId']=$this->verifyId;
  354. $data['executeId']=$this->executeId;
  355. $data['rid']=$rid;
  356. $this->render ( "/admin/remitEdit", $data );
  357. }
  358. function remitEdiDo(){
  359. $agency=$this->get_args('agency');
  360. $travel=$this->get_args('travel');
  361. $train=$this->get_args('train');
  362. $other=$this->get_args('other');
  363. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  364. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  365. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  366. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  367. if(!empty($verify)&&!empty($explanation)){
  368. Doo::loadModel('receipt');
  369. Doo::loadModel('receiptDetail');
  370. Doo::loadModel('accountItem');
  371. $accountItem=new accountItem();
  372. $receipt=new receipt();
  373. Doo::loadModel('execute');
  374. $execute=new execute();
  375. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  376. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  377. if(empty($receiptDetail))
  378. return "/saeaBorad";
  379. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  380. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  381. $ag=$tr=$ta=$ot=0;
  382. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  383. foreach ($aItem as $key=>$value){
  384. if ($value['category']==$this->AGENCY){
  385. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  386. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  387. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  388. }
  389. $ag++;
  390. }
  391. }
  392. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  393. //报销单
  394. $rid=$receipt->rid=$receiptDetail['rid'];
  395. $receipt->accountItem=json_encode($accountJson);
  396. $receipt->staff=$this->staff[0]['sid'];
  397. $receipt->sum=number_format($sum, 2, '.', '');
  398. $receipt->date=date("Y-m-d");
  399. $receipt->cid=$cid;
  400. if ($receiptDetail['Rtype']==1)
  401. $receipt->status=7;
  402. else
  403. $receipt->status=5;
  404. $receipt->verify=$verify;
  405. $receipt->executeCopy=$executeDetail['staff'];
  406. $receipt->explanation=$explanation;
  407. $receipt->update();
  408. $receiptDetail=new receiptDetail();
  409. $receiptDetail->delete(array('where'=>'rid='.$rid));
  410. //报销详情
  411. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  412. $receiptDetail=new receiptDetail();
  413. $receiptDetail->staff=$this->staff[0]['sid'];
  414. $receiptDetail->item=$value['name'];
  415. $receiptDetail->itemCategory=$this->AGENCY;
  416. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  417. $receiptDetail->date=date("Y-m-d");
  418. $receiptDetail->cid=$cid;
  419. $receiptDetail->rid=$rid;
  420. $receiptDetail->status=4;
  421. $receiptDetail->insert();
  422. }
  423. //return "/referReceipt/".$rid;
  424. }
  425. return "/saeaBorad";
  426. }
  427. function remitApproval(){
  428. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  429. $status=isset($this->params['status'])?$this->params['status']:'';
  430. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  431. $month=$this->get_args('month')?$this->get_args('month'):"";
  432. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  433. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  434. if (empty($status))
  435. $status=$this->get_args('status')?$this->get_args('status'):2;
  436. $vidList=array();
  437. $button=0;
  438. Doo::loadModel('verify');
  439. Doo::loadModel('receipt');
  440. Doo::loadModel('staff');
  441. $staff=new staff();
  442. $receipt=new receipt();
  443. $verify=new verify();
  444. Doo::loadModel('L_category');
  445. $Lcategory=new L_category();
  446. Doo::loadModel('enclosur');
  447. $enclosur=new enclosur();
  448. //user verify ID
  449. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  450. foreach ($verifyDetail as $key=>$value){
  451. array_push($vidList, $value['vid']);
  452. }
  453. $vid=implode(",", $vidList);
  454. if(empty($verifyDetail))
  455. $vid=0;
  456. $categoryList=$Lcategory->find(array('asArray'=>true));
  457. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  458. $ap="";
  459. if($status==4){
  460. $ap=4;$status=2;
  461. }
  462. //get Receipt By verifyID status 2
  463. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  464. $Locate=0;$roleId=0;
  465. if($ap==4)
  466. $status=4;
  467. foreach ($receiptList as $key=>$value){
  468. $receiptList[$key]['Locate']=$Locate;$Locate++;
  469. $receiptList[$key]['reviseDetail']=array();
  470. if (!empty($value['reviseDetail']))
  471. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  472. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  473. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  474. $receiptList[$key]['category']=$categoryDetil['title'];
  475. //检测编辑状态
  476. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  477. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  478. $verifyStaff=json_decode($value['verifyStaff'],true);
  479. Doo::loadModel('role');
  480. $role=new role();
  481. //print_r($verifyList);
  482. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  483. foreach ($verifyList as $k=>$v){
  484. //init verifyStaff
  485. if ($v[1]=='ROLE'){
  486. if (!empty($verifyStaff)){
  487. $endStaffArray=end($verifyStaff);
  488. if ($v[0]==$endStaffArray['nextStaff']){
  489. $roleId=$v[0];
  490. }
  491. }
  492. $roleVerify=json_decode($v[3],true);
  493. $roleKey=$k;$roleArray=array();
  494. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  495. foreach ($roleVerify as $o=>$p){
  496. $staffID=explode ('_',$p);
  497. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  498. //print_r($staffID);
  499. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  500. array_push($roleArray, $exp);
  501. }
  502. $roleArrayCopy[$v[0]]=$roleArray;
  503. //$verifyList[$k]['roleArray']=$roleArray;
  504. }
  505. //print_r($roleArray);
  506. $verifyList[$k]['date']="";
  507. $verifyList[$k]['opinion']="";
  508. $verifyList[$k]['status']="";
  509. if (empty($verifyStaff)){
  510. $verifyList[$k]['date']="";
  511. $verifyList[$k]['opinion']="";
  512. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  513. $verifyList[$k]['status']=4;
  514. $button=4;$flag=false;
  515. }
  516. }else{
  517. foreach ($verifyStaff as $m=>$u){
  518. if ($v[0]==$m){
  519. $verifyList[$k]['date']=$u['date'];
  520. $verifyList[$k]['opinion']=$u['opinion'];
  521. $verifyList[$k]['status']=$u['status'];
  522. $flag=false;
  523. break;
  524. }
  525. }
  526. $endStaffArray=end($verifyStaff);
  527. if (isset($endStaffArray['ROLE'])){
  528. }else{
  529. $endKey=key($verifyStaff);
  530. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  531. $button=4;
  532. $verifyList[$k]['status']=4;
  533. }
  534. }
  535. }
  536. }
  537. $rolename['name']='';
  538. if (!empty($roleId)){
  539. Doo::loadModel('role');
  540. $role=new role();
  541. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  542. }
  543. if (!empty($verifyStaff))
  544. $endStaffArray=end($verifyStaff);
  545. $KOP=false;
  546. foreach ($roleArrayCopy as $P=>$A){
  547. foreach ( $A as $MKI=>$AVL){
  548. if (!empty($verifyStaff)){
  549. //&&$rolename['rid']==$endStaffArray['nextStaff']
  550. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  551. $button=4;
  552. $roleArrayCopy[$P][$MKI]['status']=4;
  553. }
  554. foreach ($verifyStaff as $m=>$u){
  555. $AVLFK=$AVL[0].'_R';
  556. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  557. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  558. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  559. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  560. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  561. break;
  562. }
  563. }
  564. }else{
  565. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  566. $button=4;
  567. $roleArrayCopy[$P][$MKI]['status']=4;
  568. }
  569. }
  570. //$roleArray[$MKI]['rolename']=$rolename['name'];
  571. $KOP=true;
  572. }
  573. }
  574. foreach ($roleArrayCopy as $k=>$v){
  575. foreach ($verifyList as $m=>$n){
  576. if ($n[0]==$k){
  577. array_splice($verifyList,$m,1,$v);
  578. }
  579. }
  580. }
  581. $receiptList[$key]['verifyList']= $verifyList;
  582. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  583. $receiptList[$key]['button']=$button;
  584. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  585. }
  586. $mothHtml="";
  587. for($i=1;$i<=12;$i++){
  588. if($month==$i)
  589. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  590. else
  591. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  592. }
  593. //获取审批日志
  594. Doo::loadModel('receiptLog');
  595. $receiptLog=new receiptLog();
  596. $rlList=array();
  597. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  598. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  599. if (!empty($rlInfo)){
  600. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  601. }
  602. $receiptList[0]['rlList']=$rlList;
  603. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  604. $enclosurHtml='';
  605. foreach ($enclosurList as $value){
  606. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  607. }
  608. //print_r($receiptList);
  609. $data['enclosurHtml']=$enclosurHtml;
  610. $data['rolename']=$rolename['name'];
  611. $data['datetij']=$tijdate['date'];
  612. $data['mothHtml']=$mothHtml;
  613. $data['rid']=$rid;
  614. $data['receiptList']=$receiptList;
  615. $data['receiptApprovalCount']=count($receiptList);
  616. $data['status']=$status;
  617. $data['year']=$year;
  618. $data['categoryList']=$categoryList;
  619. $data['staffList']=$staffList;
  620. $data['cid']=$cid;
  621. $data['sid']=$sid;
  622. $data['ap']=$ap;
  623. $data['memu']="receipt";
  624. $data['staff']=$this->staff;
  625. $data['receiptMemu']='approvalExpenses';
  626. $data['verifyId']=$this->verifyId;
  627. $data['executeId']=$this->executeId;
  628. $this->render ( "/admin/remitApproval", $data );
  629. }
  630. function saeaLoanAdd(){
  631. Doo::loadModel('verify');
  632. $verify=new verify();
  633. Doo::loadModel("role");
  634. $role=new role();
  635. Doo::loadModel('L_category');
  636. $lCategory=new L_category();
  637. $veList=$verify->find(array('asArray'=>true));
  638. foreach ($veList as $key=>$value){
  639. $v=json_decode($value['staff']);
  640. $list=array();
  641. foreach ($v as $n=>$m){
  642. if ($m['1']=='ROLE'){
  643. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  644. $v[$n][1]=$roleInfo['name'];
  645. array_push($list, $roleInfo['name']);
  646. }else{
  647. array_push($list, $v[$n][1]);
  648. }
  649. }
  650. $veList[$key]['staff']=implode('>', $list);
  651. }
  652. $data['category']=$lCategory->find(array('asArray'=>true));
  653. $data['veList']=$veList;
  654. $data['memu']="receipt";
  655. $data['staff']=$this->staff;
  656. $data['receiptMemu']='saeaBorad';
  657. $data['verifyId']=$this->verifyId;
  658. $data['executeId']=$this->executeId;
  659. $this->render ( "/admin/saeaLoanAdd", $data );
  660. }
  661. function saeaLoanAddDo(){
  662. $agency=$this->get_args('agency');
  663. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  664. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  665. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  666. //die;
  667. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  668. Doo::loadModel('receipt');
  669. Doo::loadModel('receiptDetail');
  670. Doo::loadModel('accountItem');
  671. $accountItem=new accountItem();
  672. $receipt=new receipt();
  673. Doo::loadModel('loanReceipt');
  674. $loanReceipt=new loanReceipt();
  675. Doo::loadModel('execute');
  676. $execute=new execute();
  677. Doo::loadModel('enclosur');
  678. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  679. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  680. // if(!empty($receiptDetail))
  681. // return "/referReceipt/".$receiptDetail['rid'];
  682. $aItem=$accountItem->find(array('asArray'=>true));
  683. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  684. $ag=$tr=$ta=$ot=0;
  685. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  686. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  687. $sum+=$agency;$agencySum+=$agency;
  688. $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, '.', ''));
  689. //借款数据备份
  690. $loanReceipt->loanItem=json_encode($accountJson);
  691. $loanReceipt->staff=$this->staff[0]['sid'];
  692. $loanReceipt->sum=number_format($sum, 2, '.', '');
  693. $loanReceipt->date=date("Y-m-d");
  694. $loanReceipt->cid=$cid;
  695. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  696. $loanReceipt->status=5;
  697. $loanReceipt->Rtype=1;
  698. $loanReceipt->verify=$verify;
  699. $receipt->receiptOrder=$receipt->receiptOrder;
  700. $loanReceipt->explanation=$explanation;
  701. $loanRid=$loanReceipt->insert();
  702. //报销单
  703. $receipt->loanItem=json_encode($accountJson);
  704. $receipt->staff=$this->staff[0]['sid'];
  705. $receipt->sum=number_format($sum, 2, '.', '');
  706. $receipt->date=date("Y-m-d");
  707. $receipt->cid=$cid;
  708. //特殊状态
  709. $receipt->status=5;
  710. $receipt->Rtype=1;
  711. $receipt->loanRid=$loanRid;
  712. //修改审批流程加入角色
  713. $receipt->verify=$verify;
  714. $receipt->executeCopy=$executeDetail['staff'];
  715. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  716. $receipt->explanation=$explanation;
  717. $rid=$receipt->insert();
  718. //执行数据备份
  719. // $executeCopy->rid=$rid;
  720. // $executeCopy->staff=$executeDetail['staff'];
  721. // $executeCopy->eid=$executeDetail['eid'];
  722. // $ecid=$executeCopy->insert();
  723. }
  724. return "/saeaBorad";
  725. }
  726. function saeaLoanEdi(){
  727. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  728. Doo::loadModel('verify');
  729. $verify=new verify();
  730. Doo::loadModel("role");
  731. $role=new role();
  732. Doo::loadModel('L_category');
  733. $lCategory=new L_category();
  734. Doo::loadModel('receipt');
  735. $receipt=new receipt();
  736. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  737. $veList=$verify->find(array('asArray'=>true));
  738. foreach ($veList as $key=>$value){
  739. $v=json_decode($value['staff']);
  740. $list=array();
  741. foreach ($v as $n=>$m){
  742. if ($m['1']=='ROLE'){
  743. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  744. $v[$n][1]=$roleInfo['name'];
  745. array_push($list, $roleInfo['name']);
  746. }else{
  747. array_push($list, $v[$n][1]);
  748. }
  749. }
  750. $veList[$key]['staff']=implode('>', $list);
  751. }
  752. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  753. $data['receiptInfo']=$receiptInfo;
  754. $data['category']=$lCategory->find(array('asArray'=>true));
  755. $data['veList']=$veList;
  756. $data['memu']="receipt";
  757. $data['staff']=$this->staff;
  758. $data['receiptMemu']='saeaBorad';
  759. $data['verifyId']=$this->verifyId;
  760. $data['executeId']=$this->executeId;
  761. $this->render ( "/admin/saeaLoanEdi", $data );
  762. }
  763. function saeaLoanEdiDo(){
  764. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  765. $agency=$this->get_args('agency');
  766. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  767. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  768. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  769. //die;
  770. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  771. Doo::loadModel('receipt');
  772. Doo::loadModel('receiptDetail');
  773. Doo::loadModel('accountItem');
  774. $accountItem=new accountItem();
  775. $receipt=new receipt();
  776. Doo::loadModel('loanReceipt');
  777. $loanReceipt=new loanReceipt();
  778. Doo::loadModel('enclosur');
  779. Doo::loadModel('execute');
  780. $execute=new execute();
  781. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  782. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 and rid='.$rid,'asArray'=>true));
  783. if(empty($receiptDetail))
  784. die('参数错误');
  785. $aItem=$accountItem->find(array('asArray'=>true));
  786. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  787. $ag=$tr=$ta=$ot=0;
  788. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  789. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  790. $sum+=$agency;$agencySum+=$agency;
  791. $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, '.', ''));
  792. //报销单
  793. $receipt->loanItem=json_encode($accountJson);
  794. $receipt->sum=number_format($sum, 2, '.', '');
  795. $receipt->cid=$cid;
  796. //特殊状态
  797. //修改审批流程加入角色
  798. $receipt->verify=$verify;
  799. $receipt->explanation=$explanation;
  800. $receipt->update(array('where'=>'rid='.$rid));
  801. //借款数据更新
  802. $loanReceipt->loanItem=json_encode($accountJson);
  803. $loanReceipt->sum=number_format($sum, 2, '.', '');
  804. $loanReceipt->cid=$cid;
  805. $loanReceipt->verify=$verify;
  806. $loanReceipt->explanation=$explanation;
  807. $receipt->executeCopy=$executeDetail['staff'];
  808. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  809. }
  810. return "/saeaBorad";
  811. }
  812. function saeaLoanReceiptAdd(){
  813. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  814. Doo::loadModel('receipt');
  815. $receipt=new receipt();
  816. Doo::loadModel('loanReceipt');
  817. $loanReceipt=new loanReceipt();
  818. Doo::loadModel('L_category');
  819. $Lcategory=new L_category();
  820. Doo::loadModel('verify');
  821. Doo::loadModel('statistics');
  822. $statistics=new statistics();
  823. $verify=new verify();
  824. Doo::loadModel('staff');
  825. $staff=new staff();
  826. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  827. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  828. $Locate=0;$roleId=0;$button=0;
  829. foreach ($receiptList as $key=>$value){
  830. $receiptList[$key]['Locate']=$Locate;$Locate++;
  831. $receiptList[$key]['reviseDetail']=array();
  832. if (!empty($value['reviseDetail']))
  833. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  834. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  835. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  836. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  837. $receiptList[$key]['category']=$categoryDetil['title'];
  838. //检测编辑状态
  839. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  840. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  841. $verifyStaff=json_decode($value['verifyStaff'],true);
  842. Doo::loadModel('role');
  843. $role=new role();
  844. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  845. foreach ($verifyList as $k=>$v){
  846. //init verifyStaff
  847. if ($v[1]=='ROLE'){
  848. if (!empty($verifyStaff)){
  849. $endStaffArray=end($verifyStaff);
  850. // if ($v[0]==$endStaffArray['nextStaff']){
  851. // $roleId=$v[0];
  852. // }
  853. }
  854. $roleVerify=json_decode($v[3],true);
  855. $roleKey=$k;$roleArray=array();
  856. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  857. foreach ($roleVerify as $o=>$p){
  858. $staffID=explode ('_',$p);
  859. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  860. //print_r($staffID);
  861. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  862. array_push($roleArray, $exp);
  863. }
  864. $roleArrayCopy[$v[0]]=$roleArray;
  865. //$verifyList[$k]['roleArray']=$roleArray;
  866. }
  867. $verifyList[$k]['date']="";
  868. $verifyList[$k]['opinion']="";
  869. $verifyList[$k]['status']="";
  870. if (empty($verifyStaff)){
  871. $verifyList[$k]['date']="";
  872. $verifyList[$k]['opinion']="";
  873. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  874. $verifyList[$k]['status']=4;
  875. $flag=false;
  876. }
  877. }else{
  878. foreach ($verifyStaff as $m=>$u){
  879. if ($v[0]==$m){
  880. $verifyList[$k]['date']=$u['date'];
  881. $verifyList[$k]['opinion']=$u['opinion'];
  882. $verifyList[$k]['status']=$u['status'];
  883. $flag=false;
  884. break;
  885. }
  886. }
  887. $endStaffArray=end($verifyStaff);
  888. if (isset($endStaffArray['ROLE'])){
  889. }else{
  890. // $endKey=key($verifyStaff);
  891. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  892. // $button=4;
  893. // $verifyList[$k]['status']=4;
  894. // }
  895. }
  896. }
  897. }
  898. $rolename['name']='';
  899. if (!empty($roleId)){
  900. Doo::loadModel('role');
  901. $role=new role();
  902. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  903. }
  904. if (!empty($verifyStaff))
  905. $endStaffArray=end($verifyStaff);
  906. $KOP=false;
  907. foreach ($roleArrayCopy as $P=>$A){
  908. foreach ( $A as $MKI=>$AVL){
  909. if (!empty($verifyStaff)){
  910. //&&$rolename['rid']==$endStaffArray['nextStaff']
  911. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  912. $button=4;
  913. $roleArrayCopy[$P][$MKI]['status']=4;
  914. }
  915. foreach ($verifyStaff as $m=>$u){
  916. $AVLFK=$AVL[0].'_R';
  917. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  918. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  919. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  920. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  921. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  922. break;
  923. }
  924. }
  925. }else{
  926. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  927. $button=4;
  928. $roleArrayCopy[$P][$MKI]['status']=4;
  929. }
  930. }
  931. //$roleArray[$MKI]['rolename']=$rolename['name'];
  932. $KOP=true;
  933. }
  934. }
  935. foreach ($roleArrayCopy as $k=>$v){
  936. foreach ($verifyList as $m=>$n){
  937. if ($n[0]==$k){
  938. array_splice($verifyList,$m,1,$v);
  939. }
  940. }
  941. }
  942. $receiptList[$key]['verifyList']=$verifyList;
  943. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  944. $receiptList[$key]['button']=$button;
  945. //
  946. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  947. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  948. }
  949. $data['receiptList']=$receiptList;
  950. Doo::loadModel('L_category');
  951. $lCategory=new L_category();
  952. Doo::loadModel('accountItem');
  953. $accountItem=new accountItem();
  954. $acItem=$accountItem->find(array('asArray'=>true));
  955. $veList=$verify->find(array('asArray'=>true));
  956. foreach ($veList as $key=>$value){
  957. $v=json_decode($value['staff']);
  958. $list=array();
  959. foreach ($v as $n=>$m){
  960. if ($m['1']=='ROLE'){
  961. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  962. $v[$n][1]=$roleInfo['name'];
  963. array_push($list, $roleInfo['name']);
  964. }else{
  965. array_push($list, $v[$n][1]);
  966. }
  967. }
  968. $veList[$key]['staff']=implode('>', $list);
  969. }
  970. $data['rid']=$rid;
  971. $data['category']=$lCategory->find(array('asArray'=>true));
  972. $data['veList']=$veList;
  973. $data['acItem']=$acItem;
  974. $data['memu']="receipt";
  975. $data['staff']=$this->staff;
  976. $data['receiptMemu']='saeaBorad';
  977. $data['verifyId']=$this->verifyId;
  978. $data['executeId']=$this->executeId;
  979. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  980. }
  981. function saeaLoanReceiptAddDo(){
  982. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  983. $agency=$this->get_args('agency');
  984. $travel=$this->get_args('travel');
  985. $train=$this->get_args('train');
  986. $other=$this->get_args('other');
  987. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  988. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  989. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  990. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  991. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  992. Doo::loadModel('receipt');
  993. Doo::loadModel('receiptDetail');
  994. Doo::loadModel('accountItem');
  995. $accountItem=new accountItem();
  996. $receipt=new receipt();
  997. Doo::loadModel('enclosur');
  998. Doo::loadModel('execute');
  999. $execute=new execute();
  1000. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  1001. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1002. // if(!empty($receiptDetail))
  1003. // return "/referReceipt/".$receiptDetail['rid'];
  1004. $aItem=$accountItem->find(array('asArray'=>true));
  1005. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  1006. $ag=$tr=$ta=$ot=0;
  1007. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  1008. foreach ($aItem as $key=>$value){
  1009. if ($value['category']==$this->AGENCY){
  1010. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  1011. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  1012. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  1013. }
  1014. $ag++;
  1015. }
  1016. if($value['category']==$this->TRAVEL){
  1017. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1018. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1019. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1020. }
  1021. $tr++;
  1022. }
  1023. if($value['category']==$this->TRAIN){
  1024. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1025. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1026. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1027. }
  1028. $ta++;
  1029. }
  1030. if($value['category']==$this->OTHER){
  1031. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1032. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1033. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1034. }
  1035. $ot++;
  1036. }
  1037. }
  1038. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1039. //报销单
  1040. $receipt->accountItem=json_encode($accountJson);
  1041. $receipt->staff=$this->staff[0]['sid'];
  1042. $receipt->loanSum=$receiptDet['sum'];
  1043. $receipt->sum=number_format($sum, 2, '.', '');
  1044. $receipt->date=date("Y-m-d");
  1045. $receipt->pastDate='';
  1046. $receipt->cid=$cid;
  1047. $receipt->status=7;
  1048. //修改审批流程加入角色
  1049. $receipt->verify=$verify;
  1050. $receipt->verifyStaff='';
  1051. $receipt->executeStaff='';
  1052. $receipt->executeCopy=$executeDetail['staff'];
  1053. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1054. $receipt->explanation=$explanation;
  1055. $receipt->update(array('where'=>'rid='.$rid));
  1056. //附件
  1057. if (!empty($enclosurName)){
  1058. $enclosurArray=explode('-', $enclosurName);
  1059. foreach ($enclosurArray as $value){
  1060. $enclosur=new enclosur();
  1061. $enclosur->name=$value;
  1062. $enclosur->rid=$rid;
  1063. $enclosur->insert();
  1064. }
  1065. //print_r($enclosurArray);die;
  1066. }
  1067. //报销详情
  1068. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1069. $receiptDetail=new receiptDetail();
  1070. $receiptDetail->staff=$this->staff[0]['sid'];
  1071. $receiptDetail->item=$value['name'];
  1072. $receiptDetail->itemCategory=$this->AGENCY;
  1073. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1074. $receiptDetail->date=date("Y-m-d");
  1075. $receiptDetail->cid=$cid;
  1076. $receiptDetail->rid=$rid;
  1077. $receiptDetail->status=4;
  1078. $receiptDetail->insert();
  1079. }
  1080. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1081. $receiptDetail=new receiptDetail();
  1082. $receiptDetail->staff=$this->staff[0]['sid'];
  1083. $receiptDetail->item=$value['name'];
  1084. $receiptDetail->itemCategory=$this->TRAVEL;
  1085. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1086. $receiptDetail->date=date("Y-m-d");
  1087. $receiptDetail->cid=$cid;
  1088. $receiptDetail->rid=$rid;
  1089. $receiptDetail->status=4;
  1090. $receiptDetail->insert();
  1091. }
  1092. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1093. $receiptDetail=new receiptDetail();
  1094. $receiptDetail->staff=$this->staff[0]['sid'];
  1095. $receiptDetail->item=$value['name'];
  1096. $receiptDetail->itemCategory=$this->TRAIN;
  1097. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1098. $receiptDetail->date=date("Y-m-d");
  1099. $receiptDetail->cid=$cid;
  1100. $receiptDetail->rid=$rid;
  1101. $receiptDetail->status=4;
  1102. $receiptDetail->insert();
  1103. }
  1104. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1105. $receiptDetail=new receiptDetail();
  1106. $receiptDetail->staff=$this->staff[0]['sid'];
  1107. $receiptDetail->item=$value['name'];
  1108. $receiptDetail->itemCategory=$this->OTHER;
  1109. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1110. $receiptDetail->date=date("Y-m-d");
  1111. $receiptDetail->cid=$cid;
  1112. $receiptDetail->rid=$rid;
  1113. $receiptDetail->status=4;
  1114. $receiptDetail->insert();
  1115. }
  1116. return "/saeaBorad";
  1117. }
  1118. return "/saeaLoanReceiptAdd/".$rid;
  1119. }
  1120. function saeaLoanReceiptEdi(){
  1121. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1122. //echo $rid;
  1123. Doo::loadModel('accountItem');
  1124. Doo::loadModel('verify');
  1125. Doo::loadModel('receipt');
  1126. $receipt=new receipt();
  1127. $verify=new verify();
  1128. $accountItem=new accountItem();
  1129. Doo::loadModel('L_category');
  1130. $Lcategory=new L_category();
  1131. Doo::loadModel("role");
  1132. $role=new role();
  1133. Doo::loadModel('loanReceipt');
  1134. $loanReceipt=new loanReceipt();
  1135. Doo::loadModel('staff');
  1136. $staff=new staff();
  1137. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1138. if(empty($receiptDetail))
  1139. return "/saeaBorad";
  1140. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1141. $Locate=0;$roleId=0;$button=0;
  1142. foreach ($receiptList as $key=>$value){
  1143. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1144. $receiptList[$key]['reviseDetail']=array();
  1145. if (!empty($value['reviseDetail']))
  1146. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1147. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1148. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1149. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1150. $receiptList[$key]['category']=$categoryDetil['title'];
  1151. //检测编辑状态
  1152. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1153. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1154. $verifyStaff=json_decode($value['verifyStaff'],true);
  1155. Doo::loadModel('role');
  1156. $role=new role();
  1157. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1158. foreach ($verifyList as $k=>$v){
  1159. //init verifyStaff
  1160. if ($v[1]=='ROLE'){
  1161. if (!empty($verifyStaff)){
  1162. $endStaffArray=end($verifyStaff);
  1163. // if ($v[0]==$endStaffArray['nextStaff']){
  1164. // $roleId=$v[0];
  1165. // }
  1166. }
  1167. $roleVerify=json_decode($v[3],true);
  1168. $roleKey=$k;$roleArray=array();
  1169. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1170. foreach ($roleVerify as $o=>$p){
  1171. $staffID=explode ('_',$p);
  1172. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1173. //print_r($staffID);
  1174. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1175. array_push($roleArray, $exp);
  1176. }
  1177. $roleArrayCopy[$v[0]]=$roleArray;
  1178. //$verifyList[$k]['roleArray']=$roleArray;
  1179. }
  1180. $verifyList[$k]['date']="";
  1181. $verifyList[$k]['opinion']="";
  1182. $verifyList[$k]['status']="";
  1183. if (empty($verifyStaff)){
  1184. $verifyList[$k]['date']="";
  1185. $verifyList[$k]['opinion']="";
  1186. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1187. $verifyList[$k]['status']=4;
  1188. $flag=false;
  1189. }
  1190. }else{
  1191. foreach ($verifyStaff as $m=>$u){
  1192. if ($v[0]==$m){
  1193. $verifyList[$k]['date']=$u['date'];
  1194. $verifyList[$k]['opinion']=$u['opinion'];
  1195. $verifyList[$k]['status']=$u['status'];
  1196. $flag=false;
  1197. break;
  1198. }
  1199. }
  1200. $endStaffArray=end($verifyStaff);
  1201. if (isset($endStaffArray['ROLE'])){
  1202. }else{
  1203. // $endKey=key($verifyStaff);
  1204. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1205. // $button=4;
  1206. // $verifyList[$k]['status']=4;
  1207. // }
  1208. }
  1209. }
  1210. }
  1211. $rolename['name']='';
  1212. if (!empty($roleId)){
  1213. Doo::loadModel('role');
  1214. $role=new role();
  1215. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1216. }
  1217. if (!empty($verifyStaff))
  1218. $endStaffArray=end($verifyStaff);
  1219. $KOP=false;
  1220. foreach ($roleArrayCopy as $P=>$A){
  1221. foreach ( $A as $MKI=>$AVL){
  1222. if (!empty($verifyStaff)){
  1223. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1224. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1225. $button=4;
  1226. $roleArrayCopy[$P][$MKI]['status']=4;
  1227. }
  1228. foreach ($verifyStaff as $m=>$u){
  1229. $AVLFK=$AVL[0].'_R';
  1230. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1231. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1232. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1233. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1234. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1235. break;
  1236. }
  1237. }
  1238. }else{
  1239. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1240. $button=4;
  1241. $roleArrayCopy[$P][$MKI]['status']=4;
  1242. }
  1243. }
  1244. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1245. $KOP=true;
  1246. }
  1247. }
  1248. foreach ($roleArrayCopy as $k=>$v){
  1249. foreach ($verifyList as $m=>$n){
  1250. if ($n[0]==$k){
  1251. array_splice($verifyList,$m,1,$v);
  1252. }
  1253. }
  1254. }
  1255. $receiptList[$key]['verifyList']=$verifyList;
  1256. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1257. $receiptList[$key]['button']=$button;
  1258. //
  1259. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1260. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1261. }
  1262. $data['receiptList']=$receiptList;
  1263. $acItem=$accountItem->find(array('asArray'=>true));
  1264. $veList=$verify->find(array('asArray'=>true));
  1265. foreach ($veList as $key=>$value){
  1266. $v=json_decode($value['staff']);
  1267. $list=array();
  1268. foreach ($v as $n=>$m){
  1269. if ($m['1']=='ROLE'){
  1270. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1271. $v[$n][1]=$roleInfo['name'];
  1272. array_push($list, $roleInfo['name']);
  1273. }else{
  1274. array_push($list, $v[$n][1]);
  1275. }
  1276. }
  1277. $veList[$key]['staff']=implode('>', $list);
  1278. }
  1279. //配置编辑信息
  1280. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1281. foreach ($acItem as $key=>$value){
  1282. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1283. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1284. $acItem[$key]['price']=$v['price'];
  1285. }
  1286. }
  1287. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1288. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1289. $acItem[$key]['price']=$v['price'];
  1290. }
  1291. }
  1292. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1293. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1294. $acItem[$key]['price']=$v['price'];
  1295. }
  1296. }
  1297. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1298. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1299. $acItem[$key]['price']=$v['price'];
  1300. }
  1301. }
  1302. }
  1303. $data['category']=$Lcategory->find(array('asArray'=>true));
  1304. $data['cSum']=$accountItemList['cSum'];
  1305. $data['sum']=$receiptDetail['sum'];
  1306. $data['receiptDetail']=$receiptDetail;
  1307. $data['veList']=$veList;
  1308. $data['acItem']=$acItem;
  1309. $data['memu']="receipt";
  1310. $data['staff']=$this->staff;
  1311. $data['receiptMemu']='saeaBorad';
  1312. $data['verify']=$receiptDetail['verify'];
  1313. $data['verifyId']=$this->verifyId;
  1314. $data['executeId']=$this->executeId;
  1315. $data['rid']=$rid;
  1316. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1317. }
  1318. function confirmation(){
  1319. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1320. Doo::loadModel('receipt');
  1321. Doo::loadModel('receiptDetail');
  1322. $receipt=new receipt();
  1323. $receiptDetail=new receiptDetail();
  1324. Doo::loadModel('statistics');
  1325. Doo::loadModel('itemStatistics');
  1326. $statistics=new statistics();
  1327. $itemStatistics=new itemStatistics();
  1328. Doo::loadModel("verify");
  1329. $verify=new verify();
  1330. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1331. if(empty($receiptDetailList))
  1332. return "/saeaBorad";
  1333. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1334. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1335. if (empty($receiptDetailList['nowStaff'])){
  1336. $nowStaff="";$nowStaffList=array();
  1337. if ($verifyDetail[0][1]=='ROLE'){
  1338. $vStaffString=json_decode($verifyDetail[0][3]);
  1339. foreach ($vStaffString as $key=>$value){
  1340. $staffK=explode("_", $value);
  1341. array_push($nowStaffList, $staffK[0]);
  1342. }
  1343. $nowStaff=implode(',', $nowStaffList);
  1344. }else{
  1345. $nowStaff=$verifyDetail[0][0];
  1346. }
  1347. $receipt->nowStaff=$nowStaff;
  1348. }
  1349. // echo $nowStaff;
  1350. // print_r($verifyDetail);die;
  1351. $receipt->rid=$receiptDetailList['rid'];
  1352. $receipt->status=2;
  1353. $receipt->update();
  1354. //操作日志
  1355. Doo::loadModel("receiptLog");
  1356. $receiptLog=new receiptLog();
  1357. $verify=new verify();
  1358. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1359. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1360. $jd=json_decode($vr['staff']);$roleId=0;
  1361. foreach ($jd as $key=>$value){
  1362. if ($value[1]=='ROLE'){
  1363. $pos = strpos($value[3], $this->staff[0]['sid']);
  1364. if ($pos !== false) {
  1365. $roleId=$value[0];
  1366. }
  1367. }
  1368. }
  1369. //审批日志
  1370. //echo $roleId;die;
  1371. if (!empty($roleId)){
  1372. Doo::loadModel("role");
  1373. $role=new role();
  1374. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1375. $receiptLog->rolename=$roleInfo['name'];
  1376. }
  1377. $receiptLog->username=$this->staff[0]['username'];
  1378. $receiptLog->uid=$this->staff[0]['sid'];
  1379. $receiptLog->date=date("Y-m-d");
  1380. $receiptLog->opinion='提交审批';
  1381. $receiptLog->img=$this->staff[0]['avatar'];
  1382. $receiptLog->status=2;
  1383. $receiptLog->rid=$rid;
  1384. $receiptLog->insert();
  1385. return "/expenses";
  1386. }
  1387. function expenses(){
  1388. $item=isset($this->params['item'])?$this->params['item']:"";
  1389. if(empty($item))
  1390. $item=$this->get_args('item')?$this->get_args('item'):"";
  1391. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1392. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1393. Doo::loadModel('receipt');
  1394. $receipt=new receipt();
  1395. Doo::loadModel('L_category');
  1396. $Lcategory=new L_category();
  1397. Doo::loadModel('verify');
  1398. Doo::loadModel('statistics');
  1399. $statistics=new statistics();
  1400. $verify=new verify();
  1401. Doo::loadModel('staff');
  1402. $staff=new staff();
  1403. $condition="";
  1404. if($item=="expenses")
  1405. $condition=" and Rtype=1 ";
  1406. elseif ($item=="receipts")
  1407. $condition=" and Rtype=0 ";
  1408. elseif ($item=="remits")
  1409. $condition=" and Rtype=2 ";
  1410. $dateCondition=" and Year(date) =".$year;
  1411. if(!empty($moth)){
  1412. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1413. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1414. }else
  1415. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1416. if(empty($stList))
  1417. $stList=array('rePrice'=>0,'agPrice'=>0);
  1418. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  1419. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  1420. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1421. $Locate=0;$roleId=0;$button=0;
  1422. foreach ($receiptList as $key=>$value){
  1423. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1424. $receiptList[$key]['reviseDetail']=array();
  1425. if (!empty($value['reviseDetail']))
  1426. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1427. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1428. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1429. $receiptList[$key]['category']=$categoryDetil['title'];
  1430. //检测编辑状态
  1431. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1432. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1433. $verifyStaff=json_decode($value['verifyStaff'],true);
  1434. Doo::loadModel('role');
  1435. $role=new role();
  1436. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1437. foreach ($verifyList as $k=>$v){
  1438. //init verifyStaff
  1439. if ($v[1]=='ROLE'){
  1440. if (!empty($verifyStaff)){
  1441. $endStaffArray=end($verifyStaff);
  1442. // if ($v[0]==$endStaffArray['nextStaff']){
  1443. // $roleId=$v[0];
  1444. // }
  1445. }
  1446. $roleVerify=json_decode($v[3],true);
  1447. $roleKey=$k;$roleArray=array();
  1448. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1449. foreach ($roleVerify as $o=>$p){
  1450. $staffID=explode ('_',$p);
  1451. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1452. //print_r($staffID);
  1453. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1454. array_push($roleArray, $exp);
  1455. }
  1456. $roleArrayCopy[$v[0]]=$roleArray;
  1457. //$verifyList[$k]['roleArray']=$roleArray;
  1458. }
  1459. $verifyList[$k]['date']="";
  1460. $verifyList[$k]['opinion']="";
  1461. $verifyList[$k]['status']="";
  1462. if (empty($verifyStaff)){
  1463. $verifyList[$k]['date']="";
  1464. $verifyList[$k]['opinion']="";
  1465. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1466. $verifyList[$k]['status']=4;
  1467. $flag=false;
  1468. }
  1469. }else{
  1470. foreach ($verifyStaff as $m=>$u){
  1471. if ($v[0]==$m){
  1472. $verifyList[$k]['date']=$u['date'];
  1473. $verifyList[$k]['opinion']=$u['opinion'];
  1474. $verifyList[$k]['status']=$u['status'];
  1475. $flag=false;
  1476. break;
  1477. }
  1478. }
  1479. $endStaffArray=end($verifyStaff);
  1480. if (isset($endStaffArray['ROLE'])){
  1481. }else{
  1482. // $endKey=key($verifyStaff);
  1483. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1484. // $button=4;
  1485. // $verifyList[$k]['status']=4;
  1486. // }
  1487. }
  1488. }
  1489. }
  1490. $rolename['name']='';
  1491. if (!empty($roleId)){
  1492. Doo::loadModel('role');
  1493. $role=new role();
  1494. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1495. }
  1496. if (!empty($verifyStaff))
  1497. $endStaffArray=end($verifyStaff);
  1498. $KOP=false;
  1499. foreach ($roleArrayCopy as $P=>$A){
  1500. foreach ( $A as $MKI=>$AVL){
  1501. if (!empty($verifyStaff)){
  1502. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1503. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1504. $button=4;
  1505. $roleArrayCopy[$P][$MKI]['status']=4;
  1506. }
  1507. foreach ($verifyStaff as $m=>$u){
  1508. $AVLFK=$AVL[0].'_R';
  1509. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1510. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1511. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1512. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1513. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1514. break;
  1515. }
  1516. }
  1517. }else{
  1518. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1519. $button=4;
  1520. $roleArrayCopy[$P][$MKI]['status']=4;
  1521. }
  1522. }
  1523. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1524. $KOP=true;
  1525. }
  1526. }
  1527. foreach ($roleArrayCopy as $k=>$v){
  1528. foreach ($verifyList as $m=>$n){
  1529. if ($n[0]==$k){
  1530. array_splice($verifyList,$m,1,$v);
  1531. }
  1532. }
  1533. }
  1534. $receiptList[$key]['verifyList']=$verifyList;
  1535. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1536. $receiptList[$key]['button']=$button;
  1537. }
  1538. //print_r($receiptList);die;
  1539. $mothHtml="";
  1540. for($i=1;$i<=12;$i++){
  1541. if($moth==$i)
  1542. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1543. else
  1544. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1545. }
  1546. $data['mothHtml']=$mothHtml;
  1547. $data['receiptList']=$receiptList;
  1548. $data['memu']="receipt";
  1549. $data['staff']=$this->staff;
  1550. $data['receiptMemu']='expenses';
  1551. $data['verifyId']=$this->verifyId;
  1552. $data['executeId']=$this->executeId;
  1553. $data['item']=$item;
  1554. $data['year']=$year;
  1555. $this->render ( "/admin/expenses", $data );
  1556. }
  1557. function expensesCollect(){
  1558. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1559. Doo::loadModel('receipt');
  1560. $receipt=new receipt();
  1561. Doo::loadModel('L_category');
  1562. $Lcategory=new L_category();
  1563. Doo::loadModel('verify');
  1564. Doo::loadModel('statistics');
  1565. $statistics=new statistics();
  1566. $verify=new verify();
  1567. Doo::loadModel('staff');
  1568. $staff=new staff();
  1569. Doo::loadModel('loanReceipt');
  1570. $loanReceipt=new loanReceipt();
  1571. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1572. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1573. $Locate=0;$roleId=0;$button=0;
  1574. foreach ($loanList as $key=>$value){
  1575. $loanList[$key]['Locate']=$Locate;$Locate++;
  1576. $loanList[$key]['reviseDetail']=array();
  1577. if (!empty($value['reviseDetail']))
  1578. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1579. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1580. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1581. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1582. $loanList[$key]['category']=$categoryDetil['title'];
  1583. //检测编辑状态
  1584. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1585. $verifyList['staff']=$value['verifyBreakup'];
  1586. else
  1587. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1588. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1589. $verifyStaff=json_decode($value['verifyStaff'],true);
  1590. Doo::loadModel('role');
  1591. $role=new role();
  1592. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1593. foreach ($verifyList as $k=>$v){
  1594. //init verifyStaff
  1595. if ($v[1]=='ROLE'){
  1596. if (!empty($verifyStaff)){
  1597. $endStaffArray=end($verifyStaff);
  1598. // if ($v[0]==$endStaffArray['nextStaff']){
  1599. // $roleId=$v[0];
  1600. // }
  1601. }
  1602. $roleVerify=json_decode($v[3],true);
  1603. $roleKey=$k;$roleArray=array();
  1604. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1605. foreach ($roleVerify as $o=>$p){
  1606. $staffID=explode ('_',$p);
  1607. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1608. //print_r($staffID);
  1609. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1610. array_push($roleArray, $exp);
  1611. }
  1612. $roleArrayCopy[$v[0]]=$roleArray;
  1613. //$verifyList[$k]['roleArray']=$roleArray;
  1614. }
  1615. $verifyList[$k]['date']="";
  1616. $verifyList[$k]['opinion']="";
  1617. $verifyList[$k]['status']="";
  1618. if (empty($verifyStaff)){
  1619. $verifyList[$k]['date']="";
  1620. $verifyList[$k]['opinion']="";
  1621. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1622. $verifyList[$k]['status']=4;
  1623. $flag=false;
  1624. }
  1625. }else{
  1626. foreach ($verifyStaff as $m=>$u){
  1627. if ($v[0]==$m){
  1628. $verifyList[$k]['date']=$u['date'];
  1629. $verifyList[$k]['opinion']=$u['opinion'];
  1630. $verifyList[$k]['status']=$u['status'];
  1631. $flag=false;
  1632. break;
  1633. }
  1634. }
  1635. $endStaffArray=end($verifyStaff);
  1636. if (isset($endStaffArray['ROLE'])){
  1637. }else{
  1638. // $endKey=key($verifyStaff);
  1639. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1640. // $button=4;
  1641. // $verifyList[$k]['status']=4;
  1642. // }
  1643. }
  1644. }
  1645. }
  1646. $rolename['name']='';
  1647. if (!empty($roleId)){
  1648. Doo::loadModel('role');
  1649. $role=new role();
  1650. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1651. }
  1652. if (!empty($verifyStaff))
  1653. $endStaffArray=end($verifyStaff);
  1654. $KOP=false;
  1655. foreach ($roleArrayCopy as $P=>$A){
  1656. foreach ( $A as $MKI=>$AVL){
  1657. if (!empty($verifyStaff)){
  1658. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1659. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1660. $button=4;
  1661. $roleArrayCopy[$P][$MKI]['status']=4;
  1662. }
  1663. foreach ($verifyStaff as $m=>$u){
  1664. $AVLFK=$AVL[0].'_R';
  1665. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1666. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1667. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1668. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1669. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1670. break;
  1671. }
  1672. }
  1673. }else{
  1674. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1675. $button=4;
  1676. $roleArrayCopy[$P][$MKI]['status']=4;
  1677. }
  1678. }
  1679. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1680. $KOP=true;
  1681. }
  1682. }
  1683. foreach ($roleArrayCopy as $k=>$v){
  1684. foreach ($verifyList as $m=>$n){
  1685. if ($n[0]==$k){
  1686. array_splice($verifyList,$m,1,$v);
  1687. }
  1688. }
  1689. }
  1690. $loanList[$key]['verifyList']=$verifyList;
  1691. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1692. $loanList[$key]['button']=$button;
  1693. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1694. }
  1695. $data['loanList']=$loanList;
  1696. $Locate=0;$roleId=0;$button=0;
  1697. foreach ($receiptList as $key=>$value){
  1698. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1699. $receiptList[$key]['reviseDetail']=array();
  1700. if (!empty($value['reviseDetail']))
  1701. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1702. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1703. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1704. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1705. $receiptList[$key]['category']=$categoryDetil['title'];
  1706. //检测编辑状态
  1707. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1708. if($value['status']==8&&$value['Rtype']==1)
  1709. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1710. else
  1711. $verifyList['staff']=$value['verifyBreakup'];
  1712. }else
  1713. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1714. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1715. $verifyStaff=json_decode($value['verifyStaff'],true);
  1716. Doo::loadModel('role');
  1717. $role=new role();
  1718. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1719. foreach ($verifyList as $k=>$v){
  1720. //init verifyStaff
  1721. if ($v[1]=='ROLE'){
  1722. if (!empty($verifyStaff)){
  1723. $endStaffArray=end($verifyStaff);
  1724. // if ($v[0]==$endStaffArray['nextStaff']){
  1725. // $roleId=$v[0];
  1726. // }
  1727. }
  1728. $roleVerify=json_decode($v[3],true);
  1729. $roleKey=$k;$roleArray=array();
  1730. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1731. foreach ($roleVerify as $o=>$p){
  1732. $staffID=explode ('_',$p);
  1733. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1734. //print_r($staffID);
  1735. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1736. array_push($roleArray, $exp);
  1737. }
  1738. $roleArrayCopy[$v[0]]=$roleArray;
  1739. //$verifyList[$k]['roleArray']=$roleArray;
  1740. }
  1741. $verifyList[$k]['date']="";
  1742. $verifyList[$k]['opinion']="";
  1743. $verifyList[$k]['status']="";
  1744. if (empty($verifyStaff)){
  1745. $verifyList[$k]['date']="";
  1746. $verifyList[$k]['opinion']="";
  1747. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1748. $verifyList[$k]['status']=4;
  1749. $flag=false;
  1750. }
  1751. }else{
  1752. foreach ($verifyStaff as $m=>$u){
  1753. if ($v[0]==$m){
  1754. $verifyList[$k]['date']=$u['date'];
  1755. $verifyList[$k]['opinion']=$u['opinion'];
  1756. $verifyList[$k]['status']=$u['status'];
  1757. $flag=false;
  1758. break;
  1759. }
  1760. }
  1761. $endStaffArray=end($verifyStaff);
  1762. if (isset($endStaffArray['ROLE'])){
  1763. }else{
  1764. // $endKey=key($verifyStaff);
  1765. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1766. // $button=4;
  1767. // $verifyList[$k]['status']=4;
  1768. // }
  1769. }
  1770. }
  1771. }
  1772. $rolename['name']='';
  1773. if (!empty($roleId)){
  1774. Doo::loadModel('role');
  1775. $role=new role();
  1776. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1777. }
  1778. if (!empty($verifyStaff))
  1779. $endStaffArray=end($verifyStaff);
  1780. $KOP=false;
  1781. foreach ($roleArrayCopy as $P=>$A){
  1782. foreach ( $A as $MKI=>$AVL){
  1783. if (!empty($verifyStaff)){
  1784. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1785. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1786. $button=4;
  1787. $roleArrayCopy[$P][$MKI]['status']=4;
  1788. }
  1789. foreach ($verifyStaff as $m=>$u){
  1790. $AVLFK=$AVL[0].'_R';
  1791. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1792. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1793. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1794. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1795. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1796. break;
  1797. }
  1798. }
  1799. }else{
  1800. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1801. $button=4;
  1802. $roleArrayCopy[$P][$MKI]['status']=4;
  1803. }
  1804. }
  1805. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1806. $KOP=true;
  1807. }
  1808. }
  1809. foreach ($roleArrayCopy as $k=>$v){
  1810. foreach ($verifyList as $m=>$n){
  1811. if ($n[0]==$k){
  1812. array_splice($verifyList,$m,1,$v);
  1813. }
  1814. }
  1815. }
  1816. $receiptList[$key]['verifyList']=$verifyList;
  1817. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1818. $receiptList[$key]['button']=$button;
  1819. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1820. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1821. $relust=$value['sum']-$value['loanSum'];
  1822. $receiptList[$key]['relust']=$relust;
  1823. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1824. }
  1825. $data['receiptList']=$receiptList;
  1826. $data['memu']="receipt";
  1827. $data['staff']=$this->staff;
  1828. $data['receiptMemu']='expenses';
  1829. $data['verifyId']=$this->verifyId;
  1830. $data['executeId']=$this->executeId;
  1831. $this->render ( "/admin/expensesCollect", $data );
  1832. }
  1833. function approvalExpenses(){
  1834. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1835. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1836. $month=$this->get_args('month')?$this->get_args('month'):"";
  1837. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1838. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1839. if (empty($status))
  1840. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1841. $page_size=12;
  1842. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1843. $vidList=array();
  1844. $button=0;
  1845. Doo::loadModel('verify');
  1846. $verify=new verify();
  1847. Doo::loadModel('receipt');
  1848. $receipt=new receipt();
  1849. Doo::loadModel('staff');
  1850. $staff=new staff();
  1851. Doo::loadModel('L_category');
  1852. $Lcategory=new L_category();
  1853. //user verify ID
  1854. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  1855. foreach ($verifyDetail as $key=>$value){
  1856. array_push($vidList, $value['vid']);
  1857. }
  1858. $vid=implode(",", $vidList);
  1859. if(empty($verifyDetail))
  1860. $vid=0;
  1861. // if ($status==0)
  1862. // $dateCondition="";
  1863. // else
  1864. $dateCondition=" and Year(date) =".$year;
  1865. if(!empty($month))
  1866. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1867. $categoryList=$Lcategory->find(array('asArray'=>true));
  1868. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1869. $cateCondition="";$staffCondition="";$approvalCondition="";
  1870. if (!empty($cid))
  1871. $cateCondition=' and cid='.$cid;
  1872. if(!empty($sid)){
  1873. $staffCondition=' and staff='.$sid;
  1874. $cateCondition="";
  1875. }
  1876. $approvalCondition=" and status=".$status;
  1877. if($status==2){
  1878. //查找角色审批人
  1879. $approvalCondition=' and status='.$status.' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  1880. }
  1881. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1882. $approvalCondition=' and status=2 ';
  1883. }
  1884. if($status==1){
  1885. $approvalCondition=' and (status='.$status.' or status=6) ';
  1886. }
  1887. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1888. $pageinfo['page']=array('previous'=>'');
  1889. if ($status==0){
  1890. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1891. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1892. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1893. }else
  1894. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1895. ,'desc'=>'rid','asArray'=>true));
  1896. $rLRes=$receipt->find(array('where'=>'status=2 and nowStaff like "%'.$this->staff[0]['sid'].'%" '.$cateCondition.$staffCondition
  1897. ,'desc'=>'rid','asArray'=>true));
  1898. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1899. //print_r($pageinfo);
  1900. $Locate=0;
  1901. foreach ($receiptList as $key=>$value){
  1902. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1903. $receiptList[$key]['reviseDetail']=array();
  1904. if (!empty($value['reviseDetail']))
  1905. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1906. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1907. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1908. $receiptList[$key]['category']=$categoryDetil['title'];
  1909. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1910. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1911. $verifyStaff=json_decode($value['verifyStaff'],true);
  1912. foreach ($verifyList as $k=>$v){
  1913. //init verifyStaff
  1914. $verifyList[$k]['date']="";
  1915. $verifyList[$k]['opinion']="";
  1916. $verifyList[$k]['status']="";
  1917. if (empty($verifyStaff)){
  1918. $verifyList[$k]['date']="";
  1919. $verifyList[$k]['opinion']="";
  1920. if ($v[0]==$this->staff[0]['sid']){
  1921. $verifyList[$k]['status']=4;
  1922. $button=4;
  1923. }
  1924. }else{
  1925. $flag=true;
  1926. foreach ($verifyStaff as $m=>$u){
  1927. if ($v[0]==$m){
  1928. $verifyList[$k]['date']=$u['date'];
  1929. $verifyList[$k]['opinion']=$u['opinion'];
  1930. $verifyList[$k]['status']=$u['status'];
  1931. $flag=false;
  1932. break;
  1933. }
  1934. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1935. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1936. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1937. }
  1938. if($flag){//检测可编辑
  1939. if($v[0]==$this->staff[0]['sid']){
  1940. $verifyList[$k]['status']=4;$button=4;
  1941. }
  1942. }
  1943. }
  1944. }
  1945. $receiptList[$key]['verifyList']=$verifyList;
  1946. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1947. $receiptList[$key]['button']=$button;
  1948. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1949. }
  1950. //print_r($receiptList);die;
  1951. //$data['verifyDetail']=$verifyDetail;
  1952. $mothHtml="";
  1953. for($i=1;$i<=12;$i++){
  1954. if($month==$i)
  1955. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1956. else
  1957. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1958. }
  1959. $data['mothHtml']=$mothHtml;
  1960. $data['page']=$pageinfo;
  1961. $data['receiptList']=$receiptList;
  1962. $data['receiptApprovalCount']=count($rLRes);
  1963. $data['status']=$status;
  1964. $data['year']=$year;
  1965. $data['categoryList']=$categoryList;
  1966. $data['staffList']=$staffList;
  1967. $data['cid']=$cid;
  1968. $data['sid']=$sid;
  1969. //print_r($receiptList);
  1970. $data['memu']="receipt";
  1971. $data['staff']=$this->staff;
  1972. $data['receiptMemu']='approvalExpenses';
  1973. $data['verifyId']=$this->verifyId;
  1974. $data['executeId']=$this->executeId;
  1975. $this->render ( "/admin/approvalExpenses", $data );
  1976. }
  1977. function expensesDoc(){
  1978. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1979. Doo::loadModel('receipt');
  1980. $receipt=new receipt();
  1981. Doo::loadModel('L_category');
  1982. $Lcategory=new L_category();
  1983. Doo::loadModel('verify');
  1984. Doo::loadModel('statistics');
  1985. $statistics=new statistics();
  1986. $verify=new verify();
  1987. Doo::loadModel('staff');
  1988. $staff=new staff();
  1989. Doo::loadModel('loanReceipt');
  1990. $loanReceipt=new loanReceipt();
  1991. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  1992. $loanList=array();
  1993. if (!empty($receiptList))
  1994. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1995. $Locate=0;$roleId=0;$button=0;
  1996. foreach ($loanList as $key=>$value){
  1997. $loanList[$key]['Locate']=$Locate;$Locate++;
  1998. $loanList[$key]['reviseDetail']=array();
  1999. if (!empty($value['reviseDetail']))
  2000. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2001. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2002. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2003. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2004. $loanList[$key]['category']=$categoryDetil['title'];
  2005. //检测编辑状态
  2006. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  2007. $verifyList['staff']=$value['verifyBreakup'];
  2008. else
  2009. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2010. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2011. $verifyStaff=json_decode($value['verifyStaff'],true);
  2012. Doo::loadModel('role');
  2013. $role=new role();
  2014. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2015. foreach ($verifyList as $k=>$v){
  2016. //init verifyStaff
  2017. if ($v[1]=='ROLE'){
  2018. if (!empty($verifyStaff)){
  2019. $endStaffArray=end($verifyStaff);
  2020. // if ($v[0]==$endStaffArray['nextStaff']){
  2021. // $roleId=$v[0];
  2022. // }
  2023. }
  2024. $roleVerify=json_decode($v[3],true);
  2025. $roleKey=$k;$roleArray=array();
  2026. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2027. foreach ($roleVerify as $o=>$p){
  2028. $staffID=explode ('_',$p);
  2029. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2030. //print_r($staffID);
  2031. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2032. array_push($roleArray, $exp);
  2033. }
  2034. $roleArrayCopy[$v[0]]=$roleArray;
  2035. //$verifyList[$k]['roleArray']=$roleArray;
  2036. }
  2037. $verifyList[$k]['date']="";
  2038. $verifyList[$k]['opinion']="";
  2039. $verifyList[$k]['status']="";
  2040. if (empty($verifyStaff)){
  2041. $verifyList[$k]['date']="";
  2042. $verifyList[$k]['opinion']="";
  2043. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2044. $verifyList[$k]['status']=4;
  2045. $flag=false;
  2046. }
  2047. }else{
  2048. foreach ($verifyStaff as $m=>$u){
  2049. if ($v[0]==$m){
  2050. $verifyList[$k]['date']=$u['date'];
  2051. $verifyList[$k]['opinion']=$u['opinion'];
  2052. $verifyList[$k]['status']=$u['status'];
  2053. $flag=false;
  2054. break;
  2055. }
  2056. }
  2057. $endStaffArray=end($verifyStaff);
  2058. if (isset($endStaffArray['ROLE'])){
  2059. }else{
  2060. // $endKey=key($verifyStaff);
  2061. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2062. // $button=4;
  2063. // $verifyList[$k]['status']=4;
  2064. // }
  2065. }
  2066. }
  2067. }
  2068. $rolename['name']='';
  2069. if (!empty($roleId)){
  2070. Doo::loadModel('role');
  2071. $role=new role();
  2072. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2073. }
  2074. if (!empty($verifyStaff))
  2075. $endStaffArray=end($verifyStaff);
  2076. $KOP=false;
  2077. foreach ($roleArrayCopy as $P=>$A){
  2078. foreach ( $A as $MKI=>$AVL){
  2079. if (!empty($verifyStaff)){
  2080. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2081. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2082. $button=4;
  2083. $roleArrayCopy[$P][$MKI]['status']=4;
  2084. }
  2085. foreach ($verifyStaff as $m=>$u){
  2086. $AVLFK=$AVL[0].'_R';
  2087. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2088. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2089. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2090. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2091. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2092. break;
  2093. }
  2094. }
  2095. }else{
  2096. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2097. $button=4;
  2098. $roleArrayCopy[$P][$MKI]['status']=4;
  2099. }
  2100. }
  2101. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2102. $KOP=true;
  2103. }
  2104. }
  2105. foreach ($roleArrayCopy as $k=>$v){
  2106. foreach ($verifyList as $m=>$n){
  2107. if ($n[0]==$k){
  2108. array_splice($verifyList,$m,1,$v);
  2109. }
  2110. }
  2111. }
  2112. $loanList[$key]['verifyList']=$verifyList;
  2113. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2114. $loanList[$key]['button']=$button;
  2115. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2116. }
  2117. $data['loanList']=$loanList;
  2118. //print_r($loanList);
  2119. $Locate=0;$roleId=0;$button=0;
  2120. foreach ($receiptList as $key=>$value){
  2121. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2122. $receiptList[$key]['reviseDetail']=array();
  2123. if (!empty($value['reviseDetail']))
  2124. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2125. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2126. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2127. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2128. $receiptList[$key]['category']=$categoryDetil['title'];
  2129. //检测编辑状态
  2130. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2131. $verifyList['staff']=$value['verifyBreakup'];
  2132. }else
  2133. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2134. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2135. $verifyStaff=json_decode($value['verifyStaff'],true);
  2136. Doo::loadModel('role');
  2137. $role=new role();
  2138. if ($verifyList==NULL)
  2139. $verifyList=array();
  2140. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2141. foreach ($verifyList as $k=>$v){
  2142. //init verifyStaff
  2143. if ($v[1]=='ROLE'){
  2144. if (!empty($verifyStaff)){
  2145. $endStaffArray=end($verifyStaff);
  2146. // if ($v[0]==$endStaffArray['nextStaff']){
  2147. // $roleId=$v[0];
  2148. // }
  2149. }
  2150. $roleVerify=json_decode($v[3],true);
  2151. $roleKey=$k;$roleArray=array();
  2152. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2153. foreach ($roleVerify as $o=>$p){
  2154. $staffID=explode ('_',$p);
  2155. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2156. //print_r($staffID);
  2157. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2158. array_push($roleArray, $exp);
  2159. }
  2160. $roleArrayCopy[$v[0]]=$roleArray;
  2161. //$verifyList[$k]['roleArray']=$roleArray;
  2162. }
  2163. $verifyList[$k]['date']="";
  2164. $verifyList[$k]['opinion']="";
  2165. $verifyList[$k]['status']="";
  2166. if (empty($verifyStaff)){
  2167. $verifyList[$k]['date']="";
  2168. $verifyList[$k]['opinion']="";
  2169. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2170. $verifyList[$k]['status']=4;
  2171. $flag=false;
  2172. }
  2173. }else{
  2174. foreach ($verifyStaff as $m=>$u){
  2175. if ($v[0]==$m){
  2176. $verifyList[$k]['date']=$u['date'];
  2177. $verifyList[$k]['opinion']=$u['opinion'];
  2178. $verifyList[$k]['status']=$u['status'];
  2179. $flag=false;
  2180. break;
  2181. }
  2182. }
  2183. $endStaffArray=end($verifyStaff);
  2184. if (isset($endStaffArray['ROLE'])){
  2185. }else{
  2186. // $endKey=key($verifyStaff);
  2187. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2188. // $button=4;
  2189. // $verifyList[$k]['status']=4;
  2190. // }
  2191. }
  2192. }
  2193. }
  2194. $rolename['name']='';
  2195. if (!empty($roleId)){
  2196. Doo::loadModel('role');
  2197. $role=new role();
  2198. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2199. }
  2200. if (!empty($verifyStaff))
  2201. $endStaffArray=end($verifyStaff);
  2202. $KOP=false;
  2203. foreach ($roleArrayCopy as $P=>$A){
  2204. foreach ( $A as $MKI=>$AVL){
  2205. if (!empty($verifyStaff)){
  2206. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2207. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2208. $button=4;
  2209. $roleArrayCopy[$P][$MKI]['status']=4;
  2210. }
  2211. foreach ($verifyStaff as $m=>$u){
  2212. $AVLFK=$AVL[0].'_R';
  2213. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2214. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2215. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2216. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2217. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2218. break;
  2219. }
  2220. }
  2221. }else{
  2222. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2223. $button=4;
  2224. $roleArrayCopy[$P][$MKI]['status']=4;
  2225. }
  2226. }
  2227. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2228. $KOP=true;
  2229. }
  2230. }
  2231. foreach ($roleArrayCopy as $k=>$v){
  2232. foreach ($verifyList as $m=>$n){
  2233. if ($n[0]==$k){
  2234. array_splice($verifyList,$m,1,$v);
  2235. }
  2236. }
  2237. }
  2238. $receiptList[$key]['verifyList']=$verifyList;
  2239. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2240. $receiptList[$key]['button']=$button;
  2241. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2242. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2243. }
  2244. //获取审批日志
  2245. Doo::loadModel('receiptLog');
  2246. $receiptLog=new receiptLog();
  2247. $rlList=array();
  2248. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2249. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2250. if (!empty($rlInfo)){
  2251. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2252. }
  2253. $receiptList[0]['rlList']=$rlList;
  2254. $data['receiptList']=$receiptList;
  2255. $data['memu']="receipt";
  2256. $data['staff']=$this->staff;
  2257. $data['receiptMemu']='approvalExpenses';
  2258. $data['verifyId']=$this->verifyId;
  2259. $data['executeId']=$this->executeId;
  2260. $this->render ( "/admin/expensesDoc", $data );
  2261. }
  2262. function expensesEdi(){
  2263. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2264. $status=isset($this->params['status'])?$this->params['status']:'';
  2265. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2266. $month=$this->get_args('month')?$this->get_args('month'):"";
  2267. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2268. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2269. if (empty($status))
  2270. $status=$this->get_args('status')?$this->get_args('status'):2;
  2271. $vidList=array();
  2272. $button=0;
  2273. Doo::loadModel('verify');
  2274. Doo::loadModel('receipt');
  2275. Doo::loadModel('staff');
  2276. $staff=new staff();
  2277. $receipt=new receipt();
  2278. $verify=new verify();
  2279. Doo::loadModel('L_category');
  2280. $Lcategory=new L_category();
  2281. Doo::loadModel('enclosur');
  2282. $enclosur=new enclosur();
  2283. //user verify ID
  2284. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2285. foreach ($verifyDetail as $key=>$value){
  2286. array_push($vidList, $value['vid']);
  2287. }
  2288. $vid=implode(",", $vidList);
  2289. if(empty($verifyDetail))
  2290. $vid=0;
  2291. $categoryList=$Lcategory->find(array('asArray'=>true));
  2292. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2293. $ap="";
  2294. if($status==4){
  2295. $ap=4;$status=2;
  2296. }
  2297. //get Receipt By verifyID status 2
  2298. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2299. $Locate=0;$roleId=0;
  2300. if($ap==4)
  2301. $status=4;
  2302. foreach ($receiptList as $key=>$value){
  2303. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2304. $receiptList[$key]['reviseDetail']=array();
  2305. if (!empty($value['reviseDetail']))
  2306. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2307. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2308. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2309. $receiptList[$key]['category']=$categoryDetil['title'];
  2310. //检测编辑状态
  2311. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2312. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2313. $verifyStaff=json_decode($value['verifyStaff'],true);
  2314. Doo::loadModel('role');
  2315. $role=new role();
  2316. //print_r($verifyList);
  2317. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2318. foreach ($verifyList as $k=>$v){
  2319. //init verifyStaff
  2320. if ($v[1]=='ROLE'){
  2321. if (!empty($verifyStaff)){
  2322. $endStaffArray=end($verifyStaff);
  2323. if ($v[0]==$endStaffArray['nextStaff']){
  2324. $roleId=$v[0];
  2325. }
  2326. }
  2327. $roleVerify=json_decode($v[3],true);
  2328. $roleKey=$k;$roleArray=array();
  2329. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2330. foreach ($roleVerify as $o=>$p){
  2331. $staffID=explode ('_',$p);
  2332. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2333. //print_r($staffID);
  2334. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2335. array_push($roleArray, $exp);
  2336. }
  2337. $roleArrayCopy[$v[0]]=$roleArray;
  2338. //$verifyList[$k]['roleArray']=$roleArray;
  2339. }
  2340. //print_r($roleArray);
  2341. $verifyList[$k]['date']="";
  2342. $verifyList[$k]['opinion']="";
  2343. $verifyList[$k]['status']="";
  2344. if (empty($verifyStaff)){
  2345. $verifyList[$k]['date']="";
  2346. $verifyList[$k]['opinion']="";
  2347. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2348. $verifyList[$k]['status']=4;
  2349. $button=4;$flag=false;
  2350. }
  2351. }else{
  2352. foreach ($verifyStaff as $m=>$u){
  2353. if ($v[0]==$m){
  2354. $verifyList[$k]['date']=$u['date'];
  2355. $verifyList[$k]['opinion']=$u['opinion'];
  2356. $verifyList[$k]['status']=$u['status'];
  2357. $flag=false;
  2358. break;
  2359. }
  2360. }
  2361. $endStaffArray=end($verifyStaff);
  2362. if (isset($endStaffArray['ROLE'])){
  2363. }else{
  2364. $endKey=key($verifyStaff);
  2365. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2366. $button=4;
  2367. $verifyList[$k]['status']=4;
  2368. }
  2369. }
  2370. }
  2371. }
  2372. $rolename['name']='';
  2373. if (!empty($roleId)){
  2374. Doo::loadModel('role');
  2375. $role=new role();
  2376. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2377. }
  2378. if (!empty($verifyStaff))
  2379. $endStaffArray=end($verifyStaff);
  2380. $KOP=false;
  2381. foreach ($roleArrayCopy as $P=>$A){
  2382. foreach ( $A as $MKI=>$AVL){
  2383. if (!empty($verifyStaff)){
  2384. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2385. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2386. $button=4;
  2387. $roleArrayCopy[$P][$MKI]['status']=4;
  2388. }
  2389. foreach ($verifyStaff as $m=>$u){
  2390. $AVLFK=$AVL[0].'_R';
  2391. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2392. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2393. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2394. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2395. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2396. break;
  2397. }
  2398. }
  2399. }else{
  2400. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2401. $button=4;
  2402. $roleArrayCopy[$P][$MKI]['status']=4;
  2403. }
  2404. }
  2405. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2406. $KOP=true;
  2407. }
  2408. }
  2409. // print_r($roleArrayCopy);
  2410. // echo $roleKey;
  2411. foreach ($roleArrayCopy as $k=>$v){
  2412. foreach ($verifyList as $m=>$n){
  2413. if ($n[0]==$k){
  2414. array_splice($verifyList,$m,1,$v);
  2415. }
  2416. }
  2417. }
  2418. $receiptList[$key]['verifyList']=$verifyList;
  2419. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2420. $receiptList[$key]['button']=$button;
  2421. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2422. }
  2423. //$data['verifyDetail']=$verifyDetail;
  2424. $mothHtml="";
  2425. for($i=1;$i<=12;$i++){
  2426. if($month==$i)
  2427. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2428. else
  2429. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2430. }
  2431. //获取审批日志
  2432. Doo::loadModel('receiptLog');
  2433. $receiptLog=new receiptLog();
  2434. $rlList=array();
  2435. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2436. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2437. if (!empty($rlInfo)){
  2438. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2439. }
  2440. $receiptList[0]['rlList']=$rlList;
  2441. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2442. $enclosurHtml='';
  2443. foreach ($enclosurList as $value){
  2444. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2445. }
  2446. //print_r($receiptList);
  2447. $data['rid']=$rid;
  2448. $data['enclosurHtml']=$enclosurHtml;
  2449. $data['rolename']=$rolename['name'];
  2450. $data['datetij']=$tijdate['date'];
  2451. $data['mothHtml']=$mothHtml;
  2452. $data['receiptList']=$receiptList;
  2453. $data['receiptApprovalCount']=count($receiptList);
  2454. $data['status']=$status;
  2455. $data['year']=$year;
  2456. $data['categoryList']=$categoryList;
  2457. $data['staffList']=$staffList;
  2458. $data['cid']=$cid;
  2459. $data['sid']=$sid;
  2460. $data['ap']=$ap;
  2461. $data['memu']="receipt";
  2462. $data['staff']=$this->staff;
  2463. $data['receiptMemu']='approvalExpenses';
  2464. $data['verifyId']=$this->verifyId;
  2465. $data['executeId']=$this->executeId;
  2466. $this->render ( "/admin/expensesEdi", $data );
  2467. }
  2468. function expensesDefray(){
  2469. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2470. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2471. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2472. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2473. if(!empty($rid)){
  2474. Doo::loadModel("verify");
  2475. $verify=new verify();
  2476. Doo::loadModel("receiptDetail");
  2477. $receiptDetailObj=new receiptDetail();
  2478. Doo::loadModel("itemStatistics");
  2479. Doo::loadModel("statistics");
  2480. $statistics=new statistics();
  2481. $itemStatistics=new itemStatistics();
  2482. Doo::loadModel("receipt");
  2483. $receipt=new receipt();
  2484. Doo::loadModel("loanReceipt");
  2485. $loanReceipt=new loanReceipt();
  2486. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2487. if (empty($receiptDetail))
  2488. return "/approval";
  2489. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2490. $verifyString=$verifyDetail['staff'];
  2491. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2492. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2493. if(empty($opinion)){
  2494. if ($status==3)
  2495. $opinion="终止";
  2496. else
  2497. $opinion="同意支付";
  2498. }
  2499. $nowStaff=0;$nowStaffList=array();
  2500. if(empty($verifyStaff)){
  2501. //还需加入是否已经进入角色审批
  2502. if ($verifyDetail[0][1]=='ROLE'){
  2503. //print_r($verifyDetail);echo "ddd";
  2504. $vStaffString=json_decode($verifyDetail[0][3]);
  2505. foreach ($vStaffString as $key=>$value){
  2506. $staffK=explode("_", $value);
  2507. if ($staffK[0]!=$this->staff[0]['sid'])
  2508. array_push($nowStaffList, $staffK[0]);
  2509. }
  2510. //print_r($verifyDetail);
  2511. //die;
  2512. $nowStaff=implode(',', $nowStaffList);
  2513. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2514. }else{
  2515. if ($verifyDetail[1][1]=='ROLE'){
  2516. $vStaffString=json_decode($verifyDetail[1][3]);
  2517. //echo "dd";
  2518. foreach ($vStaffString as $key=>$value){
  2519. $staffK=explode("_", $value);
  2520. array_push($nowStaffList, $staffK[0]);
  2521. }
  2522. $nowStaff=implode(',', $nowStaffList);
  2523. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2524. }else{
  2525. $nowStaff=$verifyDetail[1][0];
  2526. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2527. }
  2528. }
  2529. if($status==3)
  2530. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2531. $vStaffString=json_encode($verifyStaff);
  2532. $receipt->nowStaff=$nowStaff;
  2533. $receipt->verifyStaff=$vStaffString;
  2534. $loanReceipt->nowStaff=$nowStaff;
  2535. $loanReceipt->verifyStaff=$vStaffString;
  2536. }else{
  2537. $VS=end($verifyStaff);
  2538. //非角色审批
  2539. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2540. $nextStaff=0;$roleSTF=false;
  2541. foreach ($verifyDetail as $key=>$value){
  2542. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2543. if (isset($verifyDetail[$key+1])){
  2544. $nextStaff=$verifyDetail[$key+1][0];
  2545. if ($verifyDetail[$key+1][1]=='ROLE')
  2546. $roleSTF=true;
  2547. }
  2548. break;
  2549. }
  2550. }
  2551. if (!$roleSTF){
  2552. $nowStaff=$nextStaff;
  2553. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2554. }else{
  2555. //获取角色下的所有用户ID
  2556. $nowStaffList=array();
  2557. foreach ($verifyDetail as $vfk){
  2558. if ($vfk[1]=='ROLE'){
  2559. $vStaffString=json_decode($vfk[3]);
  2560. foreach ($vStaffString as $key=>$value){
  2561. $staffK=explode("_", $value);
  2562. array_push($nowStaffList, $staffK[0]);
  2563. }
  2564. }
  2565. }
  2566. $nowStaff=implode(',', $nowStaffList);
  2567. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2568. }
  2569. if($status==3){
  2570. $verifyStaff['final']=$status;
  2571. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2572. }
  2573. $vStaffString=json_encode($verifyStaff);
  2574. $receipt->nowStaff=$nowStaff;
  2575. $receipt->verifyStaff=$vStaffString;
  2576. $loanReceipt->nowStaff=$nowStaff;
  2577. $loanReceipt->verifyStaff=$vStaffString;
  2578. }
  2579. //角色审批
  2580. if (isset($VS['ROLE'])){
  2581. //找出角色人 当前审批角色组
  2582. $verifyJSStaff=array();$nowStaffList2=array();
  2583. foreach ($verifyDetail as $key=>$value){
  2584. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2585. $verifyJSStaff=json_decode($value[3]);
  2586. foreach ($verifyJSStaff as $m){
  2587. $staffK=explode("_", $m);
  2588. array_push($nowStaffList2, $staffK[0]);
  2589. }
  2590. // print_r($nowStaffList2);
  2591. }
  2592. }
  2593. $RoleVerifyStaff=array();
  2594. foreach ($verifyStaff as $key=>$value){
  2595. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2596. foreach ($nowStaffList2 as $m) {
  2597. if ($key==$m."_R")
  2598. $RoleVerifyStaff[$key]=$value;
  2599. }
  2600. }
  2601. }
  2602. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2603. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2604. //下一个审批人ID
  2605. $nextStaff=0;$falg=false;
  2606. foreach ($verifyDetail as $key=>$value){
  2607. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2608. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2609. $falg=true;
  2610. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2611. foreach ($vStaffString as $v){
  2612. $staffK=explode("_", $v);
  2613. array_push($nowStaffList, $staffK[0]);
  2614. }
  2615. $nowStaff=implode(',', $nowStaffList);
  2616. $nextStaff=$verifyDetail[$key+1][0];
  2617. }elseif(isset($verifyDetail[$key+1])){
  2618. $nextStaff=$verifyDetail[$key+1][0];
  2619. $nowStaff=$nextStaff;
  2620. }else
  2621. $nowStaff='';
  2622. break;
  2623. }
  2624. }
  2625. if ($falg)
  2626. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2627. else
  2628. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2629. // print_r($verifyStaff);
  2630. // echo $nowStaff;die;
  2631. }else{ //进入下一个角色或者审批人
  2632. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2633. //
  2634. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2635. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2636. // print_r($verifyStaff);
  2637. // die;
  2638. }
  2639. if($status==3){
  2640. $verifyStaff['final']=$status;
  2641. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2642. }
  2643. $vStaffString=json_encode($verifyStaff);
  2644. $receipt->verifyStaff=$vStaffString;
  2645. $receipt->nowStaff=$nowStaff;
  2646. $loanReceipt->nowStaff=$nowStaff;
  2647. $loanReceipt->verifyStaff=$vStaffString;
  2648. //die;
  2649. //}
  2650. // print_r($verifyStaff);
  2651. // die;
  2652. }
  2653. //print_r($verifyStaff);die;
  2654. }
  2655. //print_r($verifyDetail);
  2656. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2657. foreach ($verifyDetail as $k=>$v){
  2658. if ($v[1]=='ROLE'){
  2659. $roleId=$v[0];
  2660. $roleVerify=json_decode($v[3],true);
  2661. $roleKey=$k;$roleArray=array();
  2662. foreach ($roleVerify as $o=>$p){
  2663. $staffID=explode ('_',$p);
  2664. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2665. array_push($roleArray, $exp);
  2666. }
  2667. $verifyDetailCopy[$v[0]]=$roleArray;
  2668. }
  2669. }
  2670. //print_r($verifyDetail);
  2671. foreach ($verifyDetailCopy as $k=>$v){
  2672. foreach ($verifyDetail as $m=>$n){
  2673. if ($n[0]==$k){
  2674. array_splice($verifyDetail,$m,1,$v);
  2675. }
  2676. }
  2677. }
  2678. //审批日志
  2679. if (!isset($verifyStaff['final'])){
  2680. Doo::loadModel("receiptLog");
  2681. $receiptLog=new receiptLog();
  2682. if (!empty($roleId)){
  2683. Doo::loadModel("role");
  2684. $role=new role();
  2685. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2686. $receiptLog->rolename=$roleInfo['name'];
  2687. }
  2688. $receiptLog->username=$this->staff[0]['username'];
  2689. $receiptLog->uid=$this->staff[0]['sid'];
  2690. $receiptLog->date=date("Y-m-d");
  2691. $receiptLog->opinion=$opinion;
  2692. $receiptLog->img=$this->staff[0]['avatar'];
  2693. $receiptLog->status=1;
  2694. $receiptLog->rid=$rid;
  2695. $receiptLog->insert();
  2696. }
  2697. if (isset($verifyStaff['final'])){//rDetail
  2698. $receipt->status=3;
  2699. $receipt->verifyBreakup=$verifyString;
  2700. $receiptDetailObj->status=3;
  2701. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2702. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2703. $receipt->status=6;
  2704. $receipt->pastDate=date("Y-m-d");
  2705. $receipt->isBK=1;
  2706. $loanReceipt->verifyBreakup=$verifyString;
  2707. $loanReceipt->status=1;
  2708. $loanReceipt->pastDate=date("Y-m-d");
  2709. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2710. }
  2711. $receipt->update(array('where'=>' rid = '.$rid));
  2712. return "/approvalExpenses/2";
  2713. }
  2714. }
  2715. function implement(){
  2716. Doo::loadModel('receipt');
  2717. $receipt=new receipt();
  2718. Doo::loadModel('L_category');
  2719. $Lcategory=new L_category();
  2720. Doo::loadModel('verify');
  2721. $verify=new verify();
  2722. Doo::loadModel('staff');
  2723. $staff=new staff();
  2724. Doo::loadModel("execute");
  2725. $execute=new execute();
  2726. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2727. Doo::loadModel('loanReceipt');
  2728. $loanReceipt=new loanReceipt();
  2729. //print_r($receiptList);
  2730. $loanList=array();
  2731. if (!isset($receiptList))
  2732. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2733. $Locate=0;$roleId=0;$button=0;
  2734. foreach ($loanList as $key=>$value){
  2735. $loanList[$key]['Locate']=$Locate;$Locate++;
  2736. $loanList[$key]['reviseDetail']=array();
  2737. if (!empty($value['reviseDetail']))
  2738. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2739. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2740. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2741. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2742. $loanList[$key]['category']=$categoryDetil['title'];
  2743. //检测编辑状态
  2744. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2745. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2746. $verifyStaff=json_decode($value['verifyStaff'],true);
  2747. Doo::loadModel('role');
  2748. $role=new role();
  2749. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2750. foreach ($verifyList as $k=>$v){
  2751. //init verifyStaff
  2752. if ($v[1]=='ROLE'){
  2753. if (!empty($verifyStaff)){
  2754. $endStaffArray=end($verifyStaff);
  2755. // if ($v[0]==$endStaffArray['nextStaff']){
  2756. // $roleId=$v[0];
  2757. // }
  2758. }
  2759. $roleVerify=json_decode($v[3],true);
  2760. $roleKey=$k;$roleArray=array();
  2761. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2762. foreach ($roleVerify as $o=>$p){
  2763. $staffID=explode ('_',$p);
  2764. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2765. //print_r($staffID);
  2766. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2767. array_push($roleArray, $exp);
  2768. }
  2769. $roleArrayCopy[$v[0]]=$roleArray;
  2770. //$verifyList[$k]['roleArray']=$roleArray;
  2771. }
  2772. $verifyList[$k]['date']="";
  2773. $verifyList[$k]['opinion']="";
  2774. $verifyList[$k]['status']="";
  2775. if (empty($verifyStaff)){
  2776. $verifyList[$k]['date']="";
  2777. $verifyList[$k]['opinion']="";
  2778. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2779. $verifyList[$k]['status']=4;
  2780. $flag=false;
  2781. }
  2782. }else{
  2783. foreach ($verifyStaff as $m=>$u){
  2784. if ($v[0]==$m){
  2785. $verifyList[$k]['date']=$u['date'];
  2786. $verifyList[$k]['opinion']=$u['opinion'];
  2787. $verifyList[$k]['status']=$u['status'];
  2788. $flag=false;
  2789. break;
  2790. }
  2791. }
  2792. $endStaffArray=end($verifyStaff);
  2793. if (isset($endStaffArray['ROLE'])){
  2794. }else{
  2795. // $endKey=key($verifyStaff);
  2796. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2797. // $button=4;
  2798. // $verifyList[$k]['status']=4;
  2799. // }
  2800. }
  2801. }
  2802. }
  2803. $rolename['name']='';
  2804. if (!empty($roleId)){
  2805. Doo::loadModel('role');
  2806. $role=new role();
  2807. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2808. }
  2809. if (!empty($verifyStaff))
  2810. $endStaffArray=end($verifyStaff);
  2811. $KOP=false;
  2812. foreach ($roleArrayCopy as $P=>$A){
  2813. foreach ( $A as $MKI=>$AVL){
  2814. if (!empty($verifyStaff)){
  2815. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2816. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2817. $button=4;
  2818. $roleArrayCopy[$P][$MKI]['status']=4;
  2819. }
  2820. foreach ($verifyStaff as $m=>$u){
  2821. $AVLFK=$AVL[0].'_R';
  2822. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2823. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2824. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2825. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2826. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2827. break;
  2828. }
  2829. }
  2830. }else{
  2831. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2832. $button=4;
  2833. $roleArrayCopy[$P][$MKI]['status']=4;
  2834. }
  2835. }
  2836. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2837. $KOP=true;
  2838. }
  2839. }
  2840. foreach ($roleArrayCopy as $k=>$v){
  2841. foreach ($verifyList as $m=>$n){
  2842. if ($n[0]==$k){
  2843. array_splice($verifyList,$m,1,$v);
  2844. }
  2845. }
  2846. }
  2847. $loanList[$key]['verifyList']=$verifyList;
  2848. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2849. }
  2850. $data['loanList']=$loanList;
  2851. $Locate=0;$roleId=0;$button=0;
  2852. foreach ($receiptList as $key=>$value){
  2853. $button2=0;
  2854. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2855. $receiptList[$key]['reviseDetail']=array();
  2856. if (!empty($value['reviseDetail']))
  2857. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2858. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2859. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2860. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2861. $receiptList[$key]['category']=$categoryDetil['title'];
  2862. $executeList=json_decode($value['executeCopy'],true);
  2863. $executeStaff=array();
  2864. if (!empty($value['executeStaff'] ))
  2865. $executeStaff=json_decode($value['executeStaff'],true);
  2866. if (isset($executeList)){
  2867. foreach ($executeList as $op=>$lo){
  2868. $executeList[$op]['date']="";
  2869. $executeList[$op]['opinion']="";
  2870. $executeList[$op]['status']="";
  2871. foreach ($executeStaff as $m=>$u){
  2872. if ($lo[0]==$m){
  2873. $executeList[$op]['date']=$u['date'];
  2874. $executeList[$op]['opinion']=$u['opinion'];
  2875. $executeList[$op]['status']=$u['status'];
  2876. break;
  2877. }
  2878. }
  2879. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2880. $button2=1;
  2881. $executeList[$op]['status']=4;
  2882. }
  2883. }
  2884. }
  2885. //检测编辑状态
  2886. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2887. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2888. $verifyStaff=json_decode($value['verifyStaff'],true);
  2889. Doo::loadModel('role');
  2890. $role=new role();
  2891. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2892. foreach ($verifyList as $k=>$v){
  2893. //init verifyStaff
  2894. if ($v[1]=='ROLE'){
  2895. if (!empty($verifyStaff)){
  2896. $endStaffArray=end($verifyStaff);
  2897. // if ($v[0]==$endStaffArray['nextStaff']){
  2898. // $roleId=$v[0];
  2899. // }
  2900. }
  2901. $roleVerify=json_decode($v[3],true);
  2902. $roleKey=$k;$roleArray=array();
  2903. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2904. foreach ($roleVerify as $o=>$p){
  2905. $staffID=explode ('_',$p);
  2906. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2907. //print_r($staffID);
  2908. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2909. array_push($roleArray, $exp);
  2910. }
  2911. $roleArrayCopy[$v[0]]=$roleArray;
  2912. //$verifyList[$k]['roleArray']=$roleArray;
  2913. }
  2914. $verifyList[$k]['date']="";
  2915. $verifyList[$k]['opinion']="";
  2916. $verifyList[$k]['status']="";
  2917. if (empty($verifyStaff)){
  2918. $verifyList[$k]['date']="";
  2919. $verifyList[$k]['opinion']="";
  2920. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2921. $verifyList[$k]['status']=4;
  2922. $flag=false;
  2923. }
  2924. }else{
  2925. foreach ($verifyStaff as $m=>$u){
  2926. if ($v[0]==$m){
  2927. $verifyList[$k]['date']=$u['date'];
  2928. $verifyList[$k]['opinion']=$u['opinion'];
  2929. $verifyList[$k]['status']=$u['status'];
  2930. $flag=false;
  2931. break;
  2932. }
  2933. }
  2934. $endStaffArray=end($verifyStaff);
  2935. if (isset($endStaffArray['ROLE'])){
  2936. }else{
  2937. }
  2938. }
  2939. }
  2940. $rolename['name']='';
  2941. if (!empty($roleId)){
  2942. Doo::loadModel('role');
  2943. $role=new role();
  2944. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2945. }
  2946. if (!empty($verifyStaff))
  2947. $endStaffArray=end($verifyStaff);
  2948. $KOP=false;
  2949. foreach ($roleArrayCopy as $P=>$A){
  2950. foreach ( $A as $MKI=>$AVL){
  2951. if (!empty($verifyStaff)){
  2952. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2953. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2954. $button=4;
  2955. $roleArrayCopy[$P][$MKI]['status']=4;
  2956. }
  2957. foreach ($verifyStaff as $m=>$u){
  2958. $AVLFK=$AVL[0].'_R';
  2959. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2960. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2961. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2962. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2963. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2964. break;
  2965. }
  2966. }
  2967. }else{
  2968. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2969. $button=4;
  2970. $roleArrayCopy[$P][$MKI]['status']=4;
  2971. }
  2972. }
  2973. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2974. $KOP=true;
  2975. }
  2976. }
  2977. foreach ($roleArrayCopy as $k=>$v){
  2978. foreach ($verifyList as $m=>$n){
  2979. if ($n[0]==$k){
  2980. array_splice($verifyList,$m,1,$v);
  2981. }
  2982. }
  2983. }
  2984. $receiptList[$key]['executeList']=$executeList;
  2985. $receiptList[$key]['verifyList']=$verifyList;
  2986. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2987. $receiptList[$key]['button2']=$button2;
  2988. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2989. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2990. $relust=$value['sum']-$value['loanSum'];
  2991. $receiptList[$key]['relust']=$relust;
  2992. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  2993. }
  2994. //print_r($receiptList[$key]['executeList']);
  2995. $data['receiptList']=$receiptList;
  2996. $data['memu']="receipt";
  2997. $data['staff']=$this->staff;
  2998. $data['receiptMemu']='implement';
  2999. $data['verifyId']=$this->verifyId;
  3000. $data['executeId']=$this->executeId;
  3001. $this->render ( "/admin/implement", $data );
  3002. }
  3003. function implementDo(){
  3004. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3005. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  3006. if (!empty($rid)){
  3007. Doo::loadModel('receipt');
  3008. $receipt=new receipt();
  3009. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  3010. $executeCopy=json_decode($rinfo['executeCopy'],true);
  3011. $executeStaff=json_decode($rinfo['executeStaff'],true);
  3012. if(empty($executeStaff)){
  3013. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3014. }else{
  3015. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3016. }
  3017. if (count($executeStaff)==count($executeCopy)){
  3018. $receipt->executeStaff=json_encode($executeStaff);
  3019. $receipt->status=8;
  3020. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3021. $receipt->status=9;
  3022. $receipt->executeDate= date("Y-m-d");
  3023. }else{
  3024. $receipt->executeStaff=json_encode($executeStaff);
  3025. }
  3026. $receipt->update(array('where'=>'rid='.$rid));
  3027. }
  3028. return "/implement";
  3029. }
  3030. function receiptburEdi(){
  3031. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3032. $status=isset($this->params['status'])?$this->params['status']:'';
  3033. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3034. $month=$this->get_args('month')?$this->get_args('month'):"";
  3035. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3036. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3037. if (empty($status))
  3038. $status=$this->get_args('status')?$this->get_args('status'):2;
  3039. $vidList=array();
  3040. $button=0;
  3041. Doo::loadModel('verify');
  3042. Doo::loadModel('receipt');
  3043. Doo::loadModel('staff');
  3044. $staff=new staff();
  3045. $receipt=new receipt();
  3046. $verify=new verify();
  3047. Doo::loadModel('L_category');
  3048. $Lcategory=new L_category();
  3049. Doo::loadModel('enclosur');
  3050. $enclosur=new enclosur();
  3051. Doo::loadModel('loanReceipt');
  3052. $loanReceipt=new loanReceipt();
  3053. //user verify ID
  3054. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3055. foreach ($verifyDetail as $key=>$value){
  3056. array_push($vidList, $value['vid']);
  3057. }
  3058. $vid=implode(",", $vidList);
  3059. if(empty($verifyDetail))
  3060. $vid=0;
  3061. $categoryList=$Lcategory->find(array('asArray'=>true));
  3062. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3063. $ap="";
  3064. if($status==4){
  3065. $ap=4;$status=2;
  3066. }
  3067. //get Receipt By verifyID status 2
  3068. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3069. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3070. $Locate=0;$roleId=0;$button=0;
  3071. foreach ($loanList as $key=>$value){
  3072. $loanList[$key]['Locate']=$Locate;$Locate++;
  3073. $loanList[$key]['reviseDetail']=array();
  3074. if (!empty($value['reviseDetail']))
  3075. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3076. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3077. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3078. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3079. $loanList[$key]['category']=$categoryDetil['title'];
  3080. //检测编辑状态
  3081. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3082. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3083. $verifyStaff=json_decode($value['verifyStaff'],true);
  3084. Doo::loadModel('role');
  3085. $role=new role();
  3086. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3087. foreach ($verifyList as $k=>$v){
  3088. //init verifyStaff
  3089. if ($v[1]=='ROLE'){
  3090. if (!empty($verifyStaff)){
  3091. $endStaffArray=end($verifyStaff);
  3092. }
  3093. $roleVerify=json_decode($v[3],true);
  3094. $roleKey=$k;$roleArray=array();
  3095. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3096. foreach ($roleVerify as $o=>$p){
  3097. $staffID=explode ('_',$p);
  3098. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3099. //print_r($staffID);
  3100. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3101. array_push($roleArray, $exp);
  3102. }
  3103. $roleArrayCopy[$v[0]]=$roleArray;
  3104. //$verifyList[$k]['roleArray']=$roleArray;
  3105. }
  3106. $verifyList[$k]['date']="";
  3107. $verifyList[$k]['opinion']="";
  3108. $verifyList[$k]['status']="";
  3109. if (empty($verifyStaff)){
  3110. $verifyList[$k]['date']="";
  3111. $verifyList[$k]['opinion']="";
  3112. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3113. $verifyList[$k]['status']=4;
  3114. $flag=false;
  3115. }
  3116. }else{
  3117. foreach ($verifyStaff as $m=>$u){
  3118. if ($v[0]==$m){
  3119. $verifyList[$k]['date']=$u['date'];
  3120. $verifyList[$k]['opinion']=$u['opinion'];
  3121. $verifyList[$k]['status']=$u['status'];
  3122. $flag=false;
  3123. break;
  3124. }
  3125. }
  3126. $endStaffArray=end($verifyStaff);
  3127. if (isset($endStaffArray['ROLE'])){
  3128. }else{
  3129. }
  3130. }
  3131. }
  3132. $rolename['name']='';
  3133. if (!empty($roleId)){
  3134. Doo::loadModel('role');
  3135. $role=new role();
  3136. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3137. }
  3138. if (!empty($verifyStaff))
  3139. $endStaffArray=end($verifyStaff);
  3140. $KOP=false;
  3141. foreach ($roleArrayCopy as $P=>$A){
  3142. foreach ( $A as $MKI=>$AVL){
  3143. if (!empty($verifyStaff)){
  3144. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3145. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3146. $button=4;
  3147. $roleArrayCopy[$P][$MKI]['status']=4;
  3148. }
  3149. foreach ($verifyStaff as $m=>$u){
  3150. $AVLFK=$AVL[0].'_R';
  3151. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3152. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3153. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3154. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3155. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3156. break;
  3157. }
  3158. }
  3159. }else{
  3160. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3161. $button=4;
  3162. $roleArrayCopy[$P][$MKI]['status']=4;
  3163. }
  3164. }
  3165. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3166. $KOP=true;
  3167. }
  3168. }
  3169. foreach ($roleArrayCopy as $k=>$v){
  3170. foreach ($verifyList as $m=>$n){
  3171. if ($n[0]==$k){
  3172. array_splice($verifyList,$m,1,$v);
  3173. }
  3174. }
  3175. }
  3176. $loanList[$key]['verifyList']=$verifyList;
  3177. }
  3178. $htmlLoan='';
  3179. if (isset($loanList[0])){
  3180. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3181. if ($value['status']==1)
  3182. $htmlLoan.='<li class="done" >';
  3183. elseif ($value['status']==3)
  3184. $htmlLoan.='<li class="undone" >';
  3185. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3186. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3187. if (isset($value['rolename']))
  3188. $htmlLoan.=$value['rolename'];
  3189. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3190. }
  3191. $data['loanDate']=$loanList[0]['date'];
  3192. }
  3193. $data['htmlLoan']=$htmlLoan;
  3194. /*
  3195. <!-- loop loanList.0.verifyList -->
  3196. <li <!-- if {{loanList' value.status}}==1 --> class="done" <!-- elseif {{loanList' value.status}}==3 --> class="undone" <!-- endif -->>
  3197. <div class="avtra"><img src="{{loanList' value.2}}_2.jpg"></div>
  3198. <div class="comment">
  3199. <p class="colGray"><span class="fR">{{loanList' value.date}}</span>{{loanList' value.1}}<!-- if isset({{loanList' value.rolename}}) --> ({{loanList' value.rolename}}) <!-- endif --></p>
  3200. <p>{{loanList' value.opinion}}</p>
  3201. </div>
  3202. </li>
  3203. <!-- endloop -->
  3204. */
  3205. //print_r($loanList);
  3206. $Locate=0;$roleId=0;
  3207. if($ap==4)
  3208. $status=4;
  3209. foreach ($receiptList as $key=>$value){
  3210. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3211. $receiptList[$key]['reviseDetail']=array();
  3212. if (!empty($value['reviseDetail']))
  3213. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3214. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3215. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3216. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3217. $receiptList[$key]['category']=$categoryDetil['title'];
  3218. //检测编辑状态
  3219. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3220. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3221. $verifyStaff=json_decode($value['verifyStaff'],true);
  3222. Doo::loadModel('role');
  3223. $role=new role();
  3224. //print_r($verifyList);
  3225. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3226. foreach ($verifyList as $k=>$v){
  3227. //init verifyStaff
  3228. if ($v[1]=='ROLE'){
  3229. if (!empty($verifyStaff)){
  3230. $endStaffArray=end($verifyStaff);
  3231. if ($v[0]==$endStaffArray['nextStaff']){
  3232. $roleId=$v[0];
  3233. }
  3234. }
  3235. $roleVerify=json_decode($v[3],true);
  3236. $roleKey=$k;$roleArray=array();
  3237. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3238. foreach ($roleVerify as $o=>$p){
  3239. $staffID=explode ('_',$p);
  3240. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3241. //print_r($staffID);
  3242. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3243. array_push($roleArray, $exp);
  3244. }
  3245. $roleArrayCopy[$v[0]]=$roleArray;
  3246. //$verifyList[$k]['roleArray']=$roleArray;
  3247. }
  3248. //print_r($roleArray);
  3249. $verifyList[$k]['date']="";
  3250. $verifyList[$k]['opinion']="";
  3251. $verifyList[$k]['status']="";
  3252. if (empty($verifyStaff)){
  3253. $verifyList[$k]['date']="";
  3254. $verifyList[$k]['opinion']="";
  3255. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3256. $verifyList[$k]['status']=4;
  3257. $button=4;$flag=false;
  3258. }
  3259. }else{
  3260. foreach ($verifyStaff as $m=>$u){
  3261. if ($v[0]==$m){
  3262. $verifyList[$k]['date']=$u['date'];
  3263. $verifyList[$k]['opinion']=$u['opinion'];
  3264. $verifyList[$k]['status']=$u['status'];
  3265. $flag=false;
  3266. break;
  3267. }
  3268. }
  3269. $endStaffArray=end($verifyStaff);
  3270. if (isset($endStaffArray['ROLE'])){
  3271. }else{
  3272. $endKey=key($verifyStaff);
  3273. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3274. $button=4;
  3275. $verifyList[$k]['status']=4;
  3276. }
  3277. }
  3278. }
  3279. }
  3280. $rolename['name']='';
  3281. if (!empty($roleId)){
  3282. Doo::loadModel('role');
  3283. $role=new role();
  3284. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3285. }
  3286. if (!empty($verifyStaff))
  3287. $endStaffArray=end($verifyStaff);
  3288. $KOP=false;
  3289. foreach ($roleArrayCopy as $P=>$A){
  3290. foreach ( $A as $MKI=>$AVL){
  3291. if (!empty($verifyStaff)){
  3292. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3293. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3294. $button=4;
  3295. $roleArrayCopy[$P][$MKI]['status']=4;
  3296. }
  3297. foreach ($verifyStaff as $m=>$u){
  3298. $AVLFK=$AVL[0].'_R';
  3299. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3300. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3301. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3302. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3303. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3304. break;
  3305. }
  3306. }
  3307. }else{
  3308. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3309. $button=4;
  3310. $roleArrayCopy[$P][$MKI]['status']=4;
  3311. }
  3312. }
  3313. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3314. $KOP=true;
  3315. }
  3316. }
  3317. foreach ($roleArrayCopy as $k=>$v){
  3318. foreach ($verifyList as $m=>$n){
  3319. if ($n[0]==$k){
  3320. array_splice($verifyList,$m,1,$v);
  3321. }
  3322. }
  3323. }
  3324. //print_r($verifyList);
  3325. $receiptList[$key]['verifyList']=$verifyList;
  3326. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3327. $receiptList[$key]['button']=$button;
  3328. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3329. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3330. $relust=$value['sum']-$value['loanSum'];
  3331. $receiptList[$key]['relust']=$relust;
  3332. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3333. }
  3334. //$data['verifyDetail']=$verifyDetail;
  3335. $mothHtml="";
  3336. for($i=1;$i<=12;$i++){
  3337. if($month==$i)
  3338. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3339. else
  3340. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3341. }
  3342. //获取审批日志
  3343. Doo::loadModel('receiptLog');
  3344. $receiptLog=new receiptLog();
  3345. $rlList=array();
  3346. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3347. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3348. if (!empty($rlInfo)){
  3349. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3350. }
  3351. //echo $rid;
  3352. //print_r($receiptList);
  3353. $receiptList[0]['rlList']=$rlList;
  3354. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3355. $enclosurHtml='';
  3356. foreach ($enclosurList as $value){
  3357. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3358. }
  3359. $data['enclosurHtml']=$enclosurHtml;
  3360. $data['rolename']=$rolename['name'];
  3361. // $data['datetij']=$tijdate['date'];
  3362. $data['mothHtml']=$mothHtml;
  3363. //print_r($receiptList);
  3364. $data['rid']=$rid;
  3365. $data['tijdate']=$tijdate['date'];
  3366. $data['receiptList']=$receiptList;
  3367. $data['receiptApprovalCount']=count($receiptList);
  3368. $data['status']=$status;
  3369. $data['year']=$year;
  3370. $data['categoryList']=$categoryList;
  3371. $data['staffList']=$staffList;
  3372. $data['cid']=$cid;
  3373. $data['sid']=$sid;
  3374. $data['ap']=$ap;
  3375. $data['memu']="receipt";
  3376. $data['staff']=$this->staff;
  3377. $data['receiptMemu']='approvalExpenses';
  3378. $data['verifyId']=$this->verifyId;
  3379. $data['executeId']=$this->executeId;
  3380. $this->render ( "/admin/receiptburEdi", $data );
  3381. }
  3382. function hisImplement(){
  3383. $item=isset($this->params['item'])?$this->params['item']:"";
  3384. if(empty($item))
  3385. $item=$this->get_args('item')?$this->get_args('item'):"";
  3386. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3387. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3388. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3389. Doo::loadModel('receipt');
  3390. $receipt=new receipt();
  3391. Doo::loadModel('L_category');
  3392. $Lcategory=new L_category();
  3393. Doo::loadModel('verify');
  3394. Doo::loadModel('statistics');
  3395. $statistics=new statistics();
  3396. $verify=new verify();
  3397. Doo::loadModel('staff');
  3398. $staff=new staff();
  3399. $condition="";
  3400. if($item=="expenses")
  3401. $condition=" and Rtype=1 ";
  3402. elseif ($item=="receipts")
  3403. $condition=" and Rtype=0 ";
  3404. elseif ($item=="remits")
  3405. $condition=" and Rtype=2 ";
  3406. $dateCondition=" and Year(executeDate) =".$year;
  3407. if($moth!='MONTH'){
  3408. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3409. }
  3410. if($day!='DAY')
  3411. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3412. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3413. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3414. $Locate=0;$roleId=0;$button=0;
  3415. foreach ($receiptList as $key=>$value){
  3416. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3417. $receiptList[$key]['reviseDetail']=array();
  3418. if (!empty($value['reviseDetail']))
  3419. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3420. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3421. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3422. $receiptList[$key]['category']=$categoryDetil['title'];
  3423. //检测编辑状态
  3424. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3425. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3426. $verifyStaff=json_decode($value['verifyStaff'],true);
  3427. Doo::loadModel('role');
  3428. $role=new role();
  3429. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3430. foreach ($verifyList as $k=>$v){
  3431. //init verifyStaff
  3432. if ($v[1]=='ROLE'){
  3433. if (!empty($verifyStaff)){
  3434. $endStaffArray=end($verifyStaff);
  3435. }
  3436. $roleVerify=json_decode($v[3],true);
  3437. $roleKey=$k;$roleArray=array();
  3438. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3439. foreach ($roleVerify as $o=>$p){
  3440. $staffID=explode ('_',$p);
  3441. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3442. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3443. array_push($roleArray, $exp);
  3444. }
  3445. $roleArrayCopy[$v[0]]=$roleArray;
  3446. }
  3447. $verifyList[$k]['date']="";
  3448. $verifyList[$k]['opinion']="";
  3449. $verifyList[$k]['status']="";
  3450. if (empty($verifyStaff)){
  3451. $verifyList[$k]['date']="";
  3452. $verifyList[$k]['opinion']="";
  3453. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3454. $verifyList[$k]['status']=4;
  3455. $flag=false;
  3456. }
  3457. }else{
  3458. foreach ($verifyStaff as $m=>$u){
  3459. if ($v[0]==$m){
  3460. $verifyList[$k]['date']=$u['date'];
  3461. $verifyList[$k]['opinion']=$u['opinion'];
  3462. $verifyList[$k]['status']=$u['status'];
  3463. $flag=false;
  3464. break;
  3465. }
  3466. }
  3467. $endStaffArray=end($verifyStaff);
  3468. }
  3469. }
  3470. $rolename['name']='';
  3471. if (!empty($roleId)){
  3472. Doo::loadModel('role');
  3473. $role=new role();
  3474. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3475. }
  3476. if (!empty($verifyStaff))
  3477. $endStaffArray=end($verifyStaff);
  3478. $KOP=false;
  3479. foreach ($roleArrayCopy as $P=>$A){
  3480. foreach ( $A as $MKI=>$AVL){
  3481. if (!empty($verifyStaff)){
  3482. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3483. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3484. $button=4;
  3485. $roleArrayCopy[$P][$MKI]['status']=4;
  3486. }
  3487. foreach ($verifyStaff as $m=>$u){
  3488. $AVLFK=$AVL[0].'_R';
  3489. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3490. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3491. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3492. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3493. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3494. break;
  3495. }
  3496. }
  3497. }else{
  3498. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3499. $button=4;
  3500. $roleArrayCopy[$P][$MKI]['status']=4;
  3501. }
  3502. }
  3503. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3504. $KOP=true;
  3505. }
  3506. }
  3507. foreach ($roleArrayCopy as $k=>$v){
  3508. foreach ($verifyList as $m=>$n){
  3509. if ($n[0]==$k){
  3510. array_splice($verifyList,$m,1,$v);
  3511. }
  3512. }
  3513. }
  3514. $receiptList[$key]['verifyList']=$verifyList;
  3515. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3516. $receiptList[$key]['button']=$button;
  3517. }
  3518. //print_r($receiptList);die;
  3519. $mothHtml="";
  3520. for($i=1;$i<=12;$i++){
  3521. if($moth==$i)
  3522. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3523. else
  3524. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3525. }
  3526. $dayHtml="";
  3527. if ($day!="DAY"||$moth!="MONTH"){
  3528. for($i = 1; $i <= 31; $i ++) {
  3529. if($day==$i)
  3530. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3531. else
  3532. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3533. }
  3534. }
  3535. $data['dayHtml']=$dayHtml;
  3536. $data['mothHtml']=$mothHtml;
  3537. $data['receiptList']=$receiptList;
  3538. $data['memu']="receipt";
  3539. $data['staff']=$this->staff;
  3540. $data['receiptMemu']='implement';
  3541. $data['verifyId']=$this->verifyId;
  3542. $data['executeId']=$this->executeId;
  3543. $data['item']=$item;
  3544. $data['year']=$year;
  3545. $data['moth']=$moth;
  3546. $data['day']=$day;
  3547. $this->render ( "/admin/hisImplement", $data );
  3548. }
  3549. function ajaxExamine(){
  3550. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3551. Doo::loadModel('receipt');
  3552. $receipt=new receipt();
  3553. if (!empty($rid)){
  3554. $rLRes=$receipt->find(array('where'=>'status=2 and nowStaff like "%'.$this->staff[0]['sid'].'%" and rid!='.$rid
  3555. ,'asArray'=>true));
  3556. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3557. }
  3558. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3559. }
  3560. function myReceipt(){
  3561. //all approval past withdraw
  3562. $item=isset($this->params['item'])?$this->params['item']:"";
  3563. if(empty($item))
  3564. $item=$this->get_args('item')?$this->get_args('item'):"";
  3565. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3566. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3567. Doo::loadModel('receipt');
  3568. $receipt=new receipt();
  3569. //pre-loaded
  3570. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3571. //have cache
  3572. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3573. if(!empty($moth))//yearPage
  3574. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3575. $this->showCache($path);
  3576. }
  3577. Doo::loadModel('L_category');
  3578. $Lcategory=new L_category();
  3579. Doo::loadModel('verify');
  3580. Doo::loadModel('statistics');
  3581. $statistics=new statistics();
  3582. $verify=new verify();
  3583. Doo::loadModel('staff');
  3584. $staff=new staff();
  3585. $condition=" and status!=0 ";
  3586. if($item=="approval")
  3587. $condition=" and status=2 ";
  3588. elseif ($item=="withdraw")
  3589. $condition=" and status=3 ";
  3590. elseif ($item=="past")
  3591. $condition=" and status=1 ";
  3592. elseif ($item=="whdw")
  3593. $condition=" and status=4 ";
  3594. $dateCondition=" and Year(date) =".$year;
  3595. if(!empty($moth)){
  3596. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3597. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3598. }else
  3599. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3600. if(empty($stList))
  3601. $stList=array('rePrice'=>0,'agPrice'=>0);
  3602. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3603. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3604. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3605. $Locate=0;$roleId=0;$button=0;
  3606. foreach ($receiptList as $key=>$value){
  3607. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3608. $receiptList[$key]['reviseDetail']=array();
  3609. if (!empty($value['reviseDetail']))
  3610. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3611. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3612. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3613. $receiptList[$key]['category']=$categoryDetil['title'];
  3614. //检测编辑状态
  3615. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3616. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3617. $verifyStaff=json_decode($value['verifyStaff'],true);
  3618. Doo::loadModel('role');
  3619. $role=new role();
  3620. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3621. foreach ($verifyList as $k=>$v){
  3622. //init verifyStaff
  3623. if ($v[1]=='ROLE'){
  3624. if (!empty($verifyStaff)){
  3625. $endStaffArray=end($verifyStaff);
  3626. // if ($v[0]==$endStaffArray['nextStaff']){
  3627. // $roleId=$v[0];
  3628. // }
  3629. }
  3630. $roleVerify=json_decode($v[3],true);
  3631. $roleKey=$k;$roleArray=array();
  3632. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3633. foreach ($roleVerify as $o=>$p){
  3634. $staffID=explode ('_',$p);
  3635. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3636. //print_r($staffID);
  3637. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3638. array_push($roleArray, $exp);
  3639. }
  3640. $roleArrayCopy[$v[0]]=$roleArray;
  3641. //$verifyList[$k]['roleArray']=$roleArray;
  3642. }
  3643. $verifyList[$k]['date']="";
  3644. $verifyList[$k]['opinion']="";
  3645. $verifyList[$k]['status']="";
  3646. if (empty($verifyStaff)){
  3647. $verifyList[$k]['date']="";
  3648. $verifyList[$k]['opinion']="";
  3649. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3650. $verifyList[$k]['status']=4;
  3651. $flag=false;
  3652. }
  3653. }else{
  3654. foreach ($verifyStaff as $m=>$u){
  3655. if ($v[0]==$m){
  3656. $verifyList[$k]['date']=$u['date'];
  3657. $verifyList[$k]['opinion']=$u['opinion'];
  3658. $verifyList[$k]['status']=$u['status'];
  3659. $flag=false;
  3660. break;
  3661. }
  3662. }
  3663. $endStaffArray=end($verifyStaff);
  3664. if (isset($endStaffArray['ROLE'])){
  3665. }else{
  3666. // $endKey=key($verifyStaff);
  3667. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3668. // $button=4;
  3669. // $verifyList[$k]['status']=4;
  3670. // }
  3671. }
  3672. }
  3673. }
  3674. $rolename['name']='';
  3675. if (!empty($roleId)){
  3676. Doo::loadModel('role');
  3677. $role=new role();
  3678. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3679. }
  3680. if (!empty($verifyStaff))
  3681. $endStaffArray=end($verifyStaff);
  3682. $KOP=false;
  3683. foreach ($roleArrayCopy as $P=>$A){
  3684. foreach ( $A as $MKI=>$AVL){
  3685. if (!empty($verifyStaff)){
  3686. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3687. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3688. $button=4;
  3689. $roleArrayCopy[$P][$MKI]['status']=4;
  3690. }
  3691. foreach ($verifyStaff as $m=>$u){
  3692. $AVLFK=$AVL[0].'_R';
  3693. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3694. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3695. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3696. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3697. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3698. break;
  3699. }
  3700. }
  3701. }else{
  3702. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3703. $button=4;
  3704. $roleArrayCopy[$P][$MKI]['status']=4;
  3705. }
  3706. }
  3707. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3708. $KOP=true;
  3709. }
  3710. }
  3711. foreach ($roleArrayCopy as $k=>$v){
  3712. foreach ($verifyList as $m=>$n){
  3713. if ($n[0]==$k){
  3714. array_splice($verifyList,$m,1,$v);
  3715. }
  3716. }
  3717. }
  3718. $receiptList[$key]['verifyList']=$verifyList;
  3719. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3720. $receiptList[$key]['button']=$button;
  3721. }
  3722. //print_r($receiptList);die;
  3723. $mothHtml="";
  3724. for($i=1;$i<=12;$i++){
  3725. if($moth==$i)
  3726. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3727. else
  3728. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3729. }
  3730. $data['mothHtml']=$mothHtml;
  3731. $data['receiptList']=$receiptList;
  3732. $data['memu']="receipt";
  3733. $data['staff']=$this->staff;
  3734. $data['receiptMemu']='receipt';
  3735. $data['verifyId']=$this->verifyId;
  3736. $data['executeId']=$this->executeId;
  3737. $data['item']=$item;
  3738. $data['year']=$year;
  3739. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3740. //sufficient condition to generate cache
  3741. if(empty($moth)&&($year<date("Y"))){
  3742. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3743. if(empty($receiptList)){ //generated files
  3744. ob_start();
  3745. $this->render ( "/admin/saea_myList", $data );
  3746. $this->cacheFile($path);die;
  3747. // $content = ob_get_contents();
  3748. // $fp = fopen($path, "w");
  3749. // fwrite($fp, $content);
  3750. // fclose($fp);
  3751. }
  3752. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3753. $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));
  3754. if(empty($receiptList)){ //generated files
  3755. ob_start();
  3756. $this->render ( "/admin/saea_myList", $data );
  3757. $this->cacheFile($path);die;
  3758. }
  3759. }
  3760. }
  3761. $this->render ( "/admin/saea_myList", $data );
  3762. }
  3763. function saeaCreate(){
  3764. Doo::loadModel('accountItem');
  3765. Doo::loadModel('verify');
  3766. Doo::loadModel('receipt');
  3767. Doo::loadModel('L_category');
  3768. $lCategory=new L_category();
  3769. $receipt=new receipt();
  3770. $verify=new verify();
  3771. $accountItem=new accountItem();
  3772. Doo::loadModel("role");
  3773. $role=new role();
  3774. $acItem=$accountItem->find(array('asArray'=>true));
  3775. $veList=$verify->find(array('asArray'=>true));
  3776. foreach ($veList as $key=>$value){
  3777. $v=json_decode($value['staff']);
  3778. $list=array();
  3779. foreach ($v as $n=>$m){
  3780. if ($m['1']=='ROLE'){
  3781. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3782. $v[$n][1]=$roleInfo['name'];
  3783. array_push($list, $roleInfo['name']);
  3784. }else{
  3785. array_push($list, $v[$n][1]);
  3786. }
  3787. }
  3788. $veList[$key]['staff']=implode('>', $list);
  3789. }
  3790. $data['category']=$lCategory->find(array('asArray'=>true));
  3791. $data['veList']=$veList;
  3792. $data['acItem']=$acItem;
  3793. $data['memu']="receipt";
  3794. $data['staff']=$this->staff;
  3795. $data['receiptMemu']='saeaBorad';
  3796. $data['verifyId']=$this->verifyId;
  3797. $data['executeId']=$this->executeId;
  3798. $this->render ( "/admin/saea_create", $data );
  3799. }
  3800. function addReceipt(){
  3801. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3802. $agency=$this->get_args('agency');
  3803. $travel=$this->get_args('travel');
  3804. $train=$this->get_args('train');
  3805. $other=$this->get_args('other');
  3806. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3807. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3808. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3809. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3810. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3811. Doo::loadModel('receipt');
  3812. Doo::loadModel('receiptDetail');
  3813. Doo::loadModel('accountItem');
  3814. $accountItem=new accountItem();
  3815. $receipt=new receipt();
  3816. Doo::loadModel('enclosur');
  3817. Doo::loadModel('execute');
  3818. $execute=new execute();
  3819. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3820. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3821. // if(!empty($receiptDetail))
  3822. // return "/referReceipt/".$receiptDetail['rid'];
  3823. $aItem=$accountItem->find(array('asArray'=>true));
  3824. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3825. $ag=$tr=$ta=$ot=0;
  3826. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3827. foreach ($aItem as $key=>$value){
  3828. if ($value['category']==$this->AGENCY){
  3829. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3830. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3831. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3832. }
  3833. $ag++;
  3834. }
  3835. if($value['category']==$this->TRAVEL){
  3836. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3837. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3838. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3839. }
  3840. $tr++;
  3841. }
  3842. if($value['category']==$this->TRAIN){
  3843. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3844. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3845. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3846. }
  3847. $ta++;
  3848. }
  3849. if($value['category']==$this->OTHER){
  3850. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3851. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3852. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3853. }
  3854. $ot++;
  3855. }
  3856. }
  3857. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3858. //报销单
  3859. $receipt->accountItem=json_encode($accountJson);
  3860. $receipt->staff=$this->staff[0]['sid'];
  3861. $receipt->sum=number_format($sum, 2, '.', '');
  3862. $receipt->date=date("Y-m-d");
  3863. $receipt->cid=$cid;
  3864. $receipt->status=5;
  3865. //修改审批流程加入角色
  3866. $receipt->verify=$verify;
  3867. $receipt->executeCopy=$executeDetail['staff'];
  3868. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3869. $receipt->explanation=$explanation;
  3870. $rid=$receipt->insert();
  3871. //附件
  3872. if (!empty($enclosurName)){
  3873. $enclosurArray=explode('-', $enclosurName);
  3874. foreach ($enclosurArray as $value){
  3875. $enclosur=new enclosur();
  3876. $enclosur->name=$value;
  3877. $enclosur->rid=$rid;
  3878. $enclosur->insert();
  3879. }
  3880. //print_r($enclosurArray);die;
  3881. }
  3882. //报销详情
  3883. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3884. $receiptDetail=new receiptDetail();
  3885. $receiptDetail->staff=$this->staff[0]['sid'];
  3886. $receiptDetail->item=$value['name'];
  3887. $receiptDetail->itemCategory=$this->AGENCY;
  3888. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3889. $receiptDetail->date=date("Y-m-d");
  3890. $receiptDetail->cid=$cid;
  3891. $receiptDetail->rid=$rid;
  3892. $receiptDetail->status=4;
  3893. $receiptDetail->insert();
  3894. }
  3895. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3896. $receiptDetail=new receiptDetail();
  3897. $receiptDetail->staff=$this->staff[0]['sid'];
  3898. $receiptDetail->item=$value['name'];
  3899. $receiptDetail->itemCategory=$this->TRAVEL;
  3900. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3901. $receiptDetail->date=date("Y-m-d");
  3902. $receiptDetail->cid=$cid;
  3903. $receiptDetail->rid=$rid;
  3904. $receiptDetail->status=4;
  3905. $receiptDetail->insert();
  3906. }
  3907. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3908. $receiptDetail=new receiptDetail();
  3909. $receiptDetail->staff=$this->staff[0]['sid'];
  3910. $receiptDetail->item=$value['name'];
  3911. $receiptDetail->itemCategory=$this->TRAIN;
  3912. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3913. $receiptDetail->date=date("Y-m-d");
  3914. $receiptDetail->cid=$cid;
  3915. $receiptDetail->rid=$rid;
  3916. $receiptDetail->status=4;
  3917. $receiptDetail->insert();
  3918. }
  3919. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3920. $receiptDetail=new receiptDetail();
  3921. $receiptDetail->staff=$this->staff[0]['sid'];
  3922. $receiptDetail->item=$value['name'];
  3923. $receiptDetail->itemCategory=$this->OTHER;
  3924. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3925. $receiptDetail->date=date("Y-m-d");
  3926. $receiptDetail->cid=$cid;
  3927. $receiptDetail->rid=$rid;
  3928. $receiptDetail->status=4;
  3929. $receiptDetail->insert();
  3930. }
  3931. //return "/referReceipt/".$rid;
  3932. }
  3933. return "/saeaBorad";
  3934. }
  3935. function referReceipt(){
  3936. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3937. Doo::loadModel('receipt');
  3938. Doo::loadModel('verify');
  3939. $verify=new verify();
  3940. $receipt=new receipt();
  3941. Doo::loadModel('L_category');
  3942. $lCategory=new L_category();
  3943. Doo::loadModel("role");
  3944. $role=new role();
  3945. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  3946. if(empty($receiptDetail))
  3947. return "/addReceipt";
  3948. foreach ($receiptDetail as $key=>$value){
  3949. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  3950. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3951. $v=json_decode($veList['staff']);
  3952. array_push($v[0], $veList['description']);
  3953. foreach ($v as $n=>$m){
  3954. if ($m['1']=='ROLE'){
  3955. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3956. $v[$n][1]=$roleInfo['name'];
  3957. }
  3958. }
  3959. $receiptDetail[$key]['staff']=$v;
  3960. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3961. $receiptDetail[$key]['category']=$category['title'];
  3962. }
  3963. //print_r($receiptDetail);
  3964. $data['receiptDetail']=$receiptDetail;
  3965. $data['memu']="receipt";
  3966. $data['staff']=$this->staff;
  3967. $data['receiptMemu']='saeaCreate';
  3968. $data['verifyId']=$this->verifyId;
  3969. $data['executeId']=$this->executeId;
  3970. $this->render ( "/admin/saea_confirm", $data );
  3971. }
  3972. function editReceipt(){
  3973. //edit status 4
  3974. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3975. //echo $rid;
  3976. Doo::loadModel('accountItem');
  3977. Doo::loadModel('verify');
  3978. Doo::loadModel('receipt');
  3979. $receipt=new receipt();
  3980. $verify=new verify();
  3981. $accountItem=new accountItem();
  3982. Doo::loadModel('L_category');
  3983. $lCategory=new L_category();
  3984. Doo::loadModel("role");
  3985. $role=new role();
  3986. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  3987. if(empty($receiptDetail))
  3988. return "/saeaCreate";
  3989. $acItem=$accountItem->find(array('asArray'=>true));
  3990. $veList=$verify->find(array('asArray'=>true));
  3991. foreach ($veList as $key=>$value){
  3992. $v=json_decode($value['staff']);
  3993. $list=array();
  3994. foreach ($v as $n=>$m){
  3995. if ($m['1']=='ROLE'){
  3996. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3997. $v[$n][1]=$roleInfo['name'];
  3998. array_push($list, $roleInfo['name']);
  3999. }else{
  4000. array_push($list, $v[$n][1]);
  4001. }
  4002. }
  4003. $veList[$key]['staff']=implode('>', $list);
  4004. }
  4005. //配置编辑信息
  4006. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4007. foreach ($acItem as $key=>$value){
  4008. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4009. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4010. $acItem[$key]['price']=$v['price'];
  4011. }
  4012. }
  4013. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4014. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4015. $acItem[$key]['price']=$v['price'];
  4016. }
  4017. }
  4018. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4019. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4020. $acItem[$key]['price']=$v['price'];
  4021. }
  4022. }
  4023. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4024. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4025. $acItem[$key]['price']=$v['price'];
  4026. }
  4027. }
  4028. }
  4029. $data['category']=$lCategory->find(array('asArray'=>true));
  4030. $data['cSum']=$accountItemList['cSum'];
  4031. $data['sum']=$receiptDetail['sum'];
  4032. $data['receiptDetail']=$receiptDetail;
  4033. $data['veList']=$veList;
  4034. $data['acItem']=$acItem;
  4035. $data['memu']="receipt";
  4036. $data['staff']=$this->staff;
  4037. $data['receiptMemu']='saeaBorad';
  4038. $data['verify']=$receiptDetail['verify'];
  4039. $data['verifyId']=$this->verifyId;
  4040. $data['executeId']=$this->executeId;
  4041. $data['rid']=$rid;
  4042. $this->render ( "/admin/saea_edit", $data );
  4043. }
  4044. function updateReceipt(){
  4045. $agency=$this->get_args('agency');
  4046. $travel=$this->get_args('travel');
  4047. $train=$this->get_args('train');
  4048. $other=$this->get_args('other');
  4049. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4050. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4051. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4052. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4053. if(!empty($verify)&&!empty($explanation)){
  4054. Doo::loadModel('receipt');
  4055. Doo::loadModel('receiptDetail');
  4056. Doo::loadModel('accountItem');
  4057. $accountItem=new accountItem();
  4058. $receipt=new receipt();
  4059. Doo::loadModel('execute');
  4060. $execute=new execute();
  4061. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4062. if(empty($receiptDetail))
  4063. return "/saeaBorad";
  4064. if ($receiptDetail['Rtype']==1)
  4065. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4066. else
  4067. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4068. $aItem=$accountItem->find(array('asArray'=>true));
  4069. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4070. $ag=$tr=$ta=$ot=0;
  4071. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4072. foreach ($aItem as $key=>$value){
  4073. if ($value['category']==$this->AGENCY){
  4074. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4075. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4076. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4077. }
  4078. $ag++;
  4079. }
  4080. if($value['category']==$this->TRAVEL){
  4081. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4082. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4083. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4084. }
  4085. $tr++;
  4086. }
  4087. if($value['category']==$this->TRAIN){
  4088. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4089. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4090. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4091. }
  4092. $ta++;
  4093. }
  4094. if($value['category']==$this->OTHER){
  4095. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4096. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4097. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4098. }
  4099. $ot++;
  4100. }
  4101. }
  4102. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4103. //报销单
  4104. $rid=$receipt->rid=$receiptDetail['rid'];
  4105. $receipt->accountItem=json_encode($accountJson);
  4106. $receipt->staff=$this->staff[0]['sid'];
  4107. $receipt->sum=number_format($sum, 2, '.', '');
  4108. $receipt->date=date("Y-m-d");
  4109. $receipt->cid=$cid;
  4110. if (($receiptDetail['status']!=4)){
  4111. if ($receiptDetail['Rtype']==1)
  4112. $receipt->status=7;
  4113. else
  4114. $receipt->status=5;
  4115. }
  4116. $receipt->verify=$verify;
  4117. $receipt->executeCopy=$executeDetail['staff'];
  4118. $receipt->explanation=$explanation;
  4119. $receipt->update();
  4120. $receiptDetail=new receiptDetail();
  4121. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4122. //报销详情
  4123. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4124. $receiptDetail=new receiptDetail();
  4125. $receiptDetail->staff=$this->staff[0]['sid'];
  4126. $receiptDetail->item=$value['name'];
  4127. $receiptDetail->itemCategory=$this->AGENCY;
  4128. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4129. $receiptDetail->date=date("Y-m-d");
  4130. $receiptDetail->cid=$cid;
  4131. $receiptDetail->rid=$rid;
  4132. $receiptDetail->status=4;
  4133. $receiptDetail->insert();
  4134. }
  4135. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4136. $receiptDetail=new receiptDetail();
  4137. $receiptDetail->staff=$this->staff[0]['sid'];
  4138. $receiptDetail->item=$value['name'];
  4139. $receiptDetail->itemCategory=$this->TRAVEL;
  4140. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4141. $receiptDetail->date=date("Y-m-d");
  4142. $receiptDetail->cid=$cid;
  4143. $receiptDetail->rid=$rid;
  4144. $receiptDetail->status=4;
  4145. $receiptDetail->insert();
  4146. }
  4147. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4148. $receiptDetail=new receiptDetail();
  4149. $receiptDetail->staff=$this->staff[0]['sid'];
  4150. $receiptDetail->item=$value['name'];
  4151. $receiptDetail->itemCategory=$this->TRAIN;
  4152. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4153. $receiptDetail->date=date("Y-m-d");
  4154. $receiptDetail->cid=$cid;
  4155. $receiptDetail->rid=$rid;
  4156. $receiptDetail->status=4;
  4157. $receiptDetail->insert();
  4158. }
  4159. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4160. $receiptDetail=new receiptDetail();
  4161. $receiptDetail->staff=$this->staff[0]['sid'];
  4162. $receiptDetail->item=$value['name'];
  4163. $receiptDetail->itemCategory=$this->OTHER;
  4164. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4165. $receiptDetail->date=date("Y-m-d");
  4166. $receiptDetail->cid=$cid;
  4167. $receiptDetail->rid=$rid;
  4168. $receiptDetail->status=4;
  4169. $receiptDetail->insert();
  4170. }
  4171. //return "/referReceipt/".$rid;
  4172. }
  4173. return "/saeaBorad";
  4174. }
  4175. function approvedReceipt(){
  4176. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4177. Doo::loadModel('receipt');
  4178. Doo::loadModel('receiptDetail');
  4179. $receipt=new receipt();
  4180. $receiptDetail=new receiptDetail();
  4181. Doo::loadModel('statistics');
  4182. Doo::loadModel('itemStatistics');
  4183. $statistics=new statistics();
  4184. $itemStatistics=new itemStatistics();
  4185. Doo::loadModel("verify");
  4186. $verify=new verify();
  4187. //审批状态的判定
  4188. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4189. if(empty($receiptDetailList))
  4190. return "/saeaBorad";
  4191. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4192. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4193. if (empty($receiptDetailList['nowStaff'])){
  4194. $nowStaff="";$nowStaffList=array();
  4195. if ($verifyDetail[0][1]=='ROLE'){
  4196. $vStaffString=json_decode($verifyDetail[0][3]);
  4197. foreach ($vStaffString as $key=>$value){
  4198. $staffK=explode("_", $value);
  4199. array_push($nowStaffList, $staffK[0]);
  4200. }
  4201. $nowStaff=implode(',', $nowStaffList);
  4202. }else{
  4203. $nowStaff=$verifyDetail[0][0];
  4204. }
  4205. $receipt->nowStaff=$nowStaff;
  4206. }
  4207. // echo $nowStaff;
  4208. // print_r($verifyDetail);die;
  4209. $receipt->rid=$receiptDetailList['rid'];
  4210. $receipt->date=date("Y-m-d");
  4211. $receipt->status=2;
  4212. $receipt->update();
  4213. $receiptDetail->status=2;
  4214. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4215. Doo::loadModel("receiptLog");
  4216. $receiptLog=new receiptLog();
  4217. Doo::loadModel("verify");
  4218. $verify=new verify();
  4219. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4220. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4221. $jd=json_decode($vr['staff']);$roleId=0;
  4222. foreach ($jd as $key=>$value){
  4223. if ($value[1]=='ROLE'){
  4224. $pos = strpos($value[3], $this->staff[0]['sid']);
  4225. if ($pos !== false) {
  4226. $roleId=$value[0];
  4227. }
  4228. }
  4229. }
  4230. //审批日志
  4231. //echo $roleId;die;
  4232. if (!empty($roleId)){
  4233. Doo::loadModel("role");
  4234. $role=new role();
  4235. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4236. $receiptLog->rolename=$roleInfo['name'];
  4237. }
  4238. $receiptLog->username=$this->staff[0]['username'];
  4239. $receiptLog->uid=$this->staff[0]['sid'];
  4240. $receiptLog->date=date("Y-m-d");
  4241. $receiptLog->opinion='提交审批';
  4242. $receiptLog->img=$this->staff[0]['avatar'];
  4243. $receiptLog->status=2;
  4244. $receiptLog->rid=$rid;
  4245. $receiptLog->insert();
  4246. //statistics item
  4247. $dateArray=explode("-", $receiptDetailList['date']);
  4248. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4249. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4250. //print_r($accountItem['cSum']['agencySum']);die;
  4251. // foreach ($accountItem['cSum'] as $key=>$value){
  4252. // if($key=="agencySum"){
  4253. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4254. // if(empty($iStatistics)){
  4255. // $itemStatistics->cid=$this->staff[0]['cid'];
  4256. // $itemStatistics->staff=$this->staff[0]['sid'];
  4257. // $itemStatistics->price=$value;
  4258. // $itemStatistics->itemCategory=$this->AGENCY;
  4259. // $itemStatistics->date=date("Y-m-d");
  4260. // $itemStatistics->insert();
  4261. // }else{
  4262. // if (!empty($value)){
  4263. // $itemStatistics->price=$value+$iStatistics['price'];
  4264. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4265. // }
  4266. // }
  4267. // }elseif($key=="travelSum"){
  4268. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4269. // if(empty($iStatistics)){
  4270. // $itemStatistics->cid=$this->staff[0]['cid'];
  4271. // $itemStatistics->staff=$this->staff[0]['sid'];
  4272. // $itemStatistics->price=$value;
  4273. // $itemStatistics->itemCategory=$this->TRAVEL;
  4274. // $itemStatistics->date=date("Y-m-d");
  4275. // $itemStatistics->insert();
  4276. // }else{
  4277. // if (!empty($value)){
  4278. // $itemStatistics->price=$value+$iStatistics['price'];
  4279. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4280. // }
  4281. // }
  4282. // }elseif($key=="trainSum"){
  4283. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4284. // if(empty($iStatistics)){
  4285. // $itemStatistics->cid=$this->staff[0]['cid'];
  4286. // $itemStatistics->staff=$this->staff[0]['sid'];
  4287. // $itemStatistics->price=$value;
  4288. // $itemStatistics->itemCategory=$this->TRAIN;
  4289. // $itemStatistics->date=date("Y-m-d");
  4290. // $itemStatistics->insert();
  4291. // }else{
  4292. // if (!empty($value)){
  4293. // $itemStatistics->price=$value+$iStatistics['price'];
  4294. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4295. // }
  4296. // }
  4297. // }elseif($key=="otherSum"){
  4298. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4299. // if(empty($iStatistics)){
  4300. // $itemStatistics->cid=$this->staff[0]['cid'];
  4301. // $itemStatistics->staff=$this->staff[0]['sid'];
  4302. // $itemStatistics->price=$value;
  4303. // $itemStatistics->itemCategory=$this->OTHER;
  4304. // $itemStatistics->date=date("Y-m-d");
  4305. // $itemStatistics->insert();
  4306. // }else{
  4307. // if (!empty($value)){
  4308. // $itemStatistics->price=$value+$iStatistics['price'];
  4309. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4310. // }
  4311. // }
  4312. // }
  4313. // }
  4314. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4315. if(empty($stat)){
  4316. $statistics->date=date("Y-m-d");
  4317. $statistics->cid=$this->staff[0]['cid'];
  4318. $statistics->staff=$this->staff[0]['sid'];
  4319. $statistics->agPrice=0;
  4320. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4321. $statistics->insert();
  4322. }else{
  4323. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4324. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4325. }
  4326. return "/expenses";
  4327. }
  4328. function approval(){
  4329. $status=isset($this->params['status'])?$this->params['status']:'';
  4330. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4331. $month=$this->get_args('month')?$this->get_args('month'):"";
  4332. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4333. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4334. if (empty($status))
  4335. $status=$this->get_args('status')?$this->get_args('status'):2;
  4336. $vidList=array();
  4337. $button=0;
  4338. Doo::loadModel('verify');
  4339. $verify=new verify();
  4340. Doo::loadModel('receipt');
  4341. $receipt=new receipt();
  4342. Doo::loadModel('staff');
  4343. $staff=new staff();
  4344. Doo::loadModel('L_category');
  4345. $Lcategory=new L_category();
  4346. //user verify ID
  4347. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4348. foreach ($verifyDetail as $key=>$value){
  4349. array_push($vidList, $value['vid']);
  4350. }
  4351. $vid=implode(",", $vidList);
  4352. if(empty($verifyDetail))
  4353. $vid=0;
  4354. /*
  4355. */
  4356. $dateCondition=" and Year(date) =".$year;
  4357. if(!empty($month))
  4358. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4359. $categoryList=$Lcategory->find(array('asArray'=>true));
  4360. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4361. $cateCondition="";$staffCondition="";$approvalCondition="";
  4362. if (!empty($cid))
  4363. $cateCondition=' and cid='.$cid;
  4364. if(!empty($sid)){
  4365. $staffCondition=' and staff='.$sid;
  4366. $cateCondition="";
  4367. }
  4368. // elseif($status==1){
  4369. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4370. // }
  4371. if($status==2){
  4372. //查找角色审批人
  4373. $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  4374. }
  4375. $ap="";
  4376. if($status==4){
  4377. $ap=4;$status=2;
  4378. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4379. }
  4380. if($status==5){
  4381. $status=4;$ap=5;
  4382. }
  4383. //echo $vid;
  4384. //get Receipt By verifyID status 2 .$approvalCondition
  4385. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4386. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4387. ,'desc'=>'rid','asArray'=>true));
  4388. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4389. $Locate=0;
  4390. if($ap==4)
  4391. $status=4;
  4392. elseif ($ap==5)
  4393. $status=5;
  4394. foreach ($receiptList as $key=>$value){
  4395. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4396. $receiptList[$key]['reviseDetail']=array();
  4397. if (!empty($value['reviseDetail']))
  4398. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4399. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4400. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4401. $receiptList[$key]['category']=$categoryDetil['title'];
  4402. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4403. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4404. $verifyStaff=json_decode($value['verifyStaff'],true);
  4405. foreach ($verifyList as $k=>$v){
  4406. //init verifyStaff
  4407. $verifyList[$k]['date']="";
  4408. $verifyList[$k]['opinion']="";
  4409. $verifyList[$k]['status']="";
  4410. if (empty($verifyStaff)){
  4411. $verifyList[$k]['date']="";
  4412. $verifyList[$k]['opinion']="";
  4413. if ($v[0]==$this->staff[0]['sid']){
  4414. $verifyList[$k]['status']=4;
  4415. $button=4;
  4416. }
  4417. }else{
  4418. $flag=true;
  4419. foreach ($verifyStaff as $m=>$u){
  4420. if ($v[0]==$m){
  4421. $verifyList[$k]['date']=$u['date'];
  4422. $verifyList[$k]['opinion']=$u['opinion'];
  4423. $verifyList[$k]['status']=$u['status'];
  4424. $flag=false;
  4425. break;
  4426. }
  4427. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4428. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4429. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4430. }
  4431. if($flag){//检测可编辑
  4432. if($v[0]==$this->staff[0]['sid']){
  4433. $verifyList[$k]['status']=4;$button=4;
  4434. }
  4435. }
  4436. }
  4437. }
  4438. $receiptList[$key]['verifyList']=$verifyList;
  4439. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4440. $receiptList[$key]['button']=$button;
  4441. }
  4442. //print_r($receiptList);die;
  4443. //$data['verifyDetail']=$verifyDetail;
  4444. $mothHtml="";
  4445. for($i=1;$i<=12;$i++){
  4446. if($month==$i)
  4447. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4448. else
  4449. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4450. }
  4451. $data['mothHtml']=$mothHtml;
  4452. $data['receiptList']=$receiptList;
  4453. $data['receiptApprovalCount']=count($receiptList);
  4454. $data['status']=$status;
  4455. $data['year']=$year;
  4456. $data['categoryList']=$categoryList;
  4457. $data['staffList']=$staffList;
  4458. $data['cid']=$cid;
  4459. $data['sid']=$sid;
  4460. $data['ap']=$ap;
  4461. $data['memu']="receipt";
  4462. $data['staff']=$this->staff;
  4463. $data['receiptMemu']='approval';
  4464. $data['verifyId']=$this->verifyId;
  4465. $data['executeId']=$this->executeId;
  4466. $this->render ( "/admin/saea_reportList", $data );
  4467. }
  4468. function approvalDetails(){
  4469. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4470. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4471. $month=$this->get_args('month')?$this->get_args('month'):"";
  4472. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4473. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4474. Doo::loadModel('verify');
  4475. $verify=new verify();
  4476. Doo::loadModel('receipt');
  4477. $receipt=new receipt();
  4478. Doo::loadModel('staff');
  4479. $staff=new staff();
  4480. Doo::loadModel('L_category');
  4481. $Lcategory=new L_category();
  4482. Doo::loadModel('enclosur');
  4483. $enclosur=new enclosur();
  4484. $vidList=array();
  4485. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4486. foreach ($verifyDetail as $key=>$value){
  4487. array_push($vidList, $value['vid']);
  4488. }
  4489. $vid=implode(",", $vidList);
  4490. if(empty($verifyDetail))
  4491. $vid=0;
  4492. $categoryList=$Lcategory->find(array('asArray'=>true));
  4493. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4494. $ap=0;
  4495. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4496. $Locate=0;$roleId=0;$button=0;
  4497. foreach ($receiptList as $key=>$value){
  4498. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4499. $receiptList[$key]['reviseDetail']=array();
  4500. if (!empty($value['reviseDetail']))
  4501. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4502. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4503. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4504. $receiptList[$key]['category']=$categoryDetil['title'];
  4505. //检测编辑状态
  4506. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4507. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4508. $verifyStaff=json_decode($value['verifyStaff'],true);
  4509. Doo::loadModel('role');
  4510. $role=new role();
  4511. //print_r($verifyList);
  4512. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4513. foreach ($verifyList as $k=>$v){
  4514. //init verifyStaff
  4515. if ($v[1]=='ROLE'){
  4516. if (!empty($verifyStaff)){
  4517. $endStaffArray=end($verifyStaff);
  4518. if ($v[0]==$endStaffArray['nextStaff']){
  4519. $roleId=$v[0];
  4520. }
  4521. }
  4522. $roleVerify=json_decode($v[3],true);
  4523. $roleKey=$k;$roleArray=array();
  4524. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4525. foreach ($roleVerify as $o=>$p){
  4526. $staffID=explode ('_',$p);
  4527. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4528. //print_r($staffID);
  4529. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4530. array_push($roleArray, $exp);
  4531. }
  4532. $roleArrayCopy[$v[0]]=$roleArray;
  4533. //$verifyList[$k]['roleArray']=$roleArray;
  4534. }
  4535. //print_r($roleArray);
  4536. $verifyList[$k]['date']="";
  4537. $verifyList[$k]['opinion']="";
  4538. $verifyList[$k]['status']="";
  4539. if (empty($verifyStaff)){
  4540. $verifyList[$k]['date']="";
  4541. $verifyList[$k]['opinion']="";
  4542. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4543. $verifyList[$k]['status']=4;
  4544. $button=4;$flag=false;
  4545. }
  4546. }else{
  4547. foreach ($verifyStaff as $m=>$u){
  4548. if ($v[0]==$m){
  4549. $verifyList[$k]['date']=$u['date'];
  4550. $verifyList[$k]['opinion']=$u['opinion'];
  4551. $verifyList[$k]['status']=$u['status'];
  4552. $flag=false;
  4553. break;
  4554. }
  4555. }
  4556. $endStaffArray=end($verifyStaff);
  4557. if (isset($endStaffArray['ROLE'])){
  4558. }else{
  4559. $endKey=key($verifyStaff);
  4560. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4561. $button=4;
  4562. $verifyList[$k]['status']=4;
  4563. }
  4564. }
  4565. }
  4566. }
  4567. $rolename['name']='';
  4568. if (!empty($roleId)){
  4569. Doo::loadModel('role');
  4570. $role=new role();
  4571. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4572. }
  4573. if (!empty($verifyStaff))
  4574. $endStaffArray=end($verifyStaff);
  4575. $KOP=false;
  4576. foreach ($roleArrayCopy as $P=>$A){
  4577. foreach ( $A as $MKI=>$AVL){
  4578. if (!empty($verifyStaff)){
  4579. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4580. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4581. $button=4;
  4582. $roleArrayCopy[$P][$MKI]['status']=4;
  4583. }
  4584. foreach ($verifyStaff as $m=>$u){
  4585. $AVLFK=$AVL[0].'_R';
  4586. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4587. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4588. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4589. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4590. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4591. break;
  4592. }
  4593. }
  4594. }else{
  4595. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4596. $button=4;
  4597. $roleArrayCopy[$P][$MKI]['status']=4;
  4598. }
  4599. }
  4600. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4601. $KOP=true;
  4602. }
  4603. }
  4604. foreach ($roleArrayCopy as $k=>$v){
  4605. foreach ($verifyList as $m=>$n){
  4606. if ($n[0]==$k){
  4607. array_splice($verifyList,$m,1,$v);
  4608. }
  4609. }
  4610. }
  4611. $receiptList[$key]['verifyList']=$verifyList;
  4612. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4613. $receiptList[$key]['button']=$button;
  4614. }
  4615. $mothHtml="";
  4616. for($i=1;$i<=12;$i++){
  4617. if($month==$i)
  4618. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4619. else
  4620. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4621. }
  4622. //获取审批日志
  4623. Doo::loadModel('receiptLog');
  4624. $receiptLog=new receiptLog();
  4625. $rlList=array();
  4626. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4627. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4628. if (!empty($rlInfo)){
  4629. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4630. }
  4631. $receiptList[0]['rlList']=$rlList;
  4632. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4633. $enclosurHtml='';
  4634. foreach ($enclosurList as $value){
  4635. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4636. }
  4637. $data['enclosurHtml']=$enclosurHtml;
  4638. $data['rolename']=$rolename['name'];
  4639. $data['datetij']=$tijdate['date'];
  4640. $data['mothHtml']=$mothHtml;
  4641. $data['receiptList']=$receiptList;
  4642. $data['receiptApprovalCount']=count($receiptList);
  4643. $data['year']=$year;
  4644. $data['categoryList']=$categoryList;
  4645. $data['staffList']=$staffList;
  4646. $data['cid']=$cid;
  4647. $data['sid']=$sid;
  4648. $data['status']=0;
  4649. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4650. $ap=4;
  4651. }else
  4652. $data['status']=$receiptList[0]['status'];
  4653. if ($receiptList[0]['status']==4){
  4654. $data['status']=5;
  4655. $ap=0;
  4656. }
  4657. $data['ap']=$ap;
  4658. $data['memu']="receipt";
  4659. $data['staff']=$this->staff;
  4660. $data['receiptMemu']='approval';
  4661. $data['verifyId']=$this->verifyId;
  4662. $data['executeId']=$this->executeId;
  4663. $this->render ( "/admin/saeaReportListReport", $data );
  4664. }
  4665. function approvalEdi(){
  4666. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4667. $status=isset($this->params['status'])?$this->params['status']:'';
  4668. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4669. $month=$this->get_args('month')?$this->get_args('month'):"";
  4670. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4671. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4672. if (empty($status))
  4673. $status=$this->get_args('status')?$this->get_args('status'):2;
  4674. $vidList=array();
  4675. $button=0;
  4676. Doo::loadModel('verify');
  4677. Doo::loadModel('receipt');
  4678. Doo::loadModel('staff');
  4679. $staff=new staff();
  4680. $receipt=new receipt();
  4681. $verify=new verify();
  4682. Doo::loadModel('L_category');
  4683. $Lcategory=new L_category();
  4684. Doo::loadModel('enclosur');
  4685. $enclosur=new enclosur();
  4686. //user verify ID
  4687. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4688. foreach ($verifyDetail as $key=>$value){
  4689. array_push($vidList, $value['vid']);
  4690. }
  4691. $vid=implode(",", $vidList);
  4692. if(empty($verifyDetail))
  4693. $vid=0;
  4694. $categoryList=$Lcategory->find(array('asArray'=>true));
  4695. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4696. $ap="";
  4697. if($status==4){
  4698. $ap=4;$status=2;
  4699. }
  4700. //get Receipt By verifyID status 2
  4701. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4702. $Locate=0;$roleId=0;
  4703. if($ap==4)
  4704. $status=4;
  4705. foreach ($receiptList as $key=>$value){
  4706. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4707. $receiptList[$key]['reviseDetail']=array();
  4708. if (!empty($value['reviseDetail']))
  4709. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4710. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4711. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4712. $receiptList[$key]['category']=$categoryDetil['title'];
  4713. //检测编辑状态
  4714. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4715. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4716. $verifyStaff=json_decode($value['verifyStaff'],true);
  4717. // print_r($verifyList);
  4718. //
  4719. // if (empty($verifyStaff)){
  4720. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4721. // $verifyList[0]['status']=4;$button=4;
  4722. // }
  4723. //
  4724. // }else{
  4725. //
  4726. // }
  4727. // die;
  4728. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4729. // echo array_search("green",$a);
  4730. //
  4731. Doo::loadModel('role');
  4732. $role=new role();
  4733. //print_r($verifyList);
  4734. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4735. foreach ($verifyList as $k=>$v){
  4736. //init verifyStaff
  4737. if ($v[1]=='ROLE'){
  4738. if (!empty($verifyStaff)){
  4739. $endStaffArray=end($verifyStaff);
  4740. if ($v[0]==$endStaffArray['nextStaff']){
  4741. $roleId=$v[0];
  4742. }
  4743. }
  4744. $roleVerify=json_decode($v[3],true);
  4745. $roleKey=$k;$roleArray=array();
  4746. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4747. foreach ($roleVerify as $o=>$p){
  4748. $staffID=explode ('_',$p);
  4749. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4750. //print_r($staffID);
  4751. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4752. array_push($roleArray, $exp);
  4753. }
  4754. $roleArrayCopy[$v[0]]=$roleArray;
  4755. //$verifyList[$k]['roleArray']=$roleArray;
  4756. }
  4757. //print_r($roleArray);
  4758. $verifyList[$k]['date']="";
  4759. $verifyList[$k]['opinion']="";
  4760. $verifyList[$k]['status']="";
  4761. if (empty($verifyStaff)){
  4762. $verifyList[$k]['date']="";
  4763. $verifyList[$k]['opinion']="";
  4764. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4765. $verifyList[$k]['status']=4;
  4766. $button=4;$flag=false;
  4767. }
  4768. }else{
  4769. foreach ($verifyStaff as $m=>$u){
  4770. if ($v[0]==$m){
  4771. $verifyList[$k]['date']=$u['date'];
  4772. $verifyList[$k]['opinion']=$u['opinion'];
  4773. $verifyList[$k]['status']=$u['status'];
  4774. $flag=false;
  4775. break;
  4776. }
  4777. }
  4778. $endStaffArray=end($verifyStaff);
  4779. if (isset($endStaffArray['ROLE'])){
  4780. }else{
  4781. $endKey=key($verifyStaff);
  4782. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4783. $button=4;
  4784. $verifyList[$k]['status']=4;
  4785. }
  4786. }
  4787. //print_r($endStaffArray);die;
  4788. // if (empty($verifyStaff)){
  4789. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4790. // $verifyList[$k]['status']=4;$button=4;
  4791. // }
  4792. //
  4793. // }else{
  4794. //
  4795. // }
  4796. // if($flag){//检测可编辑
  4797. // if($v[0]==$this->staff[0]['sid']){
  4798. // $verifyList[$k]['status']=4;$button=4;
  4799. // }
  4800. // }
  4801. }
  4802. }
  4803. $rolename['name']='';
  4804. if (!empty($roleId)){
  4805. Doo::loadModel('role');
  4806. $role=new role();
  4807. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4808. }
  4809. if (!empty($verifyStaff))
  4810. $endStaffArray=end($verifyStaff);
  4811. $KOP=false;
  4812. foreach ($roleArrayCopy as $P=>$A){
  4813. foreach ( $A as $MKI=>$AVL){
  4814. if (!empty($verifyStaff)){
  4815. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4816. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4817. $button=4;
  4818. $roleArrayCopy[$P][$MKI]['status']=4;
  4819. }
  4820. foreach ($verifyStaff as $m=>$u){
  4821. $AVLFK=$AVL[0].'_R';
  4822. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4823. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4824. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4825. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4826. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4827. break;
  4828. }
  4829. }
  4830. }else{
  4831. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4832. $button=4;
  4833. $roleArrayCopy[$P][$MKI]['status']=4;
  4834. }
  4835. }
  4836. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4837. $KOP=true;
  4838. }
  4839. }
  4840. // print_r($roleArrayCopy);
  4841. // echo $roleKey;
  4842. foreach ($roleArrayCopy as $k=>$v){
  4843. foreach ($verifyList as $m=>$n){
  4844. if ($n[0]==$k){
  4845. array_splice($verifyList,$m,1,$v);
  4846. }
  4847. }
  4848. }
  4849. // if ($KOP)
  4850. // array_splice($verifyList,$roleKey,1,$roleArray);
  4851. //print_r($verifyList);
  4852. $receiptList[$key]['verifyList']=$verifyList;
  4853. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4854. $receiptList[$key]['button']=$button;
  4855. }
  4856. //$data['verifyDetail']=$verifyDetail;
  4857. $mothHtml="";
  4858. for($i=1;$i<=12;$i++){
  4859. if($month==$i)
  4860. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4861. else
  4862. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4863. }
  4864. //获取审批日志
  4865. Doo::loadModel('receiptLog');
  4866. $receiptLog=new receiptLog();
  4867. $rlList=array();
  4868. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4869. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4870. if (!empty($rlInfo)){
  4871. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4872. }
  4873. $receiptList[0]['rlList']=$rlList;
  4874. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4875. $enclosurHtml='';
  4876. foreach ($enclosurList as $value){
  4877. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4878. }
  4879. $data['enclosurHtml']=$enclosurHtml;
  4880. $data['rolename']=$rolename['name'];
  4881. $data['datetij']=$tijdate['date'];
  4882. $data['mothHtml']=$mothHtml;
  4883. $data['receiptList']=$receiptList;
  4884. $data['receiptApprovalCount']=count($receiptList);
  4885. $data['status']=$status;
  4886. $data['year']=$year;
  4887. $data['categoryList']=$categoryList;
  4888. $data['staffList']=$staffList;
  4889. $data['cid']=$cid;
  4890. $data['sid']=$sid;
  4891. $data['ap']=$ap;
  4892. $data['memu']="receipt";
  4893. $data['staff']=$this->staff;
  4894. $data['receiptMemu']='approval';
  4895. $data['verifyId']=$this->verifyId;
  4896. $data['executeId']=$this->executeId;
  4897. $this->render ( "/admin/saeaReportListReport", $data );
  4898. }
  4899. function remittance(){
  4900. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4901. $month=$this->get_args('month')?$this->get_args('month'):"";
  4902. Doo::loadModel('receipt');
  4903. $receipt=new receipt();
  4904. Doo::loadModel('staff');
  4905. $staff=new staff();
  4906. $dateCondition=" and Year(pastDate) =".$year;
  4907. if(!empty($month))
  4908. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4909. //get Receipt By verifyID status 1
  4910. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4911. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4912. $dataList=array();
  4913. foreach ($dateList as $d=>$a){
  4914. $dataList[$a['pastDate']]=array();$daySum=0;
  4915. foreach ($receiptList as $key=>$value){
  4916. if($a['pastDate']==$value['pastDate']){
  4917. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4918. $list=array();$html="";
  4919. foreach ($oderList as $v){
  4920. array_push($list, $v['receiptOrder']);
  4921. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4922. }
  4923. $receiptList[$key]['receiptOrder']=$html;
  4924. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4925. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4926. $receiptList[$key]['username']=$sinfo['username'];
  4927. $daySum+=$value['sum'];
  4928. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4929. }
  4930. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4931. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4932. }
  4933. }
  4934. //print_r($dataList);
  4935. $data['dataList']=$dataList;
  4936. $mothHtml="";
  4937. for($i=1;$i<=12;$i++){
  4938. if($month==$i)
  4939. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4940. else
  4941. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4942. }
  4943. $data['year']=$year;
  4944. $data['mothHtml']=$mothHtml;
  4945. $data['memu']="receipt";
  4946. $data['staff']=$this->staff;
  4947. $data['receiptMemu']='approval';
  4948. $data['verifyId']=$this->verifyId;
  4949. $data['executeId']=$this->executeId;
  4950. $this->render ( "/admin/saeaReportListPay", $data );
  4951. }
  4952. function revocationAdjustment(){
  4953. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  4954. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  4955. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4956. //echo $price;die;
  4957. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  4958. Doo::loadModel('receipt');
  4959. $receipt=new receipt();
  4960. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4961. if (empty($receiptDetail['reviseDetail']))
  4962. return "/approval";
  4963. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  4964. $RD=array();
  4965. foreach ($reviseDetail as $key=>$value){
  4966. if ($value['price']==$price&&$value['sid']==$sid)
  4967. continue;
  4968. array_push($RD, $value);
  4969. }
  4970. $reviseDetailString=json_encode($RD);
  4971. $receipt->reviseDetail=$reviseDetailString;
  4972. $receipt->sum=$receiptDetail['sum']-$price;
  4973. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  4974. $receipt->update(array('where'=>'rid='.$rid));
  4975. }
  4976. //approvalEdi/37
  4977. return "/approvalEdi/".$rid;
  4978. }
  4979. function updateApprovalReceipt(){
  4980. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  4981. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  4982. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4983. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  4984. if(!empty($rid)){
  4985. Doo::loadModel("verify");
  4986. $verify=new verify();
  4987. Doo::loadModel("receiptDetail");
  4988. $receiptDetailObj=new receiptDetail();
  4989. Doo::loadModel("itemStatistics");
  4990. Doo::loadModel("statistics");
  4991. $statistics=new statistics();
  4992. $itemStatistics=new itemStatistics();
  4993. Doo::loadModel("receipt");
  4994. $receipt=new receipt();
  4995. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  4996. if (empty($receiptDetail))
  4997. return "/approval";
  4998. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  4999. $verifyString=$verifyDetail['staff'];
  5000. $verifyDetail=json_decode($verifyDetail['staff'],true);
  5001. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  5002. if(empty($opinion)){
  5003. if ($status==3)
  5004. $opinion="终止";
  5005. else
  5006. $opinion="同意支付";
  5007. }
  5008. $nowStaff=0;$nowStaffList=array();
  5009. if(empty($verifyStaff)){
  5010. //还需加入是否已经进入角色审批
  5011. if ($verifyDetail[0][1]=='ROLE'){
  5012. //print_r($verifyDetail);echo "ddd";
  5013. $vStaffString=json_decode($verifyDetail[0][3]);
  5014. foreach ($vStaffString as $key=>$value){
  5015. $staffK=explode("_", $value);
  5016. if ($staffK[0]!=$this->staff[0]['sid'])
  5017. array_push($nowStaffList, $staffK[0]);
  5018. }
  5019. //print_r($verifyDetail);
  5020. //die;
  5021. $nowStaff=implode(',', $nowStaffList);
  5022. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5023. }else{
  5024. if ($verifyDetail[1][1]=='ROLE'){
  5025. $vStaffString=json_decode($verifyDetail[1][3]);
  5026. //echo "dd";
  5027. foreach ($vStaffString as $key=>$value){
  5028. $staffK=explode("_", $value);
  5029. array_push($nowStaffList, $staffK[0]);
  5030. }
  5031. $nowStaff=implode(',', $nowStaffList);
  5032. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5033. }else{
  5034. $nowStaff=$verifyDetail[1][0];
  5035. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5036. }
  5037. }
  5038. if($status==3)
  5039. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5040. $vStaffString=json_encode($verifyStaff);
  5041. $receipt->nowStaff=$nowStaff;
  5042. $receipt->verifyStaff=$vStaffString;
  5043. }else{
  5044. $VS=end($verifyStaff);
  5045. //非角色审批
  5046. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5047. $nextStaff=0;$roleSTF=false;
  5048. foreach ($verifyDetail as $key=>$value){
  5049. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5050. if (isset($verifyDetail[$key+1])){
  5051. $nextStaff=$verifyDetail[$key+1][0];
  5052. if ($verifyDetail[$key+1][1]=='ROLE')
  5053. $roleSTF=true;
  5054. }
  5055. break;
  5056. }
  5057. }
  5058. if (!$roleSTF){
  5059. $nowStaff=$nextStaff;
  5060. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5061. }else{
  5062. //获取角色下的所有用户ID
  5063. $nowStaffList=array();
  5064. foreach ($verifyDetail as $vfk){
  5065. if ($vfk[1]=='ROLE'){
  5066. $vStaffString=json_decode($vfk[3]);
  5067. foreach ($vStaffString as $key=>$value){
  5068. $staffK=explode("_", $value);
  5069. array_push($nowStaffList, $staffK[0]);
  5070. }
  5071. }
  5072. }
  5073. $nowStaff=implode(',', $nowStaffList);
  5074. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5075. }
  5076. if($status==3){
  5077. $verifyStaff['final']=$status;
  5078. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5079. }
  5080. $vStaffString=json_encode($verifyStaff);
  5081. $receipt->nowStaff=$nowStaff;
  5082. $receipt->verifyStaff=$vStaffString;
  5083. }
  5084. //角色审批
  5085. if (isset($VS['ROLE'])){
  5086. //找出角色人 当前审批角色组
  5087. $verifyJSStaff=array();$nowStaffList2=array();
  5088. foreach ($verifyDetail as $key=>$value){
  5089. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5090. $verifyJSStaff=json_decode($value[3]);
  5091. foreach ($verifyJSStaff as $m){
  5092. $staffK=explode("_", $m);
  5093. array_push($nowStaffList2, $staffK[0]);
  5094. }
  5095. // print_r($nowStaffList2);
  5096. }
  5097. }
  5098. $RoleVerifyStaff=array();
  5099. foreach ($verifyStaff as $key=>$value){
  5100. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5101. foreach ($nowStaffList2 as $m) {
  5102. if ($key==$m."_R")
  5103. $RoleVerifyStaff[$key]=$value;
  5104. }
  5105. }
  5106. }
  5107. // print_r($verifyStaff);
  5108. // print_r($nowStaffList2);
  5109. // print_r($RoleVerifyStaff);
  5110. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5111. //print_r($verifyJSStaff);
  5112. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5113. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5114. //下一个审批人ID
  5115. $nextStaff=0;$falg=false;
  5116. foreach ($verifyDetail as $key=>$value){
  5117. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5118. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5119. $falg=true;
  5120. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5121. foreach ($vStaffString as $v){
  5122. $staffK=explode("_", $v);
  5123. array_push($nowStaffList, $staffK[0]);
  5124. }
  5125. $nowStaff=implode(',', $nowStaffList);
  5126. $nextStaff=$verifyDetail[$key+1][0];
  5127. }elseif(isset($verifyDetail[$key+1])){
  5128. $nextStaff=$verifyDetail[$key+1][0];
  5129. $nowStaff=$nextStaff;
  5130. }else
  5131. $nowStaff='';
  5132. break;
  5133. }
  5134. }
  5135. if ($falg)
  5136. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5137. else
  5138. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5139. // print_r($verifyStaff);
  5140. // echo $nowStaff;die;
  5141. }else{ //进入下一个角色或者审批人
  5142. /*
  5143. */
  5144. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5145. //
  5146. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5147. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5148. // print_r($verifyStaff);
  5149. // die;
  5150. }
  5151. if($status==3){
  5152. $verifyStaff['final']=$status;
  5153. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5154. }
  5155. $vStaffString=json_encode($verifyStaff);
  5156. $receipt->verifyStaff=$vStaffString;
  5157. $receipt->nowStaff=$nowStaff;
  5158. //die;
  5159. //}
  5160. // print_r($verifyStaff);
  5161. // die;
  5162. }
  5163. //print_r($verifyStaff);die;
  5164. }
  5165. //print_r($verifyDetail);
  5166. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5167. foreach ($verifyDetail as $k=>$v){
  5168. if ($v[1]=='ROLE'){
  5169. $roleId=$v[0];
  5170. $roleVerify=json_decode($v[3],true);
  5171. $roleKey=$k;$roleArray=array();
  5172. foreach ($roleVerify as $o=>$p){
  5173. $staffID=explode ('_',$p);
  5174. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5175. array_push($roleArray, $exp);
  5176. }
  5177. $verifyDetailCopy[$v[0]]=$roleArray;
  5178. }
  5179. }
  5180. //print_r($verifyDetail);
  5181. foreach ($verifyDetailCopy as $k=>$v){
  5182. foreach ($verifyDetail as $m=>$n){
  5183. if ($n[0]==$k){
  5184. array_splice($verifyDetail,$m,1,$v);
  5185. }
  5186. }
  5187. }
  5188. // die;
  5189. // if (!empty($roleArray))
  5190. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5191. // echo $roleId;
  5192. // print_r($verifyStaff);
  5193. // print_r($verifyDetail);
  5194. // die;
  5195. Doo::loadModel("receiptLog");
  5196. $receiptLog=new receiptLog();
  5197. //审批日志
  5198. if (!isset($verifyStaff['final'])){
  5199. if (!empty($roleId)){
  5200. Doo::loadModel("role");
  5201. $role=new role();
  5202. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5203. $receiptLog->rolename=$roleInfo['name'];
  5204. }
  5205. $receiptLog->username=$this->staff[0]['username'];
  5206. $receiptLog->uid=$this->staff[0]['sid'];
  5207. $receiptLog->date=date("Y-m-d");
  5208. $receiptLog->opinion=$opinion;
  5209. $receiptLog->img=$this->staff[0]['avatar'];
  5210. $receiptLog->status=1;
  5211. $receiptLog->rid=$rid;
  5212. $receiptLog->insert();
  5213. }
  5214. if (isset($verifyStaff['final'])){//rDetail
  5215. $receipt->verifyBreakup=$verifyString;
  5216. $receipt->status=3;
  5217. $receiptDetailObj->status=3;
  5218. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5219. if (!empty($roleId)){
  5220. Doo::loadModel("role");
  5221. $role=new role();
  5222. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5223. $receiptLog->rolename=$roleInfo['name'];
  5224. }
  5225. $receiptLog->username=$this->staff[0]['username'];
  5226. $receiptLog->uid=$this->staff[0]['sid'];
  5227. $receiptLog->date=date("Y-m-d");
  5228. $receiptLog->opinion=$opinion;
  5229. $receiptLog->img=$this->staff[0]['avatar'];
  5230. $receiptLog->status=3;
  5231. $receiptLog->rid=$rid;
  5232. $receiptLog->insert();
  5233. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5234. $receipt->status=1;$reviseSum=0;
  5235. $receipt->verifyBreakup=$verifyString;
  5236. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5237. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5238. foreach ($reviseDetail as $key=>$value){
  5239. $receiptDetailObj=new receiptDetail();
  5240. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5241. $receiptDetailObj->item=$value['description'];
  5242. $receiptDetailObj->itemCategory="报销金额调整";
  5243. $receiptDetailObj->price=$value['price'];
  5244. $receiptDetailObj->date=$receiptDetail['date'];
  5245. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5246. $receiptDetailObj->rid=$rid;
  5247. $receiptDetailObj->status=1;
  5248. $receiptDetailObj->insert();
  5249. $reviseSum+=$value['price'];
  5250. }
  5251. $itemStatistics=new itemStatistics();
  5252. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5253. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5254. $itemStatistics->price=$reviseSum;
  5255. $itemStatistics->itemCategory="报销金额调整";
  5256. $itemStatistics->date=$receiptDetail['date'];
  5257. $itemStatistics->insert();
  5258. }
  5259. $receiptDetailObj=new receiptDetail();
  5260. $receiptDetailObj->status=1;
  5261. $receiptDetailObj->pastDate=date("Y-m-d");
  5262. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5263. $dateArray=explode("-", $receiptDetail['date']);
  5264. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5265. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5266. if(empty($stat)){
  5267. $statistics->date=$receiptDetail['date'];
  5268. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5269. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5270. $statistics->agPrice=$receiptDetail['sum'];
  5271. $statistics->rePrice=$reviseSum;
  5272. $statistics->insert();
  5273. }else{
  5274. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5275. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5276. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5277. }
  5278. $dateArray=explode("-", $receiptDetail['date']);
  5279. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5280. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5281. foreach ($accountItem['cSum'] as $key=>$value){
  5282. if($key=="agencySum"){
  5283. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5284. if(empty($iStatistics)){
  5285. $itemStatistics->cid=$receiptDetail['cid'];;
  5286. $itemStatistics->staff=$receiptDetail['staff'];
  5287. $itemStatistics->price=$value;
  5288. $itemStatistics->itemCategory=$this->AGENCY;
  5289. $itemStatistics->date=$receiptDetail['date'];
  5290. $itemStatistics->insert();
  5291. }else{
  5292. if (!empty($value)){
  5293. $itemStatistics->price=$value+$iStatistics['price'];
  5294. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5295. }
  5296. }
  5297. }elseif($key=="travelSum"){
  5298. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5299. if(empty($iStatistics)){
  5300. $itemStatistics->cid=$receiptDetail['cid'];
  5301. $itemStatistics->staff=$receiptDetail['staff'];
  5302. $itemStatistics->price=$value;
  5303. $itemStatistics->itemCategory=$this->TRAVEL;
  5304. $itemStatistics->date=$receiptDetail['date'];
  5305. $itemStatistics->insert();
  5306. }else{
  5307. if (!empty($value)){
  5308. $itemStatistics->price=$value+$iStatistics['price'];
  5309. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5310. }
  5311. }
  5312. }elseif($key=="trainSum"){
  5313. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5314. if(empty($iStatistics)){
  5315. $itemStatistics->cid=$receiptDetail['cid'];
  5316. $itemStatistics->staff=$receiptDetail['staff'];
  5317. $itemStatistics->price=$value;
  5318. $itemStatistics->itemCategory=$this->TRAIN;
  5319. $itemStatistics->date=$receiptDetail['date'];
  5320. $itemStatistics->insert();
  5321. }else{
  5322. if (!empty($value)){
  5323. $itemStatistics->price=$value+$iStatistics['price'];
  5324. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5325. }
  5326. }
  5327. }elseif($key=="otherSum"){
  5328. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5329. if(empty($iStatistics)){
  5330. $itemStatistics->cid=$receiptDetail['cid'];
  5331. $itemStatistics->staff=$receiptDetail['staff'];
  5332. $itemStatistics->price=$value;
  5333. $itemStatistics->itemCategory=$this->OTHER;
  5334. $itemStatistics->date=$receiptDetail['date'];
  5335. $itemStatistics->insert();
  5336. }else{
  5337. if (!empty($value)){
  5338. $itemStatistics->price=$value+$iStatistics['price'];
  5339. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5340. }
  5341. }
  5342. }
  5343. }
  5344. $receipt->pastDate=date("Y-m-d");
  5345. }
  5346. $receipt->update(array('where'=>' rid = '.$rid));
  5347. return "/approvalExpenses/2";
  5348. }
  5349. }
  5350. function expensesRetreats(){
  5351. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5352. if (!empty($rid)){
  5353. //操作记录
  5354. Doo::loadModel("receipt");
  5355. $receipt=new receipt();
  5356. Doo::loadModel("receiptLog");
  5357. $receiptLog=new receiptLog();
  5358. Doo::loadModel("verify");
  5359. $verify=new verify();
  5360. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5361. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5362. $jd=json_decode($vr['staff']);$roleId=0;
  5363. foreach ($jd as $key=>$value){
  5364. if ($value[1]=='ROLE'){
  5365. $pos = strpos($value[3], $this->staff[0]['sid']);
  5366. if ($pos !== false) {
  5367. $roleId=$value[0];
  5368. }
  5369. }
  5370. }
  5371. //审批日志
  5372. //echo $roleId;die;
  5373. if (!empty($roleId)){
  5374. Doo::loadModel("role");
  5375. $role=new role();
  5376. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5377. $receiptLog->rolename=$roleInfo['name'];
  5378. }
  5379. $receiptLog->username=$this->staff[0]['username'];
  5380. $receiptLog->uid=$this->staff[0]['sid'];
  5381. $receiptLog->date=date("Y-m-d");
  5382. $receiptLog->opinion='撤回';
  5383. $receiptLog->img=$this->staff[0]['avatar'];
  5384. $receiptLog->status=4;
  5385. $receiptLog->rid=$rid;
  5386. $receiptLog->insert();
  5387. $receipt->status=4;
  5388. $receipt->update(array('where'=>'rid='.$rid));
  5389. }
  5390. //echo "ddd";
  5391. return '/approvalExpenses';
  5392. }
  5393. function updateCheReceipt(){
  5394. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5395. if (!empty($rid)){
  5396. //操作记录
  5397. Doo::loadModel("receipt");
  5398. $receipt=new receipt();
  5399. Doo::loadModel("receiptLog");
  5400. $receiptLog=new receiptLog();
  5401. Doo::loadModel("verify");
  5402. $verify=new verify();
  5403. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5404. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5405. $jd=json_decode($vr['staff']);$roleId=0;
  5406. foreach ($jd as $key=>$value){
  5407. if ($value[1]=='ROLE'){
  5408. $pos = strpos($value[3], $this->staff[0]['sid']);
  5409. if ($pos !== false) {
  5410. $roleId=$value[0];
  5411. }
  5412. }
  5413. }
  5414. //审批日志
  5415. //echo $roleId;die;
  5416. if (!empty($roleId)){
  5417. Doo::loadModel("role");
  5418. $role=new role();
  5419. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5420. $receiptLog->rolename=$roleInfo['name'];
  5421. }
  5422. $receiptLog->username=$this->staff[0]['username'];
  5423. $receiptLog->uid=$this->staff[0]['sid'];
  5424. $receiptLog->date=date("Y-m-d");
  5425. $receiptLog->opinion='撤回';
  5426. $receiptLog->img=$this->staff[0]['avatar'];
  5427. $receiptLog->status=4;
  5428. $receiptLog->rid=$rid;
  5429. $receiptLog->insert();
  5430. $receipt->status=4;
  5431. $receipt->update(array('where'=>'rid='.$rid));
  5432. }
  5433. //echo "ddd";
  5434. return '/saeaBorad';
  5435. }
  5436. function revisePrice(){
  5437. $description=$this->get_args('description')?$this->get_args('description'):"";
  5438. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5439. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5440. //echo $price;die;
  5441. if (!empty($rid)){
  5442. Doo::loadModel("receipt");
  5443. $receipt=new receipt();
  5444. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5445. if (empty($receiptDetail))
  5446. return "/approval";
  5447. $reviseDetail=array();
  5448. if (empty($receiptDetail['reviseDetail'])){
  5449. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5450. $reviseDetailString=json_encode($reviseDetail);
  5451. $receipt->reviseDetail=$reviseDetailString;
  5452. $receipt->revisePrice=$price;
  5453. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5454. }else{
  5455. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5456. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5457. $reviseDetailString=json_encode($reviseDetail);
  5458. $receipt->reviseDetail=$reviseDetailString;
  5459. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5460. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5461. }
  5462. $receipt->update(array('where'=>'rid='.$rid));
  5463. }
  5464. return '/approvalEdi/'.$rid;
  5465. }
  5466. function personalCollect(){
  5467. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5468. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5469. $this->showCache($path);
  5470. Doo::loadModel("receiptDetail");
  5471. Doo::loadModel("itemStatistics");
  5472. Doo::loadModel('statistics');
  5473. $statistics=new statistics();
  5474. $itemStatistics=new itemStatistics();
  5475. $receiptDetail=new receiptDetail();
  5476. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5477. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5478. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5479. //create collect html
  5480. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5481. $adjustment=array();
  5482. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5483. array_push($collectArray['日常相关费用'], $collectHtml);
  5484. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5485. array_push($collectArray['差旅相关费用'], $collectHtml);
  5486. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5487. array_push($collectArray['培训班费用'], $collectHtml);
  5488. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5489. array_push($collectArray['其他'], $collectHtml);
  5490. $data['collectArray']=$collectArray;
  5491. //statistics html
  5492. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5493. if(empty($stList))
  5494. $stList=array('rePrice'=>0,'agPrice'=>0);
  5495. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5496. //Adjustment price html
  5497. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5498. array_push($adjustment, $collectHtml);
  5499. $data['adjustment']=$adjustment;
  5500. //total price html
  5501. $collectHtml="";$total=0;
  5502. for ($i=1;$i<=12;$i++){
  5503. $sumPrice=0;
  5504. foreach ($receiptCollectList as $key=>$value){
  5505. if($value['month']==$i){
  5506. $sumPrice+=$value['price'];
  5507. }
  5508. }
  5509. if ($sumPrice==0)
  5510. $collectHtml.='<td class="taR">-</td>';
  5511. else
  5512. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5513. $total+=$sumPrice;
  5514. }
  5515. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5516. $data['totalPrice']=$collectHtml;
  5517. $data['year']=$year;
  5518. $data['totalYear']=$total;
  5519. $data['memu']="receipt";
  5520. $data['staff']=$this->staff;
  5521. $data['receiptMemu']='personalCollect';
  5522. $data['verifyId']=$this->verifyId;
  5523. $data['executeId']=$this->executeId;
  5524. //year staff status 2,4
  5525. if($year<date("Y")){
  5526. Doo::loadModel('receipt');
  5527. $receipt=new receipt();
  5528. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5529. if(empty($receiptList)){
  5530. ob_start();
  5531. $this->render ( "/admin/saea_slist_collect", $data );
  5532. $this->cacheFile($path);die;
  5533. }
  5534. }
  5535. $this->render ( "/admin/saea_slist_collect", $data );
  5536. }
  5537. function personalCollectDetail(){
  5538. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5539. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5540. $this->showCache($path);
  5541. Doo::loadModel("receiptDetail");
  5542. Doo::loadModel("itemStatistics");
  5543. Doo::loadModel('statistics');
  5544. Doo::loadModel('accountItem');
  5545. $accountItem=new accountItem();
  5546. $statistics=new statistics();
  5547. $itemStatistics=new itemStatistics();
  5548. $receiptDetail=new receiptDetail();
  5549. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5550. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5551. $accountList=$accountItem->find(array('asArray'=>true));
  5552. //create CollectDetail HTML
  5553. $collectHtml=array();
  5554. foreach ($accountList as $key=>$value){
  5555. $html="";$asum=0;
  5556. for ($i=1;$i<=12;$i++){
  5557. $falg=true;
  5558. foreach ($receiptCollectList as $v) {
  5559. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5560. $asum+=$v['price'];
  5561. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5562. }
  5563. }
  5564. if($falg)
  5565. $html.='<td class="taR">-</td>';
  5566. }
  5567. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5568. $collectHtml[$value['category']][$value['name']]=$html;
  5569. }
  5570. $data['collectHtml']=$collectHtml;
  5571. //create Adjustment price html
  5572. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5573. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5574. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5575. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5576. array_push($collectArray['日常相关费用'], $collectHtml);
  5577. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5578. array_push($collectArray['差旅相关费用'], $collectHtml);
  5579. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5580. array_push($collectArray['培训班费用'], $collectHtml);
  5581. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5582. array_push($collectArray['其他'], $collectHtml);
  5583. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5584. array_push($adjustment, $collectHtml);
  5585. //total price html
  5586. $collectHtml="";$total=0;
  5587. for ($i=1;$i<=12;$i++){
  5588. $sumPrice=0;
  5589. foreach ($receiptCollectList as $key=>$value){
  5590. if($value['month']==$i){
  5591. $sumPrice+=$value['price'];
  5592. }
  5593. }
  5594. if ($sumPrice==0)
  5595. $collectHtml.='<td class="taR">-</td>';
  5596. else
  5597. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5598. $total+=$sumPrice;
  5599. }
  5600. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5601. //statistics html
  5602. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5603. if(empty($stList))
  5604. $stList=array('rePrice'=>0,'agPrice'=>0);
  5605. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5606. $data['collectArray']=$collectArray;
  5607. $data['adjustment']=$adjustment;
  5608. $data['totalPrice']=$collectHtml;
  5609. $data['totalYear']=$total;
  5610. $data['year']=$year;
  5611. $data['memu']="receipt";
  5612. $data['staff']=$this->staff;
  5613. $data['receiptMemu']='personalCollect';
  5614. $data['verifyId']=$this->verifyId;
  5615. $data['executeId']=$this->executeId;
  5616. //year staff status 2,4
  5617. if($year<date("Y")){
  5618. Doo::loadModel('receipt');
  5619. $receipt=new receipt();
  5620. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5621. if(empty($receiptList)){
  5622. ob_start();
  5623. $this->render ( "/admin/saeaCollectArticles", $data );
  5624. $this->cacheFile($path);die;
  5625. }
  5626. }
  5627. $this->render ( "/admin/saeaCollectArticles", $data );
  5628. }
  5629. function companyCategoryCollect(){
  5630. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5631. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5632. $this->showCache($path);
  5633. Doo::loadModel('L_category');
  5634. Doo::loadModel('itemStatistics');
  5635. Doo::loadModel('statistics');
  5636. $statistics=new statistics();
  5637. $Lcategory=new L_category();
  5638. $itemStatistics=new itemStatistics();
  5639. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5640. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5641. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5642. //ceatre companyCollectHtml
  5643. foreach ($LcategoryList as $value){
  5644. $html="";$asum=0;
  5645. for ($i=1;$i<=12;$i++){
  5646. $falg=true;
  5647. foreach ($itemStatisticsList as $v){
  5648. if($value['cid']==$v['cid']&&$i==$v['month']){
  5649. $asum+=$v['price'];
  5650. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5651. }
  5652. }
  5653. if($falg)
  5654. $html.='<td class="taR">-</td>';
  5655. }
  5656. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5657. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5658. }
  5659. $data['companyHtml']=$collectHtml;
  5660. //total price html
  5661. $collectHtml="";$total=0;
  5662. for ($i=1;$i<=12;$i++){
  5663. $sumPrice=0;
  5664. foreach ($itemStatisticsList as $key=>$value){
  5665. if($value['month']==$i){
  5666. $sumPrice+=$value['price'];
  5667. }
  5668. }
  5669. if ($sumPrice==0)
  5670. $collectHtml.='<td class="taR">-</td>';
  5671. else
  5672. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5673. $total+=$sumPrice;
  5674. }
  5675. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5676. $data['companyTotalHtml']=$collectHtml;
  5677. $data['total']=$total;
  5678. //statistics html
  5679. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5680. if(empty($stList))
  5681. $stList=array('rePrice'=>0,'agPrice'=>0);
  5682. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5683. $data['year']=$year;
  5684. $data['memu']="receipt";
  5685. $data['staff']=$this->staff;
  5686. $data['receiptMemu']='companyCategoryCollect';
  5687. $data['verifyId']=$this->verifyId;
  5688. $data['executeId']=$this->executeId;
  5689. //year staff status 2,4
  5690. if($year<date("Y")){
  5691. Doo::loadModel('receipt');
  5692. $receipt=new receipt();
  5693. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5694. if(empty($receiptList)){
  5695. ob_start();
  5696. $this->render ( "/admin/saeaCompanyCollect", $data );
  5697. $this->cacheFile($path);die;
  5698. }
  5699. }
  5700. $this->render ( "/admin/saeaCompanyCollect", $data );
  5701. }
  5702. function categoryCollectDetail(){
  5703. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5704. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5705. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5706. $this->showCache($path);
  5707. Doo::loadModel('statistics');
  5708. $statistics=new statistics();
  5709. Doo::loadModel("receiptDetail");
  5710. $receiptDetail=new receiptDetail();
  5711. Doo::loadModel('L_category');
  5712. $Lcategory=new L_category();
  5713. Doo::loadModel('accountItem');
  5714. $accountItem=new accountItem();
  5715. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5716. if ($cid==0){
  5717. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5718. if ($cid==0)
  5719. $cid=$LcategoryList[0]['cid'];
  5720. }
  5721. $data['LcategoryList']=$LcategoryList;
  5722. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5723. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5724. $accountList=$accountItem->find(array('asArray'=>true));
  5725. //create CollectDetail HTML
  5726. $collectHtml=array();
  5727. foreach ($accountList as $key=>$value){
  5728. $html="";$asum=0;
  5729. for ($i=1;$i<=12;$i++){
  5730. $falg=true;
  5731. foreach ($receiptCollectList as $v) {
  5732. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5733. $asum+=$v['price'];
  5734. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5735. }
  5736. }
  5737. if($falg)
  5738. $html.='<td class="taR">-</td>';
  5739. }
  5740. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5741. $collectHtml[$value['category']][$value['name']]=$html;
  5742. }
  5743. $data['collectHtml']=$collectHtml;
  5744. //create Adjustment price html
  5745. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5746. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5747. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5748. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5749. array_push($collectArray['日常相关费用'], $collectHtml);
  5750. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5751. array_push($collectArray['差旅相关费用'], $collectHtml);
  5752. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5753. array_push($collectArray['培训班费用'], $collectHtml);
  5754. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5755. array_push($collectArray['其他'], $collectHtml);
  5756. $data['collectArray']=$collectArray;
  5757. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5758. array_push($adjustment, $collectHtml);
  5759. $data['adjustment']=$adjustment;
  5760. //total price html
  5761. $collectHtml="";$total=0;
  5762. for ($i=1;$i<=12;$i++){
  5763. $sumPrice=0;
  5764. foreach ($receiptCollectList as $key=>$value){
  5765. if($value['month']==$i){
  5766. $sumPrice+=$value['price'];
  5767. }
  5768. }
  5769. if ($sumPrice==0)
  5770. $collectHtml.='<td class="taR">-</td>';
  5771. else
  5772. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5773. $total+=$sumPrice;
  5774. }
  5775. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5776. //statistics html
  5777. $stList=$statistics->statisticsByCid($year,$cid);
  5778. if(empty($stList))
  5779. $stList=array('rePrice'=>0,'agPrice'=>0);
  5780. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5781. $data['totalYear']=$total;
  5782. $data['year']=$year;
  5783. $data['cid']=$cid;
  5784. $data['memu']="receipt";
  5785. $data['staff']=$this->staff;
  5786. $data['receiptMemu']='companyCategoryCollect';
  5787. $data['verifyId']=$this->verifyId;
  5788. $data['executeId']=$this->executeId;
  5789. //year staff status 2,4
  5790. if($year<date("Y")){
  5791. Doo::loadModel('receipt');
  5792. $receipt=new receipt();
  5793. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5794. if(empty($receiptList)){
  5795. ob_start();
  5796. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5797. $this->cacheFile($path);die;
  5798. }
  5799. }
  5800. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5801. }
  5802. function staffCollect(){
  5803. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5804. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5805. //$this->showCache($path);
  5806. Doo::loadModel('statistics');
  5807. $statistics=new statistics();
  5808. Doo::loadModel("receiptDetail");
  5809. $receiptDetail=new receiptDetail();
  5810. Doo::loadModel('L_category');
  5811. $Lcategory=new L_category();
  5812. Doo::loadModel('accountItem');
  5813. $accountItem=new accountItem();
  5814. Doo::loadModel('staff');
  5815. $staff=new staff();
  5816. Doo::loadModel('itemStatistics');
  5817. $itemStatistics=new itemStatistics();
  5818. /*
  5819. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5820. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5821. if(empty($stList))
  5822. $stList=array('rePrice'=>0,'agPrice'=>0);
  5823. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5824. */
  5825. //statistics html
  5826. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5827. if(empty($stList))
  5828. $stList=array('rePrice'=>0,'agPrice'=>0);
  5829. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5830. //---
  5831. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5832. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5833. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5834. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5835. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5836. //print_r($itemStatisticsList);die;
  5837. //ceatre companyCollectHtml
  5838. foreach ($categoryList as $vlu){
  5839. $count=$vlu['count']+1;
  5840. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5841. $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;
  5842. foreach ($staffList as $value){
  5843. if ($vlu['cid']==$value['cid']){
  5844. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5845. $asum=0;
  5846. for ($i=1;$i<=12;$i++){
  5847. $falg=true;
  5848. foreach ($itemStatisticsList as $v){
  5849. if($value['sid']==$v['staff']&&$i==$v['month']){
  5850. if ($v['month']==1)
  5851. $m1+=$v['price'];
  5852. if ($v['month']==2)
  5853. $m2+=$v['price'];
  5854. if ($v['month']==3)
  5855. $m3+=$v['price'];
  5856. if ($v['month']==4)
  5857. $m4+=$v['price'];
  5858. if ($v['month']==5)
  5859. $m5+=$v['price'];
  5860. if ($v['month']==6)
  5861. $m6+=$v['price'];
  5862. if ($v['month']==7)
  5863. $m7+=$v['price'];
  5864. if ($v['month']==8)
  5865. $m8+=$v['price'];
  5866. if ($v['month']==9)
  5867. $m9+=$v['price'];
  5868. if ($v['month']==10)
  5869. $m10+=$v['price'];
  5870. if ($v['month']==11)
  5871. $m11+=$v['price'];
  5872. if ($v['month']==12)
  5873. $m12+=$v['price'];
  5874. $asum+=$v['price'];
  5875. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5876. }
  5877. }
  5878. if($falg)
  5879. $html.='<td class="taR">-</td>';
  5880. }
  5881. $m13+=$asum;
  5882. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5883. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5884. $html="";
  5885. }
  5886. }
  5887. $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>
  5888. <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>
  5889. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5890. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5891. }
  5892. $data['companyHtml']=$collectHtml;
  5893. //total price html
  5894. $collectHtml="";$total=0;
  5895. for ($i=1;$i<=12;$i++){
  5896. $sumPrice=0;
  5897. foreach ($itemStatisticsList as $key=>$value){
  5898. if($value['month']==$i){
  5899. $sumPrice+=$value['price'];
  5900. }
  5901. }
  5902. if ($sumPrice==0)
  5903. $collectHtml.='<td class="taR">-</td>';
  5904. else
  5905. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5906. $total+=$sumPrice;
  5907. }
  5908. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5909. $data['companyTotalHtml']=$collectHtml;
  5910. $data['total']=$total;
  5911. $data['year']=$year;
  5912. $data['memu']="receipt";
  5913. $data['staff']=$this->staff;
  5914. $data['receiptMemu']='companyCategoryCollect';
  5915. $data['verifyId']=$this->verifyId;
  5916. $data['executeId']=$this->executeId;
  5917. if ($year<=date("Y")){
  5918. Doo::loadModel('receipt');
  5919. $receipt=new receipt();
  5920. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5921. if(empty($receiptList)){ //generated files
  5922. ob_start();
  5923. $this->render ( "/admin/saeaStaffCollectB", $data );
  5924. $this->cacheFile($path);die;
  5925. }
  5926. }
  5927. $this->render ( "/admin/saeaStaffCollectB", $data );
  5928. }
  5929. function staffCollectBak(){
  5930. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5931. $month=$this->get_args('month')?$this->get_args('month'):1;
  5932. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  5933. $this->showCache($path);
  5934. Doo::loadModel('statistics');
  5935. $statistics=new statistics();
  5936. Doo::loadModel("receiptDetail");
  5937. $receiptDetail=new receiptDetail();
  5938. Doo::loadModel('L_category');
  5939. $Lcategory=new L_category();
  5940. Doo::loadModel('accountItem');
  5941. $accountItem=new accountItem();
  5942. Doo::loadModel('staff');
  5943. $staff=new staff();
  5944. Doo::loadModel('itemStatistics');
  5945. $itemStatistics=new itemStatistics();
  5946. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5947. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  5948. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5949. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  5950. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5951. $staffList=$staff->find(array('asArray'=>true));
  5952. $htmlArray=array();
  5953. foreach ($LcategoryList as $value){
  5954. $htmlArray[$value['title']]=array();
  5955. foreach ($staffList as $v){
  5956. if($value['cid']==$v['cid']){
  5957. $html="";$falg=true;$staffSumPrice=0;
  5958. foreach ($itemStatisticsList as $a){
  5959. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  5960. if(empty($a['price'])){
  5961. $html.='<td class="taR">-</td>';$falg=false;break;
  5962. }else{
  5963. $staffSumPrice+=$a['price'];
  5964. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5965. }
  5966. }
  5967. }
  5968. if ($falg){
  5969. $html.='<td class="taR">-</td>';$falg=true;
  5970. }
  5971. $falg=true;
  5972. foreach ($itemStatisticsList as $a){
  5973. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  5974. if(empty($a['price'])){
  5975. $html.='<td class="taR">-</td>';$falg=false;break;
  5976. }else{
  5977. $staffSumPrice+=$a['price'];
  5978. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5979. }
  5980. }
  5981. }
  5982. if ($falg){
  5983. $html.='<td class="taR">-</td>';$falg=true;
  5984. }
  5985. $falg=true;
  5986. foreach ($itemStatisticsList as $a){
  5987. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  5988. if(empty($a['price'])){
  5989. $html.='<td class="taR">-</td>';$falg=false;break;
  5990. }else{
  5991. $staffSumPrice+=$a['price'];
  5992. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5993. }
  5994. }
  5995. }
  5996. if ($falg){
  5997. $html.='<td class="taR">-</td>';$falg=true;
  5998. }
  5999. $falg=true;
  6000. foreach ($itemStatisticsList as $a){
  6001. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6002. if(!empty($a['price'])){
  6003. $staffSumPrice+=$a['price'];
  6004. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6005. }else{
  6006. $html.='<td class="taR">-</td>';$falg=false;break;
  6007. }
  6008. }
  6009. }
  6010. if ($falg){
  6011. $html.='<td class="taR">-</td>';$falg=true;
  6012. }
  6013. $falg=true;
  6014. foreach ($itemStatisticsList as $a){
  6015. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6016. if(!empty($a['price'])){
  6017. $staffSumPrice+=$a['price'];
  6018. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6019. }else{
  6020. $html.='<td class="taR">-</td>';$falg=false;break;
  6021. }
  6022. }
  6023. }
  6024. if ($falg){
  6025. $html.='<td class="taR">-</td>';$falg=true;
  6026. }
  6027. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6028. $htmlArray[$value['title']][$v['username']]=$html;
  6029. }
  6030. }
  6031. /*-- ---*/
  6032. //合计费用
  6033. $cateHtml="";$catePrice=0;$cateFalg=true;
  6034. foreach ($itemCategoryList as $l){
  6035. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6036. if(empty($l['price'])){
  6037. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6038. }else{
  6039. $catePrice+=$l['price'];
  6040. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6041. }
  6042. }
  6043. }
  6044. if ($cateFalg){
  6045. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6046. }
  6047. $cateFalg=true;
  6048. foreach ($itemCategoryList as $l){
  6049. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6050. if(empty($l['price'])){
  6051. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6052. }else{
  6053. $catePrice+=$l['price'];
  6054. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6055. }
  6056. }
  6057. }
  6058. if ($cateFalg){
  6059. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6060. }
  6061. $cateFalg=true;
  6062. foreach ($itemCategoryList as $l){
  6063. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6064. if(empty($l['price'])){
  6065. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6066. }else{
  6067. $catePrice+=$l['price'];
  6068. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6069. }
  6070. }
  6071. }
  6072. if ($cateFalg){
  6073. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6074. }
  6075. $cateFalg=true;
  6076. foreach ($itemCategoryList as $l){
  6077. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6078. if(empty($l['price'])){
  6079. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6080. }else{
  6081. $catePrice+=$l['price'];
  6082. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6083. }
  6084. }
  6085. }
  6086. if ($cateFalg){
  6087. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6088. }
  6089. $cateFalg=true;
  6090. foreach ($itemCategoryList as $l){
  6091. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6092. if(empty($l['price'])){
  6093. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6094. }else{
  6095. $catePrice+=$l['price'];
  6096. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6097. }
  6098. }
  6099. }
  6100. if ($cateFalg){
  6101. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6102. }
  6103. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6104. $htmlArray[$value['title']]['合计']=$cateHtml;
  6105. /*-- ---*/
  6106. }
  6107. //print_r($htmlArray);die;
  6108. $data['htmlArray']=$htmlArray;
  6109. //statistics html
  6110. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6111. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6112. if(empty($stList))
  6113. $stList=array('rePrice'=>0,'agPrice'=>0);
  6114. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6115. $monthHtml="";
  6116. for ($i=1;$i<=12;$i++){
  6117. if ($i==$month)
  6118. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6119. else
  6120. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6121. }
  6122. $data['monthHtml']=$monthHtml;
  6123. $data['year']=$year;
  6124. $data['month']=$month;
  6125. $data['memu']="receipt";
  6126. $data['staff']=$this->staff;
  6127. $data['receiptMemu']='companyCategoryCollect';
  6128. $data['verifyId']=$this->verifyId;
  6129. $data['executeId']=$this->executeId;
  6130. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6131. Doo::loadModel('receipt');
  6132. $receipt=new receipt();
  6133. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6134. if(empty($receiptList)){ //generated files
  6135. ob_start();
  6136. $this->render ( "/admin/saeaStaffCollect", $data );
  6137. $this->cacheFile($path);die;
  6138. }
  6139. }
  6140. $this->render ( "/admin/saeaStaffCollect", $data );
  6141. }
  6142. function lyt(){
  6143. Doo::loadModel("receiptDetail");
  6144. $receiptDetail=new receiptDetail();
  6145. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6146. foreach ($receiptCollectList as $key=>$value){
  6147. $receiptDetail=new receiptDetail();
  6148. $receiptDetail->pastDate=$value['date'];
  6149. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6150. }
  6151. }
  6152. function staffCollectMonthDetail(){
  6153. $year=$this->get_args('year')?$this->get_args('year'):"";
  6154. $month=$this->get_args('month')?$this->get_args('month'):"";
  6155. if(!$year)
  6156. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6157. if(!$month)
  6158. $month=isset($this->params['month'])?$this->params['month']:1;
  6159. Doo::loadModel('staff');
  6160. $staff=new staff();
  6161. Doo::loadModel("receiptDetail");
  6162. $receiptDetail=new receiptDetail();
  6163. Doo::loadModel('accountItem');
  6164. $accountItem=new accountItem();
  6165. Doo::loadModel('statistics');
  6166. $statistics=new statistics();
  6167. Doo::loadModel('L_category');
  6168. $lCategory=new L_category();
  6169. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6170. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6171. $list=array();
  6172. foreach ($categoryList as $vlu){
  6173. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6174. $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;
  6175. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6176. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6177. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6178. $s1=0;
  6179. $m1=0;
  6180. foreach ($staffList as $value){
  6181. if ($vlu['cid']==$value['cid']){
  6182. //pastDate
  6183. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6184. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6185. // if ($value['sid']==42){
  6186. // print_r($receiptCollectList);die;
  6187. // }
  6188. if(!empty($receiptCollectList)){
  6189. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6190. $html="";
  6191. $psum=0;
  6192. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6193. foreach ($item as $va){
  6194. $falg=true;
  6195. foreach ($receiptCollectList as $v){
  6196. if($v['itemCategory']=='日常相关费用'){
  6197. if($v['item']==$va){
  6198. if ($va=='市内交通费')
  6199. $r1+=$v['price'];
  6200. if ($va=='市内出租费')
  6201. $r2+=$v['price'];
  6202. if ($va=='办事处房租')
  6203. $r3+=$v['price'];
  6204. if ($va=='电话费')
  6205. $r4+=$v['price'];
  6206. if ($va=='水费')
  6207. $r5+=$v['price'];
  6208. if ($va=='电费')
  6209. $r6+=$v['price'];
  6210. if ($va=='办公费用')
  6211. $r7+=$v['price'];
  6212. if ($va=='邮寄费')
  6213. $r8+=$v['price'];
  6214. if ($va=='其他费用')
  6215. $r9+=$v['price'];
  6216. if ($va=='车辆费用')
  6217. $r10+=$v['price'];
  6218. if ($va=='广告费')
  6219. $r11+=$v['price'];
  6220. if ($va=='团队建设费')
  6221. $r13+=$v['price'];
  6222. if ($va=='物业管理费')
  6223. $r14+=$v['price'];
  6224. if ($va=='宽带费')
  6225. $r15+=$v['price'];
  6226. $psum+=$v['price'];
  6227. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6228. }
  6229. }
  6230. }
  6231. if($falg)
  6232. $html.='<td class="taR">-</td>';
  6233. }
  6234. $r12+=$psum;
  6235. if(!empty($psum))
  6236. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6237. else
  6238. $psum='<td class="colGreen taR">-</td>';
  6239. $receiptL['日常相关费用']=$psum.$html;
  6240. /*-----------------------------------*/
  6241. $html="";
  6242. $psum=0;
  6243. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6244. foreach ($item as $va){
  6245. $falg=true;
  6246. foreach ($receiptCollectList as $v){
  6247. if($v['itemCategory']=='差旅相关费用'){
  6248. if($v['item']==$va){
  6249. if ($va=='往来交通费')
  6250. $c1+=$v['price'];
  6251. if ($va=='市内交通费')
  6252. $c2+=$v['price'];
  6253. if ($va=='出差住宿费')
  6254. $c3+=$v['price'];
  6255. if ($va=='出差补助')
  6256. $c4+=$v['price'];
  6257. if ($va=='其他费用')
  6258. $c5+=$v['price'];
  6259. $psum+=$v['price'];
  6260. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6261. }
  6262. }
  6263. }
  6264. if($falg)
  6265. $html.='<td class="taR">-</td>';
  6266. }
  6267. $c6+=$psum;
  6268. if(!empty($psum))
  6269. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6270. else
  6271. $psum='<td class="colGreen taR">-</td>';
  6272. $receiptL['差旅相关费用']=$psum.$html;
  6273. /*-------------------------------------*/
  6274. $html="";
  6275. $psum=0;
  6276. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6277. foreach ($item as $va){
  6278. $falg=true;
  6279. foreach ($receiptCollectList as $v){
  6280. if($v['itemCategory']=='培训班费用'){
  6281. if($v['item']==$va){
  6282. if ($va=='场租费')
  6283. $p1+=$v['price'];
  6284. if ($va=='薪酬')
  6285. $p2+=$v['price'];
  6286. if ($va=='住宿费')
  6287. $p3+=$v['price'];
  6288. if ($va=='交通费')
  6289. $p4+=$v['price'];
  6290. if ($va=='餐饮费')
  6291. $p5+=$v['price'];
  6292. if ($va=='办公费')
  6293. $p6+=$v['price'];
  6294. if ($va=='公关费')
  6295. $p7+=$v['price'];
  6296. if ($va=='其他')
  6297. $p8+=$v['price'];
  6298. $psum+=$v['price'];
  6299. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6300. }
  6301. }
  6302. }
  6303. if($falg)
  6304. $html.='<td class="taR">-</td>';
  6305. }
  6306. $p9+=$psum;
  6307. if(!empty($psum))
  6308. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6309. else
  6310. $psum='<td class="colGreen taR">-</td>';
  6311. $receiptL['培训班费用']=$psum.$html;
  6312. /*-------------------------------------*/
  6313. $html="";
  6314. $psum=0;
  6315. $item=array('公关费','广告费','借款','可自加费用');
  6316. foreach ($item as $va){
  6317. $falg=true;
  6318. foreach ($receiptCollectList as $v){
  6319. if($v['itemCategory']=='其他'){
  6320. // if ($value['sid']==42){
  6321. //
  6322. // echo var_dump($v['item']);
  6323. // echo var_dump($va);
  6324. // echo var_dump($v['item']==" ".$va);
  6325. // echo $v['item']."==".$va."/<br/>";
  6326. // //print_r( $receiptCollectList);//echo $va;
  6327. // }
  6328. if(trim($v['item'])==$va){
  6329. if ($va=='公关费')
  6330. $t1+=$v['price'];
  6331. if ($va=='广告费'){
  6332. $t2+=$v['price'];
  6333. }
  6334. if ($va=='借款')
  6335. $t3+=$v['price'];
  6336. if ($va=='可自加费用')
  6337. $t4+=$v['price'];
  6338. $psum+=$v['price'];
  6339. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6340. }
  6341. }
  6342. }
  6343. if($falg)
  6344. $html.='<td class="taR">-</td>';
  6345. }
  6346. $t5+=$psum;
  6347. if(!empty($psum))
  6348. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6349. else
  6350. $psum='<td class="colGreen taR">-</td>';
  6351. $receiptL['其他']=$psum.$html;
  6352. /*-------------------------------------*/
  6353. $html="";
  6354. $psum=0;
  6355. foreach ($receiptCollectList as $v){
  6356. if($v['itemCategory']=='报销金额调整'){
  6357. if (!empty($v['price'])){
  6358. $psum+=$v['price'];
  6359. }
  6360. }
  6361. }
  6362. $s1+=$psum;
  6363. if(!empty($psum))
  6364. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6365. else
  6366. $psum='<td class="taR colOrange">-</td>';
  6367. $receiptL['报销金额调整']=$psum.$html;
  6368. }else{
  6369. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6370. <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>
  6371. <td class="taR">-</td><td class="taR">-</td>';
  6372. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6373. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6374. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6375. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6376. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6377. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6378. }
  6379. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6380. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6381. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6382. if(!empty($monthStaffPrice[0]['price'])){
  6383. $m1+=$monthStaffPrice[0]['price'];
  6384. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6385. }else
  6386. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6387. $list[$value['username']]=$receiptL;
  6388. }
  6389. }
  6390. $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>
  6391. <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>
  6392. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6393. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6394. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6395. $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>
  6396. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6397. $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>';
  6398. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6399. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6400. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6401. }
  6402. $data['list']=$list;
  6403. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6404. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6405. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6406. //statistics html
  6407. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6408. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6409. if(empty($stList))
  6410. $stList=array('rePrice'=>0,'agPrice'=>0);
  6411. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6412. $monthHtml="";
  6413. for ($i=1;$i<=12;$i++){
  6414. if ($i==$month)
  6415. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6416. else
  6417. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6418. }
  6419. $data['monthHtml']=$monthHtml;
  6420. $data['year']=$year;
  6421. $data['month']=$month;
  6422. $data['memu']="receipt";
  6423. $data['staff']=$this->staff;
  6424. $data['receiptMemu']='companyCategoryCollect';
  6425. $data['verifyId']=$this->verifyId;
  6426. $data['executeId']=$this->executeId;
  6427. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6428. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6429. }
  6430. function staffCollectMonthDetail2(){
  6431. $year=$this->get_args('year')?$this->get_args('year'):"";
  6432. $month=$this->get_args('month')?$this->get_args('month'):"";
  6433. if(!$year)
  6434. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6435. if(!$month)
  6436. $month=isset($this->params['month'])?$this->params['month']:1;
  6437. Doo::loadModel('staff');
  6438. $staff=new staff();
  6439. Doo::loadModel("receiptDetail");
  6440. $receiptDetail=new receiptDetail();
  6441. Doo::loadModel('accountItem');
  6442. $accountItem=new accountItem();
  6443. Doo::loadModel('statistics');
  6444. $statistics=new statistics();
  6445. Doo::loadModel('L_category');
  6446. $lCategory=new L_category();
  6447. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6448. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6449. $list=array();
  6450. foreach ($categoryList as $vlu){
  6451. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6452. $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;
  6453. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6454. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6455. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6456. $s1=0;
  6457. $m1=0;
  6458. foreach ($staffList as $value){
  6459. if ($vlu['cid']==$value['cid']){
  6460. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6461. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6462. if(!empty($receiptCollectList)){
  6463. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6464. $html="";
  6465. $psum=0;
  6466. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6467. foreach ($item as $va){
  6468. $falg=true;
  6469. foreach ($receiptCollectList as $v){
  6470. if($v['itemCategory']=='日常相关费用'){
  6471. if($v['item']==$va){
  6472. if ($va=='市内交通费')
  6473. $r1+=$v['price'];
  6474. if ($va=='市内出租费')
  6475. $r2+=$v['price'];
  6476. if ($va=='办事处房租')
  6477. $r3+=$v['price'];
  6478. if ($va=='电话费')
  6479. $r4+=$v['price'];
  6480. if ($va=='水费')
  6481. $r5+=$v['price'];
  6482. if ($va=='电费')
  6483. $r6+=$v['price'];
  6484. if ($va=='办公费用')
  6485. $r7+=$v['price'];
  6486. if ($va=='邮寄费')
  6487. $r8+=$v['price'];
  6488. if ($va=='其他费用')
  6489. $r9+=$v['price'];
  6490. if ($va=='车辆费用')
  6491. $r10+=$v['price'];
  6492. if ($va=='广告费')
  6493. $r11+=$v['price'];
  6494. if ($va=='团队建设费')
  6495. $r13+=$v['price'];
  6496. if ($va=='物业管理费')
  6497. $r14+=$v['price'];
  6498. if ($va=='宽带费')
  6499. $r15+=$v['price'];
  6500. $psum+=$v['price'];
  6501. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6502. }
  6503. }
  6504. }
  6505. if($falg)
  6506. $html.='<td class="taR">-</td>';
  6507. }
  6508. $r12+=$psum;
  6509. if(!empty($psum))
  6510. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6511. else
  6512. $psum='<td class="colGreen taR">-</td>';
  6513. $receiptL['日常相关费用']=$psum.$html;
  6514. /*-----------------------------------*/
  6515. $html="";
  6516. $psum=0;
  6517. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6518. foreach ($item as $va){
  6519. $falg=true;
  6520. foreach ($receiptCollectList as $v){
  6521. if($v['itemCategory']=='差旅相关费用'){
  6522. if($v['item']==$va){
  6523. if ($va=='往来交通费')
  6524. $c1+=$v['price'];
  6525. if ($va=='市内交通费')
  6526. $c2+=$v['price'];
  6527. if ($va=='出差住宿费')
  6528. $c3+=$v['price'];
  6529. if ($va=='出差补助')
  6530. $c4+=$v['price'];
  6531. if ($va=='其他费用')
  6532. $c5+=$v['price'];
  6533. $psum+=$v['price'];
  6534. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6535. }
  6536. }
  6537. }
  6538. if($falg)
  6539. $html.='<td class="taR">-</td>';
  6540. }
  6541. $c6+=$psum;
  6542. if(!empty($psum))
  6543. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6544. else
  6545. $psum='<td class="colGreen taR">-</td>';
  6546. $receiptL['差旅相关费用']=$psum.$html;
  6547. /*-------------------------------------*/
  6548. $html="";
  6549. $psum=0;
  6550. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6551. foreach ($item as $va){
  6552. $falg=true;
  6553. foreach ($receiptCollectList as $v){
  6554. if($v['itemCategory']=='培训班费用'){
  6555. if($v['item']==$va){
  6556. if ($va=='场租费')
  6557. $p1+=$v['price'];
  6558. if ($va=='薪酬')
  6559. $p2+=$v['price'];
  6560. if ($va=='住宿费')
  6561. $p3+=$v['price'];
  6562. if ($va=='交通费')
  6563. $p4+=$v['price'];
  6564. if ($va=='餐饮费')
  6565. $p5+=$v['price'];
  6566. if ($va=='办公费')
  6567. $p6+=$v['price'];
  6568. if ($va=='公关费')
  6569. $p7+=$v['price'];
  6570. if ($va=='其他')
  6571. $p8+=$v['price'];
  6572. $psum+=$v['price'];
  6573. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6574. }
  6575. }
  6576. }
  6577. if($falg)
  6578. $html.='<td class="taR">-</td>';
  6579. }
  6580. $p9+=$psum;
  6581. if(!empty($psum))
  6582. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6583. else
  6584. $psum='<td class="colGreen taR">-</td>';
  6585. $receiptL['培训班费用']=$psum.$html;
  6586. /*-------------------------------------*/
  6587. $html="";
  6588. $psum=0;
  6589. $item=array('公关费','广告费','借款','可自加费用');
  6590. foreach ($item as $va){
  6591. $falg=true;
  6592. foreach ($receiptCollectList as $v){
  6593. if($v['itemCategory']=='其他'){
  6594. if($v['item']==$va){
  6595. if ($va=='公关费')
  6596. $t1+=$v['price'];
  6597. if ($va=='广告费')
  6598. $t2+=$v['price'];
  6599. if ($va=='借款')
  6600. $t3+=$v['price'];
  6601. if ($va=='可自加费用')
  6602. $t4+=$v['price'];
  6603. $psum+=$v['price'];
  6604. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6605. }
  6606. }
  6607. }
  6608. if($falg)
  6609. $html.='<td class="taR">-</td>';
  6610. }
  6611. $t5+=$psum;
  6612. if(!empty($psum))
  6613. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6614. else
  6615. $psum='<td class="colGreen taR">-</td>';
  6616. $receiptL['其他']=$psum.$html;
  6617. /*-------------------------------------*/
  6618. $html="";
  6619. $psum=0;
  6620. foreach ($receiptCollectList as $v){
  6621. if($v['itemCategory']=='报销金额调整'){
  6622. if (!empty($v['price'])){
  6623. $psum+=$v['price'];
  6624. }
  6625. }
  6626. }
  6627. $s1+=$psum;
  6628. if(!empty($psum))
  6629. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6630. else
  6631. $psum='<td class="taR colOrange">-</td>';
  6632. $receiptL['报销金额调整']=$psum.$html;
  6633. }else{
  6634. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6635. <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>';
  6636. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6637. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6638. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6639. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6640. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6641. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6642. }
  6643. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6644. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6645. if(!empty($monthStaffPrice[0]['price'])){
  6646. $m1+=$monthStaffPrice[0]['price'];
  6647. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6648. }else
  6649. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6650. $list[$value['username']]=$receiptL;
  6651. }
  6652. }
  6653. $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>
  6654. <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>
  6655. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6656. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6657. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6658. $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>
  6659. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6660. $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>';
  6661. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6662. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6663. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6664. }
  6665. $data['list']=$list;
  6666. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6667. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6668. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6669. //statistics html
  6670. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6671. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6672. if(empty($stList))
  6673. $stList=array('rePrice'=>0,'agPrice'=>0);
  6674. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6675. $monthHtml="";
  6676. for ($i=1;$i<=12;$i++){
  6677. if ($i==$month)
  6678. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6679. else
  6680. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6681. }
  6682. $data['monthHtml']=$monthHtml;
  6683. $data['year']=$year;
  6684. $data['month']=$month;
  6685. $data['memu']="receipt";
  6686. $data['staff']=$this->staff;
  6687. $data['receiptMemu']='companyCategoryCollect';
  6688. $data['verifyId']=$this->verifyId;
  6689. $data['executeId']=$this->executeId;
  6690. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6691. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6692. }
  6693. function companyMonthCollectDetail(){
  6694. $year=$this->get_args('year')?$this->get_args('year'):"";
  6695. $month=$this->get_args('month')?$this->get_args('month'):"";
  6696. if(!$year)
  6697. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6698. if(!$month)
  6699. $month=isset($this->params['month'])?$this->params['month']:1;
  6700. Doo::loadModel('staff');
  6701. $staff=new staff();
  6702. Doo::loadModel("receiptDetail");
  6703. $receiptDetail=new receiptDetail();
  6704. Doo::loadModel('accountItem');
  6705. $accountItem=new accountItem();
  6706. Doo::loadModel('statistics');
  6707. $statistics=new statistics();
  6708. Doo::loadModel('L_category');
  6709. $lCategory=new L_category();
  6710. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6711. $categoryList=$lCategory->find(array('asArray'=>true));
  6712. $list=array();
  6713. foreach ($categoryList as $value){
  6714. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6715. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6716. if(!empty($receiptCollectList)){
  6717. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6718. $html="";
  6719. $psum=0;
  6720. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6721. foreach ($item as $va){
  6722. $falg=true;
  6723. foreach ($receiptCollectList as $v){
  6724. if($v['itemCategory']=='日常相关费用'){
  6725. if($v['item']==$va){
  6726. $psum+=$v['price'];
  6727. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6728. }
  6729. }
  6730. }
  6731. if($falg)
  6732. $html.='<td class="taR">-</td>';
  6733. }
  6734. if(!empty($psum))
  6735. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6736. else
  6737. $psum='<td class="colGreen taR">-</td>';
  6738. $receiptL['日常相关费用']=$psum.$html;
  6739. /*-----------------------------------*/
  6740. $html="";
  6741. $psum=0;
  6742. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6743. foreach ($item as $va){
  6744. $falg=true;
  6745. foreach ($receiptCollectList as $v){
  6746. if($v['itemCategory']=='差旅相关费用'){
  6747. if($v['item']==$va){
  6748. $psum+=$v['price'];
  6749. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6750. }
  6751. }
  6752. }
  6753. if($falg)
  6754. $html.='<td class="taR">-</td>';
  6755. }
  6756. if(!empty($psum))
  6757. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6758. else
  6759. $psum='<td class="colGreen taR">-</td>';
  6760. $receiptL['差旅相关费用']=$psum.$html;
  6761. /*-------------------------------------*/
  6762. $html="";
  6763. $psum=0;
  6764. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6765. foreach ($item as $va){
  6766. $falg=true;
  6767. foreach ($receiptCollectList as $v){
  6768. if($v['itemCategory']=='培训班费用'){
  6769. if($v['item']==$va){
  6770. $psum+=$v['price'];
  6771. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6772. }
  6773. }
  6774. }
  6775. if($falg)
  6776. $html.='<td class="taR">-</td>';
  6777. }
  6778. if(!empty($psum))
  6779. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6780. else
  6781. $psum='<td class="colGreen taR">-</td>';
  6782. $receiptL['培训班费用']=$psum.$html;
  6783. /*-------------------------------------*/
  6784. $html="";
  6785. $psum=0;
  6786. $item=array('公关费','广告费','借款','可自加费用');
  6787. foreach ($item as $va){
  6788. $falg=true;
  6789. foreach ($receiptCollectList as $v){
  6790. if($v['itemCategory']=='其他'){
  6791. if($v['item']==$va){
  6792. $psum+=$v['price'];
  6793. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6794. }
  6795. }
  6796. }
  6797. if($falg)
  6798. $html.='<td class="taR">-</td>';
  6799. }
  6800. if(!empty($psum))
  6801. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6802. else
  6803. $psum='<td class="colGreen taR">-</td>';
  6804. $receiptL['其他']=$psum.$html;
  6805. /*-------------------------------------*/
  6806. $html="";
  6807. $psum=0;
  6808. foreach ($receiptCollectList as $v){
  6809. if($v['itemCategory']=='报销金额调整'){
  6810. if (!empty($v['price']))
  6811. $psum+=$v['price'];
  6812. }
  6813. }
  6814. if(!empty($psum))
  6815. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6816. else
  6817. $psum='<td class="taR colOrange">-</td>';
  6818. $receiptL['报销金额调整']=$psum.$html;
  6819. }else{
  6820. $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>
  6821. <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. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6823. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6824. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6825. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6826. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6827. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6828. }
  6829. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6830. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6831. if(!empty($monthStaffPrice[0]['price']))
  6832. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6833. else
  6834. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6835. $list[$value['title']]=$receiptL;
  6836. }
  6837. $data['list']=$list;
  6838. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6839. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6840. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6841. //print_r($data['monthPriceHtml']);
  6842. // foreach ($data['monthPriceHtml'] as $value){
  6843. // echo $value;
  6844. // }
  6845. // die;
  6846. //statistics html
  6847. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6848. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6849. if(empty($stList))
  6850. $stList=array('rePrice'=>0,'agPrice'=>0);
  6851. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6852. $monthHtml="";
  6853. for ($i=1;$i<=12;$i++){
  6854. if ($i==$month)
  6855. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6856. else
  6857. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6858. }
  6859. $data['monthHtml']=$monthHtml;
  6860. $data['year']=$year;
  6861. $data['month']=$month;
  6862. $data['memu']="receipt";
  6863. $data['staff']=$this->staff;
  6864. $data['receiptMemu']='companyCategoryCollect';
  6865. $data['verifyId']=$this->verifyId;
  6866. $data['executeId']=$this->executeId;
  6867. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6868. }
  6869. function staffCollectDetail(){
  6870. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6871. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6872. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6873. if(!$staffname){
  6874. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6875. $staffname= urldecode($staffname);
  6876. }
  6877. Doo::loadModel('staff');
  6878. $staff=new staff();
  6879. Doo::loadModel("receiptDetail");
  6880. $receiptDetail=new receiptDetail();
  6881. Doo::loadModel('accountItem');
  6882. $accountItem=new accountItem();
  6883. Doo::loadModel('statistics');
  6884. $statistics=new statistics();
  6885. Doo::loadModel('L_category');
  6886. $lCategory=new L_category();
  6887. $staffList=$staff->find(array('asArray'=>true));
  6888. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6889. foreach ($staffList as $value){
  6890. if ($value['username']==$staffname&&$value['username']!='admin'){
  6891. $stTitle=$value['category'].'-'.$value['username'];
  6892. $staffId=$value['sid'];
  6893. $cid=$value['cid'];
  6894. $ocid=$value['cid'];
  6895. if (!empty($value['othercid']))
  6896. $cid=$value['cid'].','.$value['othercid'];
  6897. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6898. }elseif ($value['username']!='admin')
  6899. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6900. }
  6901. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6902. if(empty($pcid))
  6903. $pcid=$ocid;
  6904. $data['ocid']=$pcid;
  6905. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6906. $this->showCache($path);
  6907. //
  6908. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6909. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6910. $accountList=$accountItem->find(array('asArray'=>true));
  6911. //create CollectDetail HTML
  6912. $collectHtml=array();
  6913. foreach ($accountList as $key=>$value){
  6914. $html="";$asum=0;
  6915. for ($i=1;$i<=12;$i++){
  6916. $falg=true;
  6917. foreach ($receiptCollectList as $v) {
  6918. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  6919. $asum+=$v['price'];
  6920. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  6921. }
  6922. }
  6923. if($falg)
  6924. $html.='<td class="taR">-</td>';
  6925. }
  6926. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  6927. $collectHtml[$value['category']][$value['name']]=$html;
  6928. }
  6929. $data['collectHtml']=$collectHtml;
  6930. //create Adjustment price html
  6931. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  6932. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  6933. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6934. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  6935. array_push($collectArray['日常相关费用'], $collectHtml);
  6936. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  6937. array_push($collectArray['差旅相关费用'], $collectHtml);
  6938. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  6939. array_push($collectArray['培训班费用'], $collectHtml);
  6940. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  6941. array_push($collectArray['其他'], $collectHtml);
  6942. $data['collectArray']=$collectArray;
  6943. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  6944. array_push($adjustment, $collectHtml);
  6945. $data['adjustment']=$adjustment;
  6946. //total price html
  6947. $collectHtml="";$total=0;
  6948. for ($i=1;$i<=12;$i++){
  6949. $sumPrice=0;
  6950. foreach ($receiptCollectList as $key=>$value){
  6951. if($value['month']==$i){
  6952. $sumPrice+=$value['price'];
  6953. }
  6954. }
  6955. if ($sumPrice==0)
  6956. $collectHtml.='<td class="taR">-</td>';
  6957. else
  6958. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  6959. $total+=$sumPrice;
  6960. }
  6961. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  6962. //statistics html
  6963. $stList=$statistics->statisticsByYear($year,$staffId);
  6964. if(empty($stList))
  6965. $stList=array('rePrice'=>0,'agPrice'=>0);
  6966. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6967. $data['totalPrice']=$collectHtml;
  6968. $data['totalYear']=$total;
  6969. $data['stHtml']=$stHtml;
  6970. $data['year']=$year;
  6971. $data['stTitle']=$stTitle;
  6972. $data['memu']="receipt";
  6973. $data['staff']=$this->staff;
  6974. $data['receiptMemu']='companyCategoryCollect';
  6975. $data['verifyId']=$this->verifyId;
  6976. $data['executeId']=$this->executeId;
  6977. if ($year<date("Y")){
  6978. Doo::loadModel('receipt');
  6979. $receipt=new receipt();
  6980. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  6981. if(empty($receiptList)){ //generated files
  6982. ob_start();
  6983. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6984. $this->cacheFile($path);die;
  6985. }
  6986. }
  6987. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6988. }
  6989. function ajaxGetReceiptOrder(){
  6990. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  6991. if (!empty($receiptOrder)){
  6992. Doo::loadModel('receipt');
  6993. $receipt=new receipt();
  6994. Doo::loadModel ( 'staff' );
  6995. $staff = new staff ();
  6996. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  6997. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  6998. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  6999. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7000. </tbody></table><table class="table table table-bordered"><tbody>';
  7001. foreach ($verifyStaff as $key=>$value){
  7002. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7003. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7004. }
  7005. $html.='</tbody></table></div></div>';
  7006. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7007. }
  7008. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7009. }
  7010. function _getMonthCollectDetail($receiptCollectList){
  7011. if(!empty($receiptCollectList)){
  7012. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7013. $html="";
  7014. $psum=0;
  7015. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7016. foreach ($item as $value){
  7017. $falg=true;
  7018. foreach ($receiptCollectList as $v){
  7019. if($v['itemCategory']=='日常相关费用'){
  7020. if($v['item']==$value){
  7021. $psum+=$v['price'];
  7022. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7023. }
  7024. }
  7025. }
  7026. if($falg)
  7027. $html.='<td class="taR">-</td>';
  7028. }
  7029. if(!empty($psum))
  7030. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7031. else
  7032. $psum='<td class="colGreen taR">-</td>';
  7033. $receiptL['日常相关费用']=$psum.$html;
  7034. /*-----------------------------------*/
  7035. $html="";
  7036. $psum=0;
  7037. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7038. foreach ($item as $value){
  7039. $falg=true;
  7040. foreach ($receiptCollectList as $v){
  7041. if($v['itemCategory']=='差旅相关费用'){
  7042. if($v['item']==$value){
  7043. $psum+=$v['price'];
  7044. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7045. }
  7046. }
  7047. }
  7048. if($falg)
  7049. $html.='<td class="taR">-</td>';
  7050. }
  7051. if(!empty($psum))
  7052. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7053. else
  7054. $psum='<td class="colGreen taR">-</td>';
  7055. $receiptL['差旅相关费用']=$psum.$html;
  7056. /*-------------------------------------*/
  7057. $html="";
  7058. $psum=0;
  7059. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7060. foreach ($item as $value){
  7061. $falg=true;
  7062. foreach ($receiptCollectList as $v){
  7063. if($v['itemCategory']=='培训班费用'){
  7064. if($v['item']==$value){
  7065. $psum+=$v['price'];
  7066. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7067. }
  7068. }
  7069. }
  7070. if($falg)
  7071. $html.='<td class="taR">-</td>';
  7072. }
  7073. if(!empty($psum))
  7074. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7075. else
  7076. $psum='<td class="colGreen taR">-</td>';
  7077. $receiptL['培训班费用']=$psum.$html;
  7078. /*-------------------------------------*/
  7079. $html="";
  7080. $psum=0;
  7081. $item=array('公关费','广告费','借款','可自加费用');
  7082. foreach ($item as $value){
  7083. $falg=true;
  7084. foreach ($receiptCollectList as $v){
  7085. if($v['itemCategory']=='其他'){
  7086. if($v['item']==$value){
  7087. $psum+=$v['price'];
  7088. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7089. }
  7090. }
  7091. }
  7092. if($falg)
  7093. $html.='<td class="taR">-</td>';
  7094. }
  7095. if(!empty($psum))
  7096. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7097. else
  7098. $psum='<td class="colGreen taR">-</td>';
  7099. $receiptL['其他']=$psum.$html;
  7100. /*-------------------------------------*/
  7101. $html="";
  7102. $psum=0;
  7103. foreach ($receiptCollectList as $v){
  7104. if($v['itemCategory']=='报销金额调整'){
  7105. if (!empty($v['price']))
  7106. $psum+=$v['price'];
  7107. }
  7108. }
  7109. if(!empty($psum))
  7110. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7111. else
  7112. $psum='<td class="taR colOrange">-</td>';
  7113. $receiptL['报销金额调整']=$psum.$html;
  7114. }else{
  7115. $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>
  7116. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7117. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7118. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7119. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7120. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7121. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7122. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7123. }
  7124. return $receiptL;
  7125. }
  7126. function eMail(){
  7127. Doo::loadModel('staff');
  7128. $staff=new staff();
  7129. Doo::loadModel('receipt');
  7130. $receipt=new receipt();
  7131. Doo::loadModel('L_category');
  7132. $Lcategory=new L_category();
  7133. Doo::loadModel("verify");
  7134. $verify=new verify();
  7135. $staffList=$staff->find(array('asArray'=>true));
  7136. foreach ($staffList as $key=>$value){
  7137. if($value['username']!='admin'){
  7138. //提交人
  7139. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7140. if(!empty($receiptList)){
  7141. $html='<br><div><style></style>
  7142. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7143. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7144. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7145. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7146. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7147. <tbody><tr>
  7148. <td style="padding: 0 40px;" align="left">
  7149. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7150. </td></tr><tr>
  7151. <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>
  7152. </tr>
  7153. </tbody> </table></td> </tr> <tr><td>
  7154. <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">
  7155. <tbody> <tr><td>
  7156. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7157. 以下报销单完成了审批,等着收款吧:</p>
  7158. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7159. foreach ($receiptList as $k=>$v){
  7160. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7161. $html.='
  7162. <tr>
  7163. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7164. <td align="left">
  7165. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7166. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7167. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7168. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7169. </tr>';
  7170. }
  7171. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7172. <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>
  7173. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7174. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7175. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7176. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7177. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7178. $receipt=new receipt();
  7179. $receipt->notice=1;
  7180. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7181. }
  7182. }
  7183. //审批人
  7184. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7185. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7186. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7187. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7188. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7189. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7190. <tbody><tr><td style="padding: 0 40px;" align="left">
  7191. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7192. </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>
  7193. </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">
  7194. <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>
  7195. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7196. foreach ($verifyList as $k=>$v){
  7197. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7198. foreach ($receiptList as $r=>$l){
  7199. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7200. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7201. $html.='
  7202. <tr>
  7203. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7204. <td align="left">
  7205. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7206. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7207. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7208. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7209. </tr>';
  7210. }
  7211. }
  7212. $html.='
  7213. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7214. <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>
  7215. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7216. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7217. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7218. // $receipt=new receipt();
  7219. // $receipt->notice=1;
  7220. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7221. }
  7222. }
  7223. }
  7224. }
  7225. // Email发送函数
  7226. function SMail($toemail, $subject, $contents) {
  7227. Doo::loadClass('class.phpmailer');
  7228. $mail = new PHPMailer();
  7229. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7230. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7231. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7232. $mail->Password = "cDO1GjtY1seH"; //密码
  7233. $mail->CharSet = "UTF8";
  7234. $mail->SMTPAuth = true;
  7235. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7236. $mail->Mailer = "smtp";
  7237. $mail->Port = 25;
  7238. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7239. $mail->MsgHTML($contents);
  7240. $mail->AddAddress($toemail);
  7241. $mail->CharSet = "UTF-8";
  7242. return $mail->Send();
  7243. }
  7244. function swfupload(){
  7245. $POST_MAX_SIZE = ini_get('post_max_size');
  7246. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7247. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7248. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7249. header("HTTP/1.1 500 Internal Server Error");
  7250. echo "POST exceeded maximum allowed size.";
  7251. exit(0);
  7252. }
  7253. // Settings
  7254. $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)
  7255. $upload_name = "Filedata";
  7256. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7257. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7258. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7259. // Other variables
  7260. $MAX_FILENAME_LENGTH = 260;
  7261. $file_name = "";
  7262. $file_extension = "";
  7263. $uploadErrors = array(
  7264. 0=>"文件上传成功",
  7265. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7266. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7267. 3=>"上传的文件仅为部分文件",
  7268. 4=>"没有文件上传",
  7269. 6=>"缺少临时文件夹"
  7270. );
  7271. $nk= time();
  7272. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7273. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7274. echo "文件无法保存.";
  7275. exit(0);
  7276. }
  7277. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7278. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7279. exit(0);
  7280. }
  7281. function _GetFileEXT($filename) {
  7282. $pics = explode ( '.', $filename );
  7283. $num = count ( $pics );
  7284. return $pics [$num - 1];
  7285. }
  7286. /**
  7287. * 获取get或者POST值
  7288. * @param string $name 属性名称
  7289. * @return fixed 值
  7290. */
  7291. function get_args($name) {
  7292. if (isset ( $_GET [$name] )) {
  7293. if (is_array ( $_GET [$name] ))
  7294. return $_GET [$name];
  7295. else
  7296. return addslashes ( $_GET [$name] );
  7297. } elseif (isset ( $_POST [$name] )) {
  7298. if (is_array ( $_POST [$name] ))
  7299. return $_POST [$name];
  7300. else
  7301. return addslashes ( $_POST [$name] );
  7302. } else
  7303. return false;
  7304. }
  7305. function num_to_rmb($num){
  7306. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7307. $c2 = "分角元拾佰仟万拾佰仟亿";
  7308. //精确到分后面就不要了,所以只留两个小数位
  7309. $num = round($num, 2);
  7310. //将数字转化为整数
  7311. $num = $num * 100;
  7312. if (strlen($num) > 10) {
  7313. return "金额太大,请检查";
  7314. }
  7315. $i = 0;
  7316. $c = "";
  7317. while (1) {
  7318. if ($i == 0) {
  7319. //获取最后一位数字
  7320. $n = substr($num, strlen($num)-1, 1);
  7321. } else {
  7322. $n = $num % 10;
  7323. }
  7324. //每次将最后一位数字转化为中文
  7325. $p1 = substr($c1, 3 * $n, 3);
  7326. $p2 = substr($c2, 3 * $i, 3);
  7327. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7328. $c = $p1 . $p2 . $c;
  7329. } else {
  7330. $c = $p1 . $c;
  7331. }
  7332. $i = $i + 1;
  7333. //去掉数字最后一位了
  7334. $num = $num / 10;
  7335. $num = (int)$num;
  7336. //结束循环
  7337. if ($num == 0) {
  7338. break;
  7339. }
  7340. }
  7341. $j = 0;
  7342. $slen = strlen($c);
  7343. while ($j < $slen) {
  7344. //utf8一个汉字相当3个字符
  7345. $m = substr($c, $j, 6);
  7346. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7347. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7348. $left = substr($c, 0, $j);
  7349. $right = substr($c, $j + 3);
  7350. $c = $left . $right;
  7351. $j = $j-3;
  7352. $slen = $slen-3;
  7353. }
  7354. $j = $j + 3;
  7355. }
  7356. //这个是为了去掉类似23.0中最后一个“零”字
  7357. if (substr($c, strlen($c)-3, 3) == '零') {
  7358. $c = substr($c, 0, strlen($c)-3);
  7359. }
  7360. //将处理的汉字加上“整”
  7361. if (empty($c)) {
  7362. return "零元整";
  7363. }else{
  7364. return $c . "整";
  7365. }
  7366. }
  7367. /**
  7368. * 获得分页数据
  7369. * @param unknown_type $table
  7370. * @param unknown_type $condition
  7371. * @param unknown_type $on_page
  7372. * @param unknown_type $page_size
  7373. */
  7374. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7375. $page_c = "";
  7376. $page ['previous'] = $this->get_previous ( $on_page );
  7377. $page ['on_page'] = $on_page;
  7378. $total_count = $this->get_table_count ( $table, $condition );
  7379. $total = intval ( $total_count / $page_size );
  7380. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7381. $page ['total_data'] = $total_count;
  7382. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7383. $i = 1;
  7384. $page_max = 1;
  7385. $page_width=3;
  7386. if ($on_page >= $page_width) {
  7387. $page_max = intval ( $on_page / $page_width ) + 1;
  7388. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7389. }
  7390. for(; $i <= $page ['total_page']; $i ++) {
  7391. if ($i == $on_page)
  7392. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7393. else
  7394. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7395. if ($i == ($page_width * $page_max))
  7396. break;
  7397. }
  7398. $page ['page'] = $page_c;
  7399. $page ['lower'] = (-- $on_page) * $page_size;
  7400. return $page;
  7401. }
  7402. /**
  7403. * 获取总页数
  7404. * @param unknown_type $table
  7405. * @param unknown_type $condition
  7406. */
  7407. public function get_table_count($table = "", $condition = "") {
  7408. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7409. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7410. //echo $sql;die;
  7411. $query = Doo::db ()->query ( $sql );
  7412. $result = $query->fetch ();
  7413. return $result ['count'];
  7414. }
  7415. /**
  7416. * 获取上一页
  7417. * @param unknown_type $on_page
  7418. */
  7419. function get_previous($on_page = 1) {
  7420. return $on_page != 0 ? $on_page - 1 : $on_page;
  7421. }
  7422. }
  7423. ?>