ReceiptController.php 308 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. //public static $NEW2 = 0;
  10. public $AGENCY="日常相关费用";
  11. public $TRAVEL="差旅相关费用";
  12. public $TRAIN="培训班费用";
  13. public $OTHER="其他";
  14. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  18. private function showCache($path){
  19. if(file_exists($path)){
  20. echo "<!DOCTYPE html>";
  21. include $path;die;
  22. }
  23. }
  24. private function cacheFile($path){
  25. $content = ob_get_contents();
  26. $fp = fopen($path, "w");
  27. fwrite($fp, $content);
  28. fclose($fp);
  29. }
  30. // private function getExeCount(){
  31. // Doo::loadModel('receipt');
  32. // $receipt=new receipt();
  33. // $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  34. // return count($receiptList);
  35. // }
  36. // private function getReceiptCount(){
  37. // $status=2;
  38. // $year=date('Y');
  39. // Doo::loadModel('receipt');
  40. // $receipt=new receipt();
  41. // $dateCondition=" and Year(date) =".$year;
  42. // $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  43. // $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  44. // return count($receiptList);
  45. // }
  46. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  47. $collectHtml="";$sumPrice=0.00;
  48. for ($i=1;$i<=12;$i++){
  49. $falg=true;
  50. foreach ($receiptCollectList as $key=>$value){
  51. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  52. $sumPrice+=$value['price'];
  53. if ($classType=="b"){
  54. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  55. }else{
  56. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  57. }
  58. }
  59. }
  60. if ($falg)
  61. $collectHtml.='<td class="taR">-</td>';
  62. }
  63. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  64. return $collectHtml;
  65. }
  66. function __construct() {
  67. if(isset($_COOKIE["staff"])){
  68. if(!empty($_COOKIE["staff"])){
  69. Doo::loadModel ( 'staff' );
  70. Doo::loadModel('verify');
  71. $verify=new verify();
  72. $staff = new staff ();
  73. Doo::loadModel("execute");
  74. $execute=new execute();
  75. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  76. $list=array();
  77. //判断角色的审批权限
  78. foreach ($verifyList as $key=>$value){
  79. $ver=json_decode($value['staff']);
  80. foreach ($ver as $k=>$v){
  81. if ($v[1]=='ROLE'){
  82. $roleList=json_decode($v[3]);
  83. foreach ($roleList as $t=>$g){
  84. $gList=explode("_", $g);
  85. array_push($list, $gList[0]);
  86. //print_r($list);
  87. }
  88. }else
  89. array_push($list, $v[0]);
  90. }
  91. }
  92. //判断执行人的审批权限
  93. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  94. $list2=array();
  95. foreach ($executeList as $key=>$value){
  96. $ver=json_decode($value['staff']);
  97. foreach ($ver as $k=>$v){
  98. array_push($list2, $v[0]);
  99. }
  100. }
  101. $eidList=file_get_contents("protected/config/execute/execute.ini");
  102. $eidList=array_filter(explode(",", $eidList));
  103. $this->executeId= array_merge($list2,$eidList);
  104. $this->verifyId=$list;
  105. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  106. return "/";
  107. }
  108. }
  109. Doo::loadCore ( 'uri/DooUriRouter' );
  110. $router = new DooUriRouter ();
  111. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  112. if($routeRs['1']!="login"){
  113. header ( 'Content-Type:text/html;charset=utf-8' );
  114. @header ( "Location: /login" );
  115. }
  116. }
  117. function saeaBorad(){
  118. Doo::loadModel('receipt');
  119. Doo::loadModel('verify');
  120. $verify=new verify();
  121. $receipt=new receipt();
  122. Doo::loadModel('L_category');
  123. $lCategory=new L_category();
  124. Doo::loadModel("role");
  125. $role=new role();
  126. Doo::loadModel("receiptLog");
  127. $receiptLog=new receiptLog();
  128. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  129. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)','desc'=>'rid','asArray'=>true));
  130. foreach ($receiptDetail as $key=>$value){
  131. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  132. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  133. $v=json_decode($veList['staff']);
  134. array_push($v[0], $veList['description']);
  135. foreach ($v as $n=>$m){
  136. if ($m['1']=='ROLE'){
  137. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  138. $v[$n][1]=$roleInfo['name'];
  139. }
  140. }
  141. $receiptDetail[$key]['staff']=$v;
  142. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  143. $receiptDetail[$key]['category']=$category['title'];
  144. }
  145. //print_r($receiptLogList);
  146. $data['receiptLogList']=$receiptLogList;
  147. $data['receiptDetail']=$receiptDetail;
  148. $data['memu']="receipt";
  149. $data['staff']=$this->staff;
  150. $data['receiptMemu']='saeaBorad';
  151. $data['verifyId']=$this->verifyId;
  152. $data['executeId']=$this->executeId;
  153. $this->render ( "/admin/saeaBorad", $data );
  154. }
  155. function remitAdd(){
  156. Doo::loadModel('accountItem');
  157. Doo::loadModel('verify');
  158. Doo::loadModel('receipt');
  159. Doo::loadModel('L_category');
  160. $lCategory=new L_category();
  161. $receipt=new receipt();
  162. $verify=new verify();
  163. $accountItem=new accountItem();
  164. Doo::loadModel("role");
  165. $role=new role();
  166. $acItem=$accountItem->find(array('asArray'=>true));
  167. $veList=$verify->find(array('asArray'=>true));
  168. foreach ($veList as $key=>$value){
  169. $v=json_decode($value['staff']);
  170. $list=array();
  171. foreach ($v as $n=>$m){
  172. if ($m['1']=='ROLE'){
  173. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  174. $v[$n][1]=$roleInfo['name'];
  175. array_push($list, $roleInfo['name']);
  176. }else{
  177. array_push($list, $v[$n][1]);
  178. }
  179. }
  180. $veList[$key]['staff']=implode('>', $list);
  181. }
  182. $data['category']=$lCategory->find(array('asArray'=>true));
  183. $data['veList']=$veList;
  184. $data['acItem']=$acItem;
  185. $data['memu']="receipt";
  186. $data['staff']=$this->staff;
  187. $data['receiptMemu']='saeaBorad';
  188. $data['verifyId']=$this->verifyId;
  189. $data['executeId']=$this->executeId;
  190. $this->render ( "/admin/remitAdd", $data );
  191. }
  192. function remitAddDo(){
  193. $agency=$this->get_args('agency');
  194. $travel=$this->get_args('travel');
  195. $train=$this->get_args('train');
  196. $other=$this->get_args('other');
  197. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  198. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  199. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  200. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  201. //print_r($agency);die;
  202. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  203. Doo::loadModel('receipt');
  204. Doo::loadModel('receiptDetail');
  205. Doo::loadModel('accountItem');
  206. $accountItem=new accountItem();
  207. $receipt=new receipt();
  208. Doo::loadModel('enclosur');
  209. Doo::loadModel('execute');
  210. $execute=new execute();
  211. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  212. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  213. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  214. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  215. $ag=$tr=$ta=$ot=0;
  216. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  217. foreach ($aItem as $key=>$value){
  218. if ($value['category']==$this->AGENCY){
  219. if (isset($agency[$ag])){
  220. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  221. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  222. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  223. }
  224. }
  225. $ag++;
  226. }
  227. }
  228. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  229. //报销单
  230. $receipt->accountItem=json_encode($accountJson);
  231. $receipt->staff=$this->staff[0]['sid'];
  232. $receipt->sum=number_format($sum, 2, '.', '');
  233. $receipt->date=date("Y-m-d");
  234. $receipt->cid=$cid;
  235. $receipt->status=5;
  236. $receipt->Rtype=2;
  237. //修改审批流程加入角色
  238. $receipt->verify=$verify;
  239. $receipt->executeCopy=$executeDetail['staff'];
  240. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  241. $receipt->explanation=$explanation;
  242. $rid=$receipt->insert();
  243. //附件
  244. if (!empty($enclosurName)){
  245. $enclosurArray=explode('-', $enclosurName);
  246. foreach ($enclosurArray as $value){
  247. $enclosur=new enclosur();
  248. $enclosur->name=$value;
  249. $enclosur->rid=$rid;
  250. $enclosur->insert();
  251. }
  252. //print_r($enclosurArray);die;
  253. }
  254. //报销详情
  255. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  256. $receiptDetail=new receiptDetail();
  257. $receiptDetail->staff=$this->staff[0]['sid'];
  258. $receiptDetail->item=$value['name'];
  259. $receiptDetail->itemCategory=$this->AGENCY;
  260. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  261. $receiptDetail->date=date("Y-m-d");
  262. $receiptDetail->cid=$cid;
  263. $receiptDetail->rid=$rid;
  264. $receiptDetail->status=4;
  265. $receiptDetail->insert();
  266. }
  267. }
  268. return "/saeaBorad";
  269. }
  270. function remitEdit(){
  271. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  272. //echo $rid;
  273. Doo::loadModel('accountItem');
  274. Doo::loadModel('verify');
  275. Doo::loadModel('receipt');
  276. $receipt=new receipt();
  277. $verify=new verify();
  278. $accountItem=new accountItem();
  279. Doo::loadModel('L_category');
  280. $lCategory=new L_category();
  281. Doo::loadModel("role");
  282. $role=new role();
  283. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  284. if(empty($receiptDetail))
  285. return "/saeaCreate";
  286. $acItem=$accountItem->find(array('asArray'=>true));
  287. $veList=$verify->find(array('asArray'=>true));
  288. foreach ($veList as $key=>$value){
  289. $v=json_decode($value['staff']);
  290. $list=array();
  291. foreach ($v as $n=>$m){
  292. if ($m['1']=='ROLE'){
  293. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  294. $v[$n][1]=$roleInfo['name'];
  295. array_push($list, $roleInfo['name']);
  296. }else{
  297. array_push($list, $v[$n][1]);
  298. }
  299. }
  300. $veList[$key]['staff']=implode('>', $list);
  301. }
  302. //配置编辑信息
  303. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  304. foreach ($acItem as $key=>$value){
  305. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  306. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  307. $acItem[$key]['price']=$v['price'];
  308. }
  309. }
  310. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  311. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  312. $acItem[$key]['price']=$v['price'];
  313. }
  314. }
  315. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  316. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  317. $acItem[$key]['price']=$v['price'];
  318. }
  319. }
  320. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  321. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  322. $acItem[$key]['price']=$v['price'];
  323. }
  324. }
  325. }
  326. $data['category']=$lCategory->find(array('asArray'=>true));
  327. $data['cSum']=$accountItemList['cSum'];
  328. $data['sum']=$receiptDetail['sum'];
  329. $data['receiptDetail']=$receiptDetail;
  330. $data['veList']=$veList;
  331. $data['acItem']=$acItem;
  332. $data['memu']="receipt";
  333. $data['staff']=$this->staff;
  334. $data['receiptMemu']='saeaBorad';
  335. $data['verify']=$receiptDetail['verify'];
  336. $data['verifyId']=$this->verifyId;
  337. $data['executeId']=$this->executeId;
  338. $data['rid']=$rid;
  339. $this->render ( "/admin/remitEdit", $data );
  340. }
  341. function remitEdiDo(){
  342. $agency=$this->get_args('agency');
  343. $travel=$this->get_args('travel');
  344. $train=$this->get_args('train');
  345. $other=$this->get_args('other');
  346. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  347. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  348. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  349. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  350. if(!empty($explanation)){
  351. Doo::loadModel('receipt');
  352. Doo::loadModel('receiptDetail');
  353. Doo::loadModel('accountItem');
  354. $accountItem=new accountItem();
  355. $receipt=new receipt();
  356. Doo::loadModel('execute');
  357. $execute=new execute();
  358. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  359. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  360. if(empty($receiptDetail))
  361. return "/saeaBorad";
  362. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  363. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  364. $ag=$tr=$ta=$ot=0;
  365. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  366. foreach ($aItem as $key=>$value){
  367. if ($value['category']==$this->AGENCY){
  368. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  369. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  370. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  371. }
  372. $ag++;
  373. }
  374. }
  375. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  376. //报销单
  377. $rid=$receipt->rid=$receiptDetail['rid'];
  378. $receipt->accountItem=json_encode($accountJson);
  379. $receipt->staff=$this->staff[0]['sid'];
  380. $receipt->sum=number_format($sum, 2, '.', '');
  381. $receipt->date=date("Y-m-d");
  382. $receipt->cid=$cid;
  383. if ($receiptDetail['Rtype']==1)
  384. $receipt->status=7;
  385. else
  386. $receipt->status=5;
  387. if ($receiptDetail['status']!=4&&!empty($verify))
  388. $receipt->verify=$verify;
  389. $receipt->executeCopy=$executeDetail['staff'];
  390. $receipt->explanation=$explanation;
  391. $receipt->update();
  392. $receiptDetail=new receiptDetail();
  393. $receiptDetail->delete(array('where'=>'rid='.$rid));
  394. //报销详情
  395. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  396. $receiptDetail=new receiptDetail();
  397. $receiptDetail->staff=$this->staff[0]['sid'];
  398. $receiptDetail->item=$value['name'];
  399. $receiptDetail->itemCategory=$this->AGENCY;
  400. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  401. $receiptDetail->date=date("Y-m-d");
  402. $receiptDetail->cid=$cid;
  403. $receiptDetail->rid=$rid;
  404. $receiptDetail->status=4;
  405. $receiptDetail->insert();
  406. }
  407. //return "/referReceipt/".$rid;
  408. }
  409. return "/saeaBorad";
  410. }
  411. function remitApproval(){
  412. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  413. $status=isset($this->params['status'])?$this->params['status']:'';
  414. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  415. $month=$this->get_args('month')?$this->get_args('month'):"";
  416. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  417. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  418. if (empty($status))
  419. $status=$this->get_args('status')?$this->get_args('status'):2;
  420. $vidList=array();
  421. $button=0;
  422. Doo::loadModel('verify');
  423. Doo::loadModel('receipt');
  424. Doo::loadModel('staff');
  425. $staff=new staff();
  426. $receipt=new receipt();
  427. $verify=new verify();
  428. Doo::loadModel('L_category');
  429. $Lcategory=new L_category();
  430. Doo::loadModel('enclosur');
  431. $enclosur=new enclosur();
  432. //user verify ID
  433. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  434. foreach ($verifyDetail as $key=>$value){
  435. array_push($vidList, $value['vid']);
  436. }
  437. $vid=implode(",", $vidList);
  438. if(empty($verifyDetail))
  439. $vid=0;
  440. $categoryList=$Lcategory->find(array('asArray'=>true));
  441. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  442. $ap="";
  443. if($status==4){
  444. $ap=4;$status=2;
  445. }
  446. //get Receipt By verifyID status 2
  447. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  448. $Locate=0;$roleId=0;
  449. if($ap==4)
  450. $status=4;
  451. foreach ($receiptList as $key=>$value){
  452. $receiptList[$key]['Locate']=$Locate;$Locate++;
  453. $receiptList[$key]['reviseDetail']=array();
  454. if (!empty($value['reviseDetail']))
  455. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  456. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  457. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  458. $receiptList[$key]['category']=$categoryDetil['title'];
  459. //检测编辑状态
  460. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  461. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  462. $verifyStaff=json_decode($value['verifyStaff'],true);
  463. Doo::loadModel('role');
  464. $role=new role();
  465. //print_r($verifyList);
  466. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  467. foreach ($verifyList as $k=>$v){
  468. //init verifyStaff
  469. if ($v[1]=='ROLE'){
  470. if (!empty($verifyStaff)){
  471. $endStaffArray=end($verifyStaff);
  472. if ($v[0]==$endStaffArray['nextStaff']){
  473. $roleId=$v[0];
  474. }
  475. }
  476. $roleVerify=json_decode($v[3],true);
  477. $roleKey=$k;$roleArray=array();
  478. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  479. foreach ($roleVerify as $o=>$p){
  480. $staffID=explode ('_',$p);
  481. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  482. //print_r($staffID);
  483. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  484. array_push($roleArray, $exp);
  485. }
  486. $roleArrayCopy[$v[0]]=$roleArray;
  487. //$verifyList[$k]['roleArray']=$roleArray;
  488. }
  489. //print_r($roleArray);
  490. $verifyList[$k]['date']="";
  491. $verifyList[$k]['opinion']="";
  492. $verifyList[$k]['status']="";
  493. if (empty($verifyStaff)){
  494. $verifyList[$k]['date']="";
  495. $verifyList[$k]['opinion']="";
  496. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  497. $verifyList[$k]['status']=4;
  498. $button=4;$flag=false;
  499. }
  500. }else{
  501. foreach ($verifyStaff as $m=>$u){
  502. if ($v[0]==$m){
  503. $verifyList[$k]['date']=$u['date'];
  504. $verifyList[$k]['opinion']=$u['opinion'];
  505. $verifyList[$k]['status']=$u['status'];
  506. $flag=false;
  507. break;
  508. }
  509. }
  510. $endStaffArray=end($verifyStaff);
  511. if (isset($endStaffArray['ROLE'])){
  512. }else{
  513. $endKey=key($verifyStaff);
  514. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  515. $button=4;
  516. $verifyList[$k]['status']=4;
  517. }
  518. }
  519. }
  520. }
  521. $rolename['name']='';
  522. if (!empty($roleId)){
  523. Doo::loadModel('role');
  524. $role=new role();
  525. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  526. }
  527. if (!empty($verifyStaff))
  528. $endStaffArray=end($verifyStaff);
  529. $KOP=false;
  530. foreach ($roleArrayCopy as $P=>$A){
  531. foreach ( $A as $MKI=>$AVL){
  532. if (!empty($verifyStaff)){
  533. //&&$rolename['rid']==$endStaffArray['nextStaff']
  534. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  535. $button=4;
  536. $roleArrayCopy[$P][$MKI]['status']=4;
  537. }
  538. foreach ($verifyStaff as $m=>$u){
  539. $AVLFK=$AVL[0].'_R';
  540. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  541. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  542. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  543. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  544. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  545. break;
  546. }
  547. }
  548. }else{
  549. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  550. $button=4;
  551. $roleArrayCopy[$P][$MKI]['status']=4;
  552. }
  553. }
  554. //$roleArray[$MKI]['rolename']=$rolename['name'];
  555. $KOP=true;
  556. }
  557. }
  558. foreach ($roleArrayCopy as $k=>$v){
  559. foreach ($verifyList as $m=>$n){
  560. if ($n[0]==$k){
  561. array_splice($verifyList,$m,1,$v);
  562. }
  563. }
  564. }
  565. $receiptList[$key]['verifyList']= $verifyList;
  566. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  567. $receiptList[$key]['button']=$button;
  568. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  569. }
  570. $mothHtml="";
  571. for($i=1;$i<=12;$i++){
  572. if($month==$i)
  573. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  574. else
  575. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  576. }
  577. //获取审批日志
  578. Doo::loadModel('receiptLog');
  579. $receiptLog=new receiptLog();
  580. $rlList=array();
  581. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  582. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  583. if (!empty($rlInfo)){
  584. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  585. }
  586. $receiptList[0]['rlList']=$rlList;
  587. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  588. $enclosurHtml='';
  589. foreach ($enclosurList as $value){
  590. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  591. }
  592. //print_r($receiptList);
  593. $data['enclosurHtml']=$enclosurHtml;
  594. $data['rolename']=$rolename['name'];
  595. $data['datetij']=$tijdate['date'];
  596. $data['mothHtml']=$mothHtml;
  597. $data['rid']=$rid;
  598. $data['receiptList']=$receiptList;
  599. $data['receiptApprovalCount']=count($receiptList);
  600. $data['status']=$status;
  601. $data['year']=$year;
  602. $data['categoryList']=$categoryList;
  603. $data['staffList']=$staffList;
  604. $data['cid']=$cid;
  605. $data['sid']=$sid;
  606. $data['ap']=$ap;
  607. $data['memu']="receipt";
  608. $data['staff']=$this->staff;
  609. $data['receiptMemu']='approvalExpenses';
  610. $data['verifyId']=$this->verifyId;
  611. $data['executeId']=$this->executeId;
  612. $this->render ( "/admin/remitApproval", $data );
  613. }
  614. function saeaLoanAdd(){
  615. Doo::loadModel('verify');
  616. $verify=new verify();
  617. Doo::loadModel("role");
  618. $role=new role();
  619. Doo::loadModel('L_category');
  620. $lCategory=new L_category();
  621. $veList=$verify->find(array('asArray'=>true));
  622. foreach ($veList as $key=>$value){
  623. $v=json_decode($value['staff']);
  624. $list=array();
  625. foreach ($v as $n=>$m){
  626. if ($m['1']=='ROLE'){
  627. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  628. $v[$n][1]=$roleInfo['name'];
  629. array_push($list, $roleInfo['name']);
  630. }else{
  631. array_push($list, $v[$n][1]);
  632. }
  633. }
  634. $veList[$key]['staff']=implode('>', $list);
  635. }
  636. $data['category']=$lCategory->find(array('asArray'=>true));
  637. $data['veList']=$veList;
  638. $data['memu']="receipt";
  639. $data['staff']=$this->staff;
  640. $data['receiptMemu']='saeaBorad';
  641. $data['verifyId']=$this->verifyId;
  642. $data['executeId']=$this->executeId;
  643. $this->render ( "/admin/saeaLoanAdd", $data );
  644. }
  645. function saeaLoanAddDo(){
  646. $agency=$this->get_args('agency');
  647. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  648. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  649. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  650. //die;
  651. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  652. Doo::loadModel('receipt');
  653. Doo::loadModel('receiptDetail');
  654. Doo::loadModel('accountItem');
  655. $accountItem=new accountItem();
  656. $receipt=new receipt();
  657. Doo::loadModel('loanReceipt');
  658. $loanReceipt=new loanReceipt();
  659. Doo::loadModel('execute');
  660. $execute=new execute();
  661. Doo::loadModel('enclosur');
  662. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  663. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  664. // if(!empty($receiptDetail))
  665. // return "/referReceipt/".$receiptDetail['rid'];
  666. $aItem=$accountItem->find(array('asArray'=>true));
  667. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  668. $ag=$tr=$ta=$ot=0;
  669. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  670. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  671. $sum+=$agency;$agencySum+=$agency;
  672. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  673. //借款数据备份
  674. $loanReceipt->loanItem=json_encode($accountJson);
  675. $loanReceipt->staff=$this->staff[0]['sid'];
  676. $loanReceipt->sum=number_format($sum, 2, '.', '');
  677. $loanReceipt->date=date("Y-m-d");
  678. $loanReceipt->cid=$cid;
  679. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  680. $loanReceipt->status=5;
  681. $loanReceipt->Rtype=1;
  682. $loanReceipt->verify=$verify;
  683. $receipt->receiptOrder=$receipt->receiptOrder;
  684. $loanReceipt->explanation=$explanation;
  685. $loanRid=$loanReceipt->insert();
  686. //报销单
  687. $receipt->loanItem=json_encode($accountJson);
  688. $receipt->staff=$this->staff[0]['sid'];
  689. $receipt->sum=number_format($sum, 2, '.', '');
  690. $receipt->date=date("Y-m-d");
  691. $receipt->cid=$cid;
  692. //特殊状态
  693. $receipt->status=5;
  694. $receipt->Rtype=1;
  695. $receipt->loanRid=$loanRid;
  696. //修改审批流程加入角色
  697. $receipt->verify=$verify;
  698. $receipt->executeCopy=$executeDetail['staff'];
  699. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  700. $receipt->explanation=$explanation;
  701. $rid=$receipt->insert();
  702. //执行数据备份
  703. // $executeCopy->rid=$rid;
  704. // $executeCopy->staff=$executeDetail['staff'];
  705. // $executeCopy->eid=$executeDetail['eid'];
  706. // $ecid=$executeCopy->insert();
  707. }
  708. return "/saeaBorad";
  709. }
  710. function saeaLoanEdi(){
  711. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  712. Doo::loadModel('verify');
  713. $verify=new verify();
  714. Doo::loadModel("role");
  715. $role=new role();
  716. Doo::loadModel('L_category');
  717. $lCategory=new L_category();
  718. Doo::loadModel('receipt');
  719. $receipt=new receipt();
  720. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  721. $veList=$verify->find(array('asArray'=>true));
  722. foreach ($veList as $key=>$value){
  723. $v=json_decode($value['staff']);
  724. $list=array();
  725. foreach ($v as $n=>$m){
  726. if ($m['1']=='ROLE'){
  727. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  728. $v[$n][1]=$roleInfo['name'];
  729. array_push($list, $roleInfo['name']);
  730. }else{
  731. array_push($list, $v[$n][1]);
  732. }
  733. }
  734. $veList[$key]['staff']=implode('>', $list);
  735. }
  736. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  737. $data['receiptInfo']=$receiptInfo;
  738. $data['category']=$lCategory->find(array('asArray'=>true));
  739. $data['veList']=$veList;
  740. $data['memu']="receipt";
  741. $data['staff']=$this->staff;
  742. $data['receiptMemu']='saeaBorad';
  743. $data['verifyId']=$this->verifyId;
  744. $data['executeId']=$this->executeId;
  745. $this->render ( "/admin/saeaLoanEdi", $data );
  746. }
  747. function saeaLoanEdiDo(){
  748. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  749. $agency=$this->get_args('agency');
  750. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  751. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  752. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  753. //die;
  754. if(!empty($cid)&&!empty($explanation)&&!empty($rid)){
  755. Doo::loadModel('receipt');
  756. Doo::loadModel('receiptDetail');
  757. Doo::loadModel('accountItem');
  758. $accountItem=new accountItem();
  759. $receipt=new receipt();
  760. Doo::loadModel('loanReceipt');
  761. $loanReceipt=new loanReceipt();
  762. Doo::loadModel('enclosur');
  763. Doo::loadModel('execute');
  764. $execute=new execute();
  765. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  766. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=5 or status=4) and rid='.$rid,'asArray'=>true));
  767. if(empty($receiptDetail))
  768. die('参数错误');
  769. $aItem=$accountItem->find(array('asArray'=>true));
  770. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  771. $ag=$tr=$ta=$ot=0;
  772. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  773. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  774. $sum+=$agency;$agencySum+=$agency;
  775. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  776. //报销单
  777. $receipt->loanItem=json_encode($accountJson);
  778. $receipt->sum=number_format($sum, 2, '.', '');
  779. $receipt->cid=$cid;
  780. //特殊状态
  781. //修改审批流程加入角色
  782. if ($receiptDetail['status']!=4)
  783. $receipt->verify=$verify;
  784. $receipt->explanation=$explanation;
  785. $receipt->update(array('where'=>'rid='.$rid));
  786. //借款数据更新
  787. $loanReceipt->loanItem=json_encode($accountJson);
  788. $loanReceipt->sum=number_format($sum, 2, '.', '');
  789. $loanReceipt->cid=$cid;
  790. if ($receiptDetail['status']!=4)
  791. $loanReceipt->verify=$verify;
  792. $loanReceipt->explanation=$explanation;
  793. $receipt->executeCopy=$executeDetail['staff'];
  794. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  795. }
  796. return "/saeaBorad";
  797. }
  798. function saeaLoanReceiptAdd(){
  799. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  800. Doo::loadModel('receipt');
  801. $receipt=new receipt();
  802. Doo::loadModel('loanReceipt');
  803. $loanReceipt=new loanReceipt();
  804. Doo::loadModel('L_category');
  805. $Lcategory=new L_category();
  806. Doo::loadModel('verify');
  807. Doo::loadModel('statistics');
  808. $statistics=new statistics();
  809. $verify=new verify();
  810. Doo::loadModel('staff');
  811. $staff=new staff();
  812. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  813. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  814. $Locate=0;$roleId=0;$button=0;
  815. foreach ($receiptList as $key=>$value){
  816. $receiptList[$key]['Locate']=$Locate;$Locate++;
  817. $receiptList[$key]['reviseDetail']=array();
  818. if (!empty($value['reviseDetail']))
  819. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  820. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  821. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  822. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  823. $receiptList[$key]['category']=$categoryDetil['title'];
  824. //检测编辑状态
  825. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  826. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  827. $verifyStaff=json_decode($value['verifyStaff'],true);
  828. Doo::loadModel('role');
  829. $role=new role();
  830. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  831. foreach ($verifyList as $k=>$v){
  832. //init verifyStaff
  833. if ($v[1]=='ROLE'){
  834. if (!empty($verifyStaff)){
  835. $endStaffArray=end($verifyStaff);
  836. // if ($v[0]==$endStaffArray['nextStaff']){
  837. // $roleId=$v[0];
  838. // }
  839. }
  840. $roleVerify=json_decode($v[3],true);
  841. $roleKey=$k;$roleArray=array();
  842. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  843. foreach ($roleVerify as $o=>$p){
  844. $staffID=explode ('_',$p);
  845. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  846. //print_r($staffID);
  847. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  848. array_push($roleArray, $exp);
  849. }
  850. $roleArrayCopy[$v[0]]=$roleArray;
  851. //$verifyList[$k]['roleArray']=$roleArray;
  852. }
  853. $verifyList[$k]['date']="";
  854. $verifyList[$k]['opinion']="";
  855. $verifyList[$k]['status']="";
  856. if (empty($verifyStaff)){
  857. $verifyList[$k]['date']="";
  858. $verifyList[$k]['opinion']="";
  859. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  860. $verifyList[$k]['status']=4;
  861. $flag=false;
  862. }
  863. }else{
  864. foreach ($verifyStaff as $m=>$u){
  865. if ($v[0]==$m){
  866. $verifyList[$k]['date']=$u['date'];
  867. $verifyList[$k]['opinion']=$u['opinion'];
  868. $verifyList[$k]['status']=$u['status'];
  869. $flag=false;
  870. break;
  871. }
  872. }
  873. $endStaffArray=end($verifyStaff);
  874. if (isset($endStaffArray['ROLE'])){
  875. }else{
  876. // $endKey=key($verifyStaff);
  877. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  878. // $button=4;
  879. // $verifyList[$k]['status']=4;
  880. // }
  881. }
  882. }
  883. }
  884. $rolename['name']='';
  885. if (!empty($roleId)){
  886. Doo::loadModel('role');
  887. $role=new role();
  888. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  889. }
  890. if (!empty($verifyStaff))
  891. $endStaffArray=end($verifyStaff);
  892. $KOP=false;
  893. foreach ($roleArrayCopy as $P=>$A){
  894. foreach ( $A as $MKI=>$AVL){
  895. if (!empty($verifyStaff)){
  896. //&&$rolename['rid']==$endStaffArray['nextStaff']
  897. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  898. $button=4;
  899. $roleArrayCopy[$P][$MKI]['status']=4;
  900. }
  901. foreach ($verifyStaff as $m=>$u){
  902. $AVLFK=$AVL[0].'_R';
  903. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  904. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  905. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  906. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  907. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  908. break;
  909. }
  910. }
  911. }else{
  912. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  913. $button=4;
  914. $roleArrayCopy[$P][$MKI]['status']=4;
  915. }
  916. }
  917. //$roleArray[$MKI]['rolename']=$rolename['name'];
  918. $KOP=true;
  919. }
  920. }
  921. foreach ($roleArrayCopy as $k=>$v){
  922. foreach ($verifyList as $m=>$n){
  923. if ($n[0]==$k){
  924. array_splice($verifyList,$m,1,$v);
  925. }
  926. }
  927. }
  928. $receiptList[$key]['verifyList']=$verifyList;
  929. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  930. $receiptList[$key]['button']=$button;
  931. //
  932. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  933. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  934. }
  935. $data['receiptList']=$receiptList;
  936. Doo::loadModel('L_category');
  937. $lCategory=new L_category();
  938. Doo::loadModel('accountItem');
  939. $accountItem=new accountItem();
  940. $acItem=$accountItem->find(array('asArray'=>true));
  941. $veList=$verify->find(array('asArray'=>true));
  942. foreach ($veList as $key=>$value){
  943. $v=json_decode($value['staff']);
  944. $list=array();
  945. foreach ($v as $n=>$m){
  946. if ($m['1']=='ROLE'){
  947. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  948. $v[$n][1]=$roleInfo['name'];
  949. array_push($list, $roleInfo['name']);
  950. }else{
  951. array_push($list, $v[$n][1]);
  952. }
  953. }
  954. $veList[$key]['staff']=implode('>', $list);
  955. }
  956. $data['rid']=$rid;
  957. $data['category']=$lCategory->find(array('asArray'=>true));
  958. $data['veList']=$veList;
  959. $data['acItem']=$acItem;
  960. $data['memu']="receipt";
  961. $data['staff']=$this->staff;
  962. $data['receiptMemu']='saeaBorad';
  963. $data['verifyId']=$this->verifyId;
  964. $data['executeId']=$this->executeId;
  965. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  966. }
  967. function saeaLoanReceiptAddDo(){
  968. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  969. $agency=$this->get_args('agency');
  970. $travel=$this->get_args('travel');
  971. $train=$this->get_args('train');
  972. $other=$this->get_args('other');
  973. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  974. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  975. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  976. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  977. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  978. Doo::loadModel('receipt');
  979. Doo::loadModel('receiptDetail');
  980. Doo::loadModel('accountItem');
  981. $accountItem=new accountItem();
  982. $receipt=new receipt();
  983. Doo::loadModel('enclosur');
  984. Doo::loadModel('execute');
  985. $execute=new execute();
  986. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  987. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  988. // if(!empty($receiptDetail))
  989. // return "/referReceipt/".$receiptDetail['rid'];
  990. $aItem=$accountItem->find(array('asArray'=>true));
  991. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  992. $ag=$tr=$ta=$ot=0;
  993. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  994. foreach ($aItem as $key=>$value){
  995. if ($value['category']==$this->AGENCY){
  996. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  997. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  998. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  999. }
  1000. $ag++;
  1001. }
  1002. if($value['category']==$this->TRAVEL){
  1003. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1004. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1005. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1006. }
  1007. $tr++;
  1008. }
  1009. if($value['category']==$this->TRAIN){
  1010. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1011. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1012. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1013. }
  1014. $ta++;
  1015. }
  1016. if($value['category']==$this->OTHER){
  1017. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1018. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1019. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1020. }
  1021. $ot++;
  1022. }
  1023. }
  1024. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1025. //报销单
  1026. $receipt->accountItem=json_encode($accountJson);
  1027. $receipt->staff=$this->staff[0]['sid'];
  1028. $receipt->loanSum=$receiptDet['sum'];
  1029. $receipt->sum=number_format($sum, 2, '.', '');
  1030. $receipt->date=date("Y-m-d");
  1031. $receipt->pastDate='';
  1032. $receipt->cid=$cid;
  1033. $receipt->status=7;
  1034. //修改审批流程加入角色
  1035. $receipt->verify=$verify;
  1036. $receipt->verifyStaff='';
  1037. $receipt->executeStaff='';
  1038. $receipt->executeCopy=$executeDetail['staff'];
  1039. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1040. $receipt->explanation=$explanation;
  1041. $receipt->update(array('where'=>'rid='.$rid));
  1042. //附件
  1043. if (!empty($enclosurName)){
  1044. $enclosurArray=explode('-', $enclosurName);
  1045. foreach ($enclosurArray as $value){
  1046. $enclosur=new enclosur();
  1047. $enclosur->name=$value;
  1048. $enclosur->rid=$rid;
  1049. $enclosur->insert();
  1050. }
  1051. //print_r($enclosurArray);die;
  1052. }
  1053. //报销详情
  1054. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1055. $receiptDetail=new receiptDetail();
  1056. $receiptDetail->staff=$this->staff[0]['sid'];
  1057. $receiptDetail->item=$value['name'];
  1058. $receiptDetail->itemCategory=$this->AGENCY;
  1059. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1060. $receiptDetail->date=date("Y-m-d");
  1061. $receiptDetail->cid=$cid;
  1062. $receiptDetail->rid=$rid;
  1063. $receiptDetail->status=4;
  1064. $receiptDetail->insert();
  1065. }
  1066. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1067. $receiptDetail=new receiptDetail();
  1068. $receiptDetail->staff=$this->staff[0]['sid'];
  1069. $receiptDetail->item=$value['name'];
  1070. $receiptDetail->itemCategory=$this->TRAVEL;
  1071. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1072. $receiptDetail->date=date("Y-m-d");
  1073. $receiptDetail->cid=$cid;
  1074. $receiptDetail->rid=$rid;
  1075. $receiptDetail->status=4;
  1076. $receiptDetail->insert();
  1077. }
  1078. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1079. $receiptDetail=new receiptDetail();
  1080. $receiptDetail->staff=$this->staff[0]['sid'];
  1081. $receiptDetail->item=$value['name'];
  1082. $receiptDetail->itemCategory=$this->TRAIN;
  1083. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1084. $receiptDetail->date=date("Y-m-d");
  1085. $receiptDetail->cid=$cid;
  1086. $receiptDetail->rid=$rid;
  1087. $receiptDetail->status=4;
  1088. $receiptDetail->insert();
  1089. }
  1090. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1091. $receiptDetail=new receiptDetail();
  1092. $receiptDetail->staff=$this->staff[0]['sid'];
  1093. $receiptDetail->item=$value['name'];
  1094. $receiptDetail->itemCategory=$this->OTHER;
  1095. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1096. $receiptDetail->date=date("Y-m-d");
  1097. $receiptDetail->cid=$cid;
  1098. $receiptDetail->rid=$rid;
  1099. $receiptDetail->status=4;
  1100. $receiptDetail->insert();
  1101. }
  1102. return "/saeaBorad";
  1103. }
  1104. return "/saeaLoanReceiptAdd/".$rid;
  1105. }
  1106. function saeaLoanReceiptEdi(){
  1107. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1108. //echo $rid;
  1109. Doo::loadModel('accountItem');
  1110. Doo::loadModel('verify');
  1111. Doo::loadModel('receipt');
  1112. $receipt=new receipt();
  1113. $verify=new verify();
  1114. $accountItem=new accountItem();
  1115. Doo::loadModel('L_category');
  1116. $Lcategory=new L_category();
  1117. Doo::loadModel("role");
  1118. $role=new role();
  1119. Doo::loadModel('loanReceipt');
  1120. $loanReceipt=new loanReceipt();
  1121. Doo::loadModel('staff');
  1122. $staff=new staff();
  1123. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1124. if(empty($receiptDetail))
  1125. return "/saeaBorad";
  1126. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1127. $Locate=0;$roleId=0;$button=0;
  1128. foreach ($receiptList as $key=>$value){
  1129. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1130. $receiptList[$key]['reviseDetail']=array();
  1131. if (!empty($value['reviseDetail']))
  1132. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1133. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1134. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1135. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1136. $receiptList[$key]['category']=$categoryDetil['title'];
  1137. //检测编辑状态
  1138. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1139. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1140. $verifyStaff=json_decode($value['verifyStaff'],true);
  1141. Doo::loadModel('role');
  1142. $role=new role();
  1143. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1144. foreach ($verifyList as $k=>$v){
  1145. //init verifyStaff
  1146. if ($v[1]=='ROLE'){
  1147. if (!empty($verifyStaff)){
  1148. $endStaffArray=end($verifyStaff);
  1149. // if ($v[0]==$endStaffArray['nextStaff']){
  1150. // $roleId=$v[0];
  1151. // }
  1152. }
  1153. $roleVerify=json_decode($v[3],true);
  1154. $roleKey=$k;$roleArray=array();
  1155. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1156. foreach ($roleVerify as $o=>$p){
  1157. $staffID=explode ('_',$p);
  1158. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1159. //print_r($staffID);
  1160. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1161. array_push($roleArray, $exp);
  1162. }
  1163. $roleArrayCopy[$v[0]]=$roleArray;
  1164. //$verifyList[$k]['roleArray']=$roleArray;
  1165. }
  1166. $verifyList[$k]['date']="";
  1167. $verifyList[$k]['opinion']="";
  1168. $verifyList[$k]['status']="";
  1169. if (empty($verifyStaff)){
  1170. $verifyList[$k]['date']="";
  1171. $verifyList[$k]['opinion']="";
  1172. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1173. $verifyList[$k]['status']=4;
  1174. $flag=false;
  1175. }
  1176. }else{
  1177. foreach ($verifyStaff as $m=>$u){
  1178. if ($v[0]==$m){
  1179. $verifyList[$k]['date']=$u['date'];
  1180. $verifyList[$k]['opinion']=$u['opinion'];
  1181. $verifyList[$k]['status']=$u['status'];
  1182. $flag=false;
  1183. break;
  1184. }
  1185. }
  1186. $endStaffArray=end($verifyStaff);
  1187. if (isset($endStaffArray['ROLE'])){
  1188. }else{
  1189. // $endKey=key($verifyStaff);
  1190. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1191. // $button=4;
  1192. // $verifyList[$k]['status']=4;
  1193. // }
  1194. }
  1195. }
  1196. }
  1197. $rolename['name']='';
  1198. if (!empty($roleId)){
  1199. Doo::loadModel('role');
  1200. $role=new role();
  1201. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1202. }
  1203. if (!empty($verifyStaff))
  1204. $endStaffArray=end($verifyStaff);
  1205. $KOP=false;
  1206. foreach ($roleArrayCopy as $P=>$A){
  1207. foreach ( $A as $MKI=>$AVL){
  1208. if (!empty($verifyStaff)){
  1209. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1210. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1211. $button=4;
  1212. $roleArrayCopy[$P][$MKI]['status']=4;
  1213. }
  1214. foreach ($verifyStaff as $m=>$u){
  1215. $AVLFK=$AVL[0].'_R';
  1216. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1217. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1218. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1219. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1220. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1221. break;
  1222. }
  1223. }
  1224. }else{
  1225. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1226. $button=4;
  1227. $roleArrayCopy[$P][$MKI]['status']=4;
  1228. }
  1229. }
  1230. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1231. $KOP=true;
  1232. }
  1233. }
  1234. foreach ($roleArrayCopy as $k=>$v){
  1235. foreach ($verifyList as $m=>$n){
  1236. if ($n[0]==$k){
  1237. array_splice($verifyList,$m,1,$v);
  1238. }
  1239. }
  1240. }
  1241. $receiptList[$key]['verifyList']=$verifyList;
  1242. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1243. $receiptList[$key]['button']=$button;
  1244. //
  1245. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1246. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1247. }
  1248. $data['receiptList']=$receiptList;
  1249. $acItem=$accountItem->find(array('asArray'=>true));
  1250. $veList=$verify->find(array('asArray'=>true));
  1251. foreach ($veList as $key=>$value){
  1252. $v=json_decode($value['staff']);
  1253. $list=array();
  1254. foreach ($v as $n=>$m){
  1255. if ($m['1']=='ROLE'){
  1256. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1257. $v[$n][1]=$roleInfo['name'];
  1258. array_push($list, $roleInfo['name']);
  1259. }else{
  1260. array_push($list, $v[$n][1]);
  1261. }
  1262. }
  1263. $veList[$key]['staff']=implode('>', $list);
  1264. }
  1265. //配置编辑信息
  1266. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1267. foreach ($acItem as $key=>$value){
  1268. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1269. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1270. $acItem[$key]['price']=$v['price'];
  1271. }
  1272. }
  1273. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1274. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1275. $acItem[$key]['price']=$v['price'];
  1276. }
  1277. }
  1278. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1279. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1280. $acItem[$key]['price']=$v['price'];
  1281. }
  1282. }
  1283. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1284. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1285. $acItem[$key]['price']=$v['price'];
  1286. }
  1287. }
  1288. }
  1289. $data['category']=$Lcategory->find(array('asArray'=>true));
  1290. $data['cSum']=$accountItemList['cSum'];
  1291. $data['sum']=$receiptDetail['sum'];
  1292. $data['receiptDetail']=$receiptDetail;
  1293. $data['veList']=$veList;
  1294. $data['acItem']=$acItem;
  1295. $data['memu']="receipt";
  1296. $data['staff']=$this->staff;
  1297. $data['receiptMemu']='saeaBorad';
  1298. $data['verify']=$receiptDetail['verify'];
  1299. $data['verifyId']=$this->verifyId;
  1300. $data['executeId']=$this->executeId;
  1301. $data['rid']=$rid;
  1302. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1303. }
  1304. function confirmation(){
  1305. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1306. Doo::loadModel('receipt');
  1307. Doo::loadModel('receiptDetail');
  1308. $receipt=new receipt();
  1309. $receiptDetail=new receiptDetail();
  1310. Doo::loadModel('statistics');
  1311. Doo::loadModel('itemStatistics');
  1312. $statistics=new statistics();
  1313. $itemStatistics=new itemStatistics();
  1314. Doo::loadModel("verify");
  1315. $verify=new verify();
  1316. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1317. if(empty($receiptDetailList))
  1318. return "/saeaBorad";
  1319. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1320. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1321. if (empty($receiptDetailList['nowStaff'])){
  1322. $nowStaff="";$nowStaffList=array();
  1323. if ($verifyDetail[0][1]=='ROLE'){
  1324. $vStaffString=json_decode($verifyDetail[0][3]);
  1325. foreach ($vStaffString as $key=>$value){
  1326. $staffK=explode("_", $value);
  1327. array_push($nowStaffList, $staffK[0]);
  1328. }
  1329. $nowStaff=implode(',', $nowStaffList);
  1330. }else{
  1331. $nowStaff=$verifyDetail[0][0];
  1332. }
  1333. $receipt->nowStaff=$nowStaff;
  1334. }
  1335. // echo $nowStaff;
  1336. // print_r($verifyDetail);die;
  1337. $receipt->rid=$receiptDetailList['rid'];
  1338. $receipt->status=2;
  1339. $receipt->update();
  1340. //操作日志
  1341. Doo::loadModel("receiptLog");
  1342. $receiptLog=new receiptLog();
  1343. $verify=new verify();
  1344. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1345. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1346. $jd=json_decode($vr['staff']);$roleId=0;
  1347. foreach ($jd as $key=>$value){
  1348. if ($value[1]=='ROLE'){
  1349. $pos = strpos($value[3], $this->staff[0]['sid']);
  1350. if ($pos !== false) {
  1351. $roleId=$value[0];
  1352. }
  1353. }
  1354. }
  1355. //审批日志
  1356. //echo $roleId;die;
  1357. if (!empty($roleId)){
  1358. Doo::loadModel("role");
  1359. $role=new role();
  1360. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1361. $receiptLog->rolename=$roleInfo['name'];
  1362. }
  1363. $receiptLog->username=$this->staff[0]['username'];
  1364. $receiptLog->uid=$this->staff[0]['sid'];
  1365. $receiptLog->date=date("Y-m-d");
  1366. $receiptLog->opinion='提交审批';
  1367. $receiptLog->img=$this->staff[0]['avatar'];
  1368. $receiptLog->status=2;
  1369. $receiptLog->rid=$rid;
  1370. $receiptLog->insert();
  1371. return "/expenses";
  1372. }
  1373. function expenses(){
  1374. $item=isset($this->params['item'])?$this->params['item']:"";
  1375. if(empty($item))
  1376. $item=$this->get_args('item')?$this->get_args('item'):"";
  1377. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1378. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1379. Doo::loadModel('receipt');
  1380. $receipt=new receipt();
  1381. Doo::loadModel('L_category');
  1382. $Lcategory=new L_category();
  1383. Doo::loadModel('verify');
  1384. Doo::loadModel('statistics');
  1385. $statistics=new statistics();
  1386. $verify=new verify();
  1387. Doo::loadModel('staff');
  1388. $staff=new staff();
  1389. $condition="";
  1390. if($item=="expenses")
  1391. $condition=" and Rtype=1 ";
  1392. elseif ($item=="receipts")
  1393. $condition=" and Rtype=0 ";
  1394. elseif ($item=="remits")
  1395. $condition=" and Rtype=2 ";
  1396. $dateCondition=" and Year(date) =".$year;
  1397. if(!empty($moth)){
  1398. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1399. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1400. }else
  1401. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1402. if(empty($stList))
  1403. $stList=array('rePrice'=>0,'agPrice'=>0);
  1404. $noPassSum=$receipt->receiptByYear($dateCondition,$this->staff[0]['sid']);
  1405. if(!isset($noPassSum['sum']))
  1406. $noPassSum['sum']=0;
  1407. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($noPassSum['sum']));
  1408. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1409. $Locate=0;$roleId=0;$button=0;
  1410. foreach ($receiptList as $key=>$value){
  1411. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1412. $receiptList[$key]['reviseDetail']=array();
  1413. if (!empty($value['reviseDetail']))
  1414. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1415. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1416. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1417. $receiptList[$key]['category']=$categoryDetil['title'];
  1418. //检测编辑状态
  1419. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1420. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1421. $verifyStaff=json_decode($value['verifyStaff'],true);
  1422. Doo::loadModel('role');
  1423. $role=new role();
  1424. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1425. foreach ($verifyList as $k=>$v){
  1426. //init verifyStaff
  1427. if ($v[1]=='ROLE'){
  1428. if (!empty($verifyStaff)){
  1429. $endStaffArray=end($verifyStaff);
  1430. // if ($v[0]==$endStaffArray['nextStaff']){
  1431. // $roleId=$v[0];
  1432. // }
  1433. }
  1434. $roleVerify=json_decode($v[3],true);
  1435. $roleKey=$k;$roleArray=array();
  1436. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1437. foreach ($roleVerify as $o=>$p){
  1438. $staffID=explode ('_',$p);
  1439. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1440. //print_r($staffID);
  1441. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1442. array_push($roleArray, $exp);
  1443. }
  1444. $roleArrayCopy[$v[0]]=$roleArray;
  1445. //$verifyList[$k]['roleArray']=$roleArray;
  1446. }
  1447. $verifyList[$k]['date']="";
  1448. $verifyList[$k]['opinion']="";
  1449. $verifyList[$k]['status']="";
  1450. if (empty($verifyStaff)){
  1451. $verifyList[$k]['date']="";
  1452. $verifyList[$k]['opinion']="";
  1453. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1454. $verifyList[$k]['status']=4;
  1455. $flag=false;
  1456. }
  1457. }else{
  1458. foreach ($verifyStaff as $m=>$u){
  1459. if ($v[0]==$m){
  1460. $verifyList[$k]['date']=$u['date'];
  1461. $verifyList[$k]['opinion']=$u['opinion'];
  1462. $verifyList[$k]['status']=$u['status'];
  1463. $flag=false;
  1464. break;
  1465. }
  1466. }
  1467. $endStaffArray=end($verifyStaff);
  1468. if (isset($endStaffArray['ROLE'])){
  1469. }else{
  1470. // $endKey=key($verifyStaff);
  1471. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1472. // $button=4;
  1473. // $verifyList[$k]['status']=4;
  1474. // }
  1475. }
  1476. }
  1477. }
  1478. $rolename['name']='';
  1479. if (!empty($roleId)){
  1480. Doo::loadModel('role');
  1481. $role=new role();
  1482. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1483. }
  1484. if (!empty($verifyStaff))
  1485. $endStaffArray=end($verifyStaff);
  1486. $KOP=false;
  1487. foreach ($roleArrayCopy as $P=>$A){
  1488. foreach ( $A as $MKI=>$AVL){
  1489. if (!empty($verifyStaff)){
  1490. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1491. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1492. $button=4;
  1493. $roleArrayCopy[$P][$MKI]['status']=4;
  1494. }
  1495. foreach ($verifyStaff as $m=>$u){
  1496. $AVLFK=$AVL[0].'_R';
  1497. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1498. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1499. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1500. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1501. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1502. break;
  1503. }
  1504. }
  1505. }else{
  1506. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1507. $button=4;
  1508. $roleArrayCopy[$P][$MKI]['status']=4;
  1509. }
  1510. }
  1511. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1512. $KOP=true;
  1513. }
  1514. }
  1515. foreach ($roleArrayCopy as $k=>$v){
  1516. foreach ($verifyList as $m=>$n){
  1517. if ($n[0]==$k){
  1518. array_splice($verifyList,$m,1,$v);
  1519. }
  1520. }
  1521. }
  1522. $receiptList[$key]['verifyList']=$verifyList;
  1523. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1524. $receiptList[$key]['button']=$button;
  1525. }
  1526. //print_r($receiptList);die;
  1527. $mothHtml="";
  1528. for($i=1;$i<=12;$i++){
  1529. if($moth==$i)
  1530. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1531. else
  1532. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1533. }
  1534. $data['mothHtml']=$mothHtml;
  1535. $data['receiptList']=$receiptList;
  1536. $data['memu']="receipt";
  1537. $data['staff']=$this->staff;
  1538. $data['receiptMemu']='expenses';
  1539. $data['verifyId']=$this->verifyId;
  1540. $data['executeId']=$this->executeId;
  1541. $data['item']=$item;
  1542. $data['year']=$year;
  1543. $this->render ( "/admin/expenses", $data );
  1544. }
  1545. function expensesCollect(){
  1546. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1547. Doo::loadModel('receipt');
  1548. $receipt=new receipt();
  1549. Doo::loadModel('L_category');
  1550. $Lcategory=new L_category();
  1551. Doo::loadModel('verify');
  1552. Doo::loadModel('statistics');
  1553. $statistics=new statistics();
  1554. $verify=new verify();
  1555. Doo::loadModel('staff');
  1556. $staff=new staff();
  1557. Doo::loadModel('loanReceipt');
  1558. $loanReceipt=new loanReceipt();
  1559. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1560. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1561. $Locate=0;$roleId=0;$button=0;
  1562. foreach ($loanList as $key=>$value){
  1563. $loanList[$key]['Locate']=$Locate;$Locate++;
  1564. $loanList[$key]['reviseDetail']=array();
  1565. if (!empty($value['reviseDetail']))
  1566. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1567. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1568. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1569. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1570. $loanList[$key]['category']=$categoryDetil['title'];
  1571. //检测编辑状态
  1572. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1573. $verifyList['staff']=$value['verifyBreakup'];
  1574. else
  1575. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1576. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1577. $verifyStaff=json_decode($value['verifyStaff'],true);
  1578. Doo::loadModel('role');
  1579. $role=new role();
  1580. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1581. foreach ($verifyList as $k=>$v){
  1582. //init verifyStaff
  1583. if ($v[1]=='ROLE'){
  1584. if (!empty($verifyStaff)){
  1585. $endStaffArray=end($verifyStaff);
  1586. // if ($v[0]==$endStaffArray['nextStaff']){
  1587. // $roleId=$v[0];
  1588. // }
  1589. }
  1590. $roleVerify=json_decode($v[3],true);
  1591. $roleKey=$k;$roleArray=array();
  1592. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1593. foreach ($roleVerify as $o=>$p){
  1594. $staffID=explode ('_',$p);
  1595. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1596. //print_r($staffID);
  1597. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1598. array_push($roleArray, $exp);
  1599. }
  1600. $roleArrayCopy[$v[0]]=$roleArray;
  1601. //$verifyList[$k]['roleArray']=$roleArray;
  1602. }
  1603. $verifyList[$k]['date']="";
  1604. $verifyList[$k]['opinion']="";
  1605. $verifyList[$k]['status']="";
  1606. if (empty($verifyStaff)){
  1607. $verifyList[$k]['date']="";
  1608. $verifyList[$k]['opinion']="";
  1609. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1610. $verifyList[$k]['status']=4;
  1611. $flag=false;
  1612. }
  1613. }else{
  1614. foreach ($verifyStaff as $m=>$u){
  1615. if ($v[0]==$m){
  1616. $verifyList[$k]['date']=$u['date'];
  1617. $verifyList[$k]['opinion']=$u['opinion'];
  1618. $verifyList[$k]['status']=$u['status'];
  1619. $flag=false;
  1620. break;
  1621. }
  1622. }
  1623. $endStaffArray=end($verifyStaff);
  1624. if (isset($endStaffArray['ROLE'])){
  1625. }else{
  1626. // $endKey=key($verifyStaff);
  1627. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1628. // $button=4;
  1629. // $verifyList[$k]['status']=4;
  1630. // }
  1631. }
  1632. }
  1633. }
  1634. $rolename['name']='';
  1635. if (!empty($roleId)){
  1636. Doo::loadModel('role');
  1637. $role=new role();
  1638. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1639. }
  1640. if (!empty($verifyStaff))
  1641. $endStaffArray=end($verifyStaff);
  1642. $KOP=false;
  1643. foreach ($roleArrayCopy as $P=>$A){
  1644. foreach ( $A as $MKI=>$AVL){
  1645. if (!empty($verifyStaff)){
  1646. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1647. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1648. $button=4;
  1649. $roleArrayCopy[$P][$MKI]['status']=4;
  1650. }
  1651. foreach ($verifyStaff as $m=>$u){
  1652. $AVLFK=$AVL[0].'_R';
  1653. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1654. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1655. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1656. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1657. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1658. break;
  1659. }
  1660. }
  1661. }else{
  1662. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1663. $button=4;
  1664. $roleArrayCopy[$P][$MKI]['status']=4;
  1665. }
  1666. }
  1667. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1668. $KOP=true;
  1669. }
  1670. }
  1671. foreach ($roleArrayCopy as $k=>$v){
  1672. foreach ($verifyList as $m=>$n){
  1673. if ($n[0]==$k){
  1674. array_splice($verifyList,$m,1,$v);
  1675. }
  1676. }
  1677. }
  1678. $loanList[$key]['verifyList']=$verifyList;
  1679. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1680. $loanList[$key]['button']=$button;
  1681. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1682. }
  1683. $data['loanList']=$loanList;
  1684. $Locate=0;$roleId=0;$button=0;
  1685. foreach ($receiptList as $key=>$value){
  1686. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1687. $receiptList[$key]['reviseDetail']=array();
  1688. if (!empty($value['reviseDetail']))
  1689. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1690. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1691. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1692. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1693. $receiptList[$key]['category']=$categoryDetil['title'];
  1694. //检测编辑状态
  1695. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1696. if($value['status']==8&&$value['Rtype']==1)
  1697. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1698. else
  1699. $verifyList['staff']=$value['verifyBreakup'];
  1700. }else
  1701. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1702. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1703. $verifyStaff=json_decode($value['verifyStaff'],true);
  1704. Doo::loadModel('role');
  1705. $role=new role();
  1706. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1707. foreach ($verifyList as $k=>$v){
  1708. //init verifyStaff
  1709. if ($v[1]=='ROLE'){
  1710. if (!empty($verifyStaff)){
  1711. $endStaffArray=end($verifyStaff);
  1712. // if ($v[0]==$endStaffArray['nextStaff']){
  1713. // $roleId=$v[0];
  1714. // }
  1715. }
  1716. $roleVerify=json_decode($v[3],true);
  1717. $roleKey=$k;$roleArray=array();
  1718. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1719. foreach ($roleVerify as $o=>$p){
  1720. $staffID=explode ('_',$p);
  1721. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1722. //print_r($staffID);
  1723. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1724. array_push($roleArray, $exp);
  1725. }
  1726. $roleArrayCopy[$v[0]]=$roleArray;
  1727. //$verifyList[$k]['roleArray']=$roleArray;
  1728. }
  1729. $verifyList[$k]['date']="";
  1730. $verifyList[$k]['opinion']="";
  1731. $verifyList[$k]['status']="";
  1732. if (empty($verifyStaff)){
  1733. $verifyList[$k]['date']="";
  1734. $verifyList[$k]['opinion']="";
  1735. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1736. $verifyList[$k]['status']=4;
  1737. $flag=false;
  1738. }
  1739. }else{
  1740. foreach ($verifyStaff as $m=>$u){
  1741. if ($v[0]==$m){
  1742. $verifyList[$k]['date']=$u['date'];
  1743. $verifyList[$k]['opinion']=$u['opinion'];
  1744. $verifyList[$k]['status']=$u['status'];
  1745. $flag=false;
  1746. break;
  1747. }
  1748. }
  1749. $endStaffArray=end($verifyStaff);
  1750. if (isset($endStaffArray['ROLE'])){
  1751. }else{
  1752. // $endKey=key($verifyStaff);
  1753. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1754. // $button=4;
  1755. // $verifyList[$k]['status']=4;
  1756. // }
  1757. }
  1758. }
  1759. }
  1760. $rolename['name']='';
  1761. if (!empty($roleId)){
  1762. Doo::loadModel('role');
  1763. $role=new role();
  1764. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1765. }
  1766. if (!empty($verifyStaff))
  1767. $endStaffArray=end($verifyStaff);
  1768. $KOP=false;
  1769. foreach ($roleArrayCopy as $P=>$A){
  1770. foreach ( $A as $MKI=>$AVL){
  1771. if (!empty($verifyStaff)){
  1772. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1773. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1774. $button=4;
  1775. $roleArrayCopy[$P][$MKI]['status']=4;
  1776. }
  1777. foreach ($verifyStaff as $m=>$u){
  1778. $AVLFK=$AVL[0].'_R';
  1779. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1780. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1781. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1782. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1783. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1784. break;
  1785. }
  1786. }
  1787. }else{
  1788. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1789. $button=4;
  1790. $roleArrayCopy[$P][$MKI]['status']=4;
  1791. }
  1792. }
  1793. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1794. $KOP=true;
  1795. }
  1796. }
  1797. foreach ($roleArrayCopy as $k=>$v){
  1798. foreach ($verifyList as $m=>$n){
  1799. if ($n[0]==$k){
  1800. array_splice($verifyList,$m,1,$v);
  1801. }
  1802. }
  1803. }
  1804. //费用执行人相关数据
  1805. $executeCopy=json_decode($value['executeCopy'],true);
  1806. $executeStaff=json_decode($value['executeStaff'],true);
  1807. foreach ($executeCopy as $k=>$v){
  1808. $executeCopy[$k]['date']='';
  1809. $executeCopy[$k]['opinion']='';
  1810. $executeCopy[$k]['status']='';
  1811. if (!empty($executeStaff))
  1812. foreach ($executeStaff as $m=>$u){
  1813. if ($v[0]==$m){
  1814. $executeCopy[$k]['date']=$u['date'];
  1815. $executeCopy[$k]['opinion']=$u['opinion'];
  1816. $executeCopy[$k]['status']=$u['status'];
  1817. break;
  1818. }
  1819. }
  1820. }
  1821. $receiptList[$key]['executeCopy']=$executeCopy;
  1822. $receiptList[$key]['verifyList']=$verifyList;
  1823. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1824. $receiptList[$key]['button']=$button;
  1825. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1826. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1827. $relust=$value['sum']-$value['loanSum'];
  1828. $receiptList[$key]['relust']=$relust;
  1829. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1830. }
  1831. $data['receiptList']=$receiptList;
  1832. $data['memu']="receipt";
  1833. $data['staff']=$this->staff;
  1834. $data['receiptMemu']='expenses';
  1835. $data['verifyId']=$this->verifyId;
  1836. $data['executeId']=$this->executeId;
  1837. $this->render ( "/admin/expensesCollect", $data );
  1838. }
  1839. function approvalExpenses(){
  1840. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1841. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1842. $month=$this->get_args('month')?$this->get_args('month'):"";
  1843. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1844. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1845. if (empty($status))
  1846. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1847. $page_size=12;
  1848. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1849. $vidList=array();
  1850. $button=0;
  1851. Doo::loadModel('verify');
  1852. $verify=new verify();
  1853. Doo::loadModel('receipt');
  1854. $receipt=new receipt();
  1855. Doo::loadModel('staff');
  1856. $staff=new staff();
  1857. Doo::loadModel('L_category');
  1858. $Lcategory=new L_category();
  1859. //user verify ID
  1860. $verifyDetail=$verify->find(array('where'=>' (staff not like "%\"'.$this->staff[0]['sid'].'\",\"ROLE%") and (staff like "%[\"'.$this->staff[0]['sid'].'\",%" or staff like "%\"'.$this->staff[0]['sid'].'\_%" )','asArray'=>true));
  1861. foreach ($verifyDetail as $key=>$value){
  1862. array_push($vidList, $value['vid']);
  1863. }
  1864. $vid=implode(",", $vidList);
  1865. if(empty($verifyDetail))
  1866. $vid=0;
  1867. // if ($status==0)
  1868. // $dateCondition="";
  1869. // else
  1870. $dateCondition=" and Year(date) =".$year;
  1871. if(!empty($month))
  1872. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1873. $categoryList=$Lcategory->find(array('asArray'=>true));
  1874. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1875. $cateCondition="";$staffCondition="";$approvalCondition="";
  1876. if (!empty($cid))
  1877. $cateCondition=' and cid='.$cid;
  1878. if(!empty($sid)){
  1879. $staffCondition=' and staff='.$sid;
  1880. $cateCondition="";
  1881. }
  1882. $approvalCondition=" and status=".$status;
  1883. if($status==2){
  1884. //查找角色审批人
  1885. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1886. }
  1887. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1888. $approvalCondition=' and status=2 ';
  1889. }
  1890. if($status==1){
  1891. $approvalCondition=' and (status='.$status.' or status=6) ';
  1892. }
  1893. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1894. $pageinfo['page']=array('previous'=>'');
  1895. if ($status==0){
  1896. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1897. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1898. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1899. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1900. }else
  1901. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1902. ,'desc'=>'rid','asArray'=>true));
  1903. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )'.$cateCondition.$staffCondition
  1904. ,'desc'=>'rid','asArray'=>true));
  1905. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1906. //print_r($pageinfo);
  1907. $Locate=0;
  1908. foreach ($receiptList as $key=>$value){
  1909. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1910. $receiptList[$key]['reviseDetail']=array();
  1911. if (!empty($value['reviseDetail']))
  1912. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1913. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1914. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1915. $receiptList[$key]['category']=$categoryDetil['title'];
  1916. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1917. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1918. $verifyStaff=json_decode($value['verifyStaff'],true);
  1919. foreach ($verifyList as $k=>$v){
  1920. //init verifyStaff
  1921. $verifyList[$k]['date']="";
  1922. $verifyList[$k]['opinion']="";
  1923. $verifyList[$k]['status']="";
  1924. if (empty($verifyStaff)){
  1925. $verifyList[$k]['date']="";
  1926. $verifyList[$k]['opinion']="";
  1927. if ($v[0]==$this->staff[0]['sid']){
  1928. $verifyList[$k]['status']=4;
  1929. $button=4;
  1930. }
  1931. }else{
  1932. $flag=true;
  1933. foreach ($verifyStaff as $m=>$u){
  1934. if ($v[0]==$m){
  1935. $verifyList[$k]['date']=$u['date'];
  1936. $verifyList[$k]['opinion']=$u['opinion'];
  1937. $verifyList[$k]['status']=$u['status'];
  1938. $flag=false;
  1939. break;
  1940. }
  1941. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1942. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1943. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1944. }
  1945. if($flag){//检测可编辑
  1946. if($v[0]==$this->staff[0]['sid']){
  1947. $verifyList[$k]['status']=4;$button=4;
  1948. }
  1949. }
  1950. }
  1951. }
  1952. $receiptList[$key]['verifyList']=$verifyList;
  1953. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1954. $receiptList[$key]['button']=$button;
  1955. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1956. }
  1957. //print_r($receiptList);die;
  1958. //$data['verifyDetail']=$verifyDetail;
  1959. $mothHtml="";
  1960. for($i=1;$i<=12;$i++){
  1961. if($month==$i)
  1962. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1963. else
  1964. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1965. }
  1966. $data['mothHtml']=$mothHtml;
  1967. $data['page']=$pageinfo;
  1968. $data['receiptList']=$receiptList;
  1969. $data['receiptApprovalCount']=count($rLRes);
  1970. $data['status']=$status;
  1971. $data['year']=$year;
  1972. $data['categoryList']=$categoryList;
  1973. $data['staffList']=$staffList;
  1974. $data['cid']=$cid;
  1975. $data['sid']=$sid;
  1976. //print_r($receiptList);
  1977. $data['memu']="receipt";
  1978. $data['staff']=$this->staff;
  1979. $data['receiptMemu']='approvalExpenses';
  1980. $data['verifyId']=$this->verifyId;
  1981. $data['executeId']=$this->executeId;
  1982. $this->render ( "/admin/approvalExpenses", $data );
  1983. }
  1984. function expensesDoc(){
  1985. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1986. Doo::loadModel('receipt');
  1987. $receipt=new receipt();
  1988. Doo::loadModel('L_category');
  1989. $Lcategory=new L_category();
  1990. Doo::loadModel('verify');
  1991. Doo::loadModel('statistics');
  1992. $statistics=new statistics();
  1993. $verify=new verify();
  1994. Doo::loadModel('staff');
  1995. $staff=new staff();
  1996. Doo::loadModel('loanReceipt');
  1997. $loanReceipt=new loanReceipt();
  1998. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  1999. $loanList=array();
  2000. if (!empty($receiptList))
  2001. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2002. $Locate=0;$roleId=0;$button=0;
  2003. foreach ($loanList as $key=>$value){
  2004. $loanList[$key]['Locate']=$Locate;$Locate++;
  2005. $loanList[$key]['reviseDetail']=array();
  2006. if (!empty($value['reviseDetail']))
  2007. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2008. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2009. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2010. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2011. $loanList[$key]['category']=$categoryDetil['title'];
  2012. //检测编辑状态
  2013. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  2014. $verifyList['staff']=$value['verifyBreakup'];
  2015. else
  2016. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2017. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2018. $verifyStaff=json_decode($value['verifyStaff'],true);
  2019. Doo::loadModel('role');
  2020. $role=new role();
  2021. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2022. foreach ($verifyList as $k=>$v){
  2023. //init verifyStaff
  2024. if ($v[1]=='ROLE'){
  2025. if (!empty($verifyStaff)){
  2026. $endStaffArray=end($verifyStaff);
  2027. // if ($v[0]==$endStaffArray['nextStaff']){
  2028. // $roleId=$v[0];
  2029. // }
  2030. }
  2031. $roleVerify=json_decode($v[3],true);
  2032. $roleKey=$k;$roleArray=array();
  2033. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2034. foreach ($roleVerify as $o=>$p){
  2035. $staffID=explode ('_',$p);
  2036. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2037. //print_r($staffID);
  2038. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2039. array_push($roleArray, $exp);
  2040. }
  2041. $roleArrayCopy[$v[0]]=$roleArray;
  2042. //$verifyList[$k]['roleArray']=$roleArray;
  2043. }
  2044. $verifyList[$k]['date']="";
  2045. $verifyList[$k]['opinion']="";
  2046. $verifyList[$k]['status']="";
  2047. if (empty($verifyStaff)){
  2048. $verifyList[$k]['date']="";
  2049. $verifyList[$k]['opinion']="";
  2050. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2051. $verifyList[$k]['status']=4;
  2052. $flag=false;
  2053. }
  2054. }else{
  2055. foreach ($verifyStaff as $m=>$u){
  2056. if ($v[0]==$m){
  2057. $verifyList[$k]['date']=$u['date'];
  2058. $verifyList[$k]['opinion']=$u['opinion'];
  2059. $verifyList[$k]['status']=$u['status'];
  2060. $flag=false;
  2061. break;
  2062. }
  2063. }
  2064. $endStaffArray=end($verifyStaff);
  2065. if (isset($endStaffArray['ROLE'])){
  2066. }else{
  2067. // $endKey=key($verifyStaff);
  2068. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2069. // $button=4;
  2070. // $verifyList[$k]['status']=4;
  2071. // }
  2072. }
  2073. }
  2074. }
  2075. $rolename['name']='';
  2076. if (!empty($roleId)){
  2077. Doo::loadModel('role');
  2078. $role=new role();
  2079. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2080. }
  2081. if (!empty($verifyStaff))
  2082. $endStaffArray=end($verifyStaff);
  2083. $KOP=false;
  2084. foreach ($roleArrayCopy as $P=>$A){
  2085. foreach ( $A as $MKI=>$AVL){
  2086. if (!empty($verifyStaff)){
  2087. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2088. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2089. $button=4;
  2090. $roleArrayCopy[$P][$MKI]['status']=4;
  2091. }
  2092. foreach ($verifyStaff as $m=>$u){
  2093. $AVLFK=$AVL[0].'_R';
  2094. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2095. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2096. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2097. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2098. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2099. break;
  2100. }
  2101. }
  2102. }else{
  2103. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2104. $button=4;
  2105. $roleArrayCopy[$P][$MKI]['status']=4;
  2106. }
  2107. }
  2108. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2109. $KOP=true;
  2110. }
  2111. }
  2112. foreach ($roleArrayCopy as $k=>$v){
  2113. foreach ($verifyList as $m=>$n){
  2114. if ($n[0]==$k){
  2115. array_splice($verifyList,$m,1,$v);
  2116. }
  2117. }
  2118. }
  2119. $loanList[$key]['verifyList']=$verifyList;
  2120. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2121. $loanList[$key]['button']=$button;
  2122. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2123. }
  2124. $data['loanList']=$loanList;
  2125. //print_r($loanList);
  2126. $Locate=0;$roleId=0;$button=0;
  2127. foreach ($receiptList as $key=>$value){
  2128. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2129. $receiptList[$key]['reviseDetail']=array();
  2130. if (!empty($value['reviseDetail']))
  2131. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2132. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2133. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2134. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2135. $receiptList[$key]['category']=$categoryDetil['title'];
  2136. //检测编辑状态
  2137. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2138. $verifyList['staff']=$value['verifyBreakup'];
  2139. }else
  2140. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2141. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2142. $verifyStaff=json_decode($value['verifyStaff'],true);
  2143. Doo::loadModel('role');
  2144. $role=new role();
  2145. if ($verifyList==NULL)
  2146. $verifyList=array();
  2147. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2148. foreach ($verifyList as $k=>$v){
  2149. //init verifyStaff
  2150. if ($v[1]=='ROLE'){
  2151. if (!empty($verifyStaff)){
  2152. $endStaffArray=end($verifyStaff);
  2153. // if ($v[0]==$endStaffArray['nextStaff']){
  2154. // $roleId=$v[0];
  2155. // }
  2156. }
  2157. $roleVerify=json_decode($v[3],true);
  2158. $roleKey=$k;$roleArray=array();
  2159. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2160. foreach ($roleVerify as $o=>$p){
  2161. $staffID=explode ('_',$p);
  2162. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2163. //print_r($staffID);
  2164. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2165. array_push($roleArray, $exp);
  2166. }
  2167. $roleArrayCopy[$v[0]]=$roleArray;
  2168. //$verifyList[$k]['roleArray']=$roleArray;
  2169. }
  2170. $verifyList[$k]['date']="";
  2171. $verifyList[$k]['opinion']="";
  2172. $verifyList[$k]['status']="";
  2173. if (empty($verifyStaff)){
  2174. $verifyList[$k]['date']="";
  2175. $verifyList[$k]['opinion']="";
  2176. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2177. $verifyList[$k]['status']=4;
  2178. $flag=false;
  2179. }
  2180. }else{
  2181. foreach ($verifyStaff as $m=>$u){
  2182. if ($v[0]==$m){
  2183. $verifyList[$k]['date']=$u['date'];
  2184. $verifyList[$k]['opinion']=$u['opinion'];
  2185. $verifyList[$k]['status']=$u['status'];
  2186. $flag=false;
  2187. break;
  2188. }
  2189. }
  2190. $endStaffArray=end($verifyStaff);
  2191. if (isset($endStaffArray['ROLE'])){
  2192. }else{
  2193. // $endKey=key($verifyStaff);
  2194. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2195. // $button=4;
  2196. // $verifyList[$k]['status']=4;
  2197. // }
  2198. }
  2199. }
  2200. }
  2201. $rolename['name']='';
  2202. if (!empty($roleId)){
  2203. Doo::loadModel('role');
  2204. $role=new role();
  2205. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2206. }
  2207. if (!empty($verifyStaff))
  2208. $endStaffArray=end($verifyStaff);
  2209. $KOP=false;
  2210. foreach ($roleArrayCopy as $P=>$A){
  2211. foreach ( $A as $MKI=>$AVL){
  2212. if (!empty($verifyStaff)){
  2213. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2214. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2215. $button=4;
  2216. $roleArrayCopy[$P][$MKI]['status']=4;
  2217. }
  2218. foreach ($verifyStaff as $m=>$u){
  2219. $AVLFK=$AVL[0].'_R';
  2220. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2221. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2222. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2223. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2224. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2225. break;
  2226. }
  2227. }
  2228. }else{
  2229. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2230. $button=4;
  2231. $roleArrayCopy[$P][$MKI]['status']=4;
  2232. }
  2233. }
  2234. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2235. $KOP=true;
  2236. }
  2237. }
  2238. foreach ($roleArrayCopy as $k=>$v){
  2239. foreach ($verifyList as $m=>$n){
  2240. if ($n[0]==$k){
  2241. array_splice($verifyList,$m,1,$v);
  2242. }
  2243. }
  2244. }
  2245. //费用执行人相关数据
  2246. $executeCopy=json_decode($value['executeCopy'],true);
  2247. $executeStaff=json_decode($value['executeStaff'],true);
  2248. foreach ($executeCopy as $k=>$v){
  2249. $executeCopy[$k]['date']='';
  2250. $executeCopy[$k]['opinion']='';
  2251. $executeCopy[$k]['status']='';
  2252. if (!empty($executeStaff))
  2253. foreach ($executeStaff as $m=>$u){
  2254. if ($v[0]==$m){
  2255. $executeCopy[$k]['date']=$u['date'];
  2256. $executeCopy[$k]['opinion']=$u['opinion'];
  2257. $executeCopy[$k]['status']=$u['status'];
  2258. break;
  2259. }
  2260. }
  2261. }
  2262. $receiptList[$key]['executeCopy']=$executeCopy;
  2263. $receiptList[$key]['verifyList']=$verifyList;
  2264. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2265. $receiptList[$key]['button']=$button;
  2266. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2267. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2268. }
  2269. //print_r($receiptList);
  2270. //获取审批日志
  2271. Doo::loadModel('receiptLog');
  2272. $receiptLog=new receiptLog();
  2273. $rlList=array();
  2274. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2275. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2276. if (!empty($rlInfo)){
  2277. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2278. }
  2279. $receiptList[0]['rlList']=$rlList;
  2280. $data['receiptList']=$receiptList;
  2281. $data['memu']="receipt";
  2282. $data['staff']=$this->staff;
  2283. $data['receiptMemu']='approvalExpenses';
  2284. $data['verifyId']=$this->verifyId;
  2285. $data['executeId']=$this->executeId;
  2286. $this->render ( "/admin/expensesDoc", $data );
  2287. }
  2288. function expensesEdi(){
  2289. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2290. $status=isset($this->params['status'])?$this->params['status']:'';
  2291. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2292. $month=$this->get_args('month')?$this->get_args('month'):"";
  2293. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2294. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2295. if (empty($status))
  2296. $status=$this->get_args('status')?$this->get_args('status'):2;
  2297. $vidList=array();
  2298. $button=0;
  2299. Doo::loadModel('verify');
  2300. Doo::loadModel('receipt');
  2301. Doo::loadModel('staff');
  2302. $staff=new staff();
  2303. $receipt=new receipt();
  2304. $verify=new verify();
  2305. Doo::loadModel('L_category');
  2306. $Lcategory=new L_category();
  2307. Doo::loadModel('enclosur');
  2308. $enclosur=new enclosur();
  2309. //user verify ID
  2310. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2311. foreach ($verifyDetail as $key=>$value){
  2312. array_push($vidList, $value['vid']);
  2313. }
  2314. $vid=implode(",", $vidList);
  2315. if(empty($verifyDetail))
  2316. $vid=0;
  2317. $categoryList=$Lcategory->find(array('asArray'=>true));
  2318. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2319. $ap="";
  2320. if($status==4){
  2321. $ap=4;$status=2;
  2322. }
  2323. //get Receipt By verifyID status 2
  2324. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2325. $Locate=0;$roleId=0;
  2326. if($ap==4)
  2327. $status=4;
  2328. foreach ($receiptList as $key=>$value){
  2329. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2330. $receiptList[$key]['reviseDetail']=array();
  2331. if (!empty($value['reviseDetail']))
  2332. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2333. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2334. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2335. $receiptList[$key]['category']=$categoryDetil['title'];
  2336. //检测编辑状态
  2337. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2338. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2339. $verifyStaff=json_decode($value['verifyStaff'],true);
  2340. Doo::loadModel('role');
  2341. $role=new role();
  2342. //print_r($verifyList);
  2343. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2344. foreach ($verifyList as $k=>$v){
  2345. //init verifyStaff
  2346. if ($v[1]=='ROLE'){
  2347. if (!empty($verifyStaff)){
  2348. $endStaffArray=end($verifyStaff);
  2349. if ($v[0]==$endStaffArray['nextStaff']){
  2350. $roleId=$v[0];
  2351. }
  2352. }
  2353. $roleVerify=json_decode($v[3],true);
  2354. $roleKey=$k;$roleArray=array();
  2355. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2356. foreach ($roleVerify as $o=>$p){
  2357. $staffID=explode ('_',$p);
  2358. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2359. //print_r($staffID);
  2360. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2361. array_push($roleArray, $exp);
  2362. }
  2363. $roleArrayCopy[$v[0]]=$roleArray;
  2364. //$verifyList[$k]['roleArray']=$roleArray;
  2365. }
  2366. //print_r($roleArray);
  2367. $verifyList[$k]['date']="";
  2368. $verifyList[$k]['opinion']="";
  2369. $verifyList[$k]['status']="";
  2370. if (empty($verifyStaff)){
  2371. $verifyList[$k]['date']="";
  2372. $verifyList[$k]['opinion']="";
  2373. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2374. $verifyList[$k]['status']=4;
  2375. $button=4;$flag=false;
  2376. }
  2377. }else{
  2378. foreach ($verifyStaff as $m=>$u){
  2379. if ($v[0]==$m){
  2380. $verifyList[$k]['date']=$u['date'];
  2381. $verifyList[$k]['opinion']=$u['opinion'];
  2382. $verifyList[$k]['status']=$u['status'];
  2383. $flag=false;
  2384. break;
  2385. }
  2386. }
  2387. $endStaffArray=end($verifyStaff);
  2388. if (isset($endStaffArray['ROLE'])){
  2389. }else{
  2390. $endKey=key($verifyStaff);
  2391. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2392. $button=4;
  2393. $verifyList[$k]['status']=4;
  2394. }
  2395. }
  2396. }
  2397. }
  2398. $rolename['name']='';
  2399. if (!empty($roleId)){
  2400. Doo::loadModel('role');
  2401. $role=new role();
  2402. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2403. }
  2404. if (!empty($verifyStaff))
  2405. $endStaffArray=end($verifyStaff);
  2406. $KOP=false;
  2407. foreach ($roleArrayCopy as $P=>$A){
  2408. foreach ( $A as $MKI=>$AVL){
  2409. if (!empty($verifyStaff)){
  2410. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2411. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2412. $button=4;
  2413. $roleArrayCopy[$P][$MKI]['status']=4;
  2414. }
  2415. foreach ($verifyStaff as $m=>$u){
  2416. $AVLFK=$AVL[0].'_R';
  2417. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2418. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2419. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2420. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2421. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2422. break;
  2423. }
  2424. }
  2425. }else{
  2426. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2427. $button=4;
  2428. $roleArrayCopy[$P][$MKI]['status']=4;
  2429. }
  2430. }
  2431. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2432. $KOP=true;
  2433. }
  2434. }
  2435. // print_r($roleArrayCopy);
  2436. // echo $roleKey;
  2437. foreach ($roleArrayCopy as $k=>$v){
  2438. foreach ($verifyList as $m=>$n){
  2439. if ($n[0]==$k){
  2440. array_splice($verifyList,$m,1,$v);
  2441. }
  2442. }
  2443. }
  2444. $receiptList[$key]['verifyList']=$verifyList;
  2445. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2446. $receiptList[$key]['button']=$button;
  2447. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2448. }
  2449. //$data['verifyDetail']=$verifyDetail;
  2450. $mothHtml="";
  2451. for($i=1;$i<=12;$i++){
  2452. if($month==$i)
  2453. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2454. else
  2455. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2456. }
  2457. //获取审批日志
  2458. Doo::loadModel('receiptLog');
  2459. $receiptLog=new receiptLog();
  2460. $rlList=array();
  2461. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2462. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2463. if (!empty($rlInfo)){
  2464. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2465. }
  2466. $receiptList[0]['rlList']=$rlList;
  2467. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2468. $enclosurHtml='';
  2469. foreach ($enclosurList as $value){
  2470. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2471. }
  2472. //print_r($receiptList);
  2473. $data['rid']=$rid;
  2474. $data['enclosurHtml']=$enclosurHtml;
  2475. $data['rolename']=$rolename['name'];
  2476. $data['datetij']=$tijdate['date'];
  2477. $data['mothHtml']=$mothHtml;
  2478. $data['receiptList']=$receiptList;
  2479. $data['receiptApprovalCount']=count($receiptList);
  2480. $data['status']=$status;
  2481. $data['year']=$year;
  2482. $data['categoryList']=$categoryList;
  2483. $data['staffList']=$staffList;
  2484. $data['cid']=$cid;
  2485. $data['sid']=$sid;
  2486. $data['ap']=$ap;
  2487. $data['memu']="receipt";
  2488. $data['staff']=$this->staff;
  2489. $data['receiptMemu']='approvalExpenses';
  2490. $data['verifyId']=$this->verifyId;
  2491. $data['executeId']=$this->executeId;
  2492. $this->render ( "/admin/expensesEdi", $data );
  2493. }
  2494. function expensesDefray(){
  2495. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2496. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2497. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2498. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2499. if(!empty($rid)){
  2500. Doo::loadModel("verify");
  2501. $verify=new verify();
  2502. Doo::loadModel("receiptDetail");
  2503. $receiptDetailObj=new receiptDetail();
  2504. Doo::loadModel("itemStatistics");
  2505. Doo::loadModel("statistics");
  2506. $statistics=new statistics();
  2507. $itemStatistics=new itemStatistics();
  2508. Doo::loadModel("receipt");
  2509. $receipt=new receipt();
  2510. Doo::loadModel("loanReceipt");
  2511. $loanReceipt=new loanReceipt();
  2512. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2513. if (empty($receiptDetail))
  2514. return "/approval";
  2515. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2516. $verifyString=$verifyDetail['staff'];
  2517. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2518. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2519. if(empty($opinion)){
  2520. if ($status==3)
  2521. $opinion="终止";
  2522. else
  2523. $opinion="同意支付";
  2524. }
  2525. $nowStaff=0;$nowStaffList=array();
  2526. if(empty($verifyStaff)){
  2527. //还需加入是否已经进入角色审批
  2528. if ($verifyDetail[0][1]=='ROLE'){
  2529. //print_r($verifyDetail);echo "ddd";
  2530. $vStaffString=json_decode($verifyDetail[0][3]);
  2531. foreach ($vStaffString as $key=>$value){
  2532. $staffK=explode("_", $value);
  2533. if ($staffK[0]!=$this->staff[0]['sid'])
  2534. array_push($nowStaffList, $staffK[0]);
  2535. }
  2536. //print_r($verifyDetail);
  2537. //die;
  2538. $nowStaff=implode(',', $nowStaffList);
  2539. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2540. }else{
  2541. if ($verifyDetail[1][1]=='ROLE'){
  2542. $vStaffString=json_decode($verifyDetail[1][3]);
  2543. //echo "dd";
  2544. foreach ($vStaffString as $key=>$value){
  2545. $staffK=explode("_", $value);
  2546. array_push($nowStaffList, $staffK[0]);
  2547. }
  2548. $nowStaff=implode(',', $nowStaffList);
  2549. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2550. }else{
  2551. $nowStaff=$verifyDetail[1][0];
  2552. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2553. }
  2554. }
  2555. if($status==3)
  2556. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2557. $vStaffString=json_encode($verifyStaff);
  2558. $receipt->nowStaff=$nowStaff;
  2559. $receipt->verifyStaff=$vStaffString;
  2560. $loanReceipt->nowStaff=$nowStaff;
  2561. $loanReceipt->verifyStaff=$vStaffString;
  2562. }else{
  2563. $VS=end($verifyStaff);
  2564. //非角色审批
  2565. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2566. $nextStaff=0;$roleSTF=false;
  2567. foreach ($verifyDetail as $key=>$value){
  2568. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2569. if (isset($verifyDetail[$key+1])){
  2570. $nextStaff=$verifyDetail[$key+1][0];
  2571. if ($verifyDetail[$key+1][1]=='ROLE')
  2572. $roleSTF=true;
  2573. }
  2574. break;
  2575. }
  2576. }
  2577. if (!$roleSTF){
  2578. $nowStaff=$nextStaff;
  2579. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2580. }else{
  2581. //获取角色下的所有用户ID
  2582. $nowStaffList=array();
  2583. foreach ($verifyDetail as $vfk){
  2584. if ($vfk[1]=='ROLE'){
  2585. $vStaffString=json_decode($vfk[3]);
  2586. foreach ($vStaffString as $key=>$value){
  2587. $staffK=explode("_", $value);
  2588. array_push($nowStaffList, $staffK[0]);
  2589. }
  2590. }
  2591. }
  2592. $nowStaff=implode(',', $nowStaffList);
  2593. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2594. }
  2595. if($status==3){
  2596. $verifyStaff['final']=$status;
  2597. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2598. }
  2599. $vStaffString=json_encode($verifyStaff);
  2600. $receipt->nowStaff=$nowStaff;
  2601. $receipt->verifyStaff=$vStaffString;
  2602. $loanReceipt->nowStaff=$nowStaff;
  2603. $loanReceipt->verifyStaff=$vStaffString;
  2604. }
  2605. //角色审批
  2606. if (isset($VS['ROLE'])){
  2607. //找出角色人 当前审批角色组
  2608. $verifyJSStaff=array();$nowStaffList2=array();
  2609. foreach ($verifyDetail as $key=>$value){
  2610. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2611. $verifyJSStaff=json_decode($value[3]);
  2612. foreach ($verifyJSStaff as $m){
  2613. $staffK=explode("_", $m);
  2614. array_push($nowStaffList2, $staffK[0]);
  2615. }
  2616. // print_r($nowStaffList2);
  2617. }
  2618. }
  2619. $RoleVerifyStaff=array();
  2620. foreach ($verifyStaff as $key=>$value){
  2621. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2622. foreach ($nowStaffList2 as $m) {
  2623. if ($key==$m."_R")
  2624. $RoleVerifyStaff[$key]=$value;
  2625. }
  2626. }
  2627. }
  2628. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2629. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2630. //下一个审批人ID
  2631. $nextStaff=0;$falg=false;
  2632. foreach ($verifyDetail as $key=>$value){
  2633. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2634. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2635. $falg=true;
  2636. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2637. foreach ($vStaffString as $v){
  2638. $staffK=explode("_", $v);
  2639. array_push($nowStaffList, $staffK[0]);
  2640. }
  2641. $nowStaff=implode(',', $nowStaffList);
  2642. $nextStaff=$verifyDetail[$key+1][0];
  2643. }elseif(isset($verifyDetail[$key+1])){
  2644. $nextStaff=$verifyDetail[$key+1][0];
  2645. $nowStaff=$nextStaff;
  2646. }else
  2647. $nowStaff='';
  2648. break;
  2649. }
  2650. }
  2651. if ($falg)
  2652. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2653. else
  2654. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2655. // print_r($verifyStaff);
  2656. // echo $nowStaff;die;
  2657. }else{ //进入下一个角色或者审批人
  2658. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2659. //
  2660. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2661. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2662. // print_r($verifyStaff);
  2663. // die;
  2664. }
  2665. if($status==3){
  2666. $verifyStaff['final']=$status;
  2667. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2668. }
  2669. $vStaffString=json_encode($verifyStaff);
  2670. $receipt->verifyStaff=$vStaffString;
  2671. $receipt->nowStaff=$nowStaff;
  2672. $loanReceipt->nowStaff=$nowStaff;
  2673. $loanReceipt->verifyStaff=$vStaffString;
  2674. //die;
  2675. //}
  2676. // print_r($verifyStaff);
  2677. // die;
  2678. }
  2679. //print_r($verifyStaff);die;
  2680. }
  2681. //print_r($verifyDetail);
  2682. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2683. foreach ($verifyDetail as $k=>$v){
  2684. if ($v[1]=='ROLE'){
  2685. $roleId=$v[0];
  2686. $roleVerify=json_decode($v[3],true);
  2687. $roleKey=$k;$roleArray=array();
  2688. foreach ($roleVerify as $o=>$p){
  2689. $staffID=explode ('_',$p);
  2690. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2691. array_push($roleArray, $exp);
  2692. }
  2693. $verifyDetailCopy[$v[0]]=$roleArray;
  2694. }
  2695. }
  2696. //print_r($verifyDetail);
  2697. foreach ($verifyDetailCopy as $k=>$v){
  2698. foreach ($verifyDetail as $m=>$n){
  2699. if ($n[0]==$k){
  2700. array_splice($verifyDetail,$m,1,$v);
  2701. }
  2702. }
  2703. }
  2704. //审批日志
  2705. if (!isset($verifyStaff['final'])){
  2706. Doo::loadModel("receiptLog");
  2707. $receiptLog=new receiptLog();
  2708. if (!empty($roleId)){
  2709. Doo::loadModel("role");
  2710. $role=new role();
  2711. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2712. $receiptLog->rolename=$roleInfo['name'];
  2713. }
  2714. $receiptLog->username=$this->staff[0]['username'];
  2715. $receiptLog->uid=$this->staff[0]['sid'];
  2716. $receiptLog->date=date("Y-m-d");
  2717. $receiptLog->opinion=$opinion;
  2718. $receiptLog->img=$this->staff[0]['avatar'];
  2719. $receiptLog->status=1;
  2720. $receiptLog->rid=$rid;
  2721. $receiptLog->insert();
  2722. }
  2723. if (isset($verifyStaff['final'])){//rDetail
  2724. $receipt->status=3;
  2725. $receipt->verifyBreakup=$verifyString;
  2726. $receiptDetailObj->status=3;
  2727. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2728. //微信企业号通知
  2729. $receipt2 = new receipt();
  2730. $receiptDetail = $receipt2->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  2731. if(!empty($receiptDetail)){
  2732. Doo::loadModel('staff');
  2733. $staff = new staff();
  2734. $staffmsg = $staff->getStaffBySid($receiptDetail['staff']);
  2735. if(!empty($staffmsg['wxid'])){
  2736. require_once (SITE_PATH . '/protected/class/client.php');
  2737. $client = new client ('http://m.cld.smartcost.com.cn/');
  2738. $user = $staffmsg['wxid'];
  2739. $receiptName = '';
  2740. switch($receiptDetail['Rtype']){
  2741. case 0:$receiptName = '报销';break;
  2742. case 1:$receiptName = '借款';break;
  2743. case 2:$receiptName = '对公汇款';break;
  2744. }
  2745. $msg = '很遗憾,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被终止。';
  2746. $result = $client->SendMsg($user,$msg,'text');
  2747. }
  2748. }
  2749. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2750. $receipt->status=6;
  2751. $receipt->pastDate=date("Y-m-d");
  2752. $receipt->isBK=1;
  2753. $loanReceipt->verifyBreakup=$verifyString;
  2754. $loanReceipt->status=1;
  2755. $loanReceipt->pastDate=date("Y-m-d");
  2756. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2757. //微信企业号通知
  2758. $receipt2 = new receipt();
  2759. $receiptDetail = $receipt2->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  2760. if(!empty($receiptDetail)){
  2761. Doo::loadModel('staff');
  2762. $staff = new staff();
  2763. $staffmsg = $staff->getStaffBySid($receiptDetail['staff']);
  2764. if(!empty($staffmsg['wxid'])){
  2765. require_once (SITE_PATH . '/protected/class/client.php');
  2766. $client = new client ('http://m.cld.smartcost.com.cn/');
  2767. $user = $staffmsg['wxid'];
  2768. $receiptName = '';
  2769. switch($receiptDetail['Rtype']){
  2770. case 0:$receiptName = '报销';break;
  2771. case 1:$receiptName = '借款';break;
  2772. case 2:$receiptName = '对公汇款';break;
  2773. }
  2774. $msg = '太好了,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已同意支付。';
  2775. $result = $client->SendMsg($user,$msg,'text');
  2776. }
  2777. }
  2778. }
  2779. $receipt->update(array('where'=>' rid = '.$rid));
  2780. return "/approvalExpenses/2";
  2781. }
  2782. }
  2783. function implement(){
  2784. Doo::loadModel('receipt');
  2785. $receipt=new receipt();
  2786. Doo::loadModel('L_category');
  2787. $Lcategory=new L_category();
  2788. Doo::loadModel('verify');
  2789. $verify=new verify();
  2790. Doo::loadModel('staff');
  2791. $staff=new staff();
  2792. Doo::loadModel("execute");
  2793. $execute=new execute();
  2794. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2795. Doo::loadModel('loanReceipt');
  2796. $loanReceipt=new loanReceipt();
  2797. //print_r($receiptList);
  2798. $loanList=array();
  2799. if (!isset($receiptList))
  2800. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2801. $Locate=0;$roleId=0;$button=0;
  2802. foreach ($loanList as $key=>$value){
  2803. $loanList[$key]['Locate']=$Locate;$Locate++;
  2804. $loanList[$key]['reviseDetail']=array();
  2805. if (!empty($value['reviseDetail']))
  2806. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2807. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2808. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2809. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2810. $loanList[$key]['category']=$categoryDetil['title'];
  2811. //检测编辑状态
  2812. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2813. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2814. $verifyStaff=json_decode($value['verifyStaff'],true);
  2815. Doo::loadModel('role');
  2816. $role=new role();
  2817. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2818. foreach ($verifyList as $k=>$v){
  2819. //init verifyStaff
  2820. if ($v[1]=='ROLE'){
  2821. if (!empty($verifyStaff)){
  2822. $endStaffArray=end($verifyStaff);
  2823. // if ($v[0]==$endStaffArray['nextStaff']){
  2824. // $roleId=$v[0];
  2825. // }
  2826. }
  2827. $roleVerify=json_decode($v[3],true);
  2828. $roleKey=$k;$roleArray=array();
  2829. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2830. foreach ($roleVerify as $o=>$p){
  2831. $staffID=explode ('_',$p);
  2832. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2833. //print_r($staffID);
  2834. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2835. array_push($roleArray, $exp);
  2836. }
  2837. $roleArrayCopy[$v[0]]=$roleArray;
  2838. //$verifyList[$k]['roleArray']=$roleArray;
  2839. }
  2840. $verifyList[$k]['date']="";
  2841. $verifyList[$k]['opinion']="";
  2842. $verifyList[$k]['status']="";
  2843. if (empty($verifyStaff)){
  2844. $verifyList[$k]['date']="";
  2845. $verifyList[$k]['opinion']="";
  2846. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2847. $verifyList[$k]['status']=4;
  2848. $flag=false;
  2849. }
  2850. }else{
  2851. foreach ($verifyStaff as $m=>$u){
  2852. if ($v[0]==$m){
  2853. $verifyList[$k]['date']=$u['date'];
  2854. $verifyList[$k]['opinion']=$u['opinion'];
  2855. $verifyList[$k]['status']=$u['status'];
  2856. $flag=false;
  2857. break;
  2858. }
  2859. }
  2860. $endStaffArray=end($verifyStaff);
  2861. if (isset($endStaffArray['ROLE'])){
  2862. }else{
  2863. // $endKey=key($verifyStaff);
  2864. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2865. // $button=4;
  2866. // $verifyList[$k]['status']=4;
  2867. // }
  2868. }
  2869. }
  2870. }
  2871. $rolename['name']='';
  2872. if (!empty($roleId)){
  2873. Doo::loadModel('role');
  2874. $role=new role();
  2875. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2876. }
  2877. if (!empty($verifyStaff))
  2878. $endStaffArray=end($verifyStaff);
  2879. $KOP=false;
  2880. foreach ($roleArrayCopy as $P=>$A){
  2881. foreach ( $A as $MKI=>$AVL){
  2882. if (!empty($verifyStaff)){
  2883. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2884. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2885. $button=4;
  2886. $roleArrayCopy[$P][$MKI]['status']=4;
  2887. }
  2888. foreach ($verifyStaff as $m=>$u){
  2889. $AVLFK=$AVL[0].'_R';
  2890. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2891. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2892. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2893. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2894. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2895. break;
  2896. }
  2897. }
  2898. }else{
  2899. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2900. $button=4;
  2901. $roleArrayCopy[$P][$MKI]['status']=4;
  2902. }
  2903. }
  2904. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2905. $KOP=true;
  2906. }
  2907. }
  2908. foreach ($roleArrayCopy as $k=>$v){
  2909. foreach ($verifyList as $m=>$n){
  2910. if ($n[0]==$k){
  2911. array_splice($verifyList,$m,1,$v);
  2912. }
  2913. }
  2914. }
  2915. $loanList[$key]['verifyList']=$verifyList;
  2916. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2917. }
  2918. $data['loanList']=$loanList;
  2919. $Locate=0;$roleId=0;$button=0;
  2920. foreach ($receiptList as $key=>$value){
  2921. $button2=0;
  2922. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2923. $receiptList[$key]['reviseDetail']=array();
  2924. if (!empty($value['reviseDetail']))
  2925. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2926. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2927. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2928. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2929. $receiptList[$key]['category']=$categoryDetil['title'];
  2930. $executeList=json_decode($value['executeCopy'],true);
  2931. $executeStaff=array();
  2932. if (!empty($value['executeStaff'] ))
  2933. $executeStaff=json_decode($value['executeStaff'],true);
  2934. if (isset($executeList)){
  2935. foreach ($executeList as $op=>$lo){
  2936. $executeList[$op]['date']="";
  2937. $executeList[$op]['opinion']="";
  2938. $executeList[$op]['status']="";
  2939. foreach ($executeStaff as $m=>$u){
  2940. if ($lo[0]==$m){
  2941. $executeList[$op]['date']=$u['date'];
  2942. $executeList[$op]['opinion']=$u['opinion'];
  2943. $executeList[$op]['status']=$u['status'];
  2944. break;
  2945. }
  2946. }
  2947. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2948. $button2=1;
  2949. $executeList[$op]['status']=4;
  2950. }
  2951. }
  2952. }
  2953. //检测编辑状态
  2954. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2955. $verifyList['staff']=$value['verifyBreakup'];
  2956. }else
  2957. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2958. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2959. $verifyStaff=json_decode($value['verifyStaff'],true);
  2960. Doo::loadModel('role');
  2961. $role=new role();
  2962. if ($verifyList==NULL)
  2963. $verifyList=array();
  2964. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2965. foreach ($verifyList as $k=>$v){
  2966. //init verifyStaff
  2967. if ($v[1]=='ROLE'){
  2968. if (!empty($verifyStaff)){
  2969. $endStaffArray=end($verifyStaff);
  2970. // if ($v[0]==$endStaffArray['nextStaff']){
  2971. // $roleId=$v[0];
  2972. // }
  2973. }
  2974. $roleVerify=json_decode($v[3],true);
  2975. $roleKey=$k;$roleArray=array();
  2976. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2977. foreach ($roleVerify as $o=>$p){
  2978. $staffID=explode ('_',$p);
  2979. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2980. //print_r($staffID);
  2981. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2982. array_push($roleArray, $exp);
  2983. }
  2984. $roleArrayCopy[$v[0]]=$roleArray;
  2985. //$verifyList[$k]['roleArray']=$roleArray;
  2986. }
  2987. $verifyList[$k]['date']="";
  2988. $verifyList[$k]['opinion']="";
  2989. $verifyList[$k]['status']="";
  2990. if (empty($verifyStaff)){
  2991. $verifyList[$k]['date']="";
  2992. $verifyList[$k]['opinion']="";
  2993. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2994. $verifyList[$k]['status']=4;
  2995. $flag=false;
  2996. }
  2997. }else{
  2998. foreach ($verifyStaff as $m=>$u){
  2999. if ($v[0]==$m){
  3000. $verifyList[$k]['date']=$u['date'];
  3001. $verifyList[$k]['opinion']=$u['opinion'];
  3002. $verifyList[$k]['status']=$u['status'];
  3003. $flag=false;
  3004. break;
  3005. }
  3006. }
  3007. $endStaffArray=end($verifyStaff);
  3008. if (isset($endStaffArray['ROLE'])){
  3009. }else{
  3010. // $endKey=key($verifyStaff);
  3011. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3012. // $button=4;
  3013. // $verifyList[$k]['status']=4;
  3014. // }
  3015. }
  3016. }
  3017. }
  3018. $rolename['name']='';
  3019. if (!empty($roleId)){
  3020. Doo::loadModel('role');
  3021. $role=new role();
  3022. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3023. }
  3024. if (!empty($verifyStaff))
  3025. $endStaffArray=end($verifyStaff);
  3026. $KOP=false;
  3027. foreach ($roleArrayCopy as $P=>$A){
  3028. foreach ( $A as $MKI=>$AVL){
  3029. if (!empty($verifyStaff)){
  3030. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3031. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3032. $button=4;
  3033. $roleArrayCopy[$P][$MKI]['status']=4;
  3034. }
  3035. foreach ($verifyStaff as $m=>$u){
  3036. $AVLFK=$AVL[0].'_R';
  3037. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3038. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3039. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3040. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3041. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3042. break;
  3043. }
  3044. }
  3045. }else{
  3046. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3047. $button=4;
  3048. $roleArrayCopy[$P][$MKI]['status']=4;
  3049. }
  3050. }
  3051. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3052. $KOP=true;
  3053. }
  3054. }
  3055. foreach ($roleArrayCopy as $k=>$v){
  3056. foreach ($verifyList as $m=>$n){
  3057. if ($n[0]==$k){
  3058. array_splice($verifyList,$m,1,$v);
  3059. }
  3060. }
  3061. }
  3062. $receiptList[$key]['verifyList']=$verifyList;
  3063. $receiptList[$key]['executeList']=$executeList;
  3064. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3065. $receiptList[$key]['button2']=$button2;
  3066. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3067. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3068. $relust=$value['sum']-$value['loanSum'];
  3069. $receiptList[$key]['relust']=$relust;
  3070. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3071. }
  3072. //print_r($receiptList[$key]['executeList']);
  3073. $data['receiptList']=$receiptList;
  3074. $data['memu']="receipt";
  3075. $data['staff']=$this->staff;
  3076. $data['receiptMemu']='implement';
  3077. $data['verifyId']=$this->verifyId;
  3078. $data['executeId']=$this->executeId;
  3079. $this->render ( "/admin/implement", $data );
  3080. }
  3081. function implementDo(){
  3082. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3083. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  3084. if (!empty($rid)){
  3085. Doo::loadModel('receipt');
  3086. $receipt=new receipt();
  3087. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  3088. $executeCopy=json_decode($rinfo['executeCopy'],true);
  3089. $executeStaff=json_decode($rinfo['executeStaff'],true);
  3090. if(empty($executeStaff)){
  3091. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3092. }else{
  3093. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3094. }
  3095. if (count($executeStaff)==count($executeCopy)){
  3096. $receipt->executeStaff=json_encode($executeStaff);
  3097. $receipt->status=8;
  3098. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3099. $receipt->status=9;
  3100. $receipt->executeDate= date("Y-m-d");
  3101. }else{
  3102. $receipt->executeStaff=json_encode($executeStaff);
  3103. }
  3104. $receipt->update(array('where'=>'rid='.$rid));
  3105. }
  3106. return "/implement";
  3107. }
  3108. function receiptburEdi(){
  3109. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3110. $status=isset($this->params['status'])?$this->params['status']:'';
  3111. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3112. $month=$this->get_args('month')?$this->get_args('month'):"";
  3113. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3114. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3115. if (empty($status))
  3116. $status=$this->get_args('status')?$this->get_args('status'):2;
  3117. $vidList=array();
  3118. $button=0;
  3119. Doo::loadModel('verify');
  3120. Doo::loadModel('receipt');
  3121. Doo::loadModel('staff');
  3122. $staff=new staff();
  3123. $receipt=new receipt();
  3124. $verify=new verify();
  3125. Doo::loadModel('L_category');
  3126. $Lcategory=new L_category();
  3127. Doo::loadModel('enclosur');
  3128. $enclosur=new enclosur();
  3129. Doo::loadModel('loanReceipt');
  3130. $loanReceipt=new loanReceipt();
  3131. //user verify ID
  3132. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3133. foreach ($verifyDetail as $key=>$value){
  3134. array_push($vidList, $value['vid']);
  3135. }
  3136. $vid=implode(",", $vidList);
  3137. if(empty($verifyDetail))
  3138. $vid=0;
  3139. $categoryList=$Lcategory->find(array('asArray'=>true));
  3140. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3141. $ap="";
  3142. if($status==4){
  3143. $ap=4;$status=2;
  3144. }
  3145. //get Receipt By verifyID status 2
  3146. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3147. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3148. $Locate=0;$roleId=0;$button=0;
  3149. foreach ($loanList as $key=>$value){
  3150. $loanList[$key]['Locate']=$Locate;$Locate++;
  3151. $loanList[$key]['reviseDetail']=array();
  3152. if (!empty($value['reviseDetail']))
  3153. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3154. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3155. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3156. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3157. $loanList[$key]['category']=$categoryDetil['title'];
  3158. //检测编辑状态
  3159. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3160. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3161. $verifyStaff=json_decode($value['verifyStaff'],true);
  3162. Doo::loadModel('role');
  3163. $role=new role();
  3164. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3165. foreach ($verifyList as $k=>$v){
  3166. //init verifyStaff
  3167. if ($v[1]=='ROLE'){
  3168. if (!empty($verifyStaff)){
  3169. $endStaffArray=end($verifyStaff);
  3170. }
  3171. $roleVerify=json_decode($v[3],true);
  3172. $roleKey=$k;$roleArray=array();
  3173. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3174. foreach ($roleVerify as $o=>$p){
  3175. $staffID=explode ('_',$p);
  3176. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3177. //print_r($staffID);
  3178. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3179. array_push($roleArray, $exp);
  3180. }
  3181. $roleArrayCopy[$v[0]]=$roleArray;
  3182. //$verifyList[$k]['roleArray']=$roleArray;
  3183. }
  3184. $verifyList[$k]['date']="";
  3185. $verifyList[$k]['opinion']="";
  3186. $verifyList[$k]['status']="";
  3187. if (empty($verifyStaff)){
  3188. $verifyList[$k]['date']="";
  3189. $verifyList[$k]['opinion']="";
  3190. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3191. $verifyList[$k]['status']=4;
  3192. $flag=false;
  3193. }
  3194. }else{
  3195. foreach ($verifyStaff as $m=>$u){
  3196. if ($v[0]==$m){
  3197. $verifyList[$k]['date']=$u['date'];
  3198. $verifyList[$k]['opinion']=$u['opinion'];
  3199. $verifyList[$k]['status']=$u['status'];
  3200. $flag=false;
  3201. break;
  3202. }
  3203. }
  3204. $endStaffArray=end($verifyStaff);
  3205. if (isset($endStaffArray['ROLE'])){
  3206. }else{
  3207. }
  3208. }
  3209. }
  3210. $rolename['name']='';
  3211. if (!empty($roleId)){
  3212. Doo::loadModel('role');
  3213. $role=new role();
  3214. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3215. }
  3216. if (!empty($verifyStaff))
  3217. $endStaffArray=end($verifyStaff);
  3218. $KOP=false;
  3219. foreach ($roleArrayCopy as $P=>$A){
  3220. foreach ( $A as $MKI=>$AVL){
  3221. if (!empty($verifyStaff)){
  3222. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3223. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3224. $button=4;
  3225. $roleArrayCopy[$P][$MKI]['status']=4;
  3226. }
  3227. foreach ($verifyStaff as $m=>$u){
  3228. $AVLFK=$AVL[0].'_R';
  3229. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3230. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3231. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3232. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3233. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3234. break;
  3235. }
  3236. }
  3237. }else{
  3238. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3239. $button=4;
  3240. $roleArrayCopy[$P][$MKI]['status']=4;
  3241. }
  3242. }
  3243. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3244. $KOP=true;
  3245. }
  3246. }
  3247. foreach ($roleArrayCopy as $k=>$v){
  3248. foreach ($verifyList as $m=>$n){
  3249. if ($n[0]==$k){
  3250. array_splice($verifyList,$m,1,$v);
  3251. }
  3252. }
  3253. }
  3254. $loanList[$key]['verifyList']=$verifyList;
  3255. }
  3256. $htmlLoan='';
  3257. if (isset($loanList[0])){
  3258. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3259. if ($value['status']==1)
  3260. $htmlLoan.='<li class="done" >';
  3261. elseif ($value['status']==3)
  3262. $htmlLoan.='<li class="undone" >';
  3263. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3264. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3265. if (isset($value['rolename']))
  3266. $htmlLoan.=$value['rolename'];
  3267. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3268. }
  3269. $data['loanDate']=$loanList[0]['date'];
  3270. }
  3271. $data['htmlLoan']=$htmlLoan;
  3272. //print_r($loanList);
  3273. $Locate=0;$roleId=0;$button=0;
  3274. if($ap==4)
  3275. $status=4;
  3276. foreach ($receiptList as $key=>$value){
  3277. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3278. $receiptList[$key]['reviseDetail']=array();
  3279. if (!empty($value['reviseDetail']))
  3280. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3281. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3282. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3283. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3284. $receiptList[$key]['category']=$categoryDetil['title'];
  3285. //检测编辑状态
  3286. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3287. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3288. $verifyStaff=json_decode($value['verifyStaff'],true);
  3289. Doo::loadModel('role');
  3290. $role=new role();
  3291. //print_r($verifyList);
  3292. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3293. foreach ($verifyList as $k=>$v){
  3294. //init verifyStaff
  3295. if ($v[1]=='ROLE'){
  3296. if (!empty($verifyStaff)){
  3297. $endStaffArray=end($verifyStaff);
  3298. if ($v[0]==$endStaffArray['nextStaff']){
  3299. $roleId=$v[0];
  3300. }
  3301. }
  3302. $roleVerify=json_decode($v[3],true);
  3303. $roleKey=$k;$roleArray=array();
  3304. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3305. foreach ($roleVerify as $o=>$p){
  3306. $staffID=explode ('_',$p);
  3307. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3308. //print_r($staffID);
  3309. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3310. array_push($roleArray, $exp);
  3311. }
  3312. $roleArrayCopy[$v[0]]=$roleArray;
  3313. //$verifyList[$k]['roleArray']=$roleArray;
  3314. }
  3315. //print_r($roleArray);
  3316. $verifyList[$k]['date']="";
  3317. $verifyList[$k]['opinion']="";
  3318. $verifyList[$k]['status']="";
  3319. if (empty($verifyStaff)){
  3320. $verifyList[$k]['date']="";
  3321. $verifyList[$k]['opinion']="";
  3322. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3323. $verifyList[$k]['status']=4;
  3324. $button=4;$flag=false;
  3325. }
  3326. }else{
  3327. foreach ($verifyStaff as $m=>$u){
  3328. if ($v[0]==$m){
  3329. $verifyList[$k]['date']=$u['date'];
  3330. $verifyList[$k]['opinion']=$u['opinion'];
  3331. $verifyList[$k]['status']=$u['status'];
  3332. $flag=false;
  3333. break;
  3334. }
  3335. }
  3336. $endStaffArray=end($verifyStaff);
  3337. if (isset($endStaffArray['ROLE'])){
  3338. }else{
  3339. $endKey=key($verifyStaff);
  3340. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3341. $button=4;
  3342. $verifyList[$k]['status']=4;
  3343. }
  3344. }
  3345. }
  3346. }
  3347. $rolename['name']='';
  3348. if (!empty($roleId)){
  3349. Doo::loadModel('role');
  3350. $role=new role();
  3351. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3352. }
  3353. if (!empty($verifyStaff))
  3354. $endStaffArray=end($verifyStaff);
  3355. $KOP=false;
  3356. foreach ($roleArrayCopy as $P=>$A){
  3357. foreach ( $A as $MKI=>$AVL){
  3358. if (!empty($verifyStaff)){
  3359. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3360. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3361. $button=4;
  3362. $roleArrayCopy[$P][$MKI]['status']=4;
  3363. }
  3364. foreach ($verifyStaff as $m=>$u){
  3365. $AVLFK=$AVL[0].'_R';
  3366. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3367. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3368. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3369. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3370. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3371. break;
  3372. }
  3373. }
  3374. }else{
  3375. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3376. $button=4;
  3377. $roleArrayCopy[$P][$MKI]['status']=4;
  3378. }
  3379. }
  3380. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3381. $KOP=true;
  3382. }
  3383. }
  3384. foreach ($roleArrayCopy as $k=>$v){
  3385. foreach ($verifyList as $m=>$n){
  3386. if ($n[0]==$k){
  3387. array_splice($verifyList,$m,1,$v);
  3388. }
  3389. }
  3390. }
  3391. //print_r($verifyList);
  3392. $receiptList[$key]['verifyList']=$verifyList;
  3393. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3394. $receiptList[$key]['button']=$button;
  3395. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3396. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3397. $relust=$value['sum']-$value['loanSum'];
  3398. $receiptList[$key]['relust']=$relust;
  3399. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3400. }
  3401. //print_r($receiptList);die;
  3402. //$data['verifyDetail']=$verifyDetail;
  3403. $mothHtml="";
  3404. for($i=1;$i<=12;$i++){
  3405. if($month==$i)
  3406. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3407. else
  3408. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3409. }
  3410. //获取审批日志
  3411. Doo::loadModel('receiptLog');
  3412. $receiptLog=new receiptLog();
  3413. $rlList=array();
  3414. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3415. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3416. if (!empty($rlInfo)){
  3417. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3418. }
  3419. //echo $rid;
  3420. //print_r($receiptList);
  3421. $receiptList[0]['rlList']=$rlList;
  3422. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3423. $enclosurHtml='';
  3424. foreach ($enclosurList as $value){
  3425. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3426. }
  3427. $data['enclosurHtml']=$enclosurHtml;
  3428. $data['rolename']=$rolename['name'];
  3429. // $data['datetij']=$tijdate['date'];
  3430. $data['mothHtml']=$mothHtml;
  3431. //print_r($receiptList);
  3432. $data['rid']=$rid;
  3433. $data['tijdate']=$tijdate['date'];
  3434. $data['receiptList']=$receiptList;
  3435. $data['receiptApprovalCount']=count($receiptList);
  3436. $data['status']=$status;
  3437. $data['year']=$year;
  3438. $data['categoryList']=$categoryList;
  3439. $data['staffList']=$staffList;
  3440. $data['cid']=$cid;
  3441. $data['sid']=$sid;
  3442. $data['ap']=$ap;
  3443. $data['memu']="receipt";
  3444. $data['staff']=$this->staff;
  3445. $data['receiptMemu']='approvalExpenses';
  3446. $data['verifyId']=$this->verifyId;
  3447. $data['executeId']=$this->executeId;
  3448. $this->render ( "/admin/receiptburEdi", $data );
  3449. }
  3450. function hisImplement(){
  3451. $item=isset($this->params['item'])?$this->params['item']:"";
  3452. if(empty($item))
  3453. $item=$this->get_args('item')?$this->get_args('item'):"";
  3454. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3455. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3456. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3457. $sop=$this->get_args('sop')?$this->get_args('sop'):'SOP';
  3458. Doo::loadModel('receipt');
  3459. $receipt=new receipt();
  3460. Doo::loadModel('L_category');
  3461. $Lcategory=new L_category();
  3462. Doo::loadModel('verify');
  3463. Doo::loadModel('statistics');
  3464. $statistics=new statistics();
  3465. $verify=new verify();
  3466. Doo::loadModel('staff');
  3467. $staff=new staff();
  3468. $condition="";
  3469. if($item=="expenses")
  3470. $condition=" and Rtype=1 ";
  3471. elseif ($item=="receipts")
  3472. $condition=" and Rtype=0 ";
  3473. elseif ($item=="remits")
  3474. $condition=" and Rtype=2 ";
  3475. $sopString="";
  3476. $dateCondition=" and Year(executeDate) =".$year;
  3477. if($moth!='MONTH'){
  3478. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3479. }
  3480. if($day!='DAY')
  3481. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3482. if ($sop!='SOP')
  3483. $sopString=" and staff=".$sop;
  3484. //$noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3485. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition.$sopString,'desc'=>'rid','asArray'=>true));
  3486. //员工筛选
  3487. $receiptList2=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3488. $sopStaff=array();
  3489. foreach ($receiptList2 as $key=>$value){
  3490. $staffDetail=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3491. $sopStaff[$value['staff']]=$staffDetail['username'];
  3492. }
  3493. $Locate=0;$roleId=0;$button=0;
  3494. foreach ($receiptList as $key=>$value){
  3495. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3496. $receiptList[$key]['reviseDetail']=array();
  3497. if (!empty($value['reviseDetail']))
  3498. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3499. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3500. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3501. $receiptList[$key]['category']=$categoryDetil['title'];
  3502. //检测编辑状态
  3503. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3504. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3505. $verifyStaff=json_decode($value['verifyStaff'],true);
  3506. Doo::loadModel('role');
  3507. $role=new role();
  3508. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3509. foreach ($verifyList as $k=>$v){
  3510. //init verifyStaff
  3511. if ($v[1]=='ROLE'){
  3512. if (!empty($verifyStaff)){
  3513. $endStaffArray=end($verifyStaff);
  3514. }
  3515. $roleVerify=json_decode($v[3],true);
  3516. $roleKey=$k;$roleArray=array();
  3517. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3518. foreach ($roleVerify as $o=>$p){
  3519. $staffID=explode ('_',$p);
  3520. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3521. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3522. array_push($roleArray, $exp);
  3523. }
  3524. $roleArrayCopy[$v[0]]=$roleArray;
  3525. }
  3526. $verifyList[$k]['date']="";
  3527. $verifyList[$k]['opinion']="";
  3528. $verifyList[$k]['status']="";
  3529. if (empty($verifyStaff)){
  3530. $verifyList[$k]['date']="";
  3531. $verifyList[$k]['opinion']="";
  3532. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3533. $verifyList[$k]['status']=4;
  3534. $flag=false;
  3535. }
  3536. }else{
  3537. foreach ($verifyStaff as $m=>$u){
  3538. if ($v[0]==$m){
  3539. $verifyList[$k]['date']=$u['date'];
  3540. $verifyList[$k]['opinion']=$u['opinion'];
  3541. $verifyList[$k]['status']=$u['status'];
  3542. $flag=false;
  3543. break;
  3544. }
  3545. }
  3546. $endStaffArray=end($verifyStaff);
  3547. }
  3548. }
  3549. $rolename['name']='';
  3550. if (!empty($roleId)){
  3551. Doo::loadModel('role');
  3552. $role=new role();
  3553. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3554. }
  3555. if (!empty($verifyStaff))
  3556. $endStaffArray=end($verifyStaff);
  3557. $KOP=false;
  3558. foreach ($roleArrayCopy as $P=>$A){
  3559. foreach ( $A as $MKI=>$AVL){
  3560. if (!empty($verifyStaff)){
  3561. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3562. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3563. $button=4;
  3564. $roleArrayCopy[$P][$MKI]['status']=4;
  3565. }
  3566. foreach ($verifyStaff as $m=>$u){
  3567. $AVLFK=$AVL[0].'_R';
  3568. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3569. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3570. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3571. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3572. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3573. break;
  3574. }
  3575. }
  3576. }else{
  3577. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3578. $button=4;
  3579. $roleArrayCopy[$P][$MKI]['status']=4;
  3580. }
  3581. }
  3582. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3583. $KOP=true;
  3584. }
  3585. }
  3586. foreach ($roleArrayCopy as $k=>$v){
  3587. foreach ($verifyList as $m=>$n){
  3588. if ($n[0]==$k){
  3589. array_splice($verifyList,$m,1,$v);
  3590. }
  3591. }
  3592. }
  3593. $receiptList[$key]['verifyList']=$verifyList;
  3594. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3595. $receiptList[$key]['button']=$button;
  3596. }
  3597. //print_r($sopStaff);
  3598. $mothHtml="";
  3599. for($i=1;$i<=12;$i++){
  3600. if($moth==$i)
  3601. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3602. else
  3603. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3604. }
  3605. $dayHtml="";
  3606. if ($day!="DAY"||$moth!="MONTH"){
  3607. for($i = 1; $i <= 31; $i ++) {
  3608. if($day==$i)
  3609. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3610. else
  3611. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3612. }
  3613. }
  3614. $sopHtml="";
  3615. foreach ($sopStaff as $key=>$value){
  3616. if($sop==$key)
  3617. $sopHtml.='<option value="'.$key.'" selected >'.$value.'</option>';
  3618. else
  3619. $sopHtml.='<option value="'.$key.'" >'.$value.'</option>';
  3620. }
  3621. $data['sopHtml']=$sopHtml;
  3622. $data['dayHtml']=$dayHtml;
  3623. $data['mothHtml']=$mothHtml;
  3624. $data['receiptList']=$receiptList;
  3625. $data['memu']="receipt";
  3626. $data['staff']=$this->staff;
  3627. $data['receiptMemu']='implement';
  3628. $data['verifyId']=$this->verifyId;
  3629. $data['executeId']=$this->executeId;
  3630. $data['item']=$item;
  3631. $data['year']=$year;
  3632. $data['moth']=$moth;
  3633. $data['day']=$day;
  3634. $data['sop']=$sop;
  3635. $this->render ( "/admin/hisImplement", $data );
  3636. }
  3637. function ajaxExamine(){
  3638. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3639. Doo::loadModel('receipt');
  3640. $receipt=new receipt();
  3641. if (!empty($rid)){
  3642. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) and rid!='.$rid
  3643. ,'asArray'=>true));
  3644. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3645. }
  3646. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3647. }
  3648. /*
  3649. * 废弃
  3650. */
  3651. function myReceipt(){
  3652. //all approval past withdraw
  3653. $item=isset($this->params['item'])?$this->params['item']:"";
  3654. if(empty($item))
  3655. $item=$this->get_args('item')?$this->get_args('item'):"";
  3656. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3657. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3658. Doo::loadModel('receipt');
  3659. $receipt=new receipt();
  3660. //pre-loaded
  3661. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3662. //have cache
  3663. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3664. if(!empty($moth))//yearPage
  3665. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3666. $this->showCache($path);
  3667. }
  3668. Doo::loadModel('L_category');
  3669. $Lcategory=new L_category();
  3670. Doo::loadModel('verify');
  3671. Doo::loadModel('statistics');
  3672. $statistics=new statistics();
  3673. $verify=new verify();
  3674. Doo::loadModel('staff');
  3675. $staff=new staff();
  3676. $condition=" and status!=0 ";
  3677. if($item=="approval")
  3678. $condition=" and status=2 ";
  3679. elseif ($item=="withdraw")
  3680. $condition=" and status=3 ";
  3681. elseif ($item=="past")
  3682. $condition=" and status=1 ";
  3683. elseif ($item=="whdw")
  3684. $condition=" and status=4 ";
  3685. $dateCondition=" and Year(date) =".$year;
  3686. if(!empty($moth)){
  3687. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3688. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3689. }else
  3690. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3691. if(empty($stList))
  3692. $stList=array('rePrice'=>0,'agPrice'=>0);
  3693. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3694. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3695. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3696. $Locate=0;$roleId=0;$button=0;
  3697. foreach ($receiptList as $key=>$value){
  3698. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3699. $receiptList[$key]['reviseDetail']=array();
  3700. if (!empty($value['reviseDetail']))
  3701. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3702. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3703. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3704. $receiptList[$key]['category']=$categoryDetil['title'];
  3705. //检测编辑状态
  3706. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3707. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3708. $verifyStaff=json_decode($value['verifyStaff'],true);
  3709. Doo::loadModel('role');
  3710. $role=new role();
  3711. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3712. foreach ($verifyList as $k=>$v){
  3713. //init verifyStaff
  3714. if ($v[1]=='ROLE'){
  3715. if (!empty($verifyStaff)){
  3716. $endStaffArray=end($verifyStaff);
  3717. // if ($v[0]==$endStaffArray['nextStaff']){
  3718. // $roleId=$v[0];
  3719. // }
  3720. }
  3721. $roleVerify=json_decode($v[3],true);
  3722. $roleKey=$k;$roleArray=array();
  3723. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3724. foreach ($roleVerify as $o=>$p){
  3725. $staffID=explode ('_',$p);
  3726. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3727. //print_r($staffID);
  3728. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3729. array_push($roleArray, $exp);
  3730. }
  3731. $roleArrayCopy[$v[0]]=$roleArray;
  3732. //$verifyList[$k]['roleArray']=$roleArray;
  3733. }
  3734. $verifyList[$k]['date']="";
  3735. $verifyList[$k]['opinion']="";
  3736. $verifyList[$k]['status']="";
  3737. if (empty($verifyStaff)){
  3738. $verifyList[$k]['date']="";
  3739. $verifyList[$k]['opinion']="";
  3740. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3741. $verifyList[$k]['status']=4;
  3742. $flag=false;
  3743. }
  3744. }else{
  3745. foreach ($verifyStaff as $m=>$u){
  3746. if ($v[0]==$m){
  3747. $verifyList[$k]['date']=$u['date'];
  3748. $verifyList[$k]['opinion']=$u['opinion'];
  3749. $verifyList[$k]['status']=$u['status'];
  3750. $flag=false;
  3751. break;
  3752. }
  3753. }
  3754. $endStaffArray=end($verifyStaff);
  3755. if (isset($endStaffArray['ROLE'])){
  3756. }else{
  3757. // $endKey=key($verifyStaff);
  3758. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3759. // $button=4;
  3760. // $verifyList[$k]['status']=4;
  3761. // }
  3762. }
  3763. }
  3764. }
  3765. $rolename['name']='';
  3766. if (!empty($roleId)){
  3767. Doo::loadModel('role');
  3768. $role=new role();
  3769. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3770. }
  3771. if (!empty($verifyStaff))
  3772. $endStaffArray=end($verifyStaff);
  3773. $KOP=false;
  3774. foreach ($roleArrayCopy as $P=>$A){
  3775. foreach ( $A as $MKI=>$AVL){
  3776. if (!empty($verifyStaff)){
  3777. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3778. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3779. $button=4;
  3780. $roleArrayCopy[$P][$MKI]['status']=4;
  3781. }
  3782. foreach ($verifyStaff as $m=>$u){
  3783. $AVLFK=$AVL[0].'_R';
  3784. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3785. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3786. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3787. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3788. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3789. break;
  3790. }
  3791. }
  3792. }else{
  3793. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3794. $button=4;
  3795. $roleArrayCopy[$P][$MKI]['status']=4;
  3796. }
  3797. }
  3798. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3799. $KOP=true;
  3800. }
  3801. }
  3802. foreach ($roleArrayCopy as $k=>$v){
  3803. foreach ($verifyList as $m=>$n){
  3804. if ($n[0]==$k){
  3805. array_splice($verifyList,$m,1,$v);
  3806. }
  3807. }
  3808. }
  3809. $receiptList[$key]['verifyList']=$verifyList;
  3810. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3811. $receiptList[$key]['button']=$button;
  3812. }
  3813. //print_r($receiptList);die;
  3814. $mothHtml="";
  3815. for($i=1;$i<=12;$i++){
  3816. if($moth==$i)
  3817. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3818. else
  3819. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3820. }
  3821. $data['mothHtml']=$mothHtml;
  3822. $data['receiptList']=$receiptList;
  3823. $data['memu']="receipt";
  3824. $data['staff']=$this->staff;
  3825. $data['receiptMemu']='receipt';
  3826. $data['verifyId']=$this->verifyId;
  3827. $data['executeId']=$this->executeId;
  3828. $data['item']=$item;
  3829. $data['year']=$year;
  3830. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3831. //sufficient condition to generate cache
  3832. if(empty($moth)&&($year<date("Y"))){
  3833. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3834. if(empty($receiptList)){ //generated files
  3835. ob_start();
  3836. $this->render ( "/admin/saea_myList", $data );
  3837. $this->cacheFile($path);die;
  3838. // $content = ob_get_contents();
  3839. // $fp = fopen($path, "w");
  3840. // fwrite($fp, $content);
  3841. // fclose($fp);
  3842. }
  3843. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3844. $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));
  3845. if(empty($receiptList)){ //generated files
  3846. ob_start();
  3847. $this->render ( "/admin/saea_myList", $data );
  3848. $this->cacheFile($path);die;
  3849. }
  3850. }
  3851. }
  3852. $this->render ( "/admin/saea_myList", $data );
  3853. }
  3854. function saeaCreate(){
  3855. Doo::loadModel('accountItem');
  3856. Doo::loadModel('verify');
  3857. Doo::loadModel('receipt');
  3858. Doo::loadModel('L_category');
  3859. $lCategory=new L_category();
  3860. $receipt=new receipt();
  3861. $verify=new verify();
  3862. $accountItem=new accountItem();
  3863. Doo::loadModel("role");
  3864. $role=new role();
  3865. $acItem=$accountItem->find(array('asArray'=>true));
  3866. $veList=$verify->find(array('asArray'=>true));
  3867. foreach ($veList as $key=>$value){
  3868. $v=json_decode($value['staff']);
  3869. $list=array();
  3870. foreach ($v as $n=>$m){
  3871. if ($m['1']=='ROLE'){
  3872. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3873. $v[$n][1]=$roleInfo['name'];
  3874. array_push($list, $roleInfo['name']);
  3875. }else{
  3876. array_push($list, $v[$n][1]);
  3877. }
  3878. }
  3879. $veList[$key]['staff']=implode('>', $list);
  3880. }
  3881. $data['category']=$lCategory->find(array('asArray'=>true));
  3882. $data['veList']=$veList;
  3883. $data['acItem']=$acItem;
  3884. $data['memu']="receipt";
  3885. $data['staff']=$this->staff;
  3886. $data['receiptMemu']='saeaBorad';
  3887. $data['verifyId']=$this->verifyId;
  3888. $data['executeId']=$this->executeId;
  3889. $this->render ( "/admin/saea_create", $data );
  3890. }
  3891. function addReceipt(){
  3892. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3893. $agency=$this->get_args('agency');
  3894. $travel=$this->get_args('travel');
  3895. $train=$this->get_args('train');
  3896. $other=$this->get_args('other');
  3897. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3898. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3899. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3900. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3901. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3902. Doo::loadModel('receipt');
  3903. Doo::loadModel('receiptDetail');
  3904. Doo::loadModel('accountItem');
  3905. $accountItem=new accountItem();
  3906. $receipt=new receipt();
  3907. Doo::loadModel('enclosur');
  3908. Doo::loadModel('execute');
  3909. $execute=new execute();
  3910. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3911. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3912. // if(!empty($receiptDetail))
  3913. // return "/referReceipt/".$receiptDetail['rid'];
  3914. $aItem=$accountItem->find(array('asArray'=>true));
  3915. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3916. $ag=$tr=$ta=$ot=0;
  3917. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3918. foreach ($aItem as $key=>$value){
  3919. if ($value['category']==$this->AGENCY){
  3920. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3921. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3922. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3923. }
  3924. $ag++;
  3925. }
  3926. if($value['category']==$this->TRAVEL){
  3927. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3928. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3929. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3930. }
  3931. $tr++;
  3932. }
  3933. if($value['category']==$this->TRAIN){
  3934. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3935. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3936. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3937. }
  3938. $ta++;
  3939. }
  3940. if($value['category']==$this->OTHER){
  3941. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3942. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3943. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3944. }
  3945. $ot++;
  3946. }
  3947. }
  3948. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3949. //报销单
  3950. $receipt->accountItem=json_encode($accountJson);
  3951. $receipt->staff=$this->staff[0]['sid'];
  3952. $receipt->sum=number_format($sum, 2, '.', '');
  3953. $receipt->date=date("Y-m-d");
  3954. $receipt->cid=$cid;
  3955. $receipt->status=5;
  3956. //修改审批流程加入角色
  3957. $receipt->verify=$verify;
  3958. $receipt->executeCopy=$executeDetail['staff'];
  3959. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3960. $receipt->explanation=$explanation;
  3961. $rid=$receipt->insert();
  3962. //附件
  3963. if (!empty($enclosurName)){
  3964. $enclosurArray=explode('-', $enclosurName);
  3965. foreach ($enclosurArray as $value){
  3966. $enclosur=new enclosur();
  3967. $enclosur->name=$value;
  3968. $enclosur->rid=$rid;
  3969. $enclosur->insert();
  3970. }
  3971. //print_r($enclosurArray);die;
  3972. }
  3973. //报销详情
  3974. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3975. $receiptDetail=new receiptDetail();
  3976. $receiptDetail->staff=$this->staff[0]['sid'];
  3977. $receiptDetail->item=$value['name'];
  3978. $receiptDetail->itemCategory=$this->AGENCY;
  3979. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3980. $receiptDetail->date=date("Y-m-d");
  3981. $receiptDetail->cid=$cid;
  3982. $receiptDetail->rid=$rid;
  3983. $receiptDetail->status=4;
  3984. $receiptDetail->insert();
  3985. }
  3986. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3987. $receiptDetail=new receiptDetail();
  3988. $receiptDetail->staff=$this->staff[0]['sid'];
  3989. $receiptDetail->item=$value['name'];
  3990. $receiptDetail->itemCategory=$this->TRAVEL;
  3991. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3992. $receiptDetail->date=date("Y-m-d");
  3993. $receiptDetail->cid=$cid;
  3994. $receiptDetail->rid=$rid;
  3995. $receiptDetail->status=4;
  3996. $receiptDetail->insert();
  3997. }
  3998. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3999. $receiptDetail=new receiptDetail();
  4000. $receiptDetail->staff=$this->staff[0]['sid'];
  4001. $receiptDetail->item=$value['name'];
  4002. $receiptDetail->itemCategory=$this->TRAIN;
  4003. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4004. $receiptDetail->date=date("Y-m-d");
  4005. $receiptDetail->cid=$cid;
  4006. $receiptDetail->rid=$rid;
  4007. $receiptDetail->status=4;
  4008. $receiptDetail->insert();
  4009. }
  4010. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4011. $receiptDetail=new receiptDetail();
  4012. $receiptDetail->staff=$this->staff[0]['sid'];
  4013. $receiptDetail->item=$value['name'];
  4014. $receiptDetail->itemCategory=$this->OTHER;
  4015. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4016. $receiptDetail->date=date("Y-m-d");
  4017. $receiptDetail->cid=$cid;
  4018. $receiptDetail->rid=$rid;
  4019. $receiptDetail->status=4;
  4020. $receiptDetail->insert();
  4021. }
  4022. //return "/referReceipt/".$rid;
  4023. }
  4024. return "/saeaBorad";
  4025. }
  4026. function referReceipt(){
  4027. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4028. Doo::loadModel('receipt');
  4029. Doo::loadModel('verify');
  4030. $verify=new verify();
  4031. $receipt=new receipt();
  4032. Doo::loadModel('L_category');
  4033. $lCategory=new L_category();
  4034. Doo::loadModel("role");
  4035. $role=new role();
  4036. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  4037. if(empty($receiptDetail))
  4038. return "/addReceipt";
  4039. foreach ($receiptDetail as $key=>$value){
  4040. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  4041. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4042. $v=json_decode($veList['staff']);
  4043. array_push($v[0], $veList['description']);
  4044. foreach ($v as $n=>$m){
  4045. if ($m['1']=='ROLE'){
  4046. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4047. $v[$n][1]=$roleInfo['name'];
  4048. }
  4049. }
  4050. $receiptDetail[$key]['staff']=$v;
  4051. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4052. $receiptDetail[$key]['category']=$category['title'];
  4053. }
  4054. //print_r($receiptDetail);
  4055. $data['receiptDetail']=$receiptDetail;
  4056. $data['memu']="receipt";
  4057. $data['staff']=$this->staff;
  4058. $data['receiptMemu']='saeaCreate';
  4059. $data['verifyId']=$this->verifyId;
  4060. $data['executeId']=$this->executeId;
  4061. $this->render ( "/admin/saea_confirm", $data );
  4062. }
  4063. function editReceipt(){
  4064. //edit status 4
  4065. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4066. //echo $rid;
  4067. Doo::loadModel('accountItem');
  4068. Doo::loadModel('verify');
  4069. Doo::loadModel('receipt');
  4070. $receipt=new receipt();
  4071. $verify=new verify();
  4072. $accountItem=new accountItem();
  4073. Doo::loadModel('L_category');
  4074. $lCategory=new L_category();
  4075. Doo::loadModel("role");
  4076. $role=new role();
  4077. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  4078. if(empty($receiptDetail))
  4079. return "/saeaCreate";
  4080. $acItem=$accountItem->find(array('asArray'=>true));
  4081. $veList=$verify->find(array('asArray'=>true));
  4082. foreach ($veList as $key=>$value){
  4083. $v=json_decode($value['staff']);
  4084. $list=array();
  4085. foreach ($v as $n=>$m){
  4086. if ($m['1']=='ROLE'){
  4087. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4088. $v[$n][1]=$roleInfo['name'];
  4089. array_push($list, $roleInfo['name']);
  4090. }else{
  4091. array_push($list, $v[$n][1]);
  4092. }
  4093. }
  4094. $veList[$key]['staff']=implode('>', $list);
  4095. }
  4096. //配置编辑信息
  4097. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4098. foreach ($acItem as $key=>$value){
  4099. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4100. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4101. $acItem[$key]['price']=$v['price'];
  4102. }
  4103. }
  4104. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4105. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4106. $acItem[$key]['price']=$v['price'];
  4107. }
  4108. }
  4109. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4110. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4111. $acItem[$key]['price']=$v['price'];
  4112. }
  4113. }
  4114. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4115. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4116. $acItem[$key]['price']=$v['price'];
  4117. }
  4118. }
  4119. }
  4120. $data['category']=$lCategory->find(array('asArray'=>true));
  4121. $data['cSum']=$accountItemList['cSum'];
  4122. $data['sum']=$receiptDetail['sum'];
  4123. $data['receiptDetail']=$receiptDetail;
  4124. $data['veList']=$veList;
  4125. $data['acItem']=$acItem;
  4126. $data['memu']="receipt";
  4127. $data['staff']=$this->staff;
  4128. $data['receiptMemu']='saeaBorad';
  4129. $data['verify']=$receiptDetail['verify'];
  4130. $data['verifyId']=$this->verifyId;
  4131. $data['executeId']=$this->executeId;
  4132. $data['rid']=$rid;
  4133. $this->render ( "/admin/saea_edit", $data );
  4134. }
  4135. function updateReceipt(){
  4136. $agency=$this->get_args('agency');
  4137. $travel=$this->get_args('travel');
  4138. $train=$this->get_args('train');
  4139. $other=$this->get_args('other');
  4140. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4141. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4142. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4143. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4144. if(!empty($explanation)){
  4145. Doo::loadModel('receipt');
  4146. Doo::loadModel('receiptDetail');
  4147. Doo::loadModel('accountItem');
  4148. $accountItem=new accountItem();
  4149. $receipt=new receipt();
  4150. Doo::loadModel('execute');
  4151. $execute=new execute();
  4152. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4153. if(empty($receiptDetail))
  4154. return "/saeaBorad";
  4155. if ($receiptDetail['Rtype']==1)
  4156. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4157. else
  4158. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4159. $aItem=$accountItem->find(array('asArray'=>true));
  4160. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4161. $ag=$tr=$ta=$ot=0;
  4162. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4163. foreach ($aItem as $key=>$value){
  4164. if ($value['category']==$this->AGENCY){
  4165. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4166. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4167. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4168. }
  4169. $ag++;
  4170. }
  4171. if($value['category']==$this->TRAVEL){
  4172. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4173. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4174. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4175. }
  4176. $tr++;
  4177. }
  4178. if($value['category']==$this->TRAIN){
  4179. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4180. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4181. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4182. }
  4183. $ta++;
  4184. }
  4185. if($value['category']==$this->OTHER){
  4186. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4187. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4188. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4189. }
  4190. $ot++;
  4191. }
  4192. }
  4193. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4194. //报销单
  4195. $rid=$receipt->rid=$receiptDetail['rid'];
  4196. $receipt->accountItem=json_encode($accountJson);
  4197. $receipt->staff=$this->staff[0]['sid'];
  4198. $receipt->sum=number_format($sum, 2, '.', '');
  4199. $receipt->date=date("Y-m-d");
  4200. $receipt->cid=$cid;
  4201. if (($receiptDetail['status']!=4)){
  4202. if ($receiptDetail['Rtype']==1)
  4203. $receipt->status=7;
  4204. else
  4205. $receipt->status=5;
  4206. }
  4207. if ($receiptDetail!=4&&!empty($verify))
  4208. $receipt->verify=$verify;
  4209. $receipt->executeCopy=$executeDetail['staff'];
  4210. $receipt->explanation=$explanation;
  4211. $receipt->update();
  4212. $receiptDetail=new receiptDetail();
  4213. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4214. //报销详情
  4215. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4216. $receiptDetail=new receiptDetail();
  4217. $receiptDetail->staff=$this->staff[0]['sid'];
  4218. $receiptDetail->item=$value['name'];
  4219. $receiptDetail->itemCategory=$this->AGENCY;
  4220. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4221. $receiptDetail->date=date("Y-m-d");
  4222. $receiptDetail->cid=$cid;
  4223. $receiptDetail->rid=$rid;
  4224. $receiptDetail->status=4;
  4225. $receiptDetail->insert();
  4226. }
  4227. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4228. $receiptDetail=new receiptDetail();
  4229. $receiptDetail->staff=$this->staff[0]['sid'];
  4230. $receiptDetail->item=$value['name'];
  4231. $receiptDetail->itemCategory=$this->TRAVEL;
  4232. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4233. $receiptDetail->date=date("Y-m-d");
  4234. $receiptDetail->cid=$cid;
  4235. $receiptDetail->rid=$rid;
  4236. $receiptDetail->status=4;
  4237. $receiptDetail->insert();
  4238. }
  4239. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4240. $receiptDetail=new receiptDetail();
  4241. $receiptDetail->staff=$this->staff[0]['sid'];
  4242. $receiptDetail->item=$value['name'];
  4243. $receiptDetail->itemCategory=$this->TRAIN;
  4244. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4245. $receiptDetail->date=date("Y-m-d");
  4246. $receiptDetail->cid=$cid;
  4247. $receiptDetail->rid=$rid;
  4248. $receiptDetail->status=4;
  4249. $receiptDetail->insert();
  4250. }
  4251. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4252. $receiptDetail=new receiptDetail();
  4253. $receiptDetail->staff=$this->staff[0]['sid'];
  4254. $receiptDetail->item=$value['name'];
  4255. $receiptDetail->itemCategory=$this->OTHER;
  4256. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4257. $receiptDetail->date=date("Y-m-d");
  4258. $receiptDetail->cid=$cid;
  4259. $receiptDetail->rid=$rid;
  4260. $receiptDetail->status=4;
  4261. $receiptDetail->insert();
  4262. }
  4263. //return "/referReceipt/".$rid;
  4264. }
  4265. return "/saeaBorad";
  4266. }
  4267. function approvedReceipt(){
  4268. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4269. Doo::loadModel('receipt');
  4270. Doo::loadModel('receiptDetail');
  4271. $receipt=new receipt();
  4272. $receiptDetail=new receiptDetail();
  4273. Doo::loadModel('statistics');
  4274. Doo::loadModel('itemStatistics');
  4275. $statistics=new statistics();
  4276. $itemStatistics=new itemStatistics();
  4277. Doo::loadModel("verify");
  4278. $verify=new verify();
  4279. //审批状态的判定
  4280. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4281. if(empty($receiptDetailList))
  4282. return "/saeaBorad";
  4283. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4284. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4285. if (empty($receiptDetailList['nowStaff'])){
  4286. $nowStaff="";$nowStaffList=array();
  4287. if ($verifyDetail[0][1]=='ROLE'){
  4288. $vStaffString=json_decode($verifyDetail[0][3]);
  4289. foreach ($vStaffString as $key=>$value){
  4290. $staffK=explode("_", $value);
  4291. array_push($nowStaffList, $staffK[0]);
  4292. }
  4293. $nowStaff=implode(',', $nowStaffList);
  4294. }else{
  4295. $nowStaff=$verifyDetail[0][0];
  4296. }
  4297. $receipt->nowStaff=$nowStaff;
  4298. }
  4299. // echo $nowStaff;
  4300. // print_r($verifyDetail);die;
  4301. $receipt->rid=$receiptDetailList['rid'];
  4302. $receipt->date=date("Y-m-d");
  4303. $receipt->status=2;
  4304. $receipt->update();
  4305. $receiptDetail->status=2;
  4306. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4307. Doo::loadModel("receiptLog");
  4308. $receiptLog=new receiptLog();
  4309. Doo::loadModel("verify");
  4310. $verify=new verify();
  4311. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4312. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4313. $jd=json_decode($vr['staff']);$roleId=0;
  4314. foreach ($jd as $key=>$value){
  4315. if ($value[1]=='ROLE'){
  4316. $pos = strpos($value[3], $this->staff[0]['sid']);
  4317. if ($pos !== false) {
  4318. $roleId=$value[0];
  4319. }
  4320. }
  4321. }
  4322. //审批日志
  4323. //echo $roleId;die;
  4324. if (!empty($roleId)){
  4325. Doo::loadModel("role");
  4326. $role=new role();
  4327. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4328. $receiptLog->rolename=$roleInfo['name'];
  4329. }
  4330. $receiptLog->username=$this->staff[0]['username'];
  4331. $receiptLog->uid=$this->staff[0]['sid'];
  4332. $receiptLog->date=date("Y-m-d");
  4333. $receiptLog->opinion='提交审批';
  4334. $receiptLog->img=$this->staff[0]['avatar'];
  4335. $receiptLog->status=2;
  4336. $receiptLog->rid=$rid;
  4337. $receiptLog->insert();
  4338. //statistics item
  4339. $dateArray=explode("-", $receiptDetailList['date']);
  4340. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4341. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4342. //print_r($accountItem['cSum']['agencySum']);die;
  4343. // foreach ($accountItem['cSum'] as $key=>$value){
  4344. // if($key=="agencySum"){
  4345. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4346. // if(empty($iStatistics)){
  4347. // $itemStatistics->cid=$this->staff[0]['cid'];
  4348. // $itemStatistics->staff=$this->staff[0]['sid'];
  4349. // $itemStatistics->price=$value;
  4350. // $itemStatistics->itemCategory=$this->AGENCY;
  4351. // $itemStatistics->date=date("Y-m-d");
  4352. // $itemStatistics->insert();
  4353. // }else{
  4354. // if (!empty($value)){
  4355. // $itemStatistics->price=$value+$iStatistics['price'];
  4356. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4357. // }
  4358. // }
  4359. // }elseif($key=="travelSum"){
  4360. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4361. // if(empty($iStatistics)){
  4362. // $itemStatistics->cid=$this->staff[0]['cid'];
  4363. // $itemStatistics->staff=$this->staff[0]['sid'];
  4364. // $itemStatistics->price=$value;
  4365. // $itemStatistics->itemCategory=$this->TRAVEL;
  4366. // $itemStatistics->date=date("Y-m-d");
  4367. // $itemStatistics->insert();
  4368. // }else{
  4369. // if (!empty($value)){
  4370. // $itemStatistics->price=$value+$iStatistics['price'];
  4371. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4372. // }
  4373. // }
  4374. // }elseif($key=="trainSum"){
  4375. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4376. // if(empty($iStatistics)){
  4377. // $itemStatistics->cid=$this->staff[0]['cid'];
  4378. // $itemStatistics->staff=$this->staff[0]['sid'];
  4379. // $itemStatistics->price=$value;
  4380. // $itemStatistics->itemCategory=$this->TRAIN;
  4381. // $itemStatistics->date=date("Y-m-d");
  4382. // $itemStatistics->insert();
  4383. // }else{
  4384. // if (!empty($value)){
  4385. // $itemStatistics->price=$value+$iStatistics['price'];
  4386. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4387. // }
  4388. // }
  4389. // }elseif($key=="otherSum"){
  4390. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4391. // if(empty($iStatistics)){
  4392. // $itemStatistics->cid=$this->staff[0]['cid'];
  4393. // $itemStatistics->staff=$this->staff[0]['sid'];
  4394. // $itemStatistics->price=$value;
  4395. // $itemStatistics->itemCategory=$this->OTHER;
  4396. // $itemStatistics->date=date("Y-m-d");
  4397. // $itemStatistics->insert();
  4398. // }else{
  4399. // if (!empty($value)){
  4400. // $itemStatistics->price=$value+$iStatistics['price'];
  4401. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4402. // }
  4403. // }
  4404. // }
  4405. // }
  4406. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4407. if(empty($stat)){
  4408. $statistics->date=date("Y-m-d");
  4409. $statistics->cid=$this->staff[0]['cid'];
  4410. $statistics->staff=$this->staff[0]['sid'];
  4411. $statistics->agPrice=0;
  4412. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4413. $statistics->insert();
  4414. }else{
  4415. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4416. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4417. }
  4418. return "/expenses";
  4419. }
  4420. function approval(){
  4421. $status=isset($this->params['status'])?$this->params['status']:'';
  4422. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4423. $month=$this->get_args('month')?$this->get_args('month'):"";
  4424. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4425. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4426. if (empty($status))
  4427. $status=$this->get_args('status')?$this->get_args('status'):2;
  4428. $vidList=array();
  4429. $button=0;
  4430. Doo::loadModel('verify');
  4431. $verify=new verify();
  4432. Doo::loadModel('receipt');
  4433. $receipt=new receipt();
  4434. Doo::loadModel('staff');
  4435. $staff=new staff();
  4436. Doo::loadModel('L_category');
  4437. $Lcategory=new L_category();
  4438. //user verify ID
  4439. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4440. foreach ($verifyDetail as $key=>$value){
  4441. array_push($vidList, $value['vid']);
  4442. }
  4443. $vid=implode(",", $vidList);
  4444. if(empty($verifyDetail))
  4445. $vid=0;
  4446. /*
  4447. */
  4448. $dateCondition=" and Year(date) =".$year;
  4449. if(!empty($month))
  4450. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4451. $categoryList=$Lcategory->find(array('asArray'=>true));
  4452. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4453. $cateCondition="";$staffCondition="";$approvalCondition="";
  4454. if (!empty($cid))
  4455. $cateCondition=' and cid='.$cid;
  4456. if(!empty($sid)){
  4457. $staffCondition=' and staff='.$sid;
  4458. $cateCondition="";
  4459. }
  4460. // elseif($status==1){
  4461. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4462. // }
  4463. if($status==2){
  4464. //查找角色审批人
  4465. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4466. }
  4467. $ap="";
  4468. if($status==4){
  4469. $ap=4;$status=2;
  4470. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4471. }
  4472. if($status==5){
  4473. $status=4;$ap=5;
  4474. }
  4475. //echo $vid;
  4476. //get Receipt By verifyID status 2 .$approvalCondition
  4477. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4478. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4479. ,'desc'=>'rid','asArray'=>true));
  4480. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4481. $Locate=0;
  4482. if($ap==4)
  4483. $status=4;
  4484. elseif ($ap==5)
  4485. $status=5;
  4486. foreach ($receiptList as $key=>$value){
  4487. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4488. $receiptList[$key]['reviseDetail']=array();
  4489. if (!empty($value['reviseDetail']))
  4490. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4491. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4492. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4493. $receiptList[$key]['category']=$categoryDetil['title'];
  4494. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4495. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4496. $verifyStaff=json_decode($value['verifyStaff'],true);
  4497. foreach ($verifyList as $k=>$v){
  4498. //init verifyStaff
  4499. $verifyList[$k]['date']="";
  4500. $verifyList[$k]['opinion']="";
  4501. $verifyList[$k]['status']="";
  4502. if (empty($verifyStaff)){
  4503. $verifyList[$k]['date']="";
  4504. $verifyList[$k]['opinion']="";
  4505. if ($v[0]==$this->staff[0]['sid']){
  4506. $verifyList[$k]['status']=4;
  4507. $button=4;
  4508. }
  4509. }else{
  4510. $flag=true;
  4511. foreach ($verifyStaff as $m=>$u){
  4512. if ($v[0]==$m){
  4513. $verifyList[$k]['date']=$u['date'];
  4514. $verifyList[$k]['opinion']=$u['opinion'];
  4515. $verifyList[$k]['status']=$u['status'];
  4516. $flag=false;
  4517. break;
  4518. }
  4519. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4520. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4521. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4522. }
  4523. if($flag){//检测可编辑
  4524. if($v[0]==$this->staff[0]['sid']){
  4525. $verifyList[$k]['status']=4;$button=4;
  4526. }
  4527. }
  4528. }
  4529. }
  4530. $receiptList[$key]['verifyList']=$verifyList;
  4531. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4532. $receiptList[$key]['button']=$button;
  4533. }
  4534. //print_r($receiptList);die;
  4535. //$data['verifyDetail']=$verifyDetail;
  4536. $mothHtml="";
  4537. for($i=1;$i<=12;$i++){
  4538. if($month==$i)
  4539. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4540. else
  4541. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4542. }
  4543. $data['mothHtml']=$mothHtml;
  4544. $data['receiptList']=$receiptList;
  4545. $data['receiptApprovalCount']=count($receiptList);
  4546. $data['status']=$status;
  4547. $data['year']=$year;
  4548. $data['categoryList']=$categoryList;
  4549. $data['staffList']=$staffList;
  4550. $data['cid']=$cid;
  4551. $data['sid']=$sid;
  4552. $data['ap']=$ap;
  4553. $data['memu']="receipt";
  4554. $data['staff']=$this->staff;
  4555. $data['receiptMemu']='approval';
  4556. $data['verifyId']=$this->verifyId;
  4557. $data['executeId']=$this->executeId;
  4558. $this->render ( "/admin/saea_reportList", $data );
  4559. }
  4560. function approvalDetails(){
  4561. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4562. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4563. $month=$this->get_args('month')?$this->get_args('month'):"";
  4564. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4565. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4566. Doo::loadModel('verify');
  4567. $verify=new verify();
  4568. Doo::loadModel('receipt');
  4569. $receipt=new receipt();
  4570. Doo::loadModel('staff');
  4571. $staff=new staff();
  4572. Doo::loadModel('L_category');
  4573. $Lcategory=new L_category();
  4574. Doo::loadModel('enclosur');
  4575. $enclosur=new enclosur();
  4576. $vidList=array();
  4577. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4578. foreach ($verifyDetail as $key=>$value){
  4579. array_push($vidList, $value['vid']);
  4580. }
  4581. $vid=implode(",", $vidList);
  4582. if(empty($verifyDetail))
  4583. $vid=0;
  4584. $categoryList=$Lcategory->find(array('asArray'=>true));
  4585. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4586. $ap=0;
  4587. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4588. $Locate=0;$roleId=0;$button=0;
  4589. foreach ($receiptList as $key=>$value){
  4590. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4591. $receiptList[$key]['reviseDetail']=array();
  4592. if (!empty($value['reviseDetail']))
  4593. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4594. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4595. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4596. $receiptList[$key]['category']=$categoryDetil['title'];
  4597. //检测编辑状态
  4598. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4599. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4600. $verifyStaff=json_decode($value['verifyStaff'],true);
  4601. Doo::loadModel('role');
  4602. $role=new role();
  4603. //print_r($verifyList);
  4604. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4605. foreach ($verifyList as $k=>$v){
  4606. //init verifyStaff
  4607. if ($v[1]=='ROLE'){
  4608. if (!empty($verifyStaff)){
  4609. $endStaffArray=end($verifyStaff);
  4610. if ($v[0]==$endStaffArray['nextStaff']){
  4611. $roleId=$v[0];
  4612. }
  4613. }
  4614. $roleVerify=json_decode($v[3],true);
  4615. $roleKey=$k;$roleArray=array();
  4616. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4617. foreach ($roleVerify as $o=>$p){
  4618. $staffID=explode ('_',$p);
  4619. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4620. //print_r($staffID);
  4621. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4622. array_push($roleArray, $exp);
  4623. }
  4624. $roleArrayCopy[$v[0]]=$roleArray;
  4625. //$verifyList[$k]['roleArray']=$roleArray;
  4626. }
  4627. //print_r($roleArray);
  4628. $verifyList[$k]['date']="";
  4629. $verifyList[$k]['opinion']="";
  4630. $verifyList[$k]['status']="";
  4631. if (empty($verifyStaff)){
  4632. $verifyList[$k]['date']="";
  4633. $verifyList[$k]['opinion']="";
  4634. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4635. $verifyList[$k]['status']=4;
  4636. $button=4;$flag=false;
  4637. }
  4638. }else{
  4639. foreach ($verifyStaff as $m=>$u){
  4640. if ($v[0]==$m){
  4641. $verifyList[$k]['date']=$u['date'];
  4642. $verifyList[$k]['opinion']=$u['opinion'];
  4643. $verifyList[$k]['status']=$u['status'];
  4644. $flag=false;
  4645. break;
  4646. }
  4647. }
  4648. $endStaffArray=end($verifyStaff);
  4649. if (isset($endStaffArray['ROLE'])){
  4650. }else{
  4651. $endKey=key($verifyStaff);
  4652. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4653. $button=4;
  4654. $verifyList[$k]['status']=4;
  4655. }
  4656. }
  4657. }
  4658. }
  4659. $rolename['name']='';
  4660. if (!empty($roleId)){
  4661. Doo::loadModel('role');
  4662. $role=new role();
  4663. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4664. }
  4665. if (!empty($verifyStaff))
  4666. $endStaffArray=end($verifyStaff);
  4667. $KOP=false;
  4668. foreach ($roleArrayCopy as $P=>$A){
  4669. foreach ( $A as $MKI=>$AVL){
  4670. if (!empty($verifyStaff)){
  4671. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4672. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4673. $button=4;
  4674. $roleArrayCopy[$P][$MKI]['status']=4;
  4675. }
  4676. foreach ($verifyStaff as $m=>$u){
  4677. $AVLFK=$AVL[0].'_R';
  4678. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4679. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4680. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4681. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4682. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4683. break;
  4684. }
  4685. }
  4686. }else{
  4687. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4688. $button=4;
  4689. $roleArrayCopy[$P][$MKI]['status']=4;
  4690. }
  4691. }
  4692. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4693. $KOP=true;
  4694. }
  4695. }
  4696. foreach ($roleArrayCopy as $k=>$v){
  4697. foreach ($verifyList as $m=>$n){
  4698. if ($n[0]==$k){
  4699. array_splice($verifyList,$m,1,$v);
  4700. }
  4701. }
  4702. }
  4703. $receiptList[$key]['verifyList']=$verifyList;
  4704. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4705. $receiptList[$key]['button']=$button;
  4706. }
  4707. $mothHtml="";
  4708. for($i=1;$i<=12;$i++){
  4709. if($month==$i)
  4710. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4711. else
  4712. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4713. }
  4714. //获取审批日志
  4715. Doo::loadModel('receiptLog');
  4716. $receiptLog=new receiptLog();
  4717. $rlList=array();
  4718. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4719. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4720. if (!empty($rlInfo)){
  4721. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4722. }
  4723. $receiptList[0]['rlList']=$rlList;
  4724. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4725. $enclosurHtml='';
  4726. foreach ($enclosurList as $value){
  4727. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4728. }
  4729. $data['enclosurHtml']=$enclosurHtml;
  4730. $data['rolename']=$rolename['name'];
  4731. $data['datetij']=$tijdate['date'];
  4732. $data['mothHtml']=$mothHtml;
  4733. $data['receiptList']=$receiptList;
  4734. $data['receiptApprovalCount']=count($receiptList);
  4735. $data['year']=$year;
  4736. $data['categoryList']=$categoryList;
  4737. $data['staffList']=$staffList;
  4738. $data['cid']=$cid;
  4739. $data['sid']=$sid;
  4740. $data['status']=0;
  4741. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4742. $ap=4;
  4743. }else
  4744. $data['status']=$receiptList[0]['status'];
  4745. if ($receiptList[0]['status']==4){
  4746. $data['status']=5;
  4747. $ap=0;
  4748. }
  4749. $data['ap']=$ap;
  4750. $data['memu']="receipt";
  4751. $data['staff']=$this->staff;
  4752. $data['receiptMemu']='approval';
  4753. $data['verifyId']=$this->verifyId;
  4754. $data['executeId']=$this->executeId;
  4755. $this->render ( "/admin/saeaReportListReport", $data );
  4756. }
  4757. function approvalEdi(){
  4758. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4759. $status=isset($this->params['status'])?$this->params['status']:'';
  4760. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4761. $month=$this->get_args('month')?$this->get_args('month'):"";
  4762. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4763. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4764. if (empty($status))
  4765. $status=$this->get_args('status')?$this->get_args('status'):2;
  4766. $vidList=array();
  4767. $button=0;
  4768. Doo::loadModel('verify');
  4769. Doo::loadModel('receipt');
  4770. Doo::loadModel('staff');
  4771. $staff=new staff();
  4772. $receipt=new receipt();
  4773. $verify=new verify();
  4774. Doo::loadModel('L_category');
  4775. $Lcategory=new L_category();
  4776. Doo::loadModel('enclosur');
  4777. $enclosur=new enclosur();
  4778. //user verify ID
  4779. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4780. foreach ($verifyDetail as $key=>$value){
  4781. array_push($vidList, $value['vid']);
  4782. }
  4783. $vid=implode(",", $vidList);
  4784. if(empty($verifyDetail))
  4785. $vid=0;
  4786. $categoryList=$Lcategory->find(array('asArray'=>true));
  4787. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4788. $ap="";
  4789. if($status==4){
  4790. $ap=4;$status=2;
  4791. }
  4792. //get Receipt By verifyID status 2
  4793. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4794. $Locate=0;$roleId=0;
  4795. if($ap==4)
  4796. $status=4;
  4797. foreach ($receiptList as $key=>$value){
  4798. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4799. $receiptList[$key]['reviseDetail']=array();
  4800. if (!empty($value['reviseDetail']))
  4801. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4802. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4803. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4804. $receiptList[$key]['category']=$categoryDetil['title'];
  4805. //检测编辑状态
  4806. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4807. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4808. $verifyStaff=json_decode($value['verifyStaff'],true);
  4809. // print_r($verifyList);
  4810. //
  4811. // if (empty($verifyStaff)){
  4812. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4813. // $verifyList[0]['status']=4;$button=4;
  4814. // }
  4815. //
  4816. // }else{
  4817. //
  4818. // }
  4819. // die;
  4820. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4821. // echo array_search("green",$a);
  4822. //
  4823. Doo::loadModel('role');
  4824. $role=new role();
  4825. //print_r($verifyList);
  4826. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4827. foreach ($verifyList as $k=>$v){
  4828. //init verifyStaff
  4829. if ($v[1]=='ROLE'){
  4830. if (!empty($verifyStaff)){
  4831. $endStaffArray=end($verifyStaff);
  4832. if ($v[0]==$endStaffArray['nextStaff']){
  4833. $roleId=$v[0];
  4834. }
  4835. }
  4836. $roleVerify=json_decode($v[3],true);
  4837. $roleKey=$k;$roleArray=array();
  4838. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4839. foreach ($roleVerify as $o=>$p){
  4840. $staffID=explode ('_',$p);
  4841. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4842. //print_r($staffID);
  4843. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4844. array_push($roleArray, $exp);
  4845. }
  4846. $roleArrayCopy[$v[0]]=$roleArray;
  4847. //$verifyList[$k]['roleArray']=$roleArray;
  4848. }
  4849. //print_r($roleArray);
  4850. $verifyList[$k]['date']="";
  4851. $verifyList[$k]['opinion']="";
  4852. $verifyList[$k]['status']="";
  4853. if (empty($verifyStaff)){
  4854. $verifyList[$k]['date']="";
  4855. $verifyList[$k]['opinion']="";
  4856. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4857. $verifyList[$k]['status']=4;
  4858. $button=4;$flag=false;
  4859. }
  4860. }else{
  4861. foreach ($verifyStaff as $m=>$u){
  4862. if ($v[0]==$m){
  4863. $verifyList[$k]['date']=$u['date'];
  4864. $verifyList[$k]['opinion']=$u['opinion'];
  4865. $verifyList[$k]['status']=$u['status'];
  4866. $flag=false;
  4867. break;
  4868. }
  4869. }
  4870. $endStaffArray=end($verifyStaff);
  4871. if (isset($endStaffArray['ROLE'])){
  4872. }else{
  4873. $endKey=key($verifyStaff);
  4874. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4875. $button=4;
  4876. $verifyList[$k]['status']=4;
  4877. }
  4878. }
  4879. //print_r($endStaffArray);die;
  4880. // if (empty($verifyStaff)){
  4881. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4882. // $verifyList[$k]['status']=4;$button=4;
  4883. // }
  4884. //
  4885. // }else{
  4886. //
  4887. // }
  4888. // if($flag){//检测可编辑
  4889. // if($v[0]==$this->staff[0]['sid']){
  4890. // $verifyList[$k]['status']=4;$button=4;
  4891. // }
  4892. // }
  4893. }
  4894. }
  4895. $rolename['name']='';
  4896. if (!empty($roleId)){
  4897. Doo::loadModel('role');
  4898. $role=new role();
  4899. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4900. }
  4901. if (!empty($verifyStaff))
  4902. $endStaffArray=end($verifyStaff);
  4903. $KOP=false;
  4904. foreach ($roleArrayCopy as $P=>$A){
  4905. foreach ( $A as $MKI=>$AVL){
  4906. if (!empty($verifyStaff)){
  4907. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4908. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4909. $button=4;
  4910. $roleArrayCopy[$P][$MKI]['status']=4;
  4911. }
  4912. foreach ($verifyStaff as $m=>$u){
  4913. $AVLFK=$AVL[0].'_R';
  4914. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4915. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4916. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4917. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4918. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4919. break;
  4920. }
  4921. }
  4922. }else{
  4923. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4924. $button=4;
  4925. $roleArrayCopy[$P][$MKI]['status']=4;
  4926. }
  4927. }
  4928. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4929. $KOP=true;
  4930. }
  4931. }
  4932. // print_r($roleArrayCopy);
  4933. // echo $roleKey;
  4934. foreach ($roleArrayCopy as $k=>$v){
  4935. foreach ($verifyList as $m=>$n){
  4936. if ($n[0]==$k){
  4937. array_splice($verifyList,$m,1,$v);
  4938. }
  4939. }
  4940. }
  4941. // if ($KOP)
  4942. // array_splice($verifyList,$roleKey,1,$roleArray);
  4943. //print_r($verifyList);
  4944. $receiptList[$key]['verifyList']=$verifyList;
  4945. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4946. $receiptList[$key]['button']=$button;
  4947. }
  4948. //$data['verifyDetail']=$verifyDetail;
  4949. $mothHtml="";
  4950. for($i=1;$i<=12;$i++){
  4951. if($month==$i)
  4952. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4953. else
  4954. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4955. }
  4956. //获取审批日志
  4957. Doo::loadModel('receiptLog');
  4958. $receiptLog=new receiptLog();
  4959. $rlList=array();
  4960. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4961. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4962. if (!empty($rlInfo)){
  4963. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4964. }
  4965. $receiptList[0]['rlList']=$rlList;
  4966. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4967. $enclosurHtml='';
  4968. foreach ($enclosurList as $value){
  4969. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4970. }
  4971. $data['enclosurHtml']=$enclosurHtml;
  4972. $data['rolename']=$rolename['name'];
  4973. $data['datetij']=$tijdate['date'];
  4974. $data['mothHtml']=$mothHtml;
  4975. $data['receiptList']=$receiptList;
  4976. $data['receiptApprovalCount']=count($receiptList);
  4977. $data['status']=$status;
  4978. $data['year']=$year;
  4979. $data['categoryList']=$categoryList;
  4980. $data['staffList']=$staffList;
  4981. $data['cid']=$cid;
  4982. $data['sid']=$sid;
  4983. $data['ap']=$ap;
  4984. $data['memu']="receipt";
  4985. $data['staff']=$this->staff;
  4986. $data['receiptMemu']='approval';
  4987. $data['verifyId']=$this->verifyId;
  4988. $data['executeId']=$this->executeId;
  4989. $this->render ( "/admin/saeaReportListReport", $data );
  4990. }
  4991. function remittance(){
  4992. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4993. $month=$this->get_args('month')?$this->get_args('month'):"";
  4994. Doo::loadModel('receipt');
  4995. $receipt=new receipt();
  4996. Doo::loadModel('staff');
  4997. $staff=new staff();
  4998. $dateCondition=" and Year(pastDate) =".$year;
  4999. if(!empty($month))
  5000. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  5001. //get Receipt By verifyID status 1
  5002. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  5003. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  5004. $dataList=array();
  5005. foreach ($dateList as $d=>$a){
  5006. $dataList[$a['pastDate']]=array();$daySum=0;
  5007. foreach ($receiptList as $key=>$value){
  5008. if($a['pastDate']==$value['pastDate']){
  5009. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  5010. $list=array();$html="";
  5011. foreach ($oderList as $v){
  5012. array_push($list, $v['receiptOrder']);
  5013. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  5014. }
  5015. $receiptList[$key]['receiptOrder']=$html;
  5016. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  5017. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  5018. $receiptList[$key]['username']=$sinfo['username'];
  5019. $daySum+=$value['sum'];
  5020. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  5021. }
  5022. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  5023. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  5024. }
  5025. }
  5026. //print_r($dataList);
  5027. $data['dataList']=$dataList;
  5028. $mothHtml="";
  5029. for($i=1;$i<=12;$i++){
  5030. if($month==$i)
  5031. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  5032. else
  5033. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  5034. }
  5035. $data['year']=$year;
  5036. $data['mothHtml']=$mothHtml;
  5037. $data['memu']="receipt";
  5038. $data['staff']=$this->staff;
  5039. $data['receiptMemu']='approval';
  5040. $data['verifyId']=$this->verifyId;
  5041. $data['executeId']=$this->executeId;
  5042. $this->render ( "/admin/saeaReportListPay", $data );
  5043. }
  5044. function revocationAdjustment(){
  5045. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  5046. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  5047. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5048. //echo $price;die;
  5049. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  5050. Doo::loadModel('receipt');
  5051. $receipt=new receipt();
  5052. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5053. if (empty($receiptDetail['reviseDetail']))
  5054. return "/approval";
  5055. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5056. $RD=array();
  5057. foreach ($reviseDetail as $key=>$value){
  5058. if ($value['price']==$price&&$value['sid']==$sid)
  5059. continue;
  5060. array_push($RD, $value);
  5061. }
  5062. $reviseDetailString=json_encode($RD);
  5063. $receipt->reviseDetail=$reviseDetailString;
  5064. $receipt->sum=$receiptDetail['sum']-$price;
  5065. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  5066. $receipt->update(array('where'=>'rid='.$rid));
  5067. }
  5068. //approvalEdi/37
  5069. return "/approvalEdi/".$rid;
  5070. }
  5071. function updateApprovalReceipt(){
  5072. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5073. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  5074. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5075. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  5076. if(!empty($rid)){
  5077. Doo::loadModel("verify");
  5078. $verify=new verify();
  5079. Doo::loadModel("receiptDetail");
  5080. $receiptDetailObj=new receiptDetail();
  5081. Doo::loadModel("itemStatistics");
  5082. Doo::loadModel("statistics");
  5083. $statistics=new statistics();
  5084. $itemStatistics=new itemStatistics();
  5085. Doo::loadModel("receipt");
  5086. $receipt=new receipt();
  5087. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5088. if (empty($receiptDetail))
  5089. return "/approval";
  5090. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  5091. $verifyString=$verifyDetail['staff'];
  5092. $verifyDetail=json_decode($verifyDetail['staff'],true);
  5093. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  5094. if(empty($opinion)){
  5095. if ($status==3)
  5096. $opinion="终止";
  5097. else
  5098. $opinion="同意支付";
  5099. }
  5100. $nowStaff=0;$nowStaffList=array();
  5101. if(empty($verifyStaff)){
  5102. //还需加入是否已经进入角色审批
  5103. if ($verifyDetail[0][1]=='ROLE'){
  5104. $vStaffString=json_decode($verifyDetail[0][3]);
  5105. foreach ($vStaffString as $key=>$value){
  5106. $staffK=explode("_", $value);
  5107. if ($staffK[0]!=$this->staff[0]['sid'])
  5108. array_push($nowStaffList, $staffK[0]);
  5109. }
  5110. //print_r($verifyDetail);
  5111. //die;
  5112. if (!empty($nowStaffList)){
  5113. $nowStaff=implode(',', $nowStaffList);
  5114. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5115. }else{
  5116. $nowStaff=$verifyDetail[1][0];
  5117. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5118. }
  5119. }else{
  5120. if ($verifyDetail[1][1]=='ROLE'){
  5121. $vStaffString=json_decode($verifyDetail[1][3]);
  5122. //echo "dd";
  5123. foreach ($vStaffString as $key=>$value){
  5124. $staffK=explode("_", $value);
  5125. array_push($nowStaffList, $staffK[0]);
  5126. }
  5127. $nowStaff=implode(',', $nowStaffList);
  5128. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5129. }else{
  5130. $nowStaff=$verifyDetail[1][0];
  5131. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5132. }
  5133. }
  5134. if($status==3)
  5135. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5136. $vStaffString=json_encode($verifyStaff);
  5137. $receipt->nowStaff=$nowStaff;
  5138. $receipt->verifyStaff=$vStaffString;
  5139. }else{
  5140. $VS=end($verifyStaff);
  5141. //非角色审批
  5142. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5143. $nextStaff=0;$roleSTF=false;
  5144. foreach ($verifyDetail as $key=>$value){
  5145. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5146. if (isset($verifyDetail[$key+1])){
  5147. $nextStaff=$verifyDetail[$key+1][0];
  5148. if ($verifyDetail[$key+1][1]=='ROLE')
  5149. $roleSTF=true;
  5150. }
  5151. break;
  5152. }
  5153. }
  5154. if (!$roleSTF){
  5155. $nowStaff=$nextStaff;
  5156. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5157. }else{
  5158. //获取角色下的所有用户ID
  5159. $nowStaffList=array();
  5160. foreach ($verifyDetail as $vfk){
  5161. if ($vfk[1]=='ROLE'){
  5162. $vStaffString=json_decode($vfk[3]);
  5163. foreach ($vStaffString as $key=>$value){
  5164. $staffK=explode("_", $value);
  5165. array_push($nowStaffList, $staffK[0]);
  5166. }
  5167. }
  5168. }
  5169. $nowStaff=implode(',', $nowStaffList);
  5170. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5171. }
  5172. if($status==3){
  5173. $verifyStaff['final']=$status;
  5174. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5175. }
  5176. $vStaffString=json_encode($verifyStaff);
  5177. $receipt->nowStaff=$nowStaff;
  5178. $receipt->verifyStaff=$vStaffString;
  5179. }
  5180. //角色审批
  5181. if (isset($VS['ROLE'])){
  5182. //找出角色人 当前审批角色组
  5183. $verifyJSStaff=array();$nowStaffList2=array();
  5184. foreach ($verifyDetail as $key=>$value){
  5185. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5186. $verifyJSStaff=json_decode($value[3]);
  5187. foreach ($verifyJSStaff as $m){
  5188. $staffK=explode("_", $m);
  5189. array_push($nowStaffList2, $staffK[0]);
  5190. }
  5191. // print_r($nowStaffList2);
  5192. }
  5193. }
  5194. $RoleVerifyStaff=array();
  5195. foreach ($verifyStaff as $key=>$value){
  5196. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5197. foreach ($nowStaffList2 as $m) {
  5198. if ($key==$m."_R")
  5199. $RoleVerifyStaff[$key]=$value;
  5200. }
  5201. }
  5202. }
  5203. // print_r($verifyStaff);
  5204. // print_r($nowStaffList2);
  5205. // print_r($RoleVerifyStaff);
  5206. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5207. //print_r($verifyJSStaff);
  5208. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5209. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5210. //下一个审批人ID
  5211. $nextStaff=0;$falg=false;
  5212. foreach ($verifyDetail as $key=>$value){
  5213. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5214. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5215. $falg=true;
  5216. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5217. foreach ($vStaffString as $v){
  5218. $staffK=explode("_", $v);
  5219. array_push($nowStaffList, $staffK[0]);
  5220. }
  5221. $nowStaff=implode(',', $nowStaffList);
  5222. $nextStaff=$verifyDetail[$key+1][0];
  5223. }elseif(isset($verifyDetail[$key+1])){
  5224. $nextStaff=$verifyDetail[$key+1][0];
  5225. $nowStaff=$nextStaff;
  5226. }else
  5227. $nowStaff='';
  5228. break;
  5229. }
  5230. }
  5231. if ($falg)
  5232. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5233. else
  5234. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5235. // print_r($verifyStaff);
  5236. // echo $nowStaff;die;
  5237. }else{ //进入下一个角色或者审批人
  5238. /*
  5239. */
  5240. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5241. //
  5242. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5243. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5244. // print_r($verifyStaff);
  5245. // die;
  5246. }
  5247. if($status==3){
  5248. $verifyStaff['final']=$status;
  5249. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5250. }
  5251. $vStaffString=json_encode($verifyStaff);
  5252. $receipt->verifyStaff=$vStaffString;
  5253. $receipt->nowStaff=$nowStaff;
  5254. //die;
  5255. //}
  5256. // print_r($verifyStaff);
  5257. // die;
  5258. }
  5259. //print_r($verifyStaff);die;
  5260. }
  5261. //print_r($verifyDetail);
  5262. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5263. foreach ($verifyDetail as $k=>$v){
  5264. if ($v[1]=='ROLE'){
  5265. $roleId=$v[0];
  5266. $roleVerify=json_decode($v[3],true);
  5267. $roleKey=$k;$roleArray=array();
  5268. foreach ($roleVerify as $o=>$p){
  5269. $staffID=explode ('_',$p);
  5270. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5271. array_push($roleArray, $exp);
  5272. }
  5273. $verifyDetailCopy[$v[0]]=$roleArray;
  5274. }
  5275. }
  5276. //print_r($verifyDetail);
  5277. foreach ($verifyDetailCopy as $k=>$v){
  5278. foreach ($verifyDetail as $m=>$n){
  5279. if ($n[0]==$k){
  5280. array_splice($verifyDetail,$m,1,$v);
  5281. }
  5282. }
  5283. }
  5284. // die;
  5285. // if (!empty($roleArray))
  5286. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5287. // echo $roleId;
  5288. // print_r($verifyStaff);
  5289. // print_r($verifyDetail);
  5290. // die;
  5291. Doo::loadModel("receiptLog");
  5292. $receiptLog=new receiptLog();
  5293. //审批日志
  5294. if (!isset($verifyStaff['final'])){
  5295. if (!empty($roleId)){
  5296. Doo::loadModel("role");
  5297. $role=new role();
  5298. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5299. $receiptLog->rolename=$roleInfo['name'];
  5300. }
  5301. $receiptLog->username=$this->staff[0]['username'];
  5302. $receiptLog->uid=$this->staff[0]['sid'];
  5303. $receiptLog->date=date("Y-m-d");
  5304. $receiptLog->opinion=$opinion;
  5305. $receiptLog->img=$this->staff[0]['avatar'];
  5306. $receiptLog->status=1;
  5307. $receiptLog->rid=$rid;
  5308. $receiptLog->insert();
  5309. }
  5310. if (isset($verifyStaff['final'])){//rDetail
  5311. $receipt->verifyBreakup=$verifyString;
  5312. $receipt->status=3;
  5313. $receiptDetailObj->status=3;
  5314. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5315. if (!empty($roleId)){
  5316. Doo::loadModel("role");
  5317. $role=new role();
  5318. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5319. $receiptLog->rolename=$roleInfo['name'];
  5320. }
  5321. $receiptLog->username=$this->staff[0]['username'];
  5322. $receiptLog->uid=$this->staff[0]['sid'];
  5323. $receiptLog->date=date("Y-m-d");
  5324. $receiptLog->opinion=$opinion;
  5325. $receiptLog->img=$this->staff[0]['avatar'];
  5326. $receiptLog->status=3;
  5327. $receiptLog->rid=$rid;
  5328. $receiptLog->insert();
  5329. //微信企业号通知
  5330. $receipt2 = new receipt();
  5331. $receiptDetail2 = $receipt2->getOne(array('where'=>'rid="'.$rid.'"','asArray'=>true));
  5332. if(!empty($receiptDetail2)){
  5333. Doo::loadModel('staff');
  5334. $staff = new staff();
  5335. $staffmsg = $staff->getStaffBySid($receiptDetail2['staff']);
  5336. if(!empty($staffmsg['wxid'])){
  5337. require_once (SITE_PATH . '/protected/class/client.php');
  5338. $client = new client ('http://m.cld.smartcost.com.cn/');
  5339. $user = $staffmsg['wxid'];
  5340. $receiptName = '';
  5341. switch($receiptDetail['Rtype']){
  5342. case 0:$receiptName = '报销';break;
  5343. case 1:$receiptName = '借款';break;
  5344. case 2:$receiptName = '对公汇款';break;
  5345. }
  5346. $msg = '很遗憾,您的'.$receiptName.' '.$receiptDetail2['receiptOrder'].',¥'.$receiptDetail2['sum'].',已被终止。';
  5347. $result = $client->SendMsg($user,$msg,'text');
  5348. }
  5349. }
  5350. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5351. $receipt->status=1;$reviseSum=0;
  5352. $receipt->verifyBreakup=$verifyString;
  5353. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5354. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5355. foreach ($reviseDetail as $key=>$value){
  5356. $receiptDetailObj=new receiptDetail();
  5357. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5358. $receiptDetailObj->item=$value['description'];
  5359. $receiptDetailObj->itemCategory="报销金额调整";
  5360. $receiptDetailObj->price=$value['price'];
  5361. $receiptDetailObj->date=$receiptDetail['date'];
  5362. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5363. $receiptDetailObj->rid=$rid;
  5364. $receiptDetailObj->status=1;
  5365. $receiptDetailObj->insert();
  5366. $reviseSum+=$value['price'];
  5367. }
  5368. $itemStatistics=new itemStatistics();
  5369. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5370. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5371. $itemStatistics->price=$reviseSum;
  5372. $itemStatistics->itemCategory="报销金额调整";
  5373. $itemStatistics->date=$receiptDetail['date'];
  5374. $itemStatistics->insert();
  5375. }
  5376. $receiptDetailObj=new receiptDetail();
  5377. $receiptDetailObj->status=1;
  5378. $receiptDetailObj->pastDate=date("Y-m-d");
  5379. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5380. $dateArray=explode("-", $receiptDetail['date']);
  5381. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5382. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5383. if(empty($stat)){
  5384. $statistics->date=$receiptDetail['date'];
  5385. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5386. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5387. $statistics->agPrice=$receiptDetail['sum'];
  5388. $statistics->rePrice=$reviseSum;
  5389. $statistics->insert();
  5390. }else{
  5391. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5392. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5393. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5394. }
  5395. $dateArray=explode("-", $receiptDetail['date']);
  5396. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5397. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5398. foreach ($accountItem['cSum'] as $key=>$value){
  5399. if($key=="agencySum"){
  5400. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5401. if(empty($iStatistics)){
  5402. $itemStatistics->cid=$receiptDetail['cid'];;
  5403. $itemStatistics->staff=$receiptDetail['staff'];
  5404. $itemStatistics->price=$value;
  5405. $itemStatistics->itemCategory=$this->AGENCY;
  5406. $itemStatistics->date=$receiptDetail['date'];
  5407. $itemStatistics->insert();
  5408. }else{
  5409. if (!empty($value)){
  5410. $itemStatistics->price=$value+$iStatistics['price'];
  5411. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5412. }
  5413. }
  5414. }elseif($key=="travelSum"){
  5415. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5416. if(empty($iStatistics)){
  5417. $itemStatistics->cid=$receiptDetail['cid'];
  5418. $itemStatistics->staff=$receiptDetail['staff'];
  5419. $itemStatistics->price=$value;
  5420. $itemStatistics->itemCategory=$this->TRAVEL;
  5421. $itemStatistics->date=$receiptDetail['date'];
  5422. $itemStatistics->insert();
  5423. }else{
  5424. if (!empty($value)){
  5425. $itemStatistics->price=$value+$iStatistics['price'];
  5426. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5427. }
  5428. }
  5429. }elseif($key=="trainSum"){
  5430. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5431. if(empty($iStatistics)){
  5432. $itemStatistics->cid=$receiptDetail['cid'];
  5433. $itemStatistics->staff=$receiptDetail['staff'];
  5434. $itemStatistics->price=$value;
  5435. $itemStatistics->itemCategory=$this->TRAIN;
  5436. $itemStatistics->date=$receiptDetail['date'];
  5437. $itemStatistics->insert();
  5438. }else{
  5439. if (!empty($value)){
  5440. $itemStatistics->price=$value+$iStatistics['price'];
  5441. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5442. }
  5443. }
  5444. }elseif($key=="otherSum"){
  5445. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5446. if(empty($iStatistics)){
  5447. $itemStatistics->cid=$receiptDetail['cid'];
  5448. $itemStatistics->staff=$receiptDetail['staff'];
  5449. $itemStatistics->price=$value;
  5450. $itemStatistics->itemCategory=$this->OTHER;
  5451. $itemStatistics->date=$receiptDetail['date'];
  5452. $itemStatistics->insert();
  5453. }else{
  5454. if (!empty($value)){
  5455. $itemStatistics->price=$value+$iStatistics['price'];
  5456. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5457. }
  5458. }
  5459. }
  5460. }
  5461. $receipt->pastDate=date("Y-m-d");
  5462. //微信企业号通知
  5463. $receipt3 = new receipt();
  5464. $receiptDetail = $receipt3->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5465. if(!empty($receiptDetail)){
  5466. Doo::loadModel('staff');
  5467. $staff = new staff();
  5468. $staffmsg = $staff->getStaffBySid($receiptDetail['staff']);
  5469. if(!empty($staffmsg['wxid'])){
  5470. require_once (SITE_PATH . '/protected/class/client.php');
  5471. $client = new client ('http://m.cld.smartcost.com.cn/');
  5472. $user = $staffmsg['wxid'];
  5473. $receiptName = '';
  5474. switch($receiptDetail['Rtype']){
  5475. case 0:$receiptName = '报销';break;
  5476. case 1:$receiptName = '借款';break;
  5477. case 2:$receiptName = '对公汇款';break;
  5478. }
  5479. $msg = '太好了,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已同意支付。';
  5480. $result = $client->SendMsg($user,$msg,'text');
  5481. }
  5482. }
  5483. }
  5484. $receipt->update(array('where'=>' rid = '.$rid));
  5485. return "/approvalExpenses/2";
  5486. }
  5487. }
  5488. function expensesRetreats(){
  5489. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5490. if (!empty($rid)){
  5491. //操作记录
  5492. Doo::loadModel("receipt");
  5493. $receipt=new receipt();
  5494. Doo::loadModel("receiptLog");
  5495. $receiptLog=new receiptLog();
  5496. Doo::loadModel("verify");
  5497. $verify=new verify();
  5498. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5499. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5500. $jd=json_decode($vr['staff']);$roleId=0;
  5501. foreach ($jd as $key=>$value){
  5502. if ($value[1]=='ROLE'){
  5503. $pos = strpos($value[3], $this->staff[0]['sid']);
  5504. if ($pos !== false) {
  5505. $roleId=$value[0];
  5506. }
  5507. }
  5508. }
  5509. //审批日志
  5510. //echo $roleId;die;
  5511. if (!empty($roleId)){
  5512. Doo::loadModel("role");
  5513. $role=new role();
  5514. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5515. $receiptLog->rolename=$roleInfo['name'];
  5516. }
  5517. $receiptLog->username=$this->staff[0]['username'];
  5518. $receiptLog->uid=$this->staff[0]['sid'];
  5519. $receiptLog->date=date("Y-m-d");
  5520. $receiptLog->opinion='撤回';
  5521. $receiptLog->img=$this->staff[0]['avatar'];
  5522. $receiptLog->status=4;
  5523. $receiptLog->rid=$rid;
  5524. $receiptLog->insert();
  5525. $receipt->status=4;
  5526. $receipt->update(array('where'=>'rid='.$rid));
  5527. //微信企业号通知
  5528. $receiptDetail = $receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5529. if(!empty($receiptDetail)){
  5530. Doo::loadModel('staff');
  5531. $staff = new staff();
  5532. $staffmsg = $staff->getStaffBySid($receiptDetail['staff']);
  5533. if(!empty($staffmsg['wxid'])){
  5534. require_once (SITE_PATH . '/protected/class/client.php');
  5535. $client = new client ('http://m.cld.smartcost.com.cn/');
  5536. $user = $staffmsg['wxid'];
  5537. $receiptName = '';
  5538. switch($receiptDetail['Rtype']){
  5539. case 0:$receiptName = '报销';break;
  5540. case 1:$receiptName = '借款';break;
  5541. case 2:$receiptName = '对公汇款';break;
  5542. }
  5543. $msg = '注意,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被撤回,请及时处理。';
  5544. $result = $client->SendMsg($user,$msg,'text');
  5545. }
  5546. }
  5547. }
  5548. //echo "ddd";
  5549. return '/approvalExpenses';
  5550. }
  5551. function updateCheReceipt(){
  5552. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5553. if (!empty($rid)){
  5554. //操作记录
  5555. Doo::loadModel("receipt");
  5556. $receipt=new receipt();
  5557. Doo::loadModel("receiptLog");
  5558. $receiptLog=new receiptLog();
  5559. Doo::loadModel("verify");
  5560. $verify=new verify();
  5561. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5562. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5563. $jd=json_decode($vr['staff']);$roleId=0;
  5564. foreach ($jd as $key=>$value){
  5565. if ($value[1]=='ROLE'){
  5566. $pos = strpos($value[3], $this->staff[0]['sid']);
  5567. if ($pos !== false) {
  5568. $roleId=$value[0];
  5569. }
  5570. }
  5571. }
  5572. //审批日志
  5573. //echo $roleId;die;
  5574. if (!empty($roleId)){
  5575. Doo::loadModel("role");
  5576. $role=new role();
  5577. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5578. $receiptLog->rolename=$roleInfo['name'];
  5579. }
  5580. $receiptLog->username=$this->staff[0]['username'];
  5581. $receiptLog->uid=$this->staff[0]['sid'];
  5582. $receiptLog->date=date("Y-m-d");
  5583. $receiptLog->opinion='撤回';
  5584. $receiptLog->img=$this->staff[0]['avatar'];
  5585. $receiptLog->status=4;
  5586. $receiptLog->rid=$rid;
  5587. $receiptLog->insert();
  5588. $receipt->status=4;
  5589. $receipt->update(array('where'=>'rid='.$rid));
  5590. //微信企业号通知
  5591. $receiptDetail = $receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5592. if(!empty($receiptDetail)){
  5593. Doo::loadModel('staff');
  5594. $staff = new staff();
  5595. $staffmsg = $staff->getStaffBySid($receiptDetail['staff']);
  5596. if(!empty($staffmsg['wxid'])){
  5597. require_once (SITE_PATH . '/protected/class/client.php');
  5598. $client = new client ('http://m.cld.smartcost.com.cn/');
  5599. $user = $staffmsg['wxid'];
  5600. $receiptName = '';
  5601. switch($receiptDetail['Rtype']){
  5602. case 0:$receiptName = '报销';break;
  5603. case 1:$receiptName = '借款';break;
  5604. case 2:$receiptName = '对公汇款';break;
  5605. }
  5606. $msg = '注意,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被撤回,请及时处理。';
  5607. $result = $client->SendMsg($user,$msg,'text');
  5608. }
  5609. }
  5610. }
  5611. //echo "ddd";
  5612. return '/saeaBorad';
  5613. }
  5614. function revisePrice(){
  5615. $description=$this->get_args('description')?$this->get_args('description'):"";
  5616. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5617. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5618. //echo $price;die;
  5619. if (!empty($rid)){
  5620. Doo::loadModel("receipt");
  5621. $receipt=new receipt();
  5622. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5623. if (empty($receiptDetail))
  5624. return "/approval";
  5625. $reviseDetail=array();
  5626. if (empty($receiptDetail['reviseDetail'])){
  5627. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5628. $reviseDetailString=json_encode($reviseDetail);
  5629. $receipt->reviseDetail=$reviseDetailString;
  5630. $receipt->revisePrice=$price;
  5631. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5632. }else{
  5633. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5634. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5635. $reviseDetailString=json_encode($reviseDetail);
  5636. $receipt->reviseDetail=$reviseDetailString;
  5637. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5638. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5639. }
  5640. $receipt->update(array('where'=>'rid='.$rid));
  5641. }
  5642. return '/approvalEdi/'.$rid;
  5643. }
  5644. function personalCollect(){
  5645. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5646. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5647. $this->showCache($path);
  5648. Doo::loadModel("receiptDetail");
  5649. Doo::loadModel("itemStatistics");
  5650. Doo::loadModel('statistics');
  5651. $statistics=new statistics();
  5652. $itemStatistics=new itemStatistics();
  5653. $receiptDetail=new receiptDetail();
  5654. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5655. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5656. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5657. //create collect html
  5658. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5659. $adjustment=array();
  5660. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5661. array_push($collectArray['日常相关费用'], $collectHtml);
  5662. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5663. array_push($collectArray['差旅相关费用'], $collectHtml);
  5664. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5665. array_push($collectArray['培训班费用'], $collectHtml);
  5666. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5667. array_push($collectArray['其他'], $collectHtml);
  5668. $data['collectArray']=$collectArray;
  5669. //statistics html
  5670. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5671. if(empty($stList))
  5672. $stList=array('rePrice'=>0,'agPrice'=>0);
  5673. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5674. //Adjustment price html
  5675. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5676. array_push($adjustment, $collectHtml);
  5677. $data['adjustment']=$adjustment;
  5678. //total price html
  5679. $collectHtml="";$total=0;
  5680. for ($i=1;$i<=12;$i++){
  5681. $sumPrice=0;
  5682. foreach ($receiptCollectList as $key=>$value){
  5683. if($value['month']==$i){
  5684. $sumPrice+=$value['price'];
  5685. }
  5686. }
  5687. if ($sumPrice==0)
  5688. $collectHtml.='<td class="taR">-</td>';
  5689. else
  5690. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5691. $total+=$sumPrice;
  5692. }
  5693. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5694. $data['totalPrice']=$collectHtml;
  5695. $data['year']=$year;
  5696. $data['totalYear']=$total;
  5697. $data['memu']="receipt";
  5698. $data['staff']=$this->staff;
  5699. $data['receiptMemu']='personalCollect';
  5700. $data['verifyId']=$this->verifyId;
  5701. $data['executeId']=$this->executeId;
  5702. //year staff status 2,4
  5703. if($year<date("Y")){
  5704. Doo::loadModel('receipt');
  5705. $receipt=new receipt();
  5706. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5707. if(empty($receiptList)){
  5708. ob_start();
  5709. $this->render ( "/admin/saea_slist_collect", $data );
  5710. $this->cacheFile($path);die;
  5711. }
  5712. }
  5713. $this->render ( "/admin/saea_slist_collect", $data );
  5714. }
  5715. function personalCollectDetail(){
  5716. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5717. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5718. $this->showCache($path);
  5719. Doo::loadModel("receiptDetail");
  5720. Doo::loadModel("itemStatistics");
  5721. Doo::loadModel('statistics');
  5722. Doo::loadModel('accountItem');
  5723. $accountItem=new accountItem();
  5724. $statistics=new statistics();
  5725. $itemStatistics=new itemStatistics();
  5726. $receiptDetail=new receiptDetail();
  5727. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5728. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5729. $accountList=$accountItem->find(array('asArray'=>true));
  5730. //create CollectDetail HTML
  5731. $collectHtml=array();
  5732. foreach ($accountList as $key=>$value){
  5733. $html="";$asum=0;
  5734. for ($i=1;$i<=12;$i++){
  5735. $falg=true;
  5736. foreach ($receiptCollectList as $v) {
  5737. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5738. $asum+=$v['price'];
  5739. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5740. }
  5741. }
  5742. if($falg)
  5743. $html.='<td class="taR">-</td>';
  5744. }
  5745. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5746. $collectHtml[$value['category']][$value['name']]=$html;
  5747. }
  5748. $data['collectHtml']=$collectHtml;
  5749. //create Adjustment price html
  5750. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5751. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5752. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5753. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5754. array_push($collectArray['日常相关费用'], $collectHtml);
  5755. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5756. array_push($collectArray['差旅相关费用'], $collectHtml);
  5757. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5758. array_push($collectArray['培训班费用'], $collectHtml);
  5759. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5760. array_push($collectArray['其他'], $collectHtml);
  5761. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5762. array_push($adjustment, $collectHtml);
  5763. //total price html
  5764. $collectHtml="";$total=0;
  5765. for ($i=1;$i<=12;$i++){
  5766. $sumPrice=0;
  5767. foreach ($receiptCollectList as $key=>$value){
  5768. if($value['month']==$i){
  5769. $sumPrice+=$value['price'];
  5770. }
  5771. }
  5772. if ($sumPrice==0)
  5773. $collectHtml.='<td class="taR">-</td>';
  5774. else
  5775. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5776. $total+=$sumPrice;
  5777. }
  5778. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5779. //statistics html
  5780. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5781. if(empty($stList))
  5782. $stList=array('rePrice'=>0,'agPrice'=>0);
  5783. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5784. $data['collectArray']=$collectArray;
  5785. $data['adjustment']=$adjustment;
  5786. $data['totalPrice']=$collectHtml;
  5787. $data['totalYear']=$total;
  5788. $data['year']=$year;
  5789. $data['memu']="receipt";
  5790. $data['staff']=$this->staff;
  5791. $data['receiptMemu']='personalCollect';
  5792. $data['verifyId']=$this->verifyId;
  5793. $data['executeId']=$this->executeId;
  5794. //year staff status 2,4
  5795. if($year<date("Y")){
  5796. Doo::loadModel('receipt');
  5797. $receipt=new receipt();
  5798. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5799. if(empty($receiptList)){
  5800. ob_start();
  5801. $this->render ( "/admin/saeaCollectArticles", $data );
  5802. $this->cacheFile($path);die;
  5803. }
  5804. }
  5805. $this->render ( "/admin/saeaCollectArticles", $data );
  5806. }
  5807. function companyCategoryCollect(){
  5808. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5809. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5810. $this->showCache($path);
  5811. Doo::loadModel('L_category');
  5812. Doo::loadModel('itemStatistics');
  5813. Doo::loadModel('statistics');
  5814. $statistics=new statistics();
  5815. $Lcategory=new L_category();
  5816. $itemStatistics=new itemStatistics();
  5817. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5818. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5819. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5820. //ceatre companyCollectHtml
  5821. foreach ($LcategoryList as $value){
  5822. $html="";$asum=0;
  5823. for ($i=1;$i<=12;$i++){
  5824. $falg=true;
  5825. foreach ($itemStatisticsList as $v){
  5826. if($value['cid']==$v['cid']&&$i==$v['month']){
  5827. $asum+=$v['price'];
  5828. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5829. }
  5830. }
  5831. if($falg)
  5832. $html.='<td class="taR">-</td>';
  5833. }
  5834. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5835. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5836. }
  5837. $data['companyHtml']=$collectHtml;
  5838. //total price html
  5839. $collectHtml="";$total=0;
  5840. for ($i=1;$i<=12;$i++){
  5841. $sumPrice=0;
  5842. foreach ($itemStatisticsList as $key=>$value){
  5843. if($value['month']==$i){
  5844. $sumPrice+=$value['price'];
  5845. }
  5846. }
  5847. if ($sumPrice==0)
  5848. $collectHtml.='<td class="taR">-</td>';
  5849. else
  5850. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5851. $total+=$sumPrice;
  5852. }
  5853. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5854. $data['companyTotalHtml']=$collectHtml;
  5855. $data['total']=$total;
  5856. //statistics html
  5857. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5858. if(empty($stList))
  5859. $stList=array('rePrice'=>0,'agPrice'=>0);
  5860. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5861. $data['year']=$year;
  5862. $data['memu']="receipt";
  5863. $data['staff']=$this->staff;
  5864. $data['receiptMemu']='companyCategoryCollect';
  5865. $data['verifyId']=$this->verifyId;
  5866. $data['executeId']=$this->executeId;
  5867. //year staff status 2,4
  5868. if($year<date("Y")){
  5869. Doo::loadModel('receipt');
  5870. $receipt=new receipt();
  5871. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5872. if(empty($receiptList)){
  5873. ob_start();
  5874. $this->render ( "/admin/saeaCompanyCollect", $data );
  5875. $this->cacheFile($path);die;
  5876. }
  5877. }
  5878. $this->render ( "/admin/saeaCompanyCollect", $data );
  5879. }
  5880. function categoryCollectDetail(){
  5881. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5882. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5883. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5884. $this->showCache($path);
  5885. Doo::loadModel('statistics');
  5886. $statistics=new statistics();
  5887. Doo::loadModel("receiptDetail");
  5888. $receiptDetail=new receiptDetail();
  5889. Doo::loadModel('L_category');
  5890. $Lcategory=new L_category();
  5891. Doo::loadModel('accountItem');
  5892. $accountItem=new accountItem();
  5893. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5894. if ($cid==0){
  5895. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5896. if ($cid==0)
  5897. $cid=$LcategoryList[0]['cid'];
  5898. }
  5899. $data['LcategoryList']=$LcategoryList;
  5900. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5901. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5902. $accountList=$accountItem->find(array('asArray'=>true));
  5903. //create CollectDetail HTML
  5904. $collectHtml=array();
  5905. foreach ($accountList as $key=>$value){
  5906. $html="";$asum=0;
  5907. for ($i=1;$i<=12;$i++){
  5908. $falg=true;
  5909. foreach ($receiptCollectList as $v) {
  5910. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5911. $asum+=$v['price'];
  5912. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5913. }
  5914. }
  5915. if($falg)
  5916. $html.='<td class="taR">-</td>';
  5917. }
  5918. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5919. $collectHtml[$value['category']][$value['name']]=$html;
  5920. }
  5921. $data['collectHtml']=$collectHtml;
  5922. //create Adjustment price html
  5923. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5924. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5925. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5926. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5927. array_push($collectArray['日常相关费用'], $collectHtml);
  5928. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5929. array_push($collectArray['差旅相关费用'], $collectHtml);
  5930. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5931. array_push($collectArray['培训班费用'], $collectHtml);
  5932. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5933. array_push($collectArray['其他'], $collectHtml);
  5934. $data['collectArray']=$collectArray;
  5935. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5936. array_push($adjustment, $collectHtml);
  5937. $data['adjustment']=$adjustment;
  5938. //total price html
  5939. $collectHtml="";$total=0;
  5940. for ($i=1;$i<=12;$i++){
  5941. $sumPrice=0;
  5942. foreach ($receiptCollectList as $key=>$value){
  5943. if($value['month']==$i){
  5944. $sumPrice+=$value['price'];
  5945. }
  5946. }
  5947. if ($sumPrice==0)
  5948. $collectHtml.='<td class="taR">-</td>';
  5949. else
  5950. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5951. $total+=$sumPrice;
  5952. }
  5953. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5954. //statistics html
  5955. $stList=$statistics->statisticsByCid($year,$cid);
  5956. if(empty($stList))
  5957. $stList=array('rePrice'=>0,'agPrice'=>0);
  5958. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5959. $data['totalYear']=$total;
  5960. $data['year']=$year;
  5961. $data['cid']=$cid;
  5962. $data['memu']="receipt";
  5963. $data['staff']=$this->staff;
  5964. $data['receiptMemu']='companyCategoryCollect';
  5965. $data['verifyId']=$this->verifyId;
  5966. $data['executeId']=$this->executeId;
  5967. //year staff status 2,4
  5968. if($year<date("Y")){
  5969. Doo::loadModel('receipt');
  5970. $receipt=new receipt();
  5971. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5972. if(empty($receiptList)){
  5973. ob_start();
  5974. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5975. $this->cacheFile($path);die;
  5976. }
  5977. }
  5978. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5979. }
  5980. function staffCollect(){
  5981. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5982. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5983. //$this->showCache($path);
  5984. Doo::loadModel('statistics');
  5985. $statistics=new statistics();
  5986. Doo::loadModel("receiptDetail");
  5987. $receiptDetail=new receiptDetail();
  5988. Doo::loadModel('L_category');
  5989. $Lcategory=new L_category();
  5990. Doo::loadModel('accountItem');
  5991. $accountItem=new accountItem();
  5992. Doo::loadModel('staff');
  5993. $staff=new staff();
  5994. Doo::loadModel('itemStatistics');
  5995. $itemStatistics=new itemStatistics();
  5996. /*
  5997. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5998. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5999. if(empty($stList))
  6000. $stList=array('rePrice'=>0,'agPrice'=>0);
  6001. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6002. */
  6003. //statistics html
  6004. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  6005. if(empty($stList))
  6006. $stList=array('rePrice'=>0,'agPrice'=>0);
  6007. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6008. //---
  6009. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  6010. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  6011. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6012. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  6013. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6014. //print_r($itemStatisticsList);die;
  6015. //ceatre companyCollectHtml
  6016. foreach ($categoryList as $vlu){
  6017. $count=$vlu['count']+1;
  6018. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  6019. $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;
  6020. foreach ($staffList as $value){
  6021. if ($vlu['cid']==$value['cid']){
  6022. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  6023. $asum=0;
  6024. for ($i=1;$i<=12;$i++){
  6025. $falg=true;
  6026. foreach ($itemStatisticsList as $v){
  6027. if($value['sid']==$v['staff']&&$i==$v['month']){
  6028. if ($v['month']==1)
  6029. $m1+=$v['price'];
  6030. if ($v['month']==2)
  6031. $m2+=$v['price'];
  6032. if ($v['month']==3)
  6033. $m3+=$v['price'];
  6034. if ($v['month']==4)
  6035. $m4+=$v['price'];
  6036. if ($v['month']==5)
  6037. $m5+=$v['price'];
  6038. if ($v['month']==6)
  6039. $m6+=$v['price'];
  6040. if ($v['month']==7)
  6041. $m7+=$v['price'];
  6042. if ($v['month']==8)
  6043. $m8+=$v['price'];
  6044. if ($v['month']==9)
  6045. $m9+=$v['price'];
  6046. if ($v['month']==10)
  6047. $m10+=$v['price'];
  6048. if ($v['month']==11)
  6049. $m11+=$v['price'];
  6050. if ($v['month']==12)
  6051. $m12+=$v['price'];
  6052. $asum+=$v['price'];
  6053. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  6054. }
  6055. }
  6056. if($falg)
  6057. $html.='<td class="taR">-</td>';
  6058. }
  6059. $m13+=$asum;
  6060. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  6061. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  6062. $html="";
  6063. }
  6064. }
  6065. $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>
  6066. <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>
  6067. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  6068. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  6069. }
  6070. $data['companyHtml']=$collectHtml;
  6071. //total price html
  6072. $collectHtml="";$total=0;
  6073. for ($i=1;$i<=12;$i++){
  6074. $sumPrice=0;
  6075. foreach ($itemStatisticsList as $key=>$value){
  6076. if($value['month']==$i){
  6077. $sumPrice+=$value['price'];
  6078. }
  6079. }
  6080. if ($sumPrice==0)
  6081. $collectHtml.='<td class="taR">-</td>';
  6082. else
  6083. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  6084. $total+=$sumPrice;
  6085. }
  6086. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  6087. $data['companyTotalHtml']=$collectHtml;
  6088. $data['total']=$total;
  6089. $data['year']=$year;
  6090. $data['memu']="receipt";
  6091. $data['staff']=$this->staff;
  6092. $data['receiptMemu']='companyCategoryCollect';
  6093. $data['verifyId']=$this->verifyId;
  6094. $data['executeId']=$this->executeId;
  6095. if ($year<=date("Y")){
  6096. Doo::loadModel('receipt');
  6097. $receipt=new receipt();
  6098. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  6099. if(empty($receiptList)){ //generated files
  6100. ob_start();
  6101. $this->render ( "/admin/saeaStaffCollectB", $data );
  6102. $this->cacheFile($path);die;
  6103. }
  6104. }
  6105. $this->render ( "/admin/saeaStaffCollectB", $data );
  6106. }
  6107. function staffCollectBak(){
  6108. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6109. $month=$this->get_args('month')?$this->get_args('month'):1;
  6110. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  6111. $this->showCache($path);
  6112. Doo::loadModel('statistics');
  6113. $statistics=new statistics();
  6114. Doo::loadModel("receiptDetail");
  6115. $receiptDetail=new receiptDetail();
  6116. Doo::loadModel('L_category');
  6117. $Lcategory=new L_category();
  6118. Doo::loadModel('accountItem');
  6119. $accountItem=new accountItem();
  6120. Doo::loadModel('staff');
  6121. $staff=new staff();
  6122. Doo::loadModel('itemStatistics');
  6123. $itemStatistics=new itemStatistics();
  6124. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6125. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  6126. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6127. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  6128. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  6129. $staffList=$staff->find(array('asArray'=>true));
  6130. $htmlArray=array();
  6131. foreach ($LcategoryList as $value){
  6132. $htmlArray[$value['title']]=array();
  6133. foreach ($staffList as $v){
  6134. if($value['cid']==$v['cid']){
  6135. $html="";$falg=true;$staffSumPrice=0;
  6136. foreach ($itemStatisticsList as $a){
  6137. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  6138. if(empty($a['price'])){
  6139. $html.='<td class="taR">-</td>';$falg=false;break;
  6140. }else{
  6141. $staffSumPrice+=$a['price'];
  6142. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6143. }
  6144. }
  6145. }
  6146. if ($falg){
  6147. $html.='<td class="taR">-</td>';$falg=true;
  6148. }
  6149. $falg=true;
  6150. foreach ($itemStatisticsList as $a){
  6151. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  6152. if(empty($a['price'])){
  6153. $html.='<td class="taR">-</td>';$falg=false;break;
  6154. }else{
  6155. $staffSumPrice+=$a['price'];
  6156. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6157. }
  6158. }
  6159. }
  6160. if ($falg){
  6161. $html.='<td class="taR">-</td>';$falg=true;
  6162. }
  6163. $falg=true;
  6164. foreach ($itemStatisticsList as $a){
  6165. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  6166. if(empty($a['price'])){
  6167. $html.='<td class="taR">-</td>';$falg=false;break;
  6168. }else{
  6169. $staffSumPrice+=$a['price'];
  6170. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6171. }
  6172. }
  6173. }
  6174. if ($falg){
  6175. $html.='<td class="taR">-</td>';$falg=true;
  6176. }
  6177. $falg=true;
  6178. foreach ($itemStatisticsList as $a){
  6179. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6180. if(!empty($a['price'])){
  6181. $staffSumPrice+=$a['price'];
  6182. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6183. }else{
  6184. $html.='<td class="taR">-</td>';$falg=false;break;
  6185. }
  6186. }
  6187. }
  6188. if ($falg){
  6189. $html.='<td class="taR">-</td>';$falg=true;
  6190. }
  6191. $falg=true;
  6192. foreach ($itemStatisticsList as $a){
  6193. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6194. if(!empty($a['price'])){
  6195. $staffSumPrice+=$a['price'];
  6196. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6197. }else{
  6198. $html.='<td class="taR">-</td>';$falg=false;break;
  6199. }
  6200. }
  6201. }
  6202. if ($falg){
  6203. $html.='<td class="taR">-</td>';$falg=true;
  6204. }
  6205. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6206. $htmlArray[$value['title']][$v['username']]=$html;
  6207. }
  6208. }
  6209. /*-- ---*/
  6210. //合计费用
  6211. $cateHtml="";$catePrice=0;$cateFalg=true;
  6212. foreach ($itemCategoryList as $l){
  6213. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6214. if(empty($l['price'])){
  6215. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6216. }else{
  6217. $catePrice+=$l['price'];
  6218. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6219. }
  6220. }
  6221. }
  6222. if ($cateFalg){
  6223. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6224. }
  6225. $cateFalg=true;
  6226. foreach ($itemCategoryList as $l){
  6227. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6228. if(empty($l['price'])){
  6229. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6230. }else{
  6231. $catePrice+=$l['price'];
  6232. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6233. }
  6234. }
  6235. }
  6236. if ($cateFalg){
  6237. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6238. }
  6239. $cateFalg=true;
  6240. foreach ($itemCategoryList as $l){
  6241. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6242. if(empty($l['price'])){
  6243. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6244. }else{
  6245. $catePrice+=$l['price'];
  6246. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6247. }
  6248. }
  6249. }
  6250. if ($cateFalg){
  6251. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6252. }
  6253. $cateFalg=true;
  6254. foreach ($itemCategoryList as $l){
  6255. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6256. if(empty($l['price'])){
  6257. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6258. }else{
  6259. $catePrice+=$l['price'];
  6260. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6261. }
  6262. }
  6263. }
  6264. if ($cateFalg){
  6265. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6266. }
  6267. $cateFalg=true;
  6268. foreach ($itemCategoryList as $l){
  6269. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6270. if(empty($l['price'])){
  6271. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6272. }else{
  6273. $catePrice+=$l['price'];
  6274. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6275. }
  6276. }
  6277. }
  6278. if ($cateFalg){
  6279. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6280. }
  6281. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6282. $htmlArray[$value['title']]['合计']=$cateHtml;
  6283. /*-- ---*/
  6284. }
  6285. //print_r($htmlArray);die;
  6286. $data['htmlArray']=$htmlArray;
  6287. //statistics html
  6288. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6289. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6290. if(empty($stList))
  6291. $stList=array('rePrice'=>0,'agPrice'=>0);
  6292. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6293. $monthHtml="";
  6294. for ($i=1;$i<=12;$i++){
  6295. if ($i==$month)
  6296. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6297. else
  6298. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6299. }
  6300. $data['monthHtml']=$monthHtml;
  6301. $data['year']=$year;
  6302. $data['month']=$month;
  6303. $data['memu']="receipt";
  6304. $data['staff']=$this->staff;
  6305. $data['receiptMemu']='companyCategoryCollect';
  6306. $data['verifyId']=$this->verifyId;
  6307. $data['executeId']=$this->executeId;
  6308. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6309. Doo::loadModel('receipt');
  6310. $receipt=new receipt();
  6311. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6312. if(empty($receiptList)){ //generated files
  6313. ob_start();
  6314. $this->render ( "/admin/saeaStaffCollect", $data );
  6315. $this->cacheFile($path);die;
  6316. }
  6317. }
  6318. $this->render ( "/admin/saeaStaffCollect", $data );
  6319. }
  6320. function lyt(){
  6321. Doo::loadModel("receiptDetail");
  6322. $receiptDetail=new receiptDetail();
  6323. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6324. foreach ($receiptCollectList as $key=>$value){
  6325. $receiptDetail=new receiptDetail();
  6326. $receiptDetail->pastDate=$value['date'];
  6327. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6328. }
  6329. }
  6330. function staffCollectMonthDetail(){
  6331. $year=$this->get_args('year')?$this->get_args('year'):"";
  6332. $month=$this->get_args('month')?$this->get_args('month'):"";
  6333. if(!$year)
  6334. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6335. if(!$month)
  6336. $month=isset($this->params['month'])?$this->params['month']:1;
  6337. Doo::loadModel('staff');
  6338. $staff=new staff();
  6339. Doo::loadModel("receiptDetail");
  6340. $receiptDetail=new receiptDetail();
  6341. Doo::loadModel('accountItem');
  6342. $accountItem=new accountItem();
  6343. Doo::loadModel('statistics');
  6344. $statistics=new statistics();
  6345. Doo::loadModel('L_category');
  6346. $lCategory=new L_category();
  6347. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6348. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6349. $list=array();
  6350. foreach ($categoryList as $vlu){
  6351. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6352. $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;
  6353. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6354. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6355. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6356. $s1=0;
  6357. $m1=0;
  6358. foreach ($staffList as $value){
  6359. if ($vlu['cid']==$value['cid']){
  6360. //pastDate
  6361. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6362. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6363. // if ($value['sid']==42){
  6364. // print_r($receiptCollectList);die;
  6365. // }
  6366. if(!empty($receiptCollectList)){
  6367. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6368. $html="";
  6369. $psum=0;
  6370. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6371. foreach ($item as $va){
  6372. $falg=true;
  6373. foreach ($receiptCollectList as $v){
  6374. if($v['itemCategory']=='日常相关费用'){
  6375. if($v['item']==$va){
  6376. if ($va=='市内交通费')
  6377. $r1+=$v['price'];
  6378. if ($va=='市内出租费')
  6379. $r2+=$v['price'];
  6380. if ($va=='办事处房租')
  6381. $r3+=$v['price'];
  6382. if ($va=='电话费')
  6383. $r4+=$v['price'];
  6384. if ($va=='水费')
  6385. $r5+=$v['price'];
  6386. if ($va=='电费')
  6387. $r6+=$v['price'];
  6388. if ($va=='办公费用')
  6389. $r7+=$v['price'];
  6390. if ($va=='邮寄费')
  6391. $r8+=$v['price'];
  6392. if ($va=='其他费用')
  6393. $r9+=$v['price'];
  6394. if ($va=='车辆费用')
  6395. $r10+=$v['price'];
  6396. if ($va=='广告费')
  6397. $r11+=$v['price'];
  6398. if ($va=='团队建设费')
  6399. $r13+=$v['price'];
  6400. if ($va=='物业管理费')
  6401. $r14+=$v['price'];
  6402. if ($va=='宽带费')
  6403. $r15+=$v['price'];
  6404. $psum+=$v['price'];
  6405. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6406. }
  6407. }
  6408. }
  6409. if($falg)
  6410. $html.='<td class="taR">-</td>';
  6411. }
  6412. $r12+=$psum;
  6413. if(!empty($psum))
  6414. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6415. else
  6416. $psum='<td class="colGreen taR">-</td>';
  6417. $receiptL['日常相关费用']=$psum.$html;
  6418. /*-----------------------------------*/
  6419. $html="";
  6420. $psum=0;
  6421. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6422. foreach ($item as $va){
  6423. $falg=true;
  6424. foreach ($receiptCollectList as $v){
  6425. if($v['itemCategory']=='差旅相关费用'){
  6426. if($v['item']==$va){
  6427. if ($va=='往来交通费')
  6428. $c1+=$v['price'];
  6429. if ($va=='市内交通费')
  6430. $c2+=$v['price'];
  6431. if ($va=='出差住宿费')
  6432. $c3+=$v['price'];
  6433. if ($va=='出差补助')
  6434. $c4+=$v['price'];
  6435. if ($va=='其他费用')
  6436. $c5+=$v['price'];
  6437. $psum+=$v['price'];
  6438. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6439. }
  6440. }
  6441. }
  6442. if($falg)
  6443. $html.='<td class="taR">-</td>';
  6444. }
  6445. $c6+=$psum;
  6446. if(!empty($psum))
  6447. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6448. else
  6449. $psum='<td class="colGreen taR">-</td>';
  6450. $receiptL['差旅相关费用']=$psum.$html;
  6451. /*-------------------------------------*/
  6452. $html="";
  6453. $psum=0;
  6454. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6455. foreach ($item as $va){
  6456. $falg=true;
  6457. foreach ($receiptCollectList as $v){
  6458. if($v['itemCategory']=='培训班费用'){
  6459. if($v['item']==$va){
  6460. if ($va=='场租费')
  6461. $p1+=$v['price'];
  6462. if ($va=='薪酬')
  6463. $p2+=$v['price'];
  6464. if ($va=='住宿费')
  6465. $p3+=$v['price'];
  6466. if ($va=='交通费')
  6467. $p4+=$v['price'];
  6468. if ($va=='餐饮费')
  6469. $p5+=$v['price'];
  6470. if ($va=='办公费')
  6471. $p6+=$v['price'];
  6472. if ($va=='公关费')
  6473. $p7+=$v['price'];
  6474. if ($va=='其他')
  6475. $p8+=$v['price'];
  6476. $psum+=$v['price'];
  6477. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6478. }
  6479. }
  6480. }
  6481. if($falg)
  6482. $html.='<td class="taR">-</td>';
  6483. }
  6484. $p9+=$psum;
  6485. if(!empty($psum))
  6486. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6487. else
  6488. $psum='<td class="colGreen taR">-</td>';
  6489. $receiptL['培训班费用']=$psum.$html;
  6490. /*-------------------------------------*/
  6491. $html="";
  6492. $psum=0;
  6493. $item=array('公关费','广告费','借款','可自加费用');
  6494. foreach ($item as $va){
  6495. $falg=true;
  6496. foreach ($receiptCollectList as $v){
  6497. if($v['itemCategory']=='其他'){
  6498. // if ($value['sid']==42){
  6499. //
  6500. // echo var_dump($v['item']);
  6501. // echo var_dump($va);
  6502. // echo var_dump($v['item']==" ".$va);
  6503. // echo $v['item']."==".$va."/<br/>";
  6504. // //print_r( $receiptCollectList);//echo $va;
  6505. // }
  6506. if(trim($v['item'])==$va){
  6507. if ($va=='公关费')
  6508. $t1+=$v['price'];
  6509. if ($va=='广告费'){
  6510. $t2+=$v['price'];
  6511. }
  6512. if ($va=='借款')
  6513. $t3+=$v['price'];
  6514. if ($va=='可自加费用')
  6515. $t4+=$v['price'];
  6516. $psum+=$v['price'];
  6517. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6518. }
  6519. }
  6520. }
  6521. if($falg)
  6522. $html.='<td class="taR">-</td>';
  6523. }
  6524. $t5+=$psum;
  6525. if(!empty($psum))
  6526. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6527. else
  6528. $psum='<td class="colGreen taR">-</td>';
  6529. $receiptL['其他']=$psum.$html;
  6530. /*-------------------------------------*/
  6531. $html="";
  6532. $psum=0;
  6533. foreach ($receiptCollectList as $v){
  6534. if($v['itemCategory']=='报销金额调整'){
  6535. if (!empty($v['price'])){
  6536. $psum+=$v['price'];
  6537. }
  6538. }
  6539. }
  6540. $s1+=$psum;
  6541. if(!empty($psum))
  6542. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6543. else
  6544. $psum='<td class="taR colOrange">-</td>';
  6545. $receiptL['报销金额调整']=$psum.$html;
  6546. }else{
  6547. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6548. <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>
  6549. <td class="taR">-</td><td class="taR">-</td>';
  6550. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6551. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6552. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6553. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6554. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6555. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6556. }
  6557. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6558. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6559. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6560. if(!empty($monthStaffPrice[0]['price'])){
  6561. $m1+=$monthStaffPrice[0]['price'];
  6562. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6563. }else
  6564. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6565. $list[$value['username']]=$receiptL;
  6566. }
  6567. }
  6568. $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>
  6569. <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>
  6570. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6571. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6572. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6573. $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>
  6574. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6575. $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>';
  6576. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6577. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6578. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6579. }
  6580. $data['list']=$list;
  6581. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6582. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6583. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6584. //statistics html
  6585. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6586. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6587. if(empty($stList))
  6588. $stList=array('rePrice'=>0,'agPrice'=>0);
  6589. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6590. $monthHtml="";
  6591. for ($i=1;$i<=12;$i++){
  6592. if ($i==$month)
  6593. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6594. else
  6595. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6596. }
  6597. $data['monthHtml']=$monthHtml;
  6598. $data['year']=$year;
  6599. $data['month']=$month;
  6600. $data['memu']="receipt";
  6601. $data['staff']=$this->staff;
  6602. $data['receiptMemu']='companyCategoryCollect';
  6603. $data['verifyId']=$this->verifyId;
  6604. $data['executeId']=$this->executeId;
  6605. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6606. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6607. }
  6608. function staffCollectMonthDetail2(){
  6609. $year=$this->get_args('year')?$this->get_args('year'):"";
  6610. $month=$this->get_args('month')?$this->get_args('month'):"";
  6611. if(!$year)
  6612. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6613. if(!$month)
  6614. $month=isset($this->params['month'])?$this->params['month']:1;
  6615. Doo::loadModel('staff');
  6616. $staff=new staff();
  6617. Doo::loadModel("receiptDetail");
  6618. $receiptDetail=new receiptDetail();
  6619. Doo::loadModel('accountItem');
  6620. $accountItem=new accountItem();
  6621. Doo::loadModel('statistics');
  6622. $statistics=new statistics();
  6623. Doo::loadModel('L_category');
  6624. $lCategory=new L_category();
  6625. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6626. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6627. $list=array();
  6628. foreach ($categoryList as $vlu){
  6629. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6630. $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;
  6631. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6632. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6633. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6634. $s1=0;
  6635. $m1=0;
  6636. foreach ($staffList as $value){
  6637. if ($vlu['cid']==$value['cid']){
  6638. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6639. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6640. if(!empty($receiptCollectList)){
  6641. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6642. $html="";
  6643. $psum=0;
  6644. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6645. foreach ($item as $va){
  6646. $falg=true;
  6647. foreach ($receiptCollectList as $v){
  6648. if($v['itemCategory']=='日常相关费用'){
  6649. if($v['item']==$va){
  6650. if ($va=='市内交通费')
  6651. $r1+=$v['price'];
  6652. if ($va=='市内出租费')
  6653. $r2+=$v['price'];
  6654. if ($va=='办事处房租')
  6655. $r3+=$v['price'];
  6656. if ($va=='电话费')
  6657. $r4+=$v['price'];
  6658. if ($va=='水费')
  6659. $r5+=$v['price'];
  6660. if ($va=='电费')
  6661. $r6+=$v['price'];
  6662. if ($va=='办公费用')
  6663. $r7+=$v['price'];
  6664. if ($va=='邮寄费')
  6665. $r8+=$v['price'];
  6666. if ($va=='其他费用')
  6667. $r9+=$v['price'];
  6668. if ($va=='车辆费用')
  6669. $r10+=$v['price'];
  6670. if ($va=='广告费')
  6671. $r11+=$v['price'];
  6672. if ($va=='团队建设费')
  6673. $r13+=$v['price'];
  6674. if ($va=='物业管理费')
  6675. $r14+=$v['price'];
  6676. if ($va=='宽带费')
  6677. $r15+=$v['price'];
  6678. $psum+=$v['price'];
  6679. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6680. }
  6681. }
  6682. }
  6683. if($falg)
  6684. $html.='<td class="taR">-</td>';
  6685. }
  6686. $r12+=$psum;
  6687. if(!empty($psum))
  6688. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6689. else
  6690. $psum='<td class="colGreen taR">-</td>';
  6691. $receiptL['日常相关费用']=$psum.$html;
  6692. /*-----------------------------------*/
  6693. $html="";
  6694. $psum=0;
  6695. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6696. foreach ($item as $va){
  6697. $falg=true;
  6698. foreach ($receiptCollectList as $v){
  6699. if($v['itemCategory']=='差旅相关费用'){
  6700. if($v['item']==$va){
  6701. if ($va=='往来交通费')
  6702. $c1+=$v['price'];
  6703. if ($va=='市内交通费')
  6704. $c2+=$v['price'];
  6705. if ($va=='出差住宿费')
  6706. $c3+=$v['price'];
  6707. if ($va=='出差补助')
  6708. $c4+=$v['price'];
  6709. if ($va=='其他费用')
  6710. $c5+=$v['price'];
  6711. $psum+=$v['price'];
  6712. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6713. }
  6714. }
  6715. }
  6716. if($falg)
  6717. $html.='<td class="taR">-</td>';
  6718. }
  6719. $c6+=$psum;
  6720. if(!empty($psum))
  6721. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6722. else
  6723. $psum='<td class="colGreen taR">-</td>';
  6724. $receiptL['差旅相关费用']=$psum.$html;
  6725. /*-------------------------------------*/
  6726. $html="";
  6727. $psum=0;
  6728. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6729. foreach ($item as $va){
  6730. $falg=true;
  6731. foreach ($receiptCollectList as $v){
  6732. if($v['itemCategory']=='培训班费用'){
  6733. if($v['item']==$va){
  6734. if ($va=='场租费')
  6735. $p1+=$v['price'];
  6736. if ($va=='薪酬')
  6737. $p2+=$v['price'];
  6738. if ($va=='住宿费')
  6739. $p3+=$v['price'];
  6740. if ($va=='交通费')
  6741. $p4+=$v['price'];
  6742. if ($va=='餐饮费')
  6743. $p5+=$v['price'];
  6744. if ($va=='办公费')
  6745. $p6+=$v['price'];
  6746. if ($va=='公关费')
  6747. $p7+=$v['price'];
  6748. if ($va=='其他')
  6749. $p8+=$v['price'];
  6750. $psum+=$v['price'];
  6751. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6752. }
  6753. }
  6754. }
  6755. if($falg)
  6756. $html.='<td class="taR">-</td>';
  6757. }
  6758. $p9+=$psum;
  6759. if(!empty($psum))
  6760. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6761. else
  6762. $psum='<td class="colGreen taR">-</td>';
  6763. $receiptL['培训班费用']=$psum.$html;
  6764. /*-------------------------------------*/
  6765. $html="";
  6766. $psum=0;
  6767. $item=array('公关费','广告费','借款','可自加费用');
  6768. foreach ($item as $va){
  6769. $falg=true;
  6770. foreach ($receiptCollectList as $v){
  6771. if($v['itemCategory']=='其他'){
  6772. if($v['item']==$va){
  6773. if ($va=='公关费')
  6774. $t1+=$v['price'];
  6775. if ($va=='广告费')
  6776. $t2+=$v['price'];
  6777. if ($va=='借款')
  6778. $t3+=$v['price'];
  6779. if ($va=='可自加费用')
  6780. $t4+=$v['price'];
  6781. $psum+=$v['price'];
  6782. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6783. }
  6784. }
  6785. }
  6786. if($falg)
  6787. $html.='<td class="taR">-</td>';
  6788. }
  6789. $t5+=$psum;
  6790. if(!empty($psum))
  6791. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6792. else
  6793. $psum='<td class="colGreen taR">-</td>';
  6794. $receiptL['其他']=$psum.$html;
  6795. /*-------------------------------------*/
  6796. $html="";
  6797. $psum=0;
  6798. foreach ($receiptCollectList as $v){
  6799. if($v['itemCategory']=='报销金额调整'){
  6800. if (!empty($v['price'])){
  6801. $psum+=$v['price'];
  6802. }
  6803. }
  6804. }
  6805. $s1+=$psum;
  6806. if(!empty($psum))
  6807. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6808. else
  6809. $psum='<td class="taR colOrange">-</td>';
  6810. $receiptL['报销金额调整']=$psum.$html;
  6811. }else{
  6812. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6813. <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>';
  6814. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6815. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6816. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6817. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6818. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6819. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6820. }
  6821. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6822. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6823. if(!empty($monthStaffPrice[0]['price'])){
  6824. $m1+=$monthStaffPrice[0]['price'];
  6825. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6826. }else
  6827. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6828. $list[$value['username']]=$receiptL;
  6829. }
  6830. }
  6831. $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>
  6832. <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>
  6833. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6834. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6835. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6836. $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>
  6837. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6838. $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>';
  6839. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6840. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6841. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6842. }
  6843. $data['list']=$list;
  6844. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6845. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6846. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6847. //statistics html
  6848. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6849. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6850. if(empty($stList))
  6851. $stList=array('rePrice'=>0,'agPrice'=>0);
  6852. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6853. $monthHtml="";
  6854. for ($i=1;$i<=12;$i++){
  6855. if ($i==$month)
  6856. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6857. else
  6858. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6859. }
  6860. $data['monthHtml']=$monthHtml;
  6861. $data['year']=$year;
  6862. $data['month']=$month;
  6863. $data['memu']="receipt";
  6864. $data['staff']=$this->staff;
  6865. $data['receiptMemu']='companyCategoryCollect';
  6866. $data['verifyId']=$this->verifyId;
  6867. $data['executeId']=$this->executeId;
  6868. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6869. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6870. }
  6871. function companyMonthCollectDetail(){
  6872. $year=$this->get_args('year')?$this->get_args('year'):"";
  6873. $month=$this->get_args('month')?$this->get_args('month'):"";
  6874. if(!$year)
  6875. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6876. if(!$month)
  6877. $month=isset($this->params['month'])?$this->params['month']:1;
  6878. Doo::loadModel('staff');
  6879. $staff=new staff();
  6880. Doo::loadModel("receiptDetail");
  6881. $receiptDetail=new receiptDetail();
  6882. Doo::loadModel('accountItem');
  6883. $accountItem=new accountItem();
  6884. Doo::loadModel('statistics');
  6885. $statistics=new statistics();
  6886. Doo::loadModel('L_category');
  6887. $lCategory=new L_category();
  6888. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6889. $categoryList=$lCategory->find(array('asArray'=>true));
  6890. $list=array();
  6891. foreach ($categoryList as $value){
  6892. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6893. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6894. if(!empty($receiptCollectList)){
  6895. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6896. $html="";
  6897. $psum=0;
  6898. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6899. foreach ($item as $va){
  6900. $falg=true;
  6901. foreach ($receiptCollectList as $v){
  6902. if($v['itemCategory']=='日常相关费用'){
  6903. if($v['item']==$va){
  6904. $psum+=$v['price'];
  6905. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6906. }
  6907. }
  6908. }
  6909. if($falg)
  6910. $html.='<td class="taR">-</td>';
  6911. }
  6912. if(!empty($psum))
  6913. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6914. else
  6915. $psum='<td class="colGreen taR">-</td>';
  6916. $receiptL['日常相关费用']=$psum.$html;
  6917. /*-----------------------------------*/
  6918. $html="";
  6919. $psum=0;
  6920. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6921. foreach ($item as $va){
  6922. $falg=true;
  6923. foreach ($receiptCollectList as $v){
  6924. if($v['itemCategory']=='差旅相关费用'){
  6925. if($v['item']==$va){
  6926. $psum+=$v['price'];
  6927. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6928. }
  6929. }
  6930. }
  6931. if($falg)
  6932. $html.='<td class="taR">-</td>';
  6933. }
  6934. if(!empty($psum))
  6935. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6936. else
  6937. $psum='<td class="colGreen taR">-</td>';
  6938. $receiptL['差旅相关费用']=$psum.$html;
  6939. /*-------------------------------------*/
  6940. $html="";
  6941. $psum=0;
  6942. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6943. foreach ($item as $va){
  6944. $falg=true;
  6945. foreach ($receiptCollectList as $v){
  6946. if($v['itemCategory']=='培训班费用'){
  6947. if($v['item']==$va){
  6948. $psum+=$v['price'];
  6949. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6950. }
  6951. }
  6952. }
  6953. if($falg)
  6954. $html.='<td class="taR">-</td>';
  6955. }
  6956. if(!empty($psum))
  6957. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6958. else
  6959. $psum='<td class="colGreen taR">-</td>';
  6960. $receiptL['培训班费用']=$psum.$html;
  6961. /*-------------------------------------*/
  6962. $html="";
  6963. $psum=0;
  6964. $item=array('公关费','广告费','借款','可自加费用');
  6965. foreach ($item as $va){
  6966. $falg=true;
  6967. foreach ($receiptCollectList as $v){
  6968. if($v['itemCategory']=='其他'){
  6969. if($v['item']==$va){
  6970. $psum+=$v['price'];
  6971. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6972. }
  6973. }
  6974. }
  6975. if($falg)
  6976. $html.='<td class="taR">-</td>';
  6977. }
  6978. if(!empty($psum))
  6979. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6980. else
  6981. $psum='<td class="colGreen taR">-</td>';
  6982. $receiptL['其他']=$psum.$html;
  6983. /*-------------------------------------*/
  6984. $html="";
  6985. $psum=0;
  6986. foreach ($receiptCollectList as $v){
  6987. if($v['itemCategory']=='报销金额调整'){
  6988. if (!empty($v['price']))
  6989. $psum+=$v['price'];
  6990. }
  6991. }
  6992. if(!empty($psum))
  6993. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6994. else
  6995. $psum='<td class="taR colOrange">-</td>';
  6996. $receiptL['报销金额调整']=$psum.$html;
  6997. }else{
  6998. $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>
  6999. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7000. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7001. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7002. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7003. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7004. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7005. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7006. }
  7007. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  7008. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  7009. if(!empty($monthStaffPrice[0]['price']))
  7010. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  7011. else
  7012. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  7013. $list[$value['title']]=$receiptL;
  7014. }
  7015. $data['list']=$list;
  7016. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  7017. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  7018. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  7019. //print_r($data['monthPriceHtml']);
  7020. // foreach ($data['monthPriceHtml'] as $value){
  7021. // echo $value;
  7022. // }
  7023. // die;
  7024. //statistics html
  7025. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  7026. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  7027. if(empty($stList))
  7028. $stList=array('rePrice'=>0,'agPrice'=>0);
  7029. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  7030. $monthHtml="";
  7031. for ($i=1;$i<=12;$i++){
  7032. if ($i==$month)
  7033. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  7034. else
  7035. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  7036. }
  7037. $data['monthHtml']=$monthHtml;
  7038. $data['year']=$year;
  7039. $data['month']=$month;
  7040. $data['memu']="receipt";
  7041. $data['staff']=$this->staff;
  7042. $data['receiptMemu']='companyCategoryCollect';
  7043. $data['verifyId']=$this->verifyId;
  7044. $data['executeId']=$this->executeId;
  7045. $this->render ( "/admin/companyMonthCollectDetail", $data );
  7046. }
  7047. function staffCollectDetail(){
  7048. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  7049. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  7050. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  7051. if(!$staffname){
  7052. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  7053. $staffname= urldecode($staffname);
  7054. }
  7055. Doo::loadModel('staff');
  7056. $staff=new staff();
  7057. Doo::loadModel("receiptDetail");
  7058. $receiptDetail=new receiptDetail();
  7059. Doo::loadModel('accountItem');
  7060. $accountItem=new accountItem();
  7061. Doo::loadModel('statistics');
  7062. $statistics=new statistics();
  7063. Doo::loadModel('L_category');
  7064. $lCategory=new L_category();
  7065. $staffList=$staff->find(array('asArray'=>true));
  7066. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  7067. foreach ($staffList as $value){
  7068. if ($value['username']==$staffname&&$value['username']!='admin'){
  7069. $stTitle=$value['category'].'-'.$value['username'];
  7070. $staffId=$value['sid'];
  7071. $cid=$value['cid'];
  7072. $ocid=$value['cid'];
  7073. if (!empty($value['othercid']))
  7074. $cid=$value['cid'].','.$value['othercid'];
  7075. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  7076. }elseif ($value['username']!='admin')
  7077. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  7078. }
  7079. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  7080. if(empty($pcid))
  7081. $pcid=$ocid;
  7082. $data['ocid']=$pcid;
  7083. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  7084. $this->showCache($path);
  7085. //
  7086. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  7087. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  7088. $accountList=$accountItem->find(array('asArray'=>true));
  7089. //create CollectDetail HTML
  7090. $collectHtml=array();
  7091. foreach ($accountList as $key=>$value){
  7092. $html="";$asum=0;
  7093. for ($i=1;$i<=12;$i++){
  7094. $falg=true;
  7095. foreach ($receiptCollectList as $v) {
  7096. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  7097. $asum+=$v['price'];
  7098. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  7099. }
  7100. }
  7101. if($falg)
  7102. $html.='<td class="taR">-</td>';
  7103. }
  7104. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  7105. $collectHtml[$value['category']][$value['name']]=$html;
  7106. }
  7107. $data['collectHtml']=$collectHtml;
  7108. //create Adjustment price html
  7109. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  7110. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  7111. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7112. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  7113. array_push($collectArray['日常相关费用'], $collectHtml);
  7114. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  7115. array_push($collectArray['差旅相关费用'], $collectHtml);
  7116. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  7117. array_push($collectArray['培训班费用'], $collectHtml);
  7118. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  7119. array_push($collectArray['其他'], $collectHtml);
  7120. $data['collectArray']=$collectArray;
  7121. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  7122. array_push($adjustment, $collectHtml);
  7123. $data['adjustment']=$adjustment;
  7124. //total price html
  7125. $collectHtml="";$total=0;
  7126. for ($i=1;$i<=12;$i++){
  7127. $sumPrice=0;
  7128. foreach ($receiptCollectList as $key=>$value){
  7129. if($value['month']==$i){
  7130. $sumPrice+=$value['price'];
  7131. }
  7132. }
  7133. if ($sumPrice==0)
  7134. $collectHtml.='<td class="taR">-</td>';
  7135. else
  7136. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  7137. $total+=$sumPrice;
  7138. }
  7139. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  7140. //statistics html
  7141. $stList=$statistics->statisticsByYear($year,$staffId);
  7142. if(empty($stList))
  7143. $stList=array('rePrice'=>0,'agPrice'=>0);
  7144. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  7145. $data['totalPrice']=$collectHtml;
  7146. $data['totalYear']=$total;
  7147. $data['stHtml']=$stHtml;
  7148. $data['year']=$year;
  7149. $data['stTitle']=$stTitle;
  7150. $data['memu']="receipt";
  7151. $data['staff']=$this->staff;
  7152. $data['receiptMemu']='companyCategoryCollect';
  7153. $data['verifyId']=$this->verifyId;
  7154. $data['executeId']=$this->executeId;
  7155. if ($year<date("Y")){
  7156. Doo::loadModel('receipt');
  7157. $receipt=new receipt();
  7158. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  7159. if(empty($receiptList)){ //generated files
  7160. ob_start();
  7161. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7162. $this->cacheFile($path);die;
  7163. }
  7164. }
  7165. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7166. }
  7167. function BUGFLAG(){
  7168. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  7169. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  7170. $month=$this->get_args('month')?$this->get_args('month'):"";
  7171. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  7172. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  7173. if (empty($status))
  7174. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  7175. $page_size=12;
  7176. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7177. $vidList=array();
  7178. $button=0;
  7179. Doo::loadModel('verify');
  7180. $verify=new verify();
  7181. Doo::loadModel('receipt');
  7182. $receipt=new receipt();
  7183. Doo::loadModel('staff');
  7184. $staff=new staff();
  7185. Doo::loadModel('L_category');
  7186. $Lcategory=new L_category();
  7187. $dateCondition=" and Year(date) =".$year;
  7188. if(!empty($month))
  7189. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  7190. $categoryList=$Lcategory->find(array('asArray'=>true));
  7191. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7192. $cateCondition="";$staffCondition="";$approvalCondition="";
  7193. if (!empty($cid))
  7194. $cateCondition=' and cid='.$cid;
  7195. if(!empty($sid)){
  7196. $staffCondition=' and staff='.$sid;
  7197. $cateCondition="";
  7198. }
  7199. $approvalCondition=" and status=".$status;
  7200. if($status==2){
  7201. //查找角色审批人
  7202. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7203. }
  7204. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7205. $approvalCondition=' and status=2 ';
  7206. }
  7207. if($status==1){
  7208. $approvalCondition=' and (status='.$status.' or status=6) ';
  7209. }
  7210. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7211. $pageinfo['page']=array('previous'=>'');
  7212. if ($status==0){
  7213. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7214. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7215. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7216. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7217. }else
  7218. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7219. ,'desc'=>'rid','asArray'=>true));
  7220. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )'.$cateCondition.$staffCondition
  7221. ,'desc'=>'rid','asArray'=>true));
  7222. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7223. //print_r($pageinfo);
  7224. $Locate=0;
  7225. foreach ($receiptList as $key=>$value){
  7226. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7227. $receiptList[$key]['reviseDetail']=array();
  7228. if (!empty($value['reviseDetail']))
  7229. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7230. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7231. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7232. $receiptList[$key]['category']=$categoryDetil['title'];
  7233. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7234. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7235. $verifyStaff=json_decode($value['verifyStaff'],true);
  7236. foreach ($verifyList as $k=>$v){
  7237. //init verifyStaff
  7238. $verifyList[$k]['date']="";
  7239. $verifyList[$k]['opinion']="";
  7240. $verifyList[$k]['status']="";
  7241. if (empty($verifyStaff)){
  7242. $verifyList[$k]['date']="";
  7243. $verifyList[$k]['opinion']="";
  7244. if ($v[0]==$this->staff[0]['sid']){
  7245. $verifyList[$k]['status']=4;
  7246. $button=4;
  7247. }
  7248. }else{
  7249. $flag=true;
  7250. foreach ($verifyStaff as $m=>$u){
  7251. if ($v[0]==$m){
  7252. $verifyList[$k]['date']=$u['date'];
  7253. $verifyList[$k]['opinion']=$u['opinion'];
  7254. $verifyList[$k]['status']=$u['status'];
  7255. $flag=false;
  7256. break;
  7257. }
  7258. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7259. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7260. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7261. }
  7262. if($flag){//检测可编辑
  7263. if($v[0]==$this->staff[0]['sid']){
  7264. $verifyList[$k]['status']=4;$button=4;
  7265. }
  7266. }
  7267. }
  7268. }
  7269. $receiptList[$key]['verifyList']=$verifyList;
  7270. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7271. $receiptList[$key]['button']=$button;
  7272. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7273. }
  7274. //print_r($receiptList);die;
  7275. //$data['verifyDetail']=$verifyDetail;
  7276. $mothHtml="";
  7277. for($i=1;$i<=12;$i++){
  7278. if($month==$i)
  7279. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7280. else
  7281. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7282. }
  7283. $data['mothHtml']=$mothHtml;
  7284. $data['page']=$pageinfo;
  7285. $data['receiptList']=$receiptList;
  7286. $data['receiptApprovalCount']=count($rLRes);
  7287. $data['status']=$status;
  7288. $data['year']=$year;
  7289. $data['categoryList']=$categoryList;
  7290. $data['staffList']=$staffList;
  7291. $data['cid']=$cid;
  7292. $data['sid']=$sid;
  7293. //print_r($receiptList);
  7294. $data['memu']="receipt";
  7295. $data['staff']=$this->staff;
  7296. $data['receiptMemu']='approvalExpenses';
  7297. $data['verifyId']=$this->verifyId;
  7298. $data['executeId']=$this->executeId;
  7299. $this->render ( "/admin/FALG", $data );
  7300. }
  7301. function ajaxGetReceiptOrder(){
  7302. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7303. if (!empty($receiptOrder)){
  7304. Doo::loadModel('receipt');
  7305. $receipt=new receipt();
  7306. Doo::loadModel ( 'staff' );
  7307. $staff = new staff ();
  7308. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7309. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7310. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7311. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7312. </tbody></table><table class="table table table-bordered"><tbody>';
  7313. foreach ($verifyStaff as $key=>$value){
  7314. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7315. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7316. }
  7317. $html.='</tbody></table></div></div>';
  7318. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7319. }
  7320. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7321. }
  7322. function _getMonthCollectDetail($receiptCollectList){
  7323. if(!empty($receiptCollectList)){
  7324. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7325. $html="";
  7326. $psum=0;
  7327. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7328. foreach ($item as $value){
  7329. $falg=true;
  7330. foreach ($receiptCollectList as $v){
  7331. if($v['itemCategory']=='日常相关费用'){
  7332. if($v['item']==$value){
  7333. $psum+=$v['price'];
  7334. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7335. }
  7336. }
  7337. }
  7338. if($falg)
  7339. $html.='<td class="taR">-</td>';
  7340. }
  7341. if(!empty($psum))
  7342. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7343. else
  7344. $psum='<td class="colGreen taR">-</td>';
  7345. $receiptL['日常相关费用']=$psum.$html;
  7346. /*-----------------------------------*/
  7347. $html="";
  7348. $psum=0;
  7349. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7350. foreach ($item as $value){
  7351. $falg=true;
  7352. foreach ($receiptCollectList as $v){
  7353. if($v['itemCategory']=='差旅相关费用'){
  7354. if($v['item']==$value){
  7355. $psum+=$v['price'];
  7356. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7357. }
  7358. }
  7359. }
  7360. if($falg)
  7361. $html.='<td class="taR">-</td>';
  7362. }
  7363. if(!empty($psum))
  7364. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7365. else
  7366. $psum='<td class="colGreen taR">-</td>';
  7367. $receiptL['差旅相关费用']=$psum.$html;
  7368. /*-------------------------------------*/
  7369. $html="";
  7370. $psum=0;
  7371. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7372. foreach ($item as $value){
  7373. $falg=true;
  7374. foreach ($receiptCollectList as $v){
  7375. if($v['itemCategory']=='培训班费用'){
  7376. if($v['item']==$value){
  7377. $psum+=$v['price'];
  7378. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7379. }
  7380. }
  7381. }
  7382. if($falg)
  7383. $html.='<td class="taR">-</td>';
  7384. }
  7385. if(!empty($psum))
  7386. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7387. else
  7388. $psum='<td class="colGreen taR">-</td>';
  7389. $receiptL['培训班费用']=$psum.$html;
  7390. /*-------------------------------------*/
  7391. $html="";
  7392. $psum=0;
  7393. $item=array('公关费','广告费','借款','可自加费用');
  7394. foreach ($item as $value){
  7395. $falg=true;
  7396. foreach ($receiptCollectList as $v){
  7397. if($v['itemCategory']=='其他'){
  7398. if($v['item']==$value){
  7399. $psum+=$v['price'];
  7400. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7401. }
  7402. }
  7403. }
  7404. if($falg)
  7405. $html.='<td class="taR">-</td>';
  7406. }
  7407. if(!empty($psum))
  7408. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7409. else
  7410. $psum='<td class="colGreen taR">-</td>';
  7411. $receiptL['其他']=$psum.$html;
  7412. /*-------------------------------------*/
  7413. $html="";
  7414. $psum=0;
  7415. foreach ($receiptCollectList as $v){
  7416. if($v['itemCategory']=='报销金额调整'){
  7417. if (!empty($v['price']))
  7418. $psum+=$v['price'];
  7419. }
  7420. }
  7421. if(!empty($psum))
  7422. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7423. else
  7424. $psum='<td class="taR colOrange">-</td>';
  7425. $receiptL['报销金额调整']=$psum.$html;
  7426. }else{
  7427. $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>
  7428. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7429. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7430. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7431. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7432. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7433. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7434. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7435. }
  7436. return $receiptL;
  7437. }
  7438. function eMail(){
  7439. Doo::loadModel('staff');
  7440. $staff=new staff();
  7441. Doo::loadModel('receipt');
  7442. $receipt=new receipt();
  7443. Doo::loadModel('L_category');
  7444. $Lcategory=new L_category();
  7445. Doo::loadModel("verify");
  7446. $verify=new verify();
  7447. $staffList=$staff->find(array('asArray'=>true));
  7448. foreach ($staffList as $key=>$value){
  7449. if($value['username']!='admin'){
  7450. //提交人
  7451. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7452. if(!empty($receiptList)){
  7453. $html='<br><div><style></style>
  7454. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7455. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7456. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7457. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7458. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7459. <tbody><tr>
  7460. <td style="padding: 0 40px;" align="left">
  7461. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7462. </td></tr><tr>
  7463. <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>
  7464. </tr>
  7465. </tbody> </table></td> </tr> <tr><td>
  7466. <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">
  7467. <tbody> <tr><td>
  7468. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7469. 以下报销单完成了审批,等着收款吧:</p>
  7470. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7471. foreach ($receiptList as $k=>$v){
  7472. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7473. $html.='
  7474. <tr>
  7475. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7476. <td align="left">
  7477. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7478. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7479. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7480. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7481. </tr>';
  7482. }
  7483. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7484. <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>
  7485. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7486. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7487. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7488. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7489. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7490. $receipt=new receipt();
  7491. $receipt->notice=1;
  7492. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7493. }
  7494. }
  7495. //审批人
  7496. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7497. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7498. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7499. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7500. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7501. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7502. <tbody><tr><td style="padding: 0 40px;" align="left">
  7503. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7504. </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>
  7505. </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">
  7506. <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>
  7507. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7508. foreach ($verifyList as $k=>$v){
  7509. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7510. foreach ($receiptList as $r=>$l){
  7511. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7512. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7513. $html.='
  7514. <tr>
  7515. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7516. <td align="left">
  7517. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7518. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7519. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7520. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7521. </tr>';
  7522. }
  7523. }
  7524. $html.='
  7525. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7526. <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>
  7527. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7528. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7529. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7530. // $receipt=new receipt();
  7531. // $receipt->notice=1;
  7532. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7533. }
  7534. }
  7535. }
  7536. }
  7537. // Email发送函数
  7538. function SMail($toemail, $subject, $contents) {
  7539. Doo::loadClass('class.phpmailer');
  7540. $mail = new PHPMailer();
  7541. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7542. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7543. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7544. $mail->Password = "cDO1GjtY1seH"; //密码
  7545. $mail->CharSet = "UTF8";
  7546. $mail->SMTPAuth = true;
  7547. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7548. $mail->Mailer = "smtp";
  7549. $mail->Port = 25;
  7550. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7551. $mail->MsgHTML($contents);
  7552. $mail->AddAddress($toemail);
  7553. $mail->CharSet = "UTF-8";
  7554. return $mail->Send();
  7555. }
  7556. function swfupload(){
  7557. $POST_MAX_SIZE = ini_get('post_max_size');
  7558. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7559. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7560. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7561. header("HTTP/1.1 500 Internal Server Error");
  7562. echo "POST exceeded maximum allowed size.";
  7563. exit(0);
  7564. }
  7565. // Settings
  7566. $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)
  7567. $upload_name = "Filedata";
  7568. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7569. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7570. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7571. // Other variables
  7572. $MAX_FILENAME_LENGTH = 260;
  7573. $file_name = "";
  7574. $file_extension = "";
  7575. $uploadErrors = array(
  7576. 0=>"文件上传成功",
  7577. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7578. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7579. 3=>"上传的文件仅为部分文件",
  7580. 4=>"没有文件上传",
  7581. 6=>"缺少临时文件夹"
  7582. );
  7583. $nk= time();
  7584. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7585. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7586. echo "文件无法保存.";
  7587. exit(0);
  7588. }
  7589. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7590. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7591. exit(0);
  7592. }
  7593. function _GetFileEXT($filename) {
  7594. $pics = explode ( '.', $filename );
  7595. $num = count ( $pics );
  7596. return $pics [$num - 1];
  7597. }
  7598. /**
  7599. * 获取get或者POST值
  7600. * @param string $name 属性名称
  7601. * @return fixed 值
  7602. */
  7603. function get_args($name) {
  7604. if (isset ( $_GET [$name] )) {
  7605. if (is_array ( $_GET [$name] ))
  7606. return $_GET [$name];
  7607. else
  7608. return addslashes ( $_GET [$name] );
  7609. } elseif (isset ( $_POST [$name] )) {
  7610. if (is_array ( $_POST [$name] ))
  7611. return $_POST [$name];
  7612. else
  7613. return addslashes ( $_POST [$name] );
  7614. } else
  7615. return false;
  7616. }
  7617. function num_to_rmb($num){
  7618. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7619. $c2 = "分角元拾佰仟万拾佰仟亿";
  7620. //精确到分后面就不要了,所以只留两个小数位
  7621. $num = round($num, 2);
  7622. //将数字转化为整数
  7623. $num = $num * 100;
  7624. if (strlen($num) > 10) {
  7625. return "金额太大,请检查";
  7626. }
  7627. $i = 0;
  7628. $c = "";
  7629. while (1) {
  7630. if ($i == 0) {
  7631. //获取最后一位数字
  7632. $n = substr($num, strlen($num)-1, 1);
  7633. } else {
  7634. $n = $num % 10;
  7635. }
  7636. //每次将最后一位数字转化为中文
  7637. $p1 = substr($c1, 3 * $n, 3);
  7638. $p2 = substr($c2, 3 * $i, 3);
  7639. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7640. $c = $p1 . $p2 . $c;
  7641. } else {
  7642. $c = $p1 . $c;
  7643. }
  7644. $i = $i + 1;
  7645. //去掉数字最后一位了
  7646. $num = $num / 10;
  7647. $num = (int)$num;
  7648. //结束循环
  7649. if ($num == 0) {
  7650. break;
  7651. }
  7652. }
  7653. $j = 0;
  7654. $slen = strlen($c);
  7655. while ($j < $slen) {
  7656. //utf8一个汉字相当3个字符
  7657. $m = substr($c, $j, 6);
  7658. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7659. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7660. $left = substr($c, 0, $j);
  7661. $right = substr($c, $j + 3);
  7662. $c = $left . $right;
  7663. $j = $j-3;
  7664. $slen = $slen-3;
  7665. }
  7666. $j = $j + 3;
  7667. }
  7668. //这个是为了去掉类似23.0中最后一个“零”字
  7669. if (substr($c, strlen($c)-3, 3) == '零') {
  7670. $c = substr($c, 0, strlen($c)-3);
  7671. }
  7672. //将处理的汉字加上“整”
  7673. if (empty($c)) {
  7674. return "零元整";
  7675. }else{
  7676. return $c . "整";
  7677. }
  7678. }
  7679. /**
  7680. * 获得分页数据
  7681. * @param unknown_type $table
  7682. * @param unknown_type $condition
  7683. * @param unknown_type $on_page
  7684. * @param unknown_type $page_size
  7685. */
  7686. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7687. $page_c = "";
  7688. $page ['previous'] = $this->get_previous ( $on_page );
  7689. $page ['on_page'] = $on_page;
  7690. $total_count = $this->get_table_count ( $table, $condition );
  7691. $total = intval ( $total_count / $page_size );
  7692. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7693. $page ['total_data'] = $total_count;
  7694. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7695. $i = 1;
  7696. $page_max = 1;
  7697. $page_width=3;
  7698. if ($on_page >= $page_width) {
  7699. $page_max = intval ( $on_page / $page_width ) + 1;
  7700. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7701. }
  7702. for(; $i <= $page ['total_page']; $i ++) {
  7703. if ($i == $on_page)
  7704. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7705. else
  7706. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7707. if ($i == ($page_width * $page_max))
  7708. break;
  7709. }
  7710. $page ['page'] = $page_c;
  7711. $page ['lower'] = (-- $on_page) * $page_size;
  7712. return $page;
  7713. }
  7714. /**
  7715. * 获取总页数
  7716. * @param unknown_type $table
  7717. * @param unknown_type $condition
  7718. */
  7719. public function get_table_count($table = "", $condition = "") {
  7720. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7721. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7722. //echo $sql;die;
  7723. $query = Doo::db ()->query ( $sql );
  7724. $result = $query->fetch ();
  7725. return $result ['count'];
  7726. }
  7727. /**
  7728. * 获取上一页
  7729. * @param unknown_type $on_page
  7730. */
  7731. function get_previous($on_page = 1) {
  7732. return $on_page != 0 ? $on_page - 1 : $on_page;
  7733. }
  7734. }
  7735. ?>