ReceiptController.php 306 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. //public static $NEW2 = 0;
  10. public $AGENCY="日常相关费用";
  11. public $TRAVEL="差旅相关费用";
  12. public $TRAIN="培训班费用";
  13. public $OTHER="其他";
  14. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  18. private function showCache($path){
  19. if(file_exists($path)){
  20. echo "<!DOCTYPE html>";
  21. include $path;die;
  22. }
  23. }
  24. private function cacheFile($path){
  25. $content = ob_get_contents();
  26. $fp = fopen($path, "w");
  27. fwrite($fp, $content);
  28. fclose($fp);
  29. }
  30. // private function getExeCount(){
  31. // Doo::loadModel('receipt');
  32. // $receipt=new receipt();
  33. // $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  34. // return count($receiptList);
  35. // }
  36. // private function getReceiptCount(){
  37. // $status=2;
  38. // $year=date('Y');
  39. // Doo::loadModel('receipt');
  40. // $receipt=new receipt();
  41. // $dateCondition=" and Year(date) =".$year;
  42. // $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  43. // $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  44. // return count($receiptList);
  45. // }
  46. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  47. $collectHtml="";$sumPrice=0.00;
  48. for ($i=1;$i<=12;$i++){
  49. $falg=true;
  50. foreach ($receiptCollectList as $key=>$value){
  51. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  52. $sumPrice+=$value['price'];
  53. if ($classType=="b"){
  54. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  55. }else{
  56. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  57. }
  58. }
  59. }
  60. if ($falg)
  61. $collectHtml.='<td class="taR">-</td>';
  62. }
  63. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  64. return $collectHtml;
  65. }
  66. function __construct() {
  67. if(isset($_COOKIE["staff"])){
  68. if(!empty($_COOKIE["staff"])){
  69. Doo::loadModel ( 'staff' );
  70. Doo::loadModel('verify');
  71. $verify=new verify();
  72. $staff = new staff ();
  73. Doo::loadModel("execute");
  74. $execute=new execute();
  75. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  76. $list=array();
  77. //判断角色的审批权限
  78. foreach ($verifyList as $key=>$value){
  79. $ver=json_decode($value['staff']);
  80. foreach ($ver as $k=>$v){
  81. if ($v[1]=='ROLE'){
  82. $roleList=json_decode($v[3]);
  83. foreach ($roleList as $t=>$g){
  84. $gList=explode("_", $g);
  85. array_push($list, $gList[0]);
  86. //print_r($list);
  87. }
  88. }else
  89. array_push($list, $v[0]);
  90. }
  91. }
  92. //判断执行人的审批权限
  93. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  94. $list2=array();
  95. foreach ($executeList as $key=>$value){
  96. $ver=json_decode($value['staff']);
  97. foreach ($ver as $k=>$v){
  98. array_push($list2, $v[0]);
  99. }
  100. }
  101. $eidList=file_get_contents("protected/config/execute/execute.ini");
  102. $eidList=array_filter(explode(",", $eidList));
  103. $this->executeId= array_merge($list2,$eidList);
  104. $this->verifyId=$list;
  105. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  106. return "/";
  107. }
  108. }
  109. Doo::loadCore ( 'uri/DooUriRouter' );
  110. $router = new DooUriRouter ();
  111. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  112. if($routeRs['1']!="login"){
  113. header ( 'Content-Type:text/html;charset=utf-8' );
  114. @header ( "Location: /login" );
  115. }
  116. }
  117. function saeaBorad(){
  118. Doo::loadModel('receipt');
  119. Doo::loadModel('verify');
  120. $verify=new verify();
  121. $receipt=new receipt();
  122. Doo::loadModel('L_category');
  123. $lCategory=new L_category();
  124. Doo::loadModel("role");
  125. $role=new role();
  126. Doo::loadModel("receiptLog");
  127. $receiptLog=new receiptLog();
  128. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  129. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)','desc'=>'rid','asArray'=>true));
  130. foreach ($receiptDetail as $key=>$value){
  131. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  132. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  133. $v=json_decode($veList['staff']);
  134. array_push($v[0], $veList['description']);
  135. foreach ($v as $n=>$m){
  136. if ($m['1']=='ROLE'){
  137. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  138. $v[$n][1]=$roleInfo['name'];
  139. }
  140. }
  141. $receiptDetail[$key]['staff']=$v;
  142. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  143. $receiptDetail[$key]['category']=$category['title'];
  144. }
  145. //print_r($receiptLogList);
  146. $data['receiptLogList']=$receiptLogList;
  147. $data['receiptDetail']=$receiptDetail;
  148. $data['memu']="receipt";
  149. $data['staff']=$this->staff;
  150. $data['receiptMemu']='saeaBorad';
  151. $data['verifyId']=$this->verifyId;
  152. $data['executeId']=$this->executeId;
  153. $this->render ( "/admin/saeaBorad", $data );
  154. }
  155. function remitAdd(){
  156. Doo::loadModel('accountItem');
  157. Doo::loadModel('verify');
  158. Doo::loadModel('receipt');
  159. Doo::loadModel('L_category');
  160. $lCategory=new L_category();
  161. $receipt=new receipt();
  162. $verify=new verify();
  163. $accountItem=new accountItem();
  164. Doo::loadModel("role");
  165. $role=new role();
  166. $acItem=$accountItem->find(array('asArray'=>true));
  167. $veList=$verify->find(array('asArray'=>true));
  168. foreach ($veList as $key=>$value){
  169. $v=json_decode($value['staff']);
  170. $list=array();
  171. foreach ($v as $n=>$m){
  172. if ($m['1']=='ROLE'){
  173. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  174. $v[$n][1]=$roleInfo['name'];
  175. array_push($list, $roleInfo['name']);
  176. }else{
  177. array_push($list, $v[$n][1]);
  178. }
  179. }
  180. $veList[$key]['staff']=implode('>', $list);
  181. }
  182. $data['category']=$lCategory->find(array('asArray'=>true));
  183. $data['veList']=$veList;
  184. $data['acItem']=$acItem;
  185. $data['memu']="receipt";
  186. $data['staff']=$this->staff;
  187. $data['receiptMemu']='saeaBorad';
  188. $data['verifyId']=$this->verifyId;
  189. $data['executeId']=$this->executeId;
  190. $this->render ( "/admin/remitAdd", $data );
  191. }
  192. function remitAddDo(){
  193. $agency=$this->get_args('agency');
  194. $travel=$this->get_args('travel');
  195. $train=$this->get_args('train');
  196. $other=$this->get_args('other');
  197. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  198. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  199. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  200. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  201. //print_r($agency);die;
  202. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  203. Doo::loadModel('receipt');
  204. Doo::loadModel('receiptDetail');
  205. Doo::loadModel('accountItem');
  206. $accountItem=new accountItem();
  207. $receipt=new receipt();
  208. Doo::loadModel('enclosur');
  209. Doo::loadModel('execute');
  210. $execute=new execute();
  211. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  212. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  213. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  214. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  215. $ag=$tr=$ta=$ot=0;
  216. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  217. foreach ($aItem as $key=>$value){
  218. if ($value['category']==$this->AGENCY){
  219. if (isset($agency[$ag])){
  220. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  221. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  222. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  223. }
  224. }
  225. $ag++;
  226. }
  227. }
  228. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  229. //报销单
  230. $receipt->accountItem=json_encode($accountJson);
  231. $receipt->staff=$this->staff[0]['sid'];
  232. $receipt->sum=number_format($sum, 2, '.', '');
  233. $receipt->date=date("Y-m-d");
  234. $receipt->cid=$cid;
  235. $receipt->status=5;
  236. $receipt->Rtype=2;
  237. //修改审批流程加入角色
  238. $receipt->verify=$verify;
  239. $receipt->executeCopy=$executeDetail['staff'];
  240. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  241. $receipt->explanation=$explanation;
  242. $rid=$receipt->insert();
  243. //附件
  244. if (!empty($enclosurName)){
  245. $enclosurArray=explode('-', $enclosurName);
  246. foreach ($enclosurArray as $value){
  247. $enclosur=new enclosur();
  248. $enclosur->name=$value;
  249. $enclosur->rid=$rid;
  250. $enclosur->insert();
  251. }
  252. //print_r($enclosurArray);die;
  253. }
  254. //报销详情
  255. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  256. $receiptDetail=new receiptDetail();
  257. $receiptDetail->staff=$this->staff[0]['sid'];
  258. $receiptDetail->item=$value['name'];
  259. $receiptDetail->itemCategory=$this->AGENCY;
  260. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  261. $receiptDetail->date=date("Y-m-d");
  262. $receiptDetail->cid=$cid;
  263. $receiptDetail->rid=$rid;
  264. $receiptDetail->status=4;
  265. $receiptDetail->insert();
  266. }
  267. }
  268. return "/saeaBorad";
  269. }
  270. function remitEdit(){
  271. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  272. //echo $rid;
  273. Doo::loadModel('accountItem');
  274. Doo::loadModel('verify');
  275. Doo::loadModel('receipt');
  276. $receipt=new receipt();
  277. $verify=new verify();
  278. $accountItem=new accountItem();
  279. Doo::loadModel('L_category');
  280. $lCategory=new L_category();
  281. Doo::loadModel("role");
  282. $role=new role();
  283. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  284. if(empty($receiptDetail))
  285. return "/saeaCreate";
  286. $acItem=$accountItem->find(array('asArray'=>true));
  287. $veList=$verify->find(array('asArray'=>true));
  288. foreach ($veList as $key=>$value){
  289. $v=json_decode($value['staff']);
  290. $list=array();
  291. foreach ($v as $n=>$m){
  292. if ($m['1']=='ROLE'){
  293. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  294. $v[$n][1]=$roleInfo['name'];
  295. array_push($list, $roleInfo['name']);
  296. }else{
  297. array_push($list, $v[$n][1]);
  298. }
  299. }
  300. $veList[$key]['staff']=implode('>', $list);
  301. }
  302. //配置编辑信息
  303. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  304. foreach ($acItem as $key=>$value){
  305. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  306. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  307. $acItem[$key]['price']=$v['price'];
  308. }
  309. }
  310. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  311. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  312. $acItem[$key]['price']=$v['price'];
  313. }
  314. }
  315. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  316. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  317. $acItem[$key]['price']=$v['price'];
  318. }
  319. }
  320. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  321. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  322. $acItem[$key]['price']=$v['price'];
  323. }
  324. }
  325. }
  326. $data['category']=$lCategory->find(array('asArray'=>true));
  327. $data['cSum']=$accountItemList['cSum'];
  328. $data['sum']=$receiptDetail['sum'];
  329. $data['receiptDetail']=$receiptDetail;
  330. $data['veList']=$veList;
  331. $data['acItem']=$acItem;
  332. $data['memu']="receipt";
  333. $data['staff']=$this->staff;
  334. $data['receiptMemu']='saeaBorad';
  335. $data['verify']=$receiptDetail['verify'];
  336. $data['verifyId']=$this->verifyId;
  337. $data['executeId']=$this->executeId;
  338. $data['rid']=$rid;
  339. $this->render ( "/admin/remitEdit", $data );
  340. }
  341. function remitEdiDo(){
  342. $agency=$this->get_args('agency');
  343. $travel=$this->get_args('travel');
  344. $train=$this->get_args('train');
  345. $other=$this->get_args('other');
  346. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  347. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  348. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  349. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  350. if(!empty($explanation)){
  351. Doo::loadModel('receipt');
  352. Doo::loadModel('receiptDetail');
  353. Doo::loadModel('accountItem');
  354. $accountItem=new accountItem();
  355. $receipt=new receipt();
  356. Doo::loadModel('execute');
  357. $execute=new execute();
  358. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  359. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  360. if(empty($receiptDetail))
  361. return "/saeaBorad";
  362. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  363. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  364. $ag=$tr=$ta=$ot=0;
  365. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  366. foreach ($aItem as $key=>$value){
  367. if ($value['category']==$this->AGENCY){
  368. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  369. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  370. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  371. }
  372. $ag++;
  373. }
  374. }
  375. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  376. //报销单
  377. $rid=$receipt->rid=$receiptDetail['rid'];
  378. $receipt->accountItem=json_encode($accountJson);
  379. $receipt->staff=$this->staff[0]['sid'];
  380. $receipt->sum=number_format($sum, 2, '.', '');
  381. $receipt->date=date("Y-m-d");
  382. $receipt->cid=$cid;
  383. if ($receiptDetail['Rtype']==1)
  384. $receipt->status=7;
  385. else
  386. $receipt->status=5;
  387. if ($receiptDetail['status']!=4&&!empty($verify))
  388. $receipt->verify=$verify;
  389. $receipt->executeCopy=$executeDetail['staff'];
  390. $receipt->explanation=$explanation;
  391. $receipt->update();
  392. $receiptDetail=new receiptDetail();
  393. $receiptDetail->delete(array('where'=>'rid='.$rid));
  394. //报销详情
  395. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  396. $receiptDetail=new receiptDetail();
  397. $receiptDetail->staff=$this->staff[0]['sid'];
  398. $receiptDetail->item=$value['name'];
  399. $receiptDetail->itemCategory=$this->AGENCY;
  400. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  401. $receiptDetail->date=date("Y-m-d");
  402. $receiptDetail->cid=$cid;
  403. $receiptDetail->rid=$rid;
  404. $receiptDetail->status=4;
  405. $receiptDetail->insert();
  406. }
  407. //return "/referReceipt/".$rid;
  408. }
  409. return "/saeaBorad";
  410. }
  411. function remitApproval(){
  412. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  413. $status=isset($this->params['status'])?$this->params['status']:'';
  414. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  415. $month=$this->get_args('month')?$this->get_args('month'):"";
  416. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  417. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  418. if (empty($status))
  419. $status=$this->get_args('status')?$this->get_args('status'):2;
  420. $vidList=array();
  421. $button=0;
  422. Doo::loadModel('verify');
  423. Doo::loadModel('receipt');
  424. Doo::loadModel('staff');
  425. $staff=new staff();
  426. $receipt=new receipt();
  427. $verify=new verify();
  428. Doo::loadModel('L_category');
  429. $Lcategory=new L_category();
  430. Doo::loadModel('enclosur');
  431. $enclosur=new enclosur();
  432. //user verify ID
  433. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  434. foreach ($verifyDetail as $key=>$value){
  435. array_push($vidList, $value['vid']);
  436. }
  437. $vid=implode(",", $vidList);
  438. if(empty($verifyDetail))
  439. $vid=0;
  440. $categoryList=$Lcategory->find(array('asArray'=>true));
  441. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  442. $ap="";
  443. if($status==4){
  444. $ap=4;$status=2;
  445. }
  446. //get Receipt By verifyID status 2
  447. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  448. $Locate=0;$roleId=0;
  449. if($ap==4)
  450. $status=4;
  451. foreach ($receiptList as $key=>$value){
  452. $receiptList[$key]['Locate']=$Locate;$Locate++;
  453. $receiptList[$key]['reviseDetail']=array();
  454. if (!empty($value['reviseDetail']))
  455. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  456. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  457. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  458. $receiptList[$key]['category']=$categoryDetil['title'];
  459. //检测编辑状态
  460. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  461. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  462. $verifyStaff=json_decode($value['verifyStaff'],true);
  463. Doo::loadModel('role');
  464. $role=new role();
  465. //print_r($verifyList);
  466. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  467. foreach ($verifyList as $k=>$v){
  468. //init verifyStaff
  469. if ($v[1]=='ROLE'){
  470. if (!empty($verifyStaff)){
  471. $endStaffArray=end($verifyStaff);
  472. if ($v[0]==$endStaffArray['nextStaff']){
  473. $roleId=$v[0];
  474. }
  475. }
  476. $roleVerify=json_decode($v[3],true);
  477. $roleKey=$k;$roleArray=array();
  478. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  479. foreach ($roleVerify as $o=>$p){
  480. $staffID=explode ('_',$p);
  481. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  482. //print_r($staffID);
  483. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  484. array_push($roleArray, $exp);
  485. }
  486. $roleArrayCopy[$v[0]]=$roleArray;
  487. //$verifyList[$k]['roleArray']=$roleArray;
  488. }
  489. //print_r($roleArray);
  490. $verifyList[$k]['date']="";
  491. $verifyList[$k]['opinion']="";
  492. $verifyList[$k]['status']="";
  493. if (empty($verifyStaff)){
  494. $verifyList[$k]['date']="";
  495. $verifyList[$k]['opinion']="";
  496. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  497. $verifyList[$k]['status']=4;
  498. $button=4;$flag=false;
  499. }
  500. }else{
  501. foreach ($verifyStaff as $m=>$u){
  502. if ($v[0]==$m){
  503. $verifyList[$k]['date']=$u['date'];
  504. $verifyList[$k]['opinion']=$u['opinion'];
  505. $verifyList[$k]['status']=$u['status'];
  506. $flag=false;
  507. break;
  508. }
  509. }
  510. $endStaffArray=end($verifyStaff);
  511. if (isset($endStaffArray['ROLE'])){
  512. }else{
  513. $endKey=key($verifyStaff);
  514. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  515. $button=4;
  516. $verifyList[$k]['status']=4;
  517. }
  518. }
  519. }
  520. }
  521. $rolename['name']='';
  522. if (!empty($roleId)){
  523. Doo::loadModel('role');
  524. $role=new role();
  525. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  526. }
  527. if (!empty($verifyStaff))
  528. $endStaffArray=end($verifyStaff);
  529. $KOP=false;
  530. foreach ($roleArrayCopy as $P=>$A){
  531. foreach ( $A as $MKI=>$AVL){
  532. if (!empty($verifyStaff)){
  533. //&&$rolename['rid']==$endStaffArray['nextStaff']
  534. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  535. $button=4;
  536. $roleArrayCopy[$P][$MKI]['status']=4;
  537. }
  538. foreach ($verifyStaff as $m=>$u){
  539. $AVLFK=$AVL[0].'_R';
  540. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  541. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  542. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  543. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  544. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  545. break;
  546. }
  547. }
  548. }else{
  549. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  550. $button=4;
  551. $roleArrayCopy[$P][$MKI]['status']=4;
  552. }
  553. }
  554. //$roleArray[$MKI]['rolename']=$rolename['name'];
  555. $KOP=true;
  556. }
  557. }
  558. foreach ($roleArrayCopy as $k=>$v){
  559. foreach ($verifyList as $m=>$n){
  560. if ($n[0]==$k){
  561. array_splice($verifyList,$m,1,$v);
  562. }
  563. }
  564. }
  565. $receiptList[$key]['verifyList']= $verifyList;
  566. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  567. $receiptList[$key]['button']=$button;
  568. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  569. }
  570. $mothHtml="";
  571. for($i=1;$i<=12;$i++){
  572. if($month==$i)
  573. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  574. else
  575. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  576. }
  577. //获取审批日志
  578. Doo::loadModel('receiptLog');
  579. $receiptLog=new receiptLog();
  580. $rlList=array();
  581. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  582. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  583. if (!empty($rlInfo)){
  584. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  585. }
  586. $receiptList[0]['rlList']=$rlList;
  587. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  588. $enclosurHtml='';
  589. foreach ($enclosurList as $value){
  590. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  591. }
  592. //print_r($receiptList);
  593. $data['enclosurHtml']=$enclosurHtml;
  594. $data['rolename']=$rolename['name'];
  595. $data['datetij']=$tijdate['date'];
  596. $data['mothHtml']=$mothHtml;
  597. $data['rid']=$rid;
  598. $data['receiptList']=$receiptList;
  599. $data['receiptApprovalCount']=count($receiptList);
  600. $data['status']=$status;
  601. $data['year']=$year;
  602. $data['categoryList']=$categoryList;
  603. $data['staffList']=$staffList;
  604. $data['cid']=$cid;
  605. $data['sid']=$sid;
  606. $data['ap']=$ap;
  607. $data['memu']="receipt";
  608. $data['staff']=$this->staff;
  609. $data['receiptMemu']='approvalExpenses';
  610. $data['verifyId']=$this->verifyId;
  611. $data['executeId']=$this->executeId;
  612. $this->render ( "/admin/remitApproval", $data );
  613. }
  614. function saeaLoanAdd(){
  615. Doo::loadModel('verify');
  616. $verify=new verify();
  617. Doo::loadModel("role");
  618. $role=new role();
  619. Doo::loadModel('L_category');
  620. $lCategory=new L_category();
  621. $veList=$verify->find(array('asArray'=>true));
  622. foreach ($veList as $key=>$value){
  623. $v=json_decode($value['staff']);
  624. $list=array();
  625. foreach ($v as $n=>$m){
  626. if ($m['1']=='ROLE'){
  627. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  628. $v[$n][1]=$roleInfo['name'];
  629. array_push($list, $roleInfo['name']);
  630. }else{
  631. array_push($list, $v[$n][1]);
  632. }
  633. }
  634. $veList[$key]['staff']=implode('>', $list);
  635. }
  636. $data['category']=$lCategory->find(array('asArray'=>true));
  637. $data['veList']=$veList;
  638. $data['memu']="receipt";
  639. $data['staff']=$this->staff;
  640. $data['receiptMemu']='saeaBorad';
  641. $data['verifyId']=$this->verifyId;
  642. $data['executeId']=$this->executeId;
  643. $this->render ( "/admin/saeaLoanAdd", $data );
  644. }
  645. function saeaLoanAddDo(){
  646. $agency=$this->get_args('agency');
  647. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  648. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  649. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  650. //die;
  651. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  652. Doo::loadModel('receipt');
  653. Doo::loadModel('receiptDetail');
  654. Doo::loadModel('accountItem');
  655. $accountItem=new accountItem();
  656. $receipt=new receipt();
  657. Doo::loadModel('loanReceipt');
  658. $loanReceipt=new loanReceipt();
  659. Doo::loadModel('execute');
  660. $execute=new execute();
  661. Doo::loadModel('enclosur');
  662. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  663. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  664. // if(!empty($receiptDetail))
  665. // return "/referReceipt/".$receiptDetail['rid'];
  666. $aItem=$accountItem->find(array('asArray'=>true));
  667. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  668. $ag=$tr=$ta=$ot=0;
  669. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  670. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  671. $sum+=$agency;$agencySum+=$agency;
  672. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  673. //借款数据备份
  674. $loanReceipt->loanItem=json_encode($accountJson);
  675. $loanReceipt->staff=$this->staff[0]['sid'];
  676. $loanReceipt->sum=number_format($sum, 2, '.', '');
  677. $loanReceipt->date=date("Y-m-d");
  678. $loanReceipt->cid=$cid;
  679. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  680. $loanReceipt->status=5;
  681. $loanReceipt->Rtype=1;
  682. $loanReceipt->verify=$verify;
  683. $receipt->receiptOrder=$receipt->receiptOrder;
  684. $loanReceipt->explanation=$explanation;
  685. $loanRid=$loanReceipt->insert();
  686. //报销单
  687. $receipt->loanItem=json_encode($accountJson);
  688. $receipt->staff=$this->staff[0]['sid'];
  689. $receipt->sum=number_format($sum, 2, '.', '');
  690. $receipt->date=date("Y-m-d");
  691. $receipt->cid=$cid;
  692. //特殊状态
  693. $receipt->status=5;
  694. $receipt->Rtype=1;
  695. $receipt->loanRid=$loanRid;
  696. //修改审批流程加入角色
  697. $receipt->verify=$verify;
  698. $receipt->executeCopy=$executeDetail['staff'];
  699. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  700. $receipt->explanation=$explanation;
  701. $rid=$receipt->insert();
  702. //执行数据备份
  703. // $executeCopy->rid=$rid;
  704. // $executeCopy->staff=$executeDetail['staff'];
  705. // $executeCopy->eid=$executeDetail['eid'];
  706. // $ecid=$executeCopy->insert();
  707. }
  708. return "/saeaBorad";
  709. }
  710. function saeaLoanEdi(){
  711. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  712. Doo::loadModel('verify');
  713. $verify=new verify();
  714. Doo::loadModel("role");
  715. $role=new role();
  716. Doo::loadModel('L_category');
  717. $lCategory=new L_category();
  718. Doo::loadModel('receipt');
  719. $receipt=new receipt();
  720. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  721. $veList=$verify->find(array('asArray'=>true));
  722. foreach ($veList as $key=>$value){
  723. $v=json_decode($value['staff']);
  724. $list=array();
  725. foreach ($v as $n=>$m){
  726. if ($m['1']=='ROLE'){
  727. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  728. $v[$n][1]=$roleInfo['name'];
  729. array_push($list, $roleInfo['name']);
  730. }else{
  731. array_push($list, $v[$n][1]);
  732. }
  733. }
  734. $veList[$key]['staff']=implode('>', $list);
  735. }
  736. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  737. $data['receiptInfo']=$receiptInfo;
  738. $data['category']=$lCategory->find(array('asArray'=>true));
  739. $data['veList']=$veList;
  740. $data['memu']="receipt";
  741. $data['staff']=$this->staff;
  742. $data['receiptMemu']='saeaBorad';
  743. $data['verifyId']=$this->verifyId;
  744. $data['executeId']=$this->executeId;
  745. $this->render ( "/admin/saeaLoanEdi", $data );
  746. }
  747. function saeaLoanEdiDo(){
  748. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  749. $agency=$this->get_args('agency');
  750. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  751. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  752. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  753. //die;
  754. if(!empty($cid)&&!empty($explanation)&&!empty($rid)){
  755. Doo::loadModel('receipt');
  756. Doo::loadModel('receiptDetail');
  757. Doo::loadModel('accountItem');
  758. $accountItem=new accountItem();
  759. $receipt=new receipt();
  760. Doo::loadModel('loanReceipt');
  761. $loanReceipt=new loanReceipt();
  762. Doo::loadModel('enclosur');
  763. Doo::loadModel('execute');
  764. $execute=new execute();
  765. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  766. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=5 or status=4) and rid='.$rid,'asArray'=>true));
  767. if(empty($receiptDetail))
  768. die('参数错误');
  769. $aItem=$accountItem->find(array('asArray'=>true));
  770. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  771. $ag=$tr=$ta=$ot=0;
  772. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  773. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  774. $sum+=$agency;$agencySum+=$agency;
  775. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  776. //报销单
  777. $receipt->loanItem=json_encode($accountJson);
  778. $receipt->sum=number_format($sum, 2, '.', '');
  779. $receipt->cid=$cid;
  780. //特殊状态
  781. //修改审批流程加入角色
  782. if ($receiptDetail['status']!=4)
  783. $receipt->verify=$verify;
  784. $receipt->explanation=$explanation;
  785. $receipt->update(array('where'=>'rid='.$rid));
  786. //借款数据更新
  787. $loanReceipt->loanItem=json_encode($accountJson);
  788. $loanReceipt->sum=number_format($sum, 2, '.', '');
  789. $loanReceipt->cid=$cid;
  790. if ($receiptDetail['status']!=4)
  791. $loanReceipt->verify=$verify;
  792. $loanReceipt->explanation=$explanation;
  793. $receipt->executeCopy=$executeDetail['staff'];
  794. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  795. }
  796. return "/saeaBorad";
  797. }
  798. function saeaLoanReceiptAdd(){
  799. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  800. Doo::loadModel('receipt');
  801. $receipt=new receipt();
  802. Doo::loadModel('loanReceipt');
  803. $loanReceipt=new loanReceipt();
  804. Doo::loadModel('L_category');
  805. $Lcategory=new L_category();
  806. Doo::loadModel('verify');
  807. Doo::loadModel('statistics');
  808. $statistics=new statistics();
  809. $verify=new verify();
  810. Doo::loadModel('staff');
  811. $staff=new staff();
  812. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  813. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  814. $Locate=0;$roleId=0;$button=0;
  815. foreach ($receiptList as $key=>$value){
  816. $receiptList[$key]['Locate']=$Locate;$Locate++;
  817. $receiptList[$key]['reviseDetail']=array();
  818. if (!empty($value['reviseDetail']))
  819. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  820. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  821. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  822. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  823. $receiptList[$key]['category']=$categoryDetil['title'];
  824. //检测编辑状态
  825. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  826. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  827. $verifyStaff=json_decode($value['verifyStaff'],true);
  828. Doo::loadModel('role');
  829. $role=new role();
  830. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  831. foreach ($verifyList as $k=>$v){
  832. //init verifyStaff
  833. if ($v[1]=='ROLE'){
  834. if (!empty($verifyStaff)){
  835. $endStaffArray=end($verifyStaff);
  836. // if ($v[0]==$endStaffArray['nextStaff']){
  837. // $roleId=$v[0];
  838. // }
  839. }
  840. $roleVerify=json_decode($v[3],true);
  841. $roleKey=$k;$roleArray=array();
  842. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  843. foreach ($roleVerify as $o=>$p){
  844. $staffID=explode ('_',$p);
  845. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  846. //print_r($staffID);
  847. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  848. array_push($roleArray, $exp);
  849. }
  850. $roleArrayCopy[$v[0]]=$roleArray;
  851. //$verifyList[$k]['roleArray']=$roleArray;
  852. }
  853. $verifyList[$k]['date']="";
  854. $verifyList[$k]['opinion']="";
  855. $verifyList[$k]['status']="";
  856. if (empty($verifyStaff)){
  857. $verifyList[$k]['date']="";
  858. $verifyList[$k]['opinion']="";
  859. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  860. $verifyList[$k]['status']=4;
  861. $flag=false;
  862. }
  863. }else{
  864. foreach ($verifyStaff as $m=>$u){
  865. if ($v[0]==$m){
  866. $verifyList[$k]['date']=$u['date'];
  867. $verifyList[$k]['opinion']=$u['opinion'];
  868. $verifyList[$k]['status']=$u['status'];
  869. $flag=false;
  870. break;
  871. }
  872. }
  873. $endStaffArray=end($verifyStaff);
  874. if (isset($endStaffArray['ROLE'])){
  875. }else{
  876. // $endKey=key($verifyStaff);
  877. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  878. // $button=4;
  879. // $verifyList[$k]['status']=4;
  880. // }
  881. }
  882. }
  883. }
  884. $rolename['name']='';
  885. if (!empty($roleId)){
  886. Doo::loadModel('role');
  887. $role=new role();
  888. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  889. }
  890. if (!empty($verifyStaff))
  891. $endStaffArray=end($verifyStaff);
  892. $KOP=false;
  893. foreach ($roleArrayCopy as $P=>$A){
  894. foreach ( $A as $MKI=>$AVL){
  895. if (!empty($verifyStaff)){
  896. //&&$rolename['rid']==$endStaffArray['nextStaff']
  897. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  898. $button=4;
  899. $roleArrayCopy[$P][$MKI]['status']=4;
  900. }
  901. foreach ($verifyStaff as $m=>$u){
  902. $AVLFK=$AVL[0].'_R';
  903. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  904. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  905. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  906. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  907. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  908. break;
  909. }
  910. }
  911. }else{
  912. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  913. $button=4;
  914. $roleArrayCopy[$P][$MKI]['status']=4;
  915. }
  916. }
  917. //$roleArray[$MKI]['rolename']=$rolename['name'];
  918. $KOP=true;
  919. }
  920. }
  921. foreach ($roleArrayCopy as $k=>$v){
  922. foreach ($verifyList as $m=>$n){
  923. if ($n[0]==$k){
  924. array_splice($verifyList,$m,1,$v);
  925. }
  926. }
  927. }
  928. $receiptList[$key]['verifyList']=$verifyList;
  929. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  930. $receiptList[$key]['button']=$button;
  931. //
  932. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  933. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  934. }
  935. $data['receiptList']=$receiptList;
  936. Doo::loadModel('L_category');
  937. $lCategory=new L_category();
  938. Doo::loadModel('accountItem');
  939. $accountItem=new accountItem();
  940. $acItem=$accountItem->find(array('asArray'=>true));
  941. $veList=$verify->find(array('asArray'=>true));
  942. foreach ($veList as $key=>$value){
  943. $v=json_decode($value['staff']);
  944. $list=array();
  945. foreach ($v as $n=>$m){
  946. if ($m['1']=='ROLE'){
  947. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  948. $v[$n][1]=$roleInfo['name'];
  949. array_push($list, $roleInfo['name']);
  950. }else{
  951. array_push($list, $v[$n][1]);
  952. }
  953. }
  954. $veList[$key]['staff']=implode('>', $list);
  955. }
  956. $data['rid']=$rid;
  957. $data['category']=$lCategory->find(array('asArray'=>true));
  958. $data['veList']=$veList;
  959. $data['acItem']=$acItem;
  960. $data['memu']="receipt";
  961. $data['staff']=$this->staff;
  962. $data['receiptMemu']='saeaBorad';
  963. $data['verifyId']=$this->verifyId;
  964. $data['executeId']=$this->executeId;
  965. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  966. }
  967. function saeaLoanReceiptAddDo(){
  968. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  969. $agency=$this->get_args('agency');
  970. $travel=$this->get_args('travel');
  971. $train=$this->get_args('train');
  972. $other=$this->get_args('other');
  973. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  974. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  975. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  976. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  977. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  978. Doo::loadModel('receipt');
  979. Doo::loadModel('receiptDetail');
  980. Doo::loadModel('accountItem');
  981. $accountItem=new accountItem();
  982. $receipt=new receipt();
  983. Doo::loadModel('enclosur');
  984. Doo::loadModel('execute');
  985. $execute=new execute();
  986. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  987. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  988. // if(!empty($receiptDetail))
  989. // return "/referReceipt/".$receiptDetail['rid'];
  990. $aItem=$accountItem->find(array('asArray'=>true));
  991. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  992. $ag=$tr=$ta=$ot=0;
  993. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  994. foreach ($aItem as $key=>$value){
  995. if ($value['category']==$this->AGENCY){
  996. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  997. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  998. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  999. }
  1000. $ag++;
  1001. }
  1002. if($value['category']==$this->TRAVEL){
  1003. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1004. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1005. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1006. }
  1007. $tr++;
  1008. }
  1009. if($value['category']==$this->TRAIN){
  1010. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1011. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1012. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1013. }
  1014. $ta++;
  1015. }
  1016. if($value['category']==$this->OTHER){
  1017. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1018. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1019. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1020. }
  1021. $ot++;
  1022. }
  1023. }
  1024. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1025. //报销单
  1026. $receipt->accountItem=json_encode($accountJson);
  1027. $receipt->staff=$this->staff[0]['sid'];
  1028. $receipt->loanSum=$receiptDet['sum'];
  1029. $receipt->sum=number_format($sum, 2, '.', '');
  1030. $receipt->date=date("Y-m-d");
  1031. $receipt->pastDate='';
  1032. $receipt->cid=$cid;
  1033. $receipt->status=7;
  1034. //修改审批流程加入角色
  1035. $receipt->verify=$verify;
  1036. $receipt->verifyStaff='';
  1037. $receipt->executeStaff='';
  1038. $receipt->executeCopy=$executeDetail['staff'];
  1039. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1040. $receipt->explanation=$explanation;
  1041. $receipt->update(array('where'=>'rid='.$rid));
  1042. //附件
  1043. if (!empty($enclosurName)){
  1044. $enclosurArray=explode('-', $enclosurName);
  1045. foreach ($enclosurArray as $value){
  1046. $enclosur=new enclosur();
  1047. $enclosur->name=$value;
  1048. $enclosur->rid=$rid;
  1049. $enclosur->insert();
  1050. }
  1051. //print_r($enclosurArray);die;
  1052. }
  1053. //报销详情
  1054. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1055. $receiptDetail=new receiptDetail();
  1056. $receiptDetail->staff=$this->staff[0]['sid'];
  1057. $receiptDetail->item=$value['name'];
  1058. $receiptDetail->itemCategory=$this->AGENCY;
  1059. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1060. $receiptDetail->date=date("Y-m-d");
  1061. $receiptDetail->cid=$cid;
  1062. $receiptDetail->rid=$rid;
  1063. $receiptDetail->status=4;
  1064. $receiptDetail->insert();
  1065. }
  1066. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1067. $receiptDetail=new receiptDetail();
  1068. $receiptDetail->staff=$this->staff[0]['sid'];
  1069. $receiptDetail->item=$value['name'];
  1070. $receiptDetail->itemCategory=$this->TRAVEL;
  1071. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1072. $receiptDetail->date=date("Y-m-d");
  1073. $receiptDetail->cid=$cid;
  1074. $receiptDetail->rid=$rid;
  1075. $receiptDetail->status=4;
  1076. $receiptDetail->insert();
  1077. }
  1078. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1079. $receiptDetail=new receiptDetail();
  1080. $receiptDetail->staff=$this->staff[0]['sid'];
  1081. $receiptDetail->item=$value['name'];
  1082. $receiptDetail->itemCategory=$this->TRAIN;
  1083. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1084. $receiptDetail->date=date("Y-m-d");
  1085. $receiptDetail->cid=$cid;
  1086. $receiptDetail->rid=$rid;
  1087. $receiptDetail->status=4;
  1088. $receiptDetail->insert();
  1089. }
  1090. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1091. $receiptDetail=new receiptDetail();
  1092. $receiptDetail->staff=$this->staff[0]['sid'];
  1093. $receiptDetail->item=$value['name'];
  1094. $receiptDetail->itemCategory=$this->OTHER;
  1095. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1096. $receiptDetail->date=date("Y-m-d");
  1097. $receiptDetail->cid=$cid;
  1098. $receiptDetail->rid=$rid;
  1099. $receiptDetail->status=4;
  1100. $receiptDetail->insert();
  1101. }
  1102. return "/saeaBorad";
  1103. }
  1104. return "/saeaLoanReceiptAdd/".$rid;
  1105. }
  1106. function saeaLoanReceiptEdi(){
  1107. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1108. //echo $rid;
  1109. Doo::loadModel('accountItem');
  1110. Doo::loadModel('verify');
  1111. Doo::loadModel('receipt');
  1112. $receipt=new receipt();
  1113. $verify=new verify();
  1114. $accountItem=new accountItem();
  1115. Doo::loadModel('L_category');
  1116. $Lcategory=new L_category();
  1117. Doo::loadModel("role");
  1118. $role=new role();
  1119. Doo::loadModel('loanReceipt');
  1120. $loanReceipt=new loanReceipt();
  1121. Doo::loadModel('staff');
  1122. $staff=new staff();
  1123. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1124. if(empty($receiptDetail))
  1125. return "/saeaBorad";
  1126. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1127. $Locate=0;$roleId=0;$button=0;
  1128. foreach ($receiptList as $key=>$value){
  1129. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1130. $receiptList[$key]['reviseDetail']=array();
  1131. if (!empty($value['reviseDetail']))
  1132. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1133. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1134. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1135. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1136. $receiptList[$key]['category']=$categoryDetil['title'];
  1137. //检测编辑状态
  1138. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1139. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1140. $verifyStaff=json_decode($value['verifyStaff'],true);
  1141. Doo::loadModel('role');
  1142. $role=new role();
  1143. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1144. foreach ($verifyList as $k=>$v){
  1145. //init verifyStaff
  1146. if ($v[1]=='ROLE'){
  1147. if (!empty($verifyStaff)){
  1148. $endStaffArray=end($verifyStaff);
  1149. // if ($v[0]==$endStaffArray['nextStaff']){
  1150. // $roleId=$v[0];
  1151. // }
  1152. }
  1153. $roleVerify=json_decode($v[3],true);
  1154. $roleKey=$k;$roleArray=array();
  1155. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1156. foreach ($roleVerify as $o=>$p){
  1157. $staffID=explode ('_',$p);
  1158. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1159. //print_r($staffID);
  1160. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1161. array_push($roleArray, $exp);
  1162. }
  1163. $roleArrayCopy[$v[0]]=$roleArray;
  1164. //$verifyList[$k]['roleArray']=$roleArray;
  1165. }
  1166. $verifyList[$k]['date']="";
  1167. $verifyList[$k]['opinion']="";
  1168. $verifyList[$k]['status']="";
  1169. if (empty($verifyStaff)){
  1170. $verifyList[$k]['date']="";
  1171. $verifyList[$k]['opinion']="";
  1172. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1173. $verifyList[$k]['status']=4;
  1174. $flag=false;
  1175. }
  1176. }else{
  1177. foreach ($verifyStaff as $m=>$u){
  1178. if ($v[0]==$m){
  1179. $verifyList[$k]['date']=$u['date'];
  1180. $verifyList[$k]['opinion']=$u['opinion'];
  1181. $verifyList[$k]['status']=$u['status'];
  1182. $flag=false;
  1183. break;
  1184. }
  1185. }
  1186. $endStaffArray=end($verifyStaff);
  1187. if (isset($endStaffArray['ROLE'])){
  1188. }else{
  1189. // $endKey=key($verifyStaff);
  1190. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1191. // $button=4;
  1192. // $verifyList[$k]['status']=4;
  1193. // }
  1194. }
  1195. }
  1196. }
  1197. $rolename['name']='';
  1198. if (!empty($roleId)){
  1199. Doo::loadModel('role');
  1200. $role=new role();
  1201. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1202. }
  1203. if (!empty($verifyStaff))
  1204. $endStaffArray=end($verifyStaff);
  1205. $KOP=false;
  1206. foreach ($roleArrayCopy as $P=>$A){
  1207. foreach ( $A as $MKI=>$AVL){
  1208. if (!empty($verifyStaff)){
  1209. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1210. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1211. $button=4;
  1212. $roleArrayCopy[$P][$MKI]['status']=4;
  1213. }
  1214. foreach ($verifyStaff as $m=>$u){
  1215. $AVLFK=$AVL[0].'_R';
  1216. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1217. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1218. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1219. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1220. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1221. break;
  1222. }
  1223. }
  1224. }else{
  1225. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1226. $button=4;
  1227. $roleArrayCopy[$P][$MKI]['status']=4;
  1228. }
  1229. }
  1230. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1231. $KOP=true;
  1232. }
  1233. }
  1234. foreach ($roleArrayCopy as $k=>$v){
  1235. foreach ($verifyList as $m=>$n){
  1236. if ($n[0]==$k){
  1237. array_splice($verifyList,$m,1,$v);
  1238. }
  1239. }
  1240. }
  1241. $receiptList[$key]['verifyList']=$verifyList;
  1242. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1243. $receiptList[$key]['button']=$button;
  1244. //
  1245. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1246. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1247. }
  1248. $data['receiptList']=$receiptList;
  1249. $acItem=$accountItem->find(array('asArray'=>true));
  1250. $veList=$verify->find(array('asArray'=>true));
  1251. foreach ($veList as $key=>$value){
  1252. $v=json_decode($value['staff']);
  1253. $list=array();
  1254. foreach ($v as $n=>$m){
  1255. if ($m['1']=='ROLE'){
  1256. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1257. $v[$n][1]=$roleInfo['name'];
  1258. array_push($list, $roleInfo['name']);
  1259. }else{
  1260. array_push($list, $v[$n][1]);
  1261. }
  1262. }
  1263. $veList[$key]['staff']=implode('>', $list);
  1264. }
  1265. //配置编辑信息
  1266. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1267. foreach ($acItem as $key=>$value){
  1268. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1269. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1270. $acItem[$key]['price']=$v['price'];
  1271. }
  1272. }
  1273. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1274. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1275. $acItem[$key]['price']=$v['price'];
  1276. }
  1277. }
  1278. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1279. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1280. $acItem[$key]['price']=$v['price'];
  1281. }
  1282. }
  1283. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1284. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1285. $acItem[$key]['price']=$v['price'];
  1286. }
  1287. }
  1288. }
  1289. $data['category']=$Lcategory->find(array('asArray'=>true));
  1290. $data['cSum']=$accountItemList['cSum'];
  1291. $data['sum']=$receiptDetail['sum'];
  1292. $data['receiptDetail']=$receiptDetail;
  1293. $data['veList']=$veList;
  1294. $data['acItem']=$acItem;
  1295. $data['memu']="receipt";
  1296. $data['staff']=$this->staff;
  1297. $data['receiptMemu']='saeaBorad';
  1298. $data['verify']=$receiptDetail['verify'];
  1299. $data['verifyId']=$this->verifyId;
  1300. $data['executeId']=$this->executeId;
  1301. $data['rid']=$rid;
  1302. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1303. }
  1304. function confirmation(){
  1305. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1306. Doo::loadModel('receipt');
  1307. Doo::loadModel('receiptDetail');
  1308. $receipt=new receipt();
  1309. $receiptDetail=new receiptDetail();
  1310. Doo::loadModel('statistics');
  1311. Doo::loadModel('itemStatistics');
  1312. $statistics=new statistics();
  1313. $itemStatistics=new itemStatistics();
  1314. Doo::loadModel("verify");
  1315. $verify=new verify();
  1316. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1317. if(empty($receiptDetailList))
  1318. return "/saeaBorad";
  1319. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1320. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1321. if (empty($receiptDetailList['nowStaff'])){
  1322. $nowStaff="";$nowStaffList=array();
  1323. if ($verifyDetail[0][1]=='ROLE'){
  1324. $vStaffString=json_decode($verifyDetail[0][3]);
  1325. foreach ($vStaffString as $key=>$value){
  1326. $staffK=explode("_", $value);
  1327. array_push($nowStaffList, $staffK[0]);
  1328. }
  1329. $nowStaff=implode(',', $nowStaffList);
  1330. }else{
  1331. $nowStaff=$verifyDetail[0][0];
  1332. }
  1333. $receipt->nowStaff=$nowStaff;
  1334. }
  1335. // echo $nowStaff;
  1336. // print_r($verifyDetail);die;
  1337. $receipt->rid=$receiptDetailList['rid'];
  1338. $receipt->status=2;
  1339. $receipt->update();
  1340. //操作日志
  1341. Doo::loadModel("receiptLog");
  1342. $receiptLog=new receiptLog();
  1343. $verify=new verify();
  1344. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1345. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1346. $jd=json_decode($vr['staff']);$roleId=0;
  1347. foreach ($jd as $key=>$value){
  1348. if ($value[1]=='ROLE'){
  1349. $pos = strpos($value[3], $this->staff[0]['sid']);
  1350. if ($pos !== false) {
  1351. $roleId=$value[0];
  1352. }
  1353. }
  1354. }
  1355. //审批日志
  1356. //echo $roleId;die;
  1357. if (!empty($roleId)){
  1358. Doo::loadModel("role");
  1359. $role=new role();
  1360. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1361. $receiptLog->rolename=$roleInfo['name'];
  1362. }
  1363. $receiptLog->username=$this->staff[0]['username'];
  1364. $receiptLog->uid=$this->staff[0]['sid'];
  1365. $receiptLog->date=date("Y-m-d");
  1366. $receiptLog->opinion='提交审批';
  1367. $receiptLog->img=$this->staff[0]['avatar'];
  1368. $receiptLog->status=2;
  1369. $receiptLog->rid=$rid;
  1370. $receiptLog->insert();
  1371. return "/expenses";
  1372. }
  1373. function expenses(){
  1374. $item=isset($this->params['item'])?$this->params['item']:"";
  1375. if(empty($item))
  1376. $item=$this->get_args('item')?$this->get_args('item'):"";
  1377. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1378. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1379. Doo::loadModel('receipt');
  1380. $receipt=new receipt();
  1381. Doo::loadModel('L_category');
  1382. $Lcategory=new L_category();
  1383. Doo::loadModel('verify');
  1384. Doo::loadModel('statistics');
  1385. $statistics=new statistics();
  1386. $verify=new verify();
  1387. Doo::loadModel('staff');
  1388. $staff=new staff();
  1389. $condition="";
  1390. if($item=="expenses")
  1391. $condition=" and Rtype=1 ";
  1392. elseif ($item=="receipts")
  1393. $condition=" and Rtype=0 ";
  1394. elseif ($item=="remits")
  1395. $condition=" and Rtype=2 ";
  1396. $dateCondition=" and Year(date) =".$year;
  1397. if(!empty($moth)){
  1398. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1399. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1400. }else
  1401. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1402. if(empty($stList))
  1403. $stList=array('rePrice'=>0,'agPrice'=>0);
  1404. $noPassSum=$receipt->receiptByYear($dateCondition,$this->staff[0]['sid']);
  1405. if(!isset($noPassSum['sum']))
  1406. $noPassSum['sum']=0;
  1407. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($noPassSum['sum']));
  1408. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1409. $Locate=0;$roleId=0;$button=0;
  1410. foreach ($receiptList as $key=>$value){
  1411. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1412. $receiptList[$key]['reviseDetail']=array();
  1413. if (!empty($value['reviseDetail']))
  1414. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1415. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1416. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1417. $receiptList[$key]['category']=$categoryDetil['title'];
  1418. //检测编辑状态
  1419. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1420. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1421. $verifyStaff=json_decode($value['verifyStaff'],true);
  1422. Doo::loadModel('role');
  1423. $role=new role();
  1424. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1425. foreach ($verifyList as $k=>$v){
  1426. //init verifyStaff
  1427. if ($v[1]=='ROLE'){
  1428. if (!empty($verifyStaff)){
  1429. $endStaffArray=end($verifyStaff);
  1430. // if ($v[0]==$endStaffArray['nextStaff']){
  1431. // $roleId=$v[0];
  1432. // }
  1433. }
  1434. $roleVerify=json_decode($v[3],true);
  1435. $roleKey=$k;$roleArray=array();
  1436. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1437. foreach ($roleVerify as $o=>$p){
  1438. $staffID=explode ('_',$p);
  1439. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1440. //print_r($staffID);
  1441. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1442. array_push($roleArray, $exp);
  1443. }
  1444. $roleArrayCopy[$v[0]]=$roleArray;
  1445. //$verifyList[$k]['roleArray']=$roleArray;
  1446. }
  1447. $verifyList[$k]['date']="";
  1448. $verifyList[$k]['opinion']="";
  1449. $verifyList[$k]['status']="";
  1450. if (empty($verifyStaff)){
  1451. $verifyList[$k]['date']="";
  1452. $verifyList[$k]['opinion']="";
  1453. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1454. $verifyList[$k]['status']=4;
  1455. $flag=false;
  1456. }
  1457. }else{
  1458. foreach ($verifyStaff as $m=>$u){
  1459. if ($v[0]==$m){
  1460. $verifyList[$k]['date']=$u['date'];
  1461. $verifyList[$k]['opinion']=$u['opinion'];
  1462. $verifyList[$k]['status']=$u['status'];
  1463. $flag=false;
  1464. break;
  1465. }
  1466. }
  1467. $endStaffArray=end($verifyStaff);
  1468. if (isset($endStaffArray['ROLE'])){
  1469. }else{
  1470. // $endKey=key($verifyStaff);
  1471. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1472. // $button=4;
  1473. // $verifyList[$k]['status']=4;
  1474. // }
  1475. }
  1476. }
  1477. }
  1478. $rolename['name']='';
  1479. if (!empty($roleId)){
  1480. Doo::loadModel('role');
  1481. $role=new role();
  1482. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1483. }
  1484. if (!empty($verifyStaff))
  1485. $endStaffArray=end($verifyStaff);
  1486. $KOP=false;
  1487. foreach ($roleArrayCopy as $P=>$A){
  1488. foreach ( $A as $MKI=>$AVL){
  1489. if (!empty($verifyStaff)){
  1490. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1491. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1492. $button=4;
  1493. $roleArrayCopy[$P][$MKI]['status']=4;
  1494. }
  1495. foreach ($verifyStaff as $m=>$u){
  1496. $AVLFK=$AVL[0].'_R';
  1497. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1498. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1499. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1500. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1501. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1502. break;
  1503. }
  1504. }
  1505. }else{
  1506. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1507. $button=4;
  1508. $roleArrayCopy[$P][$MKI]['status']=4;
  1509. }
  1510. }
  1511. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1512. $KOP=true;
  1513. }
  1514. }
  1515. foreach ($roleArrayCopy as $k=>$v){
  1516. foreach ($verifyList as $m=>$n){
  1517. if ($n[0]==$k){
  1518. array_splice($verifyList,$m,1,$v);
  1519. }
  1520. }
  1521. }
  1522. $receiptList[$key]['verifyList']=$verifyList;
  1523. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1524. $receiptList[$key]['button']=$button;
  1525. }
  1526. //print_r($receiptList);die;
  1527. $mothHtml="";
  1528. for($i=1;$i<=12;$i++){
  1529. if($moth==$i)
  1530. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1531. else
  1532. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1533. }
  1534. $data['mothHtml']=$mothHtml;
  1535. $data['receiptList']=$receiptList;
  1536. $data['memu']="receipt";
  1537. $data['staff']=$this->staff;
  1538. $data['receiptMemu']='expenses';
  1539. $data['verifyId']=$this->verifyId;
  1540. $data['executeId']=$this->executeId;
  1541. $data['item']=$item;
  1542. $data['year']=$year;
  1543. $this->render ( "/admin/expenses", $data );
  1544. }
  1545. function expensesCollect(){
  1546. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1547. Doo::loadModel('receipt');
  1548. $receipt=new receipt();
  1549. Doo::loadModel('L_category');
  1550. $Lcategory=new L_category();
  1551. Doo::loadModel('verify');
  1552. Doo::loadModel('statistics');
  1553. $statistics=new statistics();
  1554. $verify=new verify();
  1555. Doo::loadModel('staff');
  1556. $staff=new staff();
  1557. Doo::loadModel('loanReceipt');
  1558. $loanReceipt=new loanReceipt();
  1559. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1560. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1561. /*
  1562. $Locate=0;$roleId=0;$button=0;
  1563. foreach ($loanList as $key=>$value){
  1564. $loanList[$key]['Locate']=$Locate;$Locate++;
  1565. $loanList[$key]['reviseDetail']=array();
  1566. if (!empty($value['reviseDetail']))
  1567. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1568. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1569. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1570. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1571. $loanList[$key]['category']=$categoryDetil['title'];
  1572. //检测编辑状态
  1573. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1574. $verifyList['staff']=$value['verifyBreakup'];
  1575. else
  1576. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1577. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1578. $verifyStaff=json_decode($value['verifyStaff'],true);
  1579. Doo::loadModel('role');
  1580. $role=new role();
  1581. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1582. foreach ($verifyList as $k=>$v){
  1583. //init verifyStaff
  1584. if ($v[1]=='ROLE'){
  1585. if (!empty($verifyStaff)){
  1586. $endStaffArray=end($verifyStaff);
  1587. // if ($v[0]==$endStaffArray['nextStaff']){
  1588. // $roleId=$v[0];
  1589. // }
  1590. }
  1591. $roleVerify=json_decode($v[3],true);
  1592. $roleKey=$k;$roleArray=array();
  1593. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1594. foreach ($roleVerify as $o=>$p){
  1595. $staffID=explode ('_',$p);
  1596. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1597. //print_r($staffID);
  1598. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1599. array_push($roleArray, $exp);
  1600. }
  1601. $roleArrayCopy[$v[0]]=$roleArray;
  1602. //$verifyList[$k]['roleArray']=$roleArray;
  1603. }
  1604. $verifyList[$k]['date']="";
  1605. $verifyList[$k]['opinion']="";
  1606. $verifyList[$k]['status']="";
  1607. if (empty($verifyStaff)){
  1608. $verifyList[$k]['date']="";
  1609. $verifyList[$k]['opinion']="";
  1610. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1611. $verifyList[$k]['status']=4;
  1612. $flag=false;
  1613. }
  1614. }else{
  1615. foreach ($verifyStaff as $m=>$u){
  1616. if ($v[0]==$m){
  1617. $verifyList[$k]['date']=$u['date'];
  1618. $verifyList[$k]['opinion']=$u['opinion'];
  1619. $verifyList[$k]['status']=$u['status'];
  1620. $flag=false;
  1621. break;
  1622. }
  1623. }
  1624. $endStaffArray=end($verifyStaff);
  1625. if (isset($endStaffArray['ROLE'])){
  1626. }else{
  1627. // $endKey=key($verifyStaff);
  1628. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1629. // $button=4;
  1630. // $verifyList[$k]['status']=4;
  1631. // }
  1632. }
  1633. }
  1634. }
  1635. $rolename['name']='';
  1636. if (!empty($roleId)){
  1637. Doo::loadModel('role');
  1638. $role=new role();
  1639. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1640. }
  1641. if (!empty($verifyStaff))
  1642. $endStaffArray=end($verifyStaff);
  1643. $KOP=false;
  1644. foreach ($roleArrayCopy as $P=>$A){
  1645. foreach ( $A as $MKI=>$AVL){
  1646. if (!empty($verifyStaff)){
  1647. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1648. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1649. $button=4;
  1650. $roleArrayCopy[$P][$MKI]['status']=4;
  1651. }
  1652. foreach ($verifyStaff as $m=>$u){
  1653. $AVLFK=$AVL[0].'_R';
  1654. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1655. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1656. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1657. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1658. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1659. break;
  1660. }
  1661. }
  1662. }else{
  1663. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1664. $button=4;
  1665. $roleArrayCopy[$P][$MKI]['status']=4;
  1666. }
  1667. }
  1668. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1669. $KOP=true;
  1670. }
  1671. }
  1672. foreach ($roleArrayCopy as $k=>$v){
  1673. foreach ($verifyList as $m=>$n){
  1674. if ($n[0]==$k){
  1675. array_splice($verifyList,$m,1,$v);
  1676. }
  1677. }
  1678. }
  1679. $loanList[$key]['verifyList']=$verifyList;
  1680. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1681. $loanList[$key]['button']=$button;
  1682. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1683. }
  1684. $data['loanList']=$loanList;
  1685. */
  1686. $Locate=0;$roleId=0;$button=0;
  1687. foreach ($receiptList as $key=>$value){
  1688. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1689. $receiptList[$key]['reviseDetail']=array();
  1690. if (!empty($value['reviseDetail']))
  1691. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1692. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1693. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1694. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1695. $receiptList[$key]['category']=$categoryDetil['title'];
  1696. //检测编辑状态
  1697. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1698. if($value['status']==8&&$value['Rtype']==1)
  1699. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1700. else
  1701. $verifyList['staff']=$value['verifyBreakup'];
  1702. }else
  1703. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1704. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1705. $verifyStaff=json_decode($value['verifyStaff'],true);
  1706. Doo::loadModel('role');
  1707. $role=new role();
  1708. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1709. foreach ($verifyList as $k=>$v){
  1710. //init verifyStaff
  1711. if ($v[1]=='ROLE'){
  1712. if (!empty($verifyStaff)){
  1713. $endStaffArray=end($verifyStaff);
  1714. // if ($v[0]==$endStaffArray['nextStaff']){
  1715. // $roleId=$v[0];
  1716. // }
  1717. }
  1718. $roleVerify=json_decode($v[3],true);
  1719. $roleKey=$k;$roleArray=array();
  1720. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1721. foreach ($roleVerify as $o=>$p){
  1722. $staffID=explode ('_',$p);
  1723. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1724. //print_r($staffID);
  1725. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1726. array_push($roleArray, $exp);
  1727. }
  1728. $roleArrayCopy[$v[0]]=$roleArray;
  1729. //$verifyList[$k]['roleArray']=$roleArray;
  1730. }
  1731. $verifyList[$k]['date']="";
  1732. $verifyList[$k]['opinion']="";
  1733. $verifyList[$k]['status']="";
  1734. if (empty($verifyStaff)){
  1735. $verifyList[$k]['date']="";
  1736. $verifyList[$k]['opinion']="";
  1737. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1738. $verifyList[$k]['status']=4;
  1739. $flag=false;
  1740. }
  1741. }else{
  1742. foreach ($verifyStaff as $m=>$u){
  1743. if ($v[0]==$m){
  1744. $verifyList[$k]['date']=$u['date'];
  1745. $verifyList[$k]['opinion']=$u['opinion'];
  1746. $verifyList[$k]['status']=$u['status'];
  1747. $flag=false;
  1748. break;
  1749. }
  1750. }
  1751. $endStaffArray=end($verifyStaff);
  1752. if (isset($endStaffArray['ROLE'])){
  1753. }else{
  1754. // $endKey=key($verifyStaff);
  1755. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1756. // $button=4;
  1757. // $verifyList[$k]['status']=4;
  1758. // }
  1759. }
  1760. }
  1761. }
  1762. $rolename['name']='';
  1763. if (!empty($roleId)){
  1764. Doo::loadModel('role');
  1765. $role=new role();
  1766. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1767. }
  1768. if (!empty($verifyStaff))
  1769. $endStaffArray=end($verifyStaff);
  1770. $KOP=false;
  1771. foreach ($roleArrayCopy as $P=>$A){
  1772. foreach ( $A as $MKI=>$AVL){
  1773. if (!empty($verifyStaff)){
  1774. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1775. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1776. $button=4;
  1777. $roleArrayCopy[$P][$MKI]['status']=4;
  1778. }
  1779. foreach ($verifyStaff as $m=>$u){
  1780. $AVLFK=$AVL[0].'_R';
  1781. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1782. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1783. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1784. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1785. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1786. break;
  1787. }
  1788. }
  1789. }else{
  1790. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1791. $button=4;
  1792. $roleArrayCopy[$P][$MKI]['status']=4;
  1793. }
  1794. }
  1795. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1796. $KOP=true;
  1797. }
  1798. }
  1799. foreach ($roleArrayCopy as $k=>$v){
  1800. foreach ($verifyList as $m=>$n){
  1801. if ($n[0]==$k){
  1802. array_splice($verifyList,$m,1,$v);
  1803. }
  1804. }
  1805. }
  1806. //费用执行人相关数据
  1807. $executeCopy=json_decode($value['executeCopy'],true);
  1808. $executeStaff=json_decode($value['executeStaff'],true);
  1809. foreach ($executeCopy as $k=>$v){
  1810. $executeCopy[$k]['date']='';
  1811. $executeCopy[$k]['opinion']='';
  1812. $executeCopy[$k]['status']='';
  1813. if (!empty($executeStaff))
  1814. foreach ($executeStaff as $m=>$u){
  1815. if ($v[0]==$m){
  1816. $executeCopy[$k]['date']=$u['date'];
  1817. $executeCopy[$k]['opinion']=$u['opinion'];
  1818. $executeCopy[$k]['status']=$u['status'];
  1819. break;
  1820. }
  1821. }
  1822. }
  1823. $receiptList[$key]['executeCopy']=$executeCopy;
  1824. $receiptList[$key]['verifyList']=$verifyList;
  1825. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1826. $receiptList[$key]['button']=$button;
  1827. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1828. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1829. $relust=$value['sum']-$value['loanSum'];
  1830. $receiptList[$key]['relust']=$relust;
  1831. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1832. }
  1833. //print_r($receiptList);
  1834. $data['receiptList']=$receiptList;
  1835. $data['memu']="receipt";
  1836. $data['staff']=$this->staff;
  1837. $data['receiptMemu']='expenses';
  1838. $data['verifyId']=$this->verifyId;
  1839. $data['executeId']=$this->executeId;
  1840. $this->render ( "/admin/expensesCollect", $data );
  1841. }
  1842. function approvalExpenses(){
  1843. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1844. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1845. $month=$this->get_args('month')?$this->get_args('month'):"";
  1846. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1847. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1848. if (empty($status))
  1849. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1850. $page_size=12;
  1851. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1852. $vidList=array();
  1853. $button=0;
  1854. Doo::loadModel('verify');
  1855. $verify=new verify();
  1856. Doo::loadModel('receipt');
  1857. $receipt=new receipt();
  1858. Doo::loadModel('staff');
  1859. $staff=new staff();
  1860. Doo::loadModel('L_category');
  1861. $Lcategory=new L_category();
  1862. //user verify ID
  1863. $verifyDetail=$verify->find(array('where'=>' (staff not like "%\"'.$this->staff[0]['sid'].'\",\"ROLE%") and (staff like "%[\"'.$this->staff[0]['sid'].'\",%" or staff like "%\"'.$this->staff[0]['sid'].'\_%" )','asArray'=>true));
  1864. foreach ($verifyDetail as $key=>$value){
  1865. array_push($vidList, $value['vid']);
  1866. }
  1867. $vid=implode(",", $vidList);
  1868. if(empty($verifyDetail))
  1869. $vid=0;
  1870. // if ($status==0)
  1871. // $dateCondition="";
  1872. // else
  1873. $dateCondition=" and Year(date) =".$year;
  1874. if(!empty($month))
  1875. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1876. $categoryList=$Lcategory->find(array('asArray'=>true));
  1877. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1878. $cateCondition="";$staffCondition="";$approvalCondition="";
  1879. if (!empty($cid))
  1880. $cateCondition=' and cid='.$cid;
  1881. if(!empty($sid)){
  1882. $staffCondition=' and staff='.$sid;
  1883. $cateCondition="";
  1884. }
  1885. $approvalCondition=" and status=".$status;
  1886. if($status==2){
  1887. //查找角色审批人
  1888. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1889. }
  1890. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1891. $approvalCondition=' and status=2 ';
  1892. }
  1893. if($status==1){
  1894. $approvalCondition=' and (status='.$status.' or status=6) ';
  1895. }
  1896. if($status==8){
  1897. $approvalCondition=' and (status='.$status.' or status=9) ';
  1898. }
  1899. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1900. $pageinfo['page']=array('previous'=>'');
  1901. if ($status==0){
  1902. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1903. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1904. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1905. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1906. }else
  1907. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1908. ,'desc'=>'rid','asArray'=>true));
  1909. $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
  1910. ,'desc'=>'rid','asArray'=>true));
  1911. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1912. //print_r($pageinfo);
  1913. $Locate=0;
  1914. foreach ($receiptList as $key=>$value){
  1915. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1916. $receiptList[$key]['reviseDetail']=array();
  1917. if (!empty($value['reviseDetail']))
  1918. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1919. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1920. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1921. $receiptList[$key]['category']=$categoryDetil['title'];
  1922. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1923. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1924. $verifyStaff=json_decode($value['verifyStaff'],true);
  1925. foreach ($verifyList as $k=>$v){
  1926. //init verifyStaff
  1927. $verifyList[$k]['date']="";
  1928. $verifyList[$k]['opinion']="";
  1929. $verifyList[$k]['status']="";
  1930. if (empty($verifyStaff)){
  1931. $verifyList[$k]['date']="";
  1932. $verifyList[$k]['opinion']="";
  1933. if ($v[0]==$this->staff[0]['sid']){
  1934. $verifyList[$k]['status']=4;
  1935. $button=4;
  1936. }
  1937. }else{
  1938. $flag=true;
  1939. foreach ($verifyStaff as $m=>$u){
  1940. if ($v[0]==$m){
  1941. $verifyList[$k]['date']=$u['date'];
  1942. $verifyList[$k]['opinion']=$u['opinion'];
  1943. $verifyList[$k]['status']=$u['status'];
  1944. $flag=false;
  1945. break;
  1946. }
  1947. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1948. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1949. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1950. }
  1951. if($flag){//检测可编辑
  1952. if($v[0]==$this->staff[0]['sid']){
  1953. $verifyList[$k]['status']=4;$button=4;
  1954. }
  1955. }
  1956. }
  1957. }
  1958. $receiptList[$key]['verifyList']=$verifyList;
  1959. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1960. $receiptList[$key]['button']=$button;
  1961. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1962. }
  1963. //print_r($receiptList);die;
  1964. //$data['verifyDetail']=$verifyDetail;
  1965. $mothHtml="";
  1966. for($i=1;$i<=12;$i++){
  1967. if($month==$i)
  1968. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1969. else
  1970. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1971. }
  1972. $data['mothHtml']=$mothHtml;
  1973. $data['page']=$pageinfo;
  1974. $data['receiptList']=$receiptList;
  1975. $data['receiptApprovalCount']=count($rLRes);
  1976. $data['status']=$status;
  1977. $data['year']=$year;
  1978. $data['categoryList']=$categoryList;
  1979. $data['staffList']=$staffList;
  1980. $data['cid']=$cid;
  1981. $data['sid']=$sid;
  1982. //print_r($receiptList);
  1983. $data['memu']="receipt";
  1984. $data['staff']=$this->staff;
  1985. $data['receiptMemu']='approvalExpenses';
  1986. $data['verifyId']=$this->verifyId;
  1987. $data['executeId']=$this->executeId;
  1988. $this->render ( "/admin/approvalExpenses", $data );
  1989. }
  1990. function expensesDoc(){
  1991. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1992. Doo::loadModel('receipt');
  1993. $receipt=new receipt();
  1994. Doo::loadModel('L_category');
  1995. $Lcategory=new L_category();
  1996. Doo::loadModel('verify');
  1997. Doo::loadModel('statistics');
  1998. $statistics=new statistics();
  1999. $verify=new verify();
  2000. Doo::loadModel('staff');
  2001. $staff=new staff();
  2002. Doo::loadModel('loanReceipt');
  2003. $loanReceipt=new loanReceipt();
  2004. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  2005. $loanList=array();
  2006. if (!empty($receiptList))
  2007. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2008. $Locate=0;$roleId=0;$button=0;
  2009. foreach ($loanList as $key=>$value){
  2010. $loanList[$key]['Locate']=$Locate;$Locate++;
  2011. $loanList[$key]['reviseDetail']=array();
  2012. if (!empty($value['reviseDetail']))
  2013. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2014. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2015. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2016. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2017. $loanList[$key]['category']=$categoryDetil['title'];
  2018. //检测编辑状态
  2019. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  2020. $verifyList['staff']=$value['verifyBreakup'];
  2021. else
  2022. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2023. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2024. $verifyStaff=json_decode($value['verifyStaff'],true);
  2025. Doo::loadModel('role');
  2026. $role=new role();
  2027. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2028. foreach ($verifyList as $k=>$v){
  2029. //init verifyStaff
  2030. if ($v[1]=='ROLE'){
  2031. if (!empty($verifyStaff)){
  2032. $endStaffArray=end($verifyStaff);
  2033. // if ($v[0]==$endStaffArray['nextStaff']){
  2034. // $roleId=$v[0];
  2035. // }
  2036. }
  2037. $roleVerify=json_decode($v[3],true);
  2038. $roleKey=$k;$roleArray=array();
  2039. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2040. foreach ($roleVerify as $o=>$p){
  2041. $staffID=explode ('_',$p);
  2042. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2043. //print_r($staffID);
  2044. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2045. array_push($roleArray, $exp);
  2046. }
  2047. $roleArrayCopy[$v[0]]=$roleArray;
  2048. //$verifyList[$k]['roleArray']=$roleArray;
  2049. }
  2050. $verifyList[$k]['date']="";
  2051. $verifyList[$k]['opinion']="";
  2052. $verifyList[$k]['status']="";
  2053. if (empty($verifyStaff)){
  2054. $verifyList[$k]['date']="";
  2055. $verifyList[$k]['opinion']="";
  2056. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2057. $verifyList[$k]['status']=4;
  2058. $flag=false;
  2059. }
  2060. }else{
  2061. foreach ($verifyStaff as $m=>$u){
  2062. if ($v[0]==$m){
  2063. $verifyList[$k]['date']=$u['date'];
  2064. $verifyList[$k]['opinion']=$u['opinion'];
  2065. $verifyList[$k]['status']=$u['status'];
  2066. $flag=false;
  2067. break;
  2068. }
  2069. }
  2070. $endStaffArray=end($verifyStaff);
  2071. if (isset($endStaffArray['ROLE'])){
  2072. }else{
  2073. // $endKey=key($verifyStaff);
  2074. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2075. // $button=4;
  2076. // $verifyList[$k]['status']=4;
  2077. // }
  2078. }
  2079. }
  2080. }
  2081. $rolename['name']='';
  2082. if (!empty($roleId)){
  2083. Doo::loadModel('role');
  2084. $role=new role();
  2085. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2086. }
  2087. if (!empty($verifyStaff))
  2088. $endStaffArray=end($verifyStaff);
  2089. $KOP=false;
  2090. foreach ($roleArrayCopy as $P=>$A){
  2091. foreach ( $A as $MKI=>$AVL){
  2092. if (!empty($verifyStaff)){
  2093. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2094. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2095. $button=4;
  2096. $roleArrayCopy[$P][$MKI]['status']=4;
  2097. }
  2098. foreach ($verifyStaff as $m=>$u){
  2099. $AVLFK=$AVL[0].'_R';
  2100. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2101. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2102. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2103. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2104. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2105. break;
  2106. }
  2107. }
  2108. }else{
  2109. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2110. $button=4;
  2111. $roleArrayCopy[$P][$MKI]['status']=4;
  2112. }
  2113. }
  2114. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2115. $KOP=true;
  2116. }
  2117. }
  2118. foreach ($roleArrayCopy as $k=>$v){
  2119. foreach ($verifyList as $m=>$n){
  2120. if ($n[0]==$k){
  2121. array_splice($verifyList,$m,1,$v);
  2122. }
  2123. }
  2124. }
  2125. $loanList[$key]['verifyList']=$verifyList;
  2126. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2127. $loanList[$key]['button']=$button;
  2128. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2129. }
  2130. $data['loanList']=$loanList;
  2131. //print_r($loanList);
  2132. $Locate=0;$roleId=0;$button=0;
  2133. foreach ($receiptList as $key=>$value){
  2134. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2135. $receiptList[$key]['reviseDetail']=array();
  2136. if (!empty($value['reviseDetail']))
  2137. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2138. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2139. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2140. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2141. $receiptList[$key]['category']=$categoryDetil['title'];
  2142. //检测编辑状态
  2143. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2144. $verifyList['staff']=$value['verifyBreakup'];
  2145. }else
  2146. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2147. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2148. $verifyStaff=json_decode($value['verifyStaff'],true);
  2149. Doo::loadModel('role');
  2150. $role=new role();
  2151. if ($verifyList==NULL)
  2152. $verifyList=array();
  2153. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2154. foreach ($verifyList as $k=>$v){
  2155. //init verifyStaff
  2156. if ($v[1]=='ROLE'){
  2157. if (!empty($verifyStaff)){
  2158. $endStaffArray=end($verifyStaff);
  2159. // if ($v[0]==$endStaffArray['nextStaff']){
  2160. // $roleId=$v[0];
  2161. // }
  2162. }
  2163. $roleVerify=json_decode($v[3],true);
  2164. $roleKey=$k;$roleArray=array();
  2165. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2166. foreach ($roleVerify as $o=>$p){
  2167. $staffID=explode ('_',$p);
  2168. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2169. //print_r($staffID);
  2170. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2171. array_push($roleArray, $exp);
  2172. }
  2173. $roleArrayCopy[$v[0]]=$roleArray;
  2174. //$verifyList[$k]['roleArray']=$roleArray;
  2175. }
  2176. $verifyList[$k]['date']="";
  2177. $verifyList[$k]['opinion']="";
  2178. $verifyList[$k]['status']="";
  2179. if (empty($verifyStaff)){
  2180. $verifyList[$k]['date']="";
  2181. $verifyList[$k]['opinion']="";
  2182. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2183. $verifyList[$k]['status']=4;
  2184. $flag=false;
  2185. }
  2186. }else{
  2187. foreach ($verifyStaff as $m=>$u){
  2188. if ($v[0]==$m){
  2189. $verifyList[$k]['date']=$u['date'];
  2190. $verifyList[$k]['opinion']=$u['opinion'];
  2191. $verifyList[$k]['status']=$u['status'];
  2192. $flag=false;
  2193. break;
  2194. }
  2195. }
  2196. $endStaffArray=end($verifyStaff);
  2197. if (isset($endStaffArray['ROLE'])){
  2198. }else{
  2199. // $endKey=key($verifyStaff);
  2200. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2201. // $button=4;
  2202. // $verifyList[$k]['status']=4;
  2203. // }
  2204. }
  2205. }
  2206. }
  2207. $rolename['name']='';
  2208. if (!empty($roleId)){
  2209. Doo::loadModel('role');
  2210. $role=new role();
  2211. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2212. }
  2213. if (!empty($verifyStaff))
  2214. $endStaffArray=end($verifyStaff);
  2215. $KOP=false;
  2216. foreach ($roleArrayCopy as $P=>$A){
  2217. foreach ( $A as $MKI=>$AVL){
  2218. if (!empty($verifyStaff)){
  2219. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2220. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2221. $button=4;
  2222. $roleArrayCopy[$P][$MKI]['status']=4;
  2223. }
  2224. foreach ($verifyStaff as $m=>$u){
  2225. $AVLFK=$AVL[0].'_R';
  2226. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2227. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2228. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2229. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2230. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2231. break;
  2232. }
  2233. }
  2234. }else{
  2235. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2236. $button=4;
  2237. $roleArrayCopy[$P][$MKI]['status']=4;
  2238. }
  2239. }
  2240. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2241. $KOP=true;
  2242. }
  2243. }
  2244. foreach ($roleArrayCopy as $k=>$v){
  2245. foreach ($verifyList as $m=>$n){
  2246. if ($n[0]==$k){
  2247. array_splice($verifyList,$m,1,$v);
  2248. }
  2249. }
  2250. }
  2251. //费用执行人相关数据
  2252. $executeCopy=json_decode($value['executeCopy'],true);
  2253. $executeStaff=json_decode($value['executeStaff'],true);
  2254. foreach ($executeCopy as $k=>$v){
  2255. $executeCopy[$k]['date']='';
  2256. $executeCopy[$k]['opinion']='';
  2257. $executeCopy[$k]['status']='';
  2258. if (!empty($executeStaff))
  2259. foreach ($executeStaff as $m=>$u){
  2260. if ($v[0]==$m){
  2261. $executeCopy[$k]['date']=$u['date'];
  2262. $executeCopy[$k]['opinion']=$u['opinion'];
  2263. $executeCopy[$k]['status']=$u['status'];
  2264. break;
  2265. }
  2266. }
  2267. }
  2268. $receiptList[$key]['executeCopy']=$executeCopy;
  2269. $receiptList[$key]['verifyList']=$verifyList;
  2270. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2271. $receiptList[$key]['button']=$button;
  2272. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2273. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2274. }
  2275. //print_r($receiptList);
  2276. //获取审批日志
  2277. Doo::loadModel('receiptLog');
  2278. $receiptLog=new receiptLog();
  2279. $rlList=array();
  2280. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2281. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2282. if (!empty($rlInfo)){
  2283. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2284. }
  2285. $receiptList[0]['rlList']=$rlList;
  2286. $data['receiptList']=$receiptList;
  2287. $data['memu']="receipt";
  2288. $data['staff']=$this->staff;
  2289. $data['receiptMemu']='approvalExpenses';
  2290. $data['verifyId']=$this->verifyId;
  2291. $data['executeId']=$this->executeId;
  2292. $this->render ( "/admin/expensesDoc", $data );
  2293. }
  2294. function expensesEdi(){
  2295. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2296. $status=isset($this->params['status'])?$this->params['status']:'';
  2297. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2298. $month=$this->get_args('month')?$this->get_args('month'):"";
  2299. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2300. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2301. if (empty($status))
  2302. $status=$this->get_args('status')?$this->get_args('status'):2;
  2303. $vidList=array();
  2304. $button=0;
  2305. Doo::loadModel('verify');
  2306. Doo::loadModel('receipt');
  2307. Doo::loadModel('staff');
  2308. $staff=new staff();
  2309. $receipt=new receipt();
  2310. $verify=new verify();
  2311. Doo::loadModel('L_category');
  2312. $Lcategory=new L_category();
  2313. Doo::loadModel('enclosur');
  2314. $enclosur=new enclosur();
  2315. //user verify ID
  2316. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2317. foreach ($verifyDetail as $key=>$value){
  2318. array_push($vidList, $value['vid']);
  2319. }
  2320. $vid=implode(",", $vidList);
  2321. if(empty($verifyDetail))
  2322. $vid=0;
  2323. $categoryList=$Lcategory->find(array('asArray'=>true));
  2324. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2325. $ap="";
  2326. if($status==4){
  2327. $ap=4;$status=2;
  2328. }
  2329. //get Receipt By verifyID status 2
  2330. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2331. $Locate=0;$roleId=0;
  2332. if($ap==4)
  2333. $status=4;
  2334. foreach ($receiptList as $key=>$value){
  2335. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2336. $receiptList[$key]['reviseDetail']=array();
  2337. if (!empty($value['reviseDetail']))
  2338. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2339. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2340. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2341. $receiptList[$key]['category']=$categoryDetil['title'];
  2342. //检测编辑状态
  2343. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2344. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2345. $verifyStaff=json_decode($value['verifyStaff'],true);
  2346. Doo::loadModel('role');
  2347. $role=new role();
  2348. //print_r($verifyList);
  2349. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2350. foreach ($verifyList as $k=>$v){
  2351. //init verifyStaff
  2352. if ($v[1]=='ROLE'){
  2353. if (!empty($verifyStaff)){
  2354. $endStaffArray=end($verifyStaff);
  2355. if ($v[0]==$endStaffArray['nextStaff']){
  2356. $roleId=$v[0];
  2357. }
  2358. }
  2359. $roleVerify=json_decode($v[3],true);
  2360. $roleKey=$k;$roleArray=array();
  2361. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2362. foreach ($roleVerify as $o=>$p){
  2363. $staffID=explode ('_',$p);
  2364. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2365. //print_r($staffID);
  2366. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2367. array_push($roleArray, $exp);
  2368. }
  2369. $roleArrayCopy[$v[0]]=$roleArray;
  2370. //$verifyList[$k]['roleArray']=$roleArray;
  2371. }
  2372. //print_r($roleArray);
  2373. $verifyList[$k]['date']="";
  2374. $verifyList[$k]['opinion']="";
  2375. $verifyList[$k]['status']="";
  2376. if (empty($verifyStaff)){
  2377. $verifyList[$k]['date']="";
  2378. $verifyList[$k]['opinion']="";
  2379. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2380. $verifyList[$k]['status']=4;
  2381. $button=4;$flag=false;
  2382. }
  2383. }else{
  2384. foreach ($verifyStaff as $m=>$u){
  2385. if ($v[0]==$m){
  2386. $verifyList[$k]['date']=$u['date'];
  2387. $verifyList[$k]['opinion']=$u['opinion'];
  2388. $verifyList[$k]['status']=$u['status'];
  2389. $flag=false;
  2390. break;
  2391. }
  2392. }
  2393. $endStaffArray=end($verifyStaff);
  2394. if (isset($endStaffArray['ROLE'])){
  2395. }else{
  2396. $endKey=key($verifyStaff);
  2397. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2398. $button=4;
  2399. $verifyList[$k]['status']=4;
  2400. }
  2401. }
  2402. }
  2403. }
  2404. $rolename['name']='';
  2405. if (!empty($roleId)){
  2406. Doo::loadModel('role');
  2407. $role=new role();
  2408. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2409. }
  2410. if (!empty($verifyStaff))
  2411. $endStaffArray=end($verifyStaff);
  2412. $KOP=false;
  2413. foreach ($roleArrayCopy as $P=>$A){
  2414. foreach ( $A as $MKI=>$AVL){
  2415. if (!empty($verifyStaff)){
  2416. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2417. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2418. $button=4;
  2419. $roleArrayCopy[$P][$MKI]['status']=4;
  2420. }
  2421. foreach ($verifyStaff as $m=>$u){
  2422. $AVLFK=$AVL[0].'_R';
  2423. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2424. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2425. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2426. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2427. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2428. break;
  2429. }
  2430. }
  2431. }else{
  2432. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2433. $button=4;
  2434. $roleArrayCopy[$P][$MKI]['status']=4;
  2435. }
  2436. }
  2437. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2438. $KOP=true;
  2439. }
  2440. }
  2441. // print_r($roleArrayCopy);
  2442. // echo $roleKey;
  2443. foreach ($roleArrayCopy as $k=>$v){
  2444. foreach ($verifyList as $m=>$n){
  2445. if ($n[0]==$k){
  2446. array_splice($verifyList,$m,1,$v);
  2447. }
  2448. }
  2449. }
  2450. $receiptList[$key]['verifyList']=$verifyList;
  2451. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2452. $receiptList[$key]['button']=$button;
  2453. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2454. }
  2455. //$data['verifyDetail']=$verifyDetail;
  2456. $mothHtml="";
  2457. for($i=1;$i<=12;$i++){
  2458. if($month==$i)
  2459. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2460. else
  2461. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2462. }
  2463. //获取审批日志
  2464. Doo::loadModel('receiptLog');
  2465. $receiptLog=new receiptLog();
  2466. $rlList=array();
  2467. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2468. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2469. if (!empty($rlInfo)){
  2470. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2471. }
  2472. $receiptList[0]['rlList']=$rlList;
  2473. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2474. $enclosurHtml='';
  2475. foreach ($enclosurList as $value){
  2476. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2477. }
  2478. //print_r($receiptList);
  2479. $data['rid']=$rid;
  2480. $data['enclosurHtml']=$enclosurHtml;
  2481. $data['rolename']=$rolename['name'];
  2482. $data['datetij']=$tijdate['date'];
  2483. $data['mothHtml']=$mothHtml;
  2484. $data['receiptList']=$receiptList;
  2485. $data['receiptApprovalCount']=count($receiptList);
  2486. $data['status']=$status;
  2487. $data['year']=$year;
  2488. $data['categoryList']=$categoryList;
  2489. $data['staffList']=$staffList;
  2490. $data['cid']=$cid;
  2491. $data['sid']=$sid;
  2492. $data['ap']=$ap;
  2493. $data['memu']="receipt";
  2494. $data['staff']=$this->staff;
  2495. $data['receiptMemu']='approvalExpenses';
  2496. $data['verifyId']=$this->verifyId;
  2497. $data['executeId']=$this->executeId;
  2498. $this->render ( "/admin/expensesEdi", $data );
  2499. }
  2500. function expensesDefray(){
  2501. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2502. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2503. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2504. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2505. if(!empty($rid)){
  2506. Doo::loadModel("verify");
  2507. $verify=new verify();
  2508. Doo::loadModel("receiptDetail");
  2509. $receiptDetailObj=new receiptDetail();
  2510. Doo::loadModel("itemStatistics");
  2511. Doo::loadModel("statistics");
  2512. $statistics=new statistics();
  2513. $itemStatistics=new itemStatistics();
  2514. Doo::loadModel("receipt");
  2515. $receipt=new receipt();
  2516. Doo::loadModel("loanReceipt");
  2517. $loanReceipt=new loanReceipt();
  2518. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2519. if (empty($receiptDetail))
  2520. return "/approval";
  2521. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2522. $verifyString=$verifyDetail['staff'];
  2523. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2524. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2525. if(empty($opinion)){
  2526. if ($status==3)
  2527. $opinion="终止";
  2528. else
  2529. $opinion="同意支付";
  2530. }
  2531. $nowStaff=0;$nowStaffList=array();
  2532. if(empty($verifyStaff)){
  2533. //还需加入是否已经进入角色审批
  2534. if ($verifyDetail[0][1]=='ROLE'){
  2535. //print_r($verifyDetail);echo "ddd";
  2536. $vStaffString=json_decode($verifyDetail[0][3]);
  2537. foreach ($vStaffString as $key=>$value){
  2538. $staffK=explode("_", $value);
  2539. if ($staffK[0]!=$this->staff[0]['sid'])
  2540. array_push($nowStaffList, $staffK[0]);
  2541. }
  2542. //print_r($verifyDetail);
  2543. //die;
  2544. if (!empty($nowStaffList)){
  2545. $nowStaff=implode(',', $nowStaffList);
  2546. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2547. }else{
  2548. $nowStaff=$verifyDetail[1][0];
  2549. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2550. }
  2551. }else{
  2552. if ($verifyDetail[1][1]=='ROLE'){
  2553. $vStaffString=json_decode($verifyDetail[1][3]);
  2554. //echo "dd";
  2555. foreach ($vStaffString as $key=>$value){
  2556. $staffK=explode("_", $value);
  2557. array_push($nowStaffList, $staffK[0]);
  2558. }
  2559. $nowStaff=implode(',', $nowStaffList);
  2560. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2561. }else{
  2562. $nowStaff=$verifyDetail[1][0];
  2563. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2564. }
  2565. }
  2566. if($status==3)
  2567. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2568. $vStaffString=json_encode($verifyStaff);
  2569. $receipt->nowStaff=$nowStaff;
  2570. $receipt->verifyStaff=$vStaffString;
  2571. $loanReceipt->nowStaff=$nowStaff;
  2572. $loanReceipt->verifyStaff=$vStaffString;
  2573. }else{
  2574. $VS=end($verifyStaff);
  2575. //非角色审批
  2576. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2577. $nextStaff=0;$roleSTF=false;
  2578. foreach ($verifyDetail as $key=>$value){
  2579. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2580. if (isset($verifyDetail[$key+1])){
  2581. $nextStaff=$verifyDetail[$key+1][0];
  2582. if ($verifyDetail[$key+1][1]=='ROLE')
  2583. $roleSTF=true;
  2584. }
  2585. break;
  2586. }
  2587. }
  2588. if (!$roleSTF){
  2589. $nowStaff=$nextStaff;
  2590. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2591. }else{
  2592. //获取角色下的所有用户ID
  2593. $nowStaffList=array();
  2594. foreach ($verifyDetail as $vfk){
  2595. if ($vfk[1]=='ROLE'){
  2596. $vStaffString=json_decode($vfk[3]);
  2597. foreach ($vStaffString as $key=>$value){
  2598. $staffK=explode("_", $value);
  2599. array_push($nowStaffList, $staffK[0]);
  2600. }
  2601. }
  2602. }
  2603. $nowStaff=implode(',', $nowStaffList);
  2604. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2605. }
  2606. if($status==3){
  2607. $verifyStaff['final']=$status;
  2608. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2609. }
  2610. $vStaffString=json_encode($verifyStaff);
  2611. $receipt->nowStaff=$nowStaff;
  2612. $receipt->verifyStaff=$vStaffString;
  2613. $loanReceipt->nowStaff=$nowStaff;
  2614. $loanReceipt->verifyStaff=$vStaffString;
  2615. }
  2616. //角色审批
  2617. if (isset($VS['ROLE'])){
  2618. //找出角色人 当前审批角色组
  2619. $verifyJSStaff=array();$nowStaffList2=array();
  2620. foreach ($verifyDetail as $key=>$value){
  2621. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2622. $verifyJSStaff=json_decode($value[3]);
  2623. foreach ($verifyJSStaff as $m){
  2624. $staffK=explode("_", $m);
  2625. array_push($nowStaffList2, $staffK[0]);
  2626. }
  2627. // print_r($nowStaffList2);
  2628. }
  2629. }
  2630. $RoleVerifyStaff=array();
  2631. foreach ($verifyStaff as $key=>$value){
  2632. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2633. foreach ($nowStaffList2 as $m) {
  2634. if ($key==$m."_R")
  2635. $RoleVerifyStaff[$key]=$value;
  2636. }
  2637. }
  2638. }
  2639. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2640. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2641. //下一个审批人ID
  2642. $nextStaff=0;$falg=false;
  2643. foreach ($verifyDetail as $key=>$value){
  2644. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2645. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2646. $falg=true;
  2647. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2648. foreach ($vStaffString as $v){
  2649. $staffK=explode("_", $v);
  2650. array_push($nowStaffList, $staffK[0]);
  2651. }
  2652. $nowStaff=implode(',', $nowStaffList);
  2653. $nextStaff=$verifyDetail[$key+1][0];
  2654. }elseif(isset($verifyDetail[$key+1])){
  2655. $nextStaff=$verifyDetail[$key+1][0];
  2656. $nowStaff=$nextStaff;
  2657. }else
  2658. $nowStaff='';
  2659. break;
  2660. }
  2661. }
  2662. if ($falg)
  2663. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2664. else
  2665. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2666. // print_r($verifyStaff);
  2667. // echo $nowStaff;die;
  2668. }else{ //进入下一个角色或者审批人
  2669. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2670. //
  2671. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2672. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2673. // print_r($verifyStaff);
  2674. // die;
  2675. }
  2676. if($status==3){
  2677. $verifyStaff['final']=$status;
  2678. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2679. }
  2680. $vStaffString=json_encode($verifyStaff);
  2681. $receipt->verifyStaff=$vStaffString;
  2682. $receipt->nowStaff=$nowStaff;
  2683. $loanReceipt->nowStaff=$nowStaff;
  2684. $loanReceipt->verifyStaff=$vStaffString;
  2685. //die;
  2686. //}
  2687. // print_r($verifyStaff);
  2688. // die;
  2689. }
  2690. //print_r($verifyStaff);die;
  2691. }
  2692. //print_r($verifyDetail);
  2693. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2694. foreach ($verifyDetail as $k=>$v){
  2695. if ($v[1]=='ROLE'){
  2696. $roleId=$v[0];
  2697. $roleVerify=json_decode($v[3],true);
  2698. $roleKey=$k;$roleArray=array();
  2699. foreach ($roleVerify as $o=>$p){
  2700. $staffID=explode ('_',$p);
  2701. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2702. array_push($roleArray, $exp);
  2703. }
  2704. $verifyDetailCopy[$v[0]]=$roleArray;
  2705. }
  2706. }
  2707. //print_r($verifyDetail);
  2708. foreach ($verifyDetailCopy as $k=>$v){
  2709. foreach ($verifyDetail as $m=>$n){
  2710. if ($n[0]==$k){
  2711. array_splice($verifyDetail,$m,1,$v);
  2712. }
  2713. }
  2714. }
  2715. //审批日志
  2716. if (!isset($verifyStaff['final'])){
  2717. Doo::loadModel("receiptLog");
  2718. $receiptLog=new receiptLog();
  2719. if (!empty($roleId)){
  2720. Doo::loadModel("role");
  2721. $role=new role();
  2722. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2723. $receiptLog->rolename=$roleInfo['name'];
  2724. }
  2725. $receiptLog->username=$this->staff[0]['username'];
  2726. $receiptLog->uid=$this->staff[0]['sid'];
  2727. $receiptLog->date=date("Y-m-d");
  2728. $receiptLog->opinion=$opinion;
  2729. $receiptLog->img=$this->staff[0]['avatar'];
  2730. $receiptLog->status=1;
  2731. $receiptLog->rid=$rid;
  2732. $receiptLog->insert();
  2733. }
  2734. if (isset($verifyStaff['final'])){//rDetail
  2735. $receipt->status=3;
  2736. $receipt->verifyBreakup=$verifyString;
  2737. $receiptDetailObj->status=3;
  2738. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2739. //微信企业号通知
  2740. $this->setWXMsg($rid,3);
  2741. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2742. $receipt->status=6;
  2743. $receipt->pastDate=date("Y-m-d");
  2744. $receipt->isBK=1;
  2745. $loanReceipt->verifyBreakup=$verifyString;
  2746. $loanReceipt->status=1;
  2747. $loanReceipt->pastDate=date("Y-m-d");
  2748. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2749. //微信企业号通知
  2750. $this->setWXMsg($rid,1);
  2751. }
  2752. $receipt->update(array('where'=>' rid = '.$rid));
  2753. return "/approvalExpenses/2";
  2754. }
  2755. }
  2756. function implement(){
  2757. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2758. Doo::loadClass ( 'XDeode' );
  2759. $XDeode = new XDeode ( 5 );
  2760. Doo::loadModel('receipt');
  2761. $receipt=new receipt();
  2762. Doo::loadModel('L_category');
  2763. $Lcategory=new L_category();
  2764. Doo::loadModel('verify');
  2765. $verify=new verify();
  2766. Doo::loadModel('staff');
  2767. $staff=new staff();
  2768. Doo::loadModel("execute");
  2769. $execute=new execute();
  2770. $rid = $XDeode->decode ( $rid );
  2771. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6) and rid='.$rid,'desc'=>'rid','asArray'=>true));
  2772. Doo::loadModel('loanReceipt');
  2773. $loanReceipt=new loanReceipt();
  2774. //print_r($receiptList);
  2775. $loanList=array();
  2776. if (!isset($receiptList))
  2777. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2778. $Locate=0;$roleId=0;$button=0;
  2779. foreach ($loanList as $key=>$value){
  2780. $loanList[$key]['Locate']=$Locate;$Locate++;
  2781. $loanList[$key]['reviseDetail']=array();
  2782. if (!empty($value['reviseDetail']))
  2783. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2784. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2785. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2786. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2787. $loanList[$key]['category']=$categoryDetil['title'];
  2788. //检测编辑状态
  2789. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2790. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2791. $verifyStaff=json_decode($value['verifyStaff'],true);
  2792. Doo::loadModel('role');
  2793. $role=new role();
  2794. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2795. foreach ($verifyList as $k=>$v){
  2796. //init verifyStaff
  2797. if ($v[1]=='ROLE'){
  2798. if (!empty($verifyStaff)){
  2799. $endStaffArray=end($verifyStaff);
  2800. // if ($v[0]==$endStaffArray['nextStaff']){
  2801. // $roleId=$v[0];
  2802. // }
  2803. }
  2804. $roleVerify=json_decode($v[3],true);
  2805. $roleKey=$k;$roleArray=array();
  2806. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2807. foreach ($roleVerify as $o=>$p){
  2808. $staffID=explode ('_',$p);
  2809. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2810. //print_r($staffID);
  2811. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2812. array_push($roleArray, $exp);
  2813. }
  2814. $roleArrayCopy[$v[0]]=$roleArray;
  2815. //$verifyList[$k]['roleArray']=$roleArray;
  2816. }
  2817. $verifyList[$k]['date']="";
  2818. $verifyList[$k]['opinion']="";
  2819. $verifyList[$k]['status']="";
  2820. if (empty($verifyStaff)){
  2821. $verifyList[$k]['date']="";
  2822. $verifyList[$k]['opinion']="";
  2823. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2824. $verifyList[$k]['status']=4;
  2825. $flag=false;
  2826. }
  2827. }else{
  2828. foreach ($verifyStaff as $m=>$u){
  2829. if ($v[0]==$m){
  2830. $verifyList[$k]['date']=$u['date'];
  2831. $verifyList[$k]['opinion']=$u['opinion'];
  2832. $verifyList[$k]['status']=$u['status'];
  2833. $flag=false;
  2834. break;
  2835. }
  2836. }
  2837. $endStaffArray=end($verifyStaff);
  2838. if (isset($endStaffArray['ROLE'])){
  2839. }else{
  2840. // $endKey=key($verifyStaff);
  2841. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2842. // $button=4;
  2843. // $verifyList[$k]['status']=4;
  2844. // }
  2845. }
  2846. }
  2847. }
  2848. $rolename['name']='';
  2849. if (!empty($roleId)){
  2850. Doo::loadModel('role');
  2851. $role=new role();
  2852. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2853. }
  2854. if (!empty($verifyStaff))
  2855. $endStaffArray=end($verifyStaff);
  2856. $KOP=false;
  2857. foreach ($roleArrayCopy as $P=>$A){
  2858. foreach ( $A as $MKI=>$AVL){
  2859. if (!empty($verifyStaff)){
  2860. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2861. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2862. $button=4;
  2863. $roleArrayCopy[$P][$MKI]['status']=4;
  2864. }
  2865. foreach ($verifyStaff as $m=>$u){
  2866. $AVLFK=$AVL[0].'_R';
  2867. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2868. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2869. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2870. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2871. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2872. break;
  2873. }
  2874. }
  2875. }else{
  2876. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2877. $button=4;
  2878. $roleArrayCopy[$P][$MKI]['status']=4;
  2879. }
  2880. }
  2881. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2882. $KOP=true;
  2883. }
  2884. }
  2885. foreach ($roleArrayCopy as $k=>$v){
  2886. foreach ($verifyList as $m=>$n){
  2887. if ($n[0]==$k){
  2888. array_splice($verifyList,$m,1,$v);
  2889. }
  2890. }
  2891. }
  2892. $loanList[$key]['verifyList']=$verifyList;
  2893. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2894. }
  2895. $data['loanList']=$loanList;
  2896. $Locate=0;$roleId=0;$button=0;
  2897. foreach ($receiptList as $key=>$value){
  2898. $button2=0;
  2899. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2900. $receiptList[$key]['reviseDetail']=array();
  2901. if (!empty($value['reviseDetail']))
  2902. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2903. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2904. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2905. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2906. $receiptList[$key]['category']=$categoryDetil['title'];
  2907. $executeList=json_decode($value['executeCopy'],true);
  2908. $executeStaff=array();
  2909. if (!empty($value['executeStaff'] ))
  2910. $executeStaff=json_decode($value['executeStaff'],true);
  2911. if (isset($executeList)){
  2912. foreach ($executeList as $op=>$lo){
  2913. $executeList[$op]['date']="";
  2914. $executeList[$op]['opinion']="";
  2915. $executeList[$op]['status']="";
  2916. foreach ($executeStaff as $m=>$u){
  2917. if ($lo[0]==$m){
  2918. $executeList[$op]['date']=$u['date'];
  2919. $executeList[$op]['opinion']=$u['opinion'];
  2920. $executeList[$op]['status']=$u['status'];
  2921. break;
  2922. }
  2923. }
  2924. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2925. $button2=1;
  2926. $executeList[$op]['status']=4;
  2927. }
  2928. }
  2929. }
  2930. //检测编辑状态
  2931. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2932. $verifyList['staff']=$value['verifyBreakup'];
  2933. }else
  2934. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2935. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2936. $verifyStaff=json_decode($value['verifyStaff'],true);
  2937. Doo::loadModel('role');
  2938. $role=new role();
  2939. if ($verifyList==NULL)
  2940. $verifyList=array();
  2941. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2942. foreach ($verifyList as $k=>$v){
  2943. //init verifyStaff
  2944. if ($v[1]=='ROLE'){
  2945. if (!empty($verifyStaff)){
  2946. $endStaffArray=end($verifyStaff);
  2947. // if ($v[0]==$endStaffArray['nextStaff']){
  2948. // $roleId=$v[0];
  2949. // }
  2950. }
  2951. $roleVerify=json_decode($v[3],true);
  2952. $roleKey=$k;$roleArray=array();
  2953. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2954. foreach ($roleVerify as $o=>$p){
  2955. $staffID=explode ('_',$p);
  2956. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2957. //print_r($staffID);
  2958. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2959. array_push($roleArray, $exp);
  2960. }
  2961. $roleArrayCopy[$v[0]]=$roleArray;
  2962. //$verifyList[$k]['roleArray']=$roleArray;
  2963. }
  2964. $verifyList[$k]['date']="";
  2965. $verifyList[$k]['opinion']="";
  2966. $verifyList[$k]['status']="";
  2967. if (empty($verifyStaff)){
  2968. $verifyList[$k]['date']="";
  2969. $verifyList[$k]['opinion']="";
  2970. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2971. $verifyList[$k]['status']=4;
  2972. $flag=false;
  2973. }
  2974. }else{
  2975. foreach ($verifyStaff as $m=>$u){
  2976. if ($v[0]==$m){
  2977. $verifyList[$k]['date']=$u['date'];
  2978. $verifyList[$k]['opinion']=$u['opinion'];
  2979. $verifyList[$k]['status']=$u['status'];
  2980. $flag=false;
  2981. break;
  2982. }
  2983. }
  2984. $endStaffArray=end($verifyStaff);
  2985. if (isset($endStaffArray['ROLE'])){
  2986. }else{
  2987. // $endKey=key($verifyStaff);
  2988. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2989. // $button=4;
  2990. // $verifyList[$k]['status']=4;
  2991. // }
  2992. }
  2993. }
  2994. }
  2995. $rolename['name']='';
  2996. if (!empty($roleId)){
  2997. Doo::loadModel('role');
  2998. $role=new role();
  2999. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3000. }
  3001. if (!empty($verifyStaff))
  3002. $endStaffArray=end($verifyStaff);
  3003. $KOP=false;
  3004. foreach ($roleArrayCopy as $P=>$A){
  3005. foreach ( $A as $MKI=>$AVL){
  3006. if (!empty($verifyStaff)){
  3007. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3008. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3009. $button=4;
  3010. $roleArrayCopy[$P][$MKI]['status']=4;
  3011. }
  3012. foreach ($verifyStaff as $m=>$u){
  3013. $AVLFK=$AVL[0].'_R';
  3014. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3015. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3016. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3017. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3018. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3019. break;
  3020. }
  3021. }
  3022. }else{
  3023. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3024. $button=4;
  3025. $roleArrayCopy[$P][$MKI]['status']=4;
  3026. }
  3027. }
  3028. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3029. $KOP=true;
  3030. }
  3031. }
  3032. foreach ($roleArrayCopy as $k=>$v){
  3033. foreach ($verifyList as $m=>$n){
  3034. if ($n[0]==$k){
  3035. array_splice($verifyList,$m,1,$v);
  3036. }
  3037. }
  3038. }
  3039. $receiptList[$key]['verifyList']=$verifyList;
  3040. $receiptList[$key]['executeList']=$executeList;
  3041. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3042. $receiptList[$key]['button2']=$button2;
  3043. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3044. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3045. $relust=$value['sum']-$value['loanSum'];
  3046. $receiptList[$key]['relust']=$relust;
  3047. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3048. }
  3049. //print_r($receiptList[$key]['executeList']);
  3050. $data['receiptList']=$receiptList;
  3051. $data['memu']="receipt";
  3052. $data['staff']=$this->staff;
  3053. $data['receiptMemu']='implement';
  3054. $data['verifyId']=$this->verifyId;
  3055. $data['executeId']=$this->executeId;
  3056. $this->render ( "/admin/implement", $data );
  3057. }
  3058. function implementDo(){
  3059. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3060. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  3061. if (!empty($rid)){
  3062. Doo::loadModel('receipt');
  3063. $receipt=new receipt();
  3064. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  3065. $executeCopy=json_decode($rinfo['executeCopy'],true);
  3066. $executeStaff=json_decode($rinfo['executeStaff'],true);
  3067. if(empty($executeStaff)){
  3068. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3069. }else{
  3070. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3071. }
  3072. if (count($executeStaff)==count($executeCopy)){
  3073. $receipt->executeStaff=json_encode($executeStaff);
  3074. $receipt->status=8;
  3075. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3076. $receipt->status=9;
  3077. $receipt->executeDate= date("Y-m-d");
  3078. }else{
  3079. $receipt->executeStaff=json_encode($executeStaff);
  3080. }
  3081. $receipt->update(array('where'=>'rid='.$rid));
  3082. }
  3083. return "/implement";
  3084. }
  3085. function receiptburEdi(){
  3086. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3087. $status=isset($this->params['status'])?$this->params['status']:'';
  3088. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3089. $month=$this->get_args('month')?$this->get_args('month'):"";
  3090. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3091. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3092. if (empty($status))
  3093. $status=$this->get_args('status')?$this->get_args('status'):2;
  3094. $vidList=array();
  3095. $button=0;
  3096. Doo::loadModel('verify');
  3097. Doo::loadModel('receipt');
  3098. Doo::loadModel('staff');
  3099. $staff=new staff();
  3100. $receipt=new receipt();
  3101. $verify=new verify();
  3102. Doo::loadModel('L_category');
  3103. $Lcategory=new L_category();
  3104. Doo::loadModel('enclosur');
  3105. $enclosur=new enclosur();
  3106. Doo::loadModel('loanReceipt');
  3107. $loanReceipt=new loanReceipt();
  3108. //user verify ID
  3109. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3110. foreach ($verifyDetail as $key=>$value){
  3111. array_push($vidList, $value['vid']);
  3112. }
  3113. $vid=implode(",", $vidList);
  3114. if(empty($verifyDetail))
  3115. $vid=0;
  3116. $categoryList=$Lcategory->find(array('asArray'=>true));
  3117. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3118. $ap="";
  3119. if($status==4){
  3120. $ap=4;$status=2;
  3121. }
  3122. //get Receipt By verifyID status 2
  3123. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3124. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3125. $Locate=0;$roleId=0;$button=0;
  3126. foreach ($loanList as $key=>$value){
  3127. $loanList[$key]['Locate']=$Locate;$Locate++;
  3128. $loanList[$key]['reviseDetail']=array();
  3129. if (!empty($value['reviseDetail']))
  3130. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3131. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3132. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3133. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3134. $loanList[$key]['category']=$categoryDetil['title'];
  3135. //检测编辑状态
  3136. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3137. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3138. $verifyStaff=json_decode($value['verifyStaff'],true);
  3139. Doo::loadModel('role');
  3140. $role=new role();
  3141. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3142. foreach ($verifyList as $k=>$v){
  3143. //init verifyStaff
  3144. if ($v[1]=='ROLE'){
  3145. if (!empty($verifyStaff)){
  3146. $endStaffArray=end($verifyStaff);
  3147. }
  3148. $roleVerify=json_decode($v[3],true);
  3149. $roleKey=$k;$roleArray=array();
  3150. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3151. foreach ($roleVerify as $o=>$p){
  3152. $staffID=explode ('_',$p);
  3153. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3154. //print_r($staffID);
  3155. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3156. array_push($roleArray, $exp);
  3157. }
  3158. $roleArrayCopy[$v[0]]=$roleArray;
  3159. //$verifyList[$k]['roleArray']=$roleArray;
  3160. }
  3161. $verifyList[$k]['date']="";
  3162. $verifyList[$k]['opinion']="";
  3163. $verifyList[$k]['status']="";
  3164. if (empty($verifyStaff)){
  3165. $verifyList[$k]['date']="";
  3166. $verifyList[$k]['opinion']="";
  3167. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3168. $verifyList[$k]['status']=4;
  3169. $flag=false;
  3170. }
  3171. }else{
  3172. foreach ($verifyStaff as $m=>$u){
  3173. if ($v[0]==$m){
  3174. $verifyList[$k]['date']=$u['date'];
  3175. $verifyList[$k]['opinion']=$u['opinion'];
  3176. $verifyList[$k]['status']=$u['status'];
  3177. $flag=false;
  3178. break;
  3179. }
  3180. }
  3181. $endStaffArray=end($verifyStaff);
  3182. if (isset($endStaffArray['ROLE'])){
  3183. }else{
  3184. }
  3185. }
  3186. }
  3187. $rolename['name']='';
  3188. if (!empty($roleId)){
  3189. Doo::loadModel('role');
  3190. $role=new role();
  3191. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3192. }
  3193. if (!empty($verifyStaff))
  3194. $endStaffArray=end($verifyStaff);
  3195. $KOP=false;
  3196. foreach ($roleArrayCopy as $P=>$A){
  3197. foreach ( $A as $MKI=>$AVL){
  3198. if (!empty($verifyStaff)){
  3199. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3200. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3201. $button=4;
  3202. $roleArrayCopy[$P][$MKI]['status']=4;
  3203. }
  3204. foreach ($verifyStaff as $m=>$u){
  3205. $AVLFK=$AVL[0].'_R';
  3206. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3207. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3208. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3209. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3210. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3211. break;
  3212. }
  3213. }
  3214. }else{
  3215. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3216. $button=4;
  3217. $roleArrayCopy[$P][$MKI]['status']=4;
  3218. }
  3219. }
  3220. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3221. $KOP=true;
  3222. }
  3223. }
  3224. foreach ($roleArrayCopy as $k=>$v){
  3225. foreach ($verifyList as $m=>$n){
  3226. if ($n[0]==$k){
  3227. array_splice($verifyList,$m,1,$v);
  3228. }
  3229. }
  3230. }
  3231. $loanList[$key]['verifyList']=$verifyList;
  3232. }
  3233. $htmlLoan='';
  3234. if (isset($loanList[0])){
  3235. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3236. if ($value['status']==1)
  3237. $htmlLoan.='<li class="done" >';
  3238. elseif ($value['status']==3)
  3239. $htmlLoan.='<li class="undone" >';
  3240. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3241. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3242. if (isset($value['rolename']))
  3243. $htmlLoan.=$value['rolename'];
  3244. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3245. }
  3246. $data['loanDate']=$loanList[0]['date'];
  3247. }
  3248. $data['htmlLoan']=$htmlLoan;
  3249. //print_r($loanList);
  3250. $Locate=0;$roleId=0;$button=0;
  3251. if($ap==4)
  3252. $status=4;
  3253. foreach ($receiptList as $key=>$value){
  3254. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3255. $receiptList[$key]['reviseDetail']=array();
  3256. if (!empty($value['reviseDetail']))
  3257. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3258. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3259. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3260. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3261. $receiptList[$key]['category']=$categoryDetil['title'];
  3262. //检测编辑状态
  3263. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3264. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3265. $verifyStaff=json_decode($value['verifyStaff'],true);
  3266. Doo::loadModel('role');
  3267. $role=new role();
  3268. //print_r($verifyList);
  3269. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3270. foreach ($verifyList as $k=>$v){
  3271. //init verifyStaff
  3272. if ($v[1]=='ROLE'){
  3273. if (!empty($verifyStaff)){
  3274. $endStaffArray=end($verifyStaff);
  3275. if ($v[0]==$endStaffArray['nextStaff']){
  3276. $roleId=$v[0];
  3277. }
  3278. }
  3279. $roleVerify=json_decode($v[3],true);
  3280. $roleKey=$k;$roleArray=array();
  3281. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3282. foreach ($roleVerify as $o=>$p){
  3283. $staffID=explode ('_',$p);
  3284. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3285. //print_r($staffID);
  3286. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3287. array_push($roleArray, $exp);
  3288. }
  3289. $roleArrayCopy[$v[0]]=$roleArray;
  3290. //$verifyList[$k]['roleArray']=$roleArray;
  3291. }
  3292. //print_r($roleArray);
  3293. $verifyList[$k]['date']="";
  3294. $verifyList[$k]['opinion']="";
  3295. $verifyList[$k]['status']="";
  3296. if (empty($verifyStaff)){
  3297. $verifyList[$k]['date']="";
  3298. $verifyList[$k]['opinion']="";
  3299. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3300. $verifyList[$k]['status']=4;
  3301. $button=4;$flag=false;
  3302. }
  3303. }else{
  3304. foreach ($verifyStaff as $m=>$u){
  3305. if ($v[0]==$m){
  3306. $verifyList[$k]['date']=$u['date'];
  3307. $verifyList[$k]['opinion']=$u['opinion'];
  3308. $verifyList[$k]['status']=$u['status'];
  3309. $flag=false;
  3310. break;
  3311. }
  3312. }
  3313. $endStaffArray=end($verifyStaff);
  3314. if (isset($endStaffArray['ROLE'])){
  3315. }else{
  3316. $endKey=key($verifyStaff);
  3317. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3318. $button=4;
  3319. $verifyList[$k]['status']=4;
  3320. }
  3321. }
  3322. }
  3323. }
  3324. $rolename['name']='';
  3325. if (!empty($roleId)){
  3326. Doo::loadModel('role');
  3327. $role=new role();
  3328. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3329. }
  3330. if (!empty($verifyStaff))
  3331. $endStaffArray=end($verifyStaff);
  3332. $KOP=false;
  3333. foreach ($roleArrayCopy as $P=>$A){
  3334. foreach ( $A as $MKI=>$AVL){
  3335. if (!empty($verifyStaff)){
  3336. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3337. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3338. $button=4;
  3339. $roleArrayCopy[$P][$MKI]['status']=4;
  3340. }
  3341. foreach ($verifyStaff as $m=>$u){
  3342. $AVLFK=$AVL[0].'_R';
  3343. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3344. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3345. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3346. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3347. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3348. break;
  3349. }
  3350. }
  3351. }else{
  3352. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3353. $button=4;
  3354. $roleArrayCopy[$P][$MKI]['status']=4;
  3355. }
  3356. }
  3357. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3358. $KOP=true;
  3359. }
  3360. }
  3361. foreach ($roleArrayCopy as $k=>$v){
  3362. foreach ($verifyList as $m=>$n){
  3363. if ($n[0]==$k){
  3364. array_splice($verifyList,$m,1,$v);
  3365. }
  3366. }
  3367. }
  3368. //print_r($verifyList);
  3369. $receiptList[$key]['verifyList']=$verifyList;
  3370. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3371. $receiptList[$key]['button']=$button;
  3372. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3373. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3374. $relust=$value['sum']-$value['loanSum'];
  3375. $receiptList[$key]['relust']=$relust;
  3376. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3377. }
  3378. //print_r($receiptList);die;
  3379. //$data['verifyDetail']=$verifyDetail;
  3380. $mothHtml="";
  3381. for($i=1;$i<=12;$i++){
  3382. if($month==$i)
  3383. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3384. else
  3385. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3386. }
  3387. //获取审批日志
  3388. Doo::loadModel('receiptLog');
  3389. $receiptLog=new receiptLog();
  3390. $rlList=array();
  3391. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3392. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3393. if (!empty($rlInfo)){
  3394. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3395. }
  3396. //echo $rid;
  3397. //print_r($receiptList);
  3398. $receiptList[0]['rlList']=$rlList;
  3399. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3400. $enclosurHtml='';
  3401. foreach ($enclosurList as $value){
  3402. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3403. }
  3404. $data['enclosurHtml']=$enclosurHtml;
  3405. $data['rolename']=$rolename['name'];
  3406. // $data['datetij']=$tijdate['date'];
  3407. $data['mothHtml']=$mothHtml;
  3408. //print_r($receiptList);
  3409. $data['rid']=$rid;
  3410. $data['tijdate']=$tijdate['date'];
  3411. $data['receiptList']=$receiptList;
  3412. $data['receiptApprovalCount']=count($receiptList);
  3413. $data['status']=$status;
  3414. $data['year']=$year;
  3415. $data['categoryList']=$categoryList;
  3416. $data['staffList']=$staffList;
  3417. $data['cid']=$cid;
  3418. $data['sid']=$sid;
  3419. $data['ap']=$ap;
  3420. $data['memu']="receipt";
  3421. $data['staff']=$this->staff;
  3422. $data['receiptMemu']='approvalExpenses';
  3423. $data['verifyId']=$this->verifyId;
  3424. $data['executeId']=$this->executeId;
  3425. $this->render ( "/admin/receiptburEdi", $data );
  3426. }
  3427. function hisImplement(){
  3428. $item=isset($this->params['item'])?$this->params['item']:"";
  3429. if(empty($item))
  3430. $item=$this->get_args('item')?$this->get_args('item'):"";
  3431. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3432. $moth=$this->get_args('moth')?$this->get_args('moth'):'MONTH';
  3433. $day=$this->get_args('day')?$this->get_args('day'):'DAY';
  3434. $sop=$this->get_args('sop')?$this->get_args('sop'):'SOP';
  3435. Doo::loadModel('receipt');
  3436. $receipt=new receipt();
  3437. Doo::loadModel('L_category');
  3438. $Lcategory=new L_category();
  3439. Doo::loadModel('verify');
  3440. Doo::loadModel('statistics');
  3441. $statistics=new statistics();
  3442. $verify=new verify();
  3443. Doo::loadModel('staff');
  3444. $staff=new staff();
  3445. Doo::loadClass ( 'XDeode' );
  3446. $XDeode = new XDeode ( 5 );
  3447. $condition="";
  3448. if($item=="expenses")
  3449. $condition=" and Rtype=1 ";
  3450. elseif ($item=="receipts")
  3451. $condition=" and Rtype=0 ";
  3452. elseif ($item=="remits")
  3453. $condition=" and Rtype=2 ";
  3454. $sopString="";
  3455. $dateCondition=" and Year(date) =".$year;
  3456. if($moth!='MONTH'){
  3457. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3458. }
  3459. if($day!='DAY')
  3460. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth." and day(date)=".$day;
  3461. if ($sop!='SOP')
  3462. $sopString=" and staff=".$sop;
  3463. $statusCon='(status=8 or status=9 or status=1 or status=6 )';
  3464. if ($item=='teipts')
  3465. $statusCon='(status=1 or status=6 )';
  3466. //$noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']); and (status=1 or status=6)
  3467. $receiptList=$receipt->find(array('where'=>$statusCon.$condition.$dateCondition.$sopString,'desc'=>'rid','asArray'=>true));
  3468. //员工筛选
  3469. $receiptList2=$receipt->find(array('where'=>$statusCon.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3470. $sopStaff=array();
  3471. foreach ($receiptList2 as $key=>$value){
  3472. $staffDetail=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3473. $sopStaff[$value['staff']]=$staffDetail['username'];
  3474. }
  3475. $Locate=0;$roleId=0;$button=0;
  3476. foreach ($receiptList as $key=>$value){
  3477. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  3478. $receiptList[$key]['Texe']='false';
  3479. if (strstr($value['executeCopy'],'["'.$this->staff[0]['sid'].'"')!=false){
  3480. $receiptList[$key]['Texe']='true';
  3481. }
  3482. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3483. $receiptList[$key]['reviseDetail']=array();
  3484. if (!empty($value['reviseDetail']))
  3485. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3486. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3487. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3488. $receiptList[$key]['category']=$categoryDetil['title'];
  3489. //检测编辑状态
  3490. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3491. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3492. $verifyStaff=json_decode($value['verifyStaff'],true);
  3493. Doo::loadModel('role');
  3494. $role=new role();
  3495. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3496. foreach ($verifyList as $k=>$v){
  3497. //init verifyStaff
  3498. if ($v[1]=='ROLE'){
  3499. if (!empty($verifyStaff)){
  3500. $endStaffArray=end($verifyStaff);
  3501. }
  3502. $roleVerify=json_decode($v[3],true);
  3503. $roleKey=$k;$roleArray=array();
  3504. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3505. foreach ($roleVerify as $o=>$p){
  3506. $staffID=explode ('_',$p);
  3507. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3508. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3509. array_push($roleArray, $exp);
  3510. }
  3511. $roleArrayCopy[$v[0]]=$roleArray;
  3512. }
  3513. $verifyList[$k]['date']="";
  3514. $verifyList[$k]['opinion']="";
  3515. $verifyList[$k]['status']="";
  3516. if (empty($verifyStaff)){
  3517. $verifyList[$k]['date']="";
  3518. $verifyList[$k]['opinion']="";
  3519. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3520. $verifyList[$k]['status']=4;
  3521. $flag=false;
  3522. }
  3523. }else{
  3524. foreach ($verifyStaff as $m=>$u){
  3525. if ($v[0]==$m){
  3526. $verifyList[$k]['date']=$u['date'];
  3527. $verifyList[$k]['opinion']=$u['opinion'];
  3528. $verifyList[$k]['status']=$u['status'];
  3529. $flag=false;
  3530. break;
  3531. }
  3532. }
  3533. $endStaffArray=end($verifyStaff);
  3534. }
  3535. }
  3536. $rolename['name']='';
  3537. if (!empty($roleId)){
  3538. Doo::loadModel('role');
  3539. $role=new role();
  3540. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3541. }
  3542. if (!empty($verifyStaff))
  3543. $endStaffArray=end($verifyStaff);
  3544. $KOP=false;
  3545. foreach ($roleArrayCopy as $P=>$A){
  3546. foreach ( $A as $MKI=>$AVL){
  3547. if (!empty($verifyStaff)){
  3548. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3549. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3550. $button=4;
  3551. $roleArrayCopy[$P][$MKI]['status']=4;
  3552. }
  3553. foreach ($verifyStaff as $m=>$u){
  3554. $AVLFK=$AVL[0].'_R';
  3555. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3556. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3557. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3558. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3559. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3560. break;
  3561. }
  3562. }
  3563. }else{
  3564. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3565. $button=4;
  3566. $roleArrayCopy[$P][$MKI]['status']=4;
  3567. }
  3568. }
  3569. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3570. $KOP=true;
  3571. }
  3572. }
  3573. foreach ($roleArrayCopy as $k=>$v){
  3574. foreach ($verifyList as $m=>$n){
  3575. if ($n[0]==$k){
  3576. array_splice($verifyList,$m,1,$v);
  3577. }
  3578. }
  3579. }
  3580. $receiptList[$key]['verifyList']=$verifyList;
  3581. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3582. $receiptList[$key]['button']=$button;
  3583. }
  3584. //print_r($receiptList);
  3585. $mothHtml="";
  3586. for($i=1;$i<=12;$i++){
  3587. if($moth==$i)
  3588. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3589. else
  3590. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3591. }
  3592. $dayHtml="";
  3593. if ($day!="DAY"||$moth!="MONTH"){
  3594. for($i = 1; $i <= 31; $i ++) {
  3595. if($day==$i)
  3596. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3597. else
  3598. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3599. }
  3600. }
  3601. $sopHtml="";
  3602. foreach ($sopStaff as $key=>$value){
  3603. if($sop==$key)
  3604. $sopHtml.='<option value="'.$key.'" selected >'.$value.'</option>';
  3605. else
  3606. $sopHtml.='<option value="'.$key.'" >'.$value.'</option>';
  3607. }
  3608. $data['sopHtml']=$sopHtml;
  3609. $data['dayHtml']=$dayHtml;
  3610. $data['mothHtml']=$mothHtml;
  3611. $data['receiptList']=$receiptList;
  3612. $data['memu']="receipt";
  3613. $data['staff']=$this->staff;
  3614. $data['receiptMemu']='implement';
  3615. $data['verifyId']=$this->verifyId;
  3616. $data['executeId']=$this->executeId;
  3617. $data['item']=$item;
  3618. $data['year']=$year;
  3619. $data['moth']=$moth;
  3620. $data['day']=$day;
  3621. $data['sop']=$sop;
  3622. $this->render ( "/admin/hisImplement", $data );
  3623. }
  3624. function ajaxExamine(){
  3625. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3626. Doo::loadModel('receipt');
  3627. $receipt=new receipt();
  3628. if (!empty($rid)){
  3629. $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
  3630. ,'asArray'=>true));
  3631. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3632. }
  3633. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3634. }
  3635. /*
  3636. * 废弃
  3637. */
  3638. function myReceipt(){
  3639. //all approval past withdraw
  3640. $item=isset($this->params['item'])?$this->params['item']:"";
  3641. if(empty($item))
  3642. $item=$this->get_args('item')?$this->get_args('item'):"";
  3643. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3644. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3645. Doo::loadModel('receipt');
  3646. $receipt=new receipt();
  3647. //pre-loaded
  3648. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3649. //have cache
  3650. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3651. if(!empty($moth))//yearPage
  3652. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3653. $this->showCache($path);
  3654. }
  3655. Doo::loadModel('L_category');
  3656. $Lcategory=new L_category();
  3657. Doo::loadModel('verify');
  3658. Doo::loadModel('statistics');
  3659. $statistics=new statistics();
  3660. $verify=new verify();
  3661. Doo::loadModel('staff');
  3662. $staff=new staff();
  3663. $condition=" and status!=0 ";
  3664. if($item=="approval")
  3665. $condition=" and status=2 ";
  3666. elseif ($item=="withdraw")
  3667. $condition=" and status=3 ";
  3668. elseif ($item=="past")
  3669. $condition=" and status=1 ";
  3670. elseif ($item=="whdw")
  3671. $condition=" and status=4 ";
  3672. $dateCondition=" and Year(date) =".$year;
  3673. if(!empty($moth)){
  3674. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3675. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3676. }else
  3677. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3678. if(empty($stList))
  3679. $stList=array('rePrice'=>0,'agPrice'=>0);
  3680. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3681. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3682. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3683. $Locate=0;$roleId=0;$button=0;
  3684. foreach ($receiptList as $key=>$value){
  3685. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3686. $receiptList[$key]['reviseDetail']=array();
  3687. if (!empty($value['reviseDetail']))
  3688. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3689. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3690. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3691. $receiptList[$key]['category']=$categoryDetil['title'];
  3692. //检测编辑状态
  3693. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3694. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3695. $verifyStaff=json_decode($value['verifyStaff'],true);
  3696. Doo::loadModel('role');
  3697. $role=new role();
  3698. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3699. foreach ($verifyList as $k=>$v){
  3700. //init verifyStaff
  3701. if ($v[1]=='ROLE'){
  3702. if (!empty($verifyStaff)){
  3703. $endStaffArray=end($verifyStaff);
  3704. // if ($v[0]==$endStaffArray['nextStaff']){
  3705. // $roleId=$v[0];
  3706. // }
  3707. }
  3708. $roleVerify=json_decode($v[3],true);
  3709. $roleKey=$k;$roleArray=array();
  3710. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3711. foreach ($roleVerify as $o=>$p){
  3712. $staffID=explode ('_',$p);
  3713. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3714. //print_r($staffID);
  3715. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3716. array_push($roleArray, $exp);
  3717. }
  3718. $roleArrayCopy[$v[0]]=$roleArray;
  3719. //$verifyList[$k]['roleArray']=$roleArray;
  3720. }
  3721. $verifyList[$k]['date']="";
  3722. $verifyList[$k]['opinion']="";
  3723. $verifyList[$k]['status']="";
  3724. if (empty($verifyStaff)){
  3725. $verifyList[$k]['date']="";
  3726. $verifyList[$k]['opinion']="";
  3727. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3728. $verifyList[$k]['status']=4;
  3729. $flag=false;
  3730. }
  3731. }else{
  3732. foreach ($verifyStaff as $m=>$u){
  3733. if ($v[0]==$m){
  3734. $verifyList[$k]['date']=$u['date'];
  3735. $verifyList[$k]['opinion']=$u['opinion'];
  3736. $verifyList[$k]['status']=$u['status'];
  3737. $flag=false;
  3738. break;
  3739. }
  3740. }
  3741. $endStaffArray=end($verifyStaff);
  3742. if (isset($endStaffArray['ROLE'])){
  3743. }else{
  3744. // $endKey=key($verifyStaff);
  3745. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3746. // $button=4;
  3747. // $verifyList[$k]['status']=4;
  3748. // }
  3749. }
  3750. }
  3751. }
  3752. $rolename['name']='';
  3753. if (!empty($roleId)){
  3754. Doo::loadModel('role');
  3755. $role=new role();
  3756. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3757. }
  3758. if (!empty($verifyStaff))
  3759. $endStaffArray=end($verifyStaff);
  3760. $KOP=false;
  3761. foreach ($roleArrayCopy as $P=>$A){
  3762. foreach ( $A as $MKI=>$AVL){
  3763. if (!empty($verifyStaff)){
  3764. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3765. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3766. $button=4;
  3767. $roleArrayCopy[$P][$MKI]['status']=4;
  3768. }
  3769. foreach ($verifyStaff as $m=>$u){
  3770. $AVLFK=$AVL[0].'_R';
  3771. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3772. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3773. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3774. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3775. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3776. break;
  3777. }
  3778. }
  3779. }else{
  3780. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3781. $button=4;
  3782. $roleArrayCopy[$P][$MKI]['status']=4;
  3783. }
  3784. }
  3785. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3786. $KOP=true;
  3787. }
  3788. }
  3789. foreach ($roleArrayCopy as $k=>$v){
  3790. foreach ($verifyList as $m=>$n){
  3791. if ($n[0]==$k){
  3792. array_splice($verifyList,$m,1,$v);
  3793. }
  3794. }
  3795. }
  3796. $receiptList[$key]['verifyList']=$verifyList;
  3797. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3798. $receiptList[$key]['button']=$button;
  3799. }
  3800. //print_r($receiptList);die;
  3801. $mothHtml="";
  3802. for($i=1;$i<=12;$i++){
  3803. if($moth==$i)
  3804. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3805. else
  3806. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3807. }
  3808. $data['mothHtml']=$mothHtml;
  3809. $data['receiptList']=$receiptList;
  3810. $data['memu']="receipt";
  3811. $data['staff']=$this->staff;
  3812. $data['receiptMemu']='receipt';
  3813. $data['verifyId']=$this->verifyId;
  3814. $data['executeId']=$this->executeId;
  3815. $data['item']=$item;
  3816. $data['year']=$year;
  3817. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3818. //sufficient condition to generate cache
  3819. if(empty($moth)&&($year<date("Y"))){
  3820. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3821. if(empty($receiptList)){ //generated files
  3822. ob_start();
  3823. $this->render ( "/admin/saea_myList", $data );
  3824. $this->cacheFile($path);die;
  3825. // $content = ob_get_contents();
  3826. // $fp = fopen($path, "w");
  3827. // fwrite($fp, $content);
  3828. // fclose($fp);
  3829. }
  3830. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3831. $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));
  3832. if(empty($receiptList)){ //generated files
  3833. ob_start();
  3834. $this->render ( "/admin/saea_myList", $data );
  3835. $this->cacheFile($path);die;
  3836. }
  3837. }
  3838. }
  3839. $this->render ( "/admin/saea_myList", $data );
  3840. }
  3841. function saeaCreate(){
  3842. Doo::loadModel('accountItem');
  3843. Doo::loadModel('verify');
  3844. Doo::loadModel('receipt');
  3845. Doo::loadModel('L_category');
  3846. $lCategory=new L_category();
  3847. $receipt=new receipt();
  3848. $verify=new verify();
  3849. $accountItem=new accountItem();
  3850. Doo::loadModel("role");
  3851. $role=new role();
  3852. $acItem=$accountItem->find(array('asArray'=>true));
  3853. $veList=$verify->find(array('asArray'=>true));
  3854. foreach ($veList as $key=>$value){
  3855. $v=json_decode($value['staff']);
  3856. $list=array();
  3857. foreach ($v as $n=>$m){
  3858. if ($m['1']=='ROLE'){
  3859. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3860. $v[$n][1]=$roleInfo['name'];
  3861. array_push($list, $roleInfo['name']);
  3862. }else{
  3863. array_push($list, $v[$n][1]);
  3864. }
  3865. }
  3866. $veList[$key]['staff']=implode('>', $list);
  3867. }
  3868. $data['category']=$lCategory->find(array('asArray'=>true));
  3869. $data['veList']=$veList;
  3870. $data['acItem']=$acItem;
  3871. $data['memu']="receipt";
  3872. $data['staff']=$this->staff;
  3873. $data['receiptMemu']='saeaBorad';
  3874. $data['verifyId']=$this->verifyId;
  3875. $data['executeId']=$this->executeId;
  3876. $this->render ( "/admin/saea_create", $data );
  3877. }
  3878. function addReceipt(){
  3879. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3880. $agency=$this->get_args('agency');
  3881. $travel=$this->get_args('travel');
  3882. $train=$this->get_args('train');
  3883. $other=$this->get_args('other');
  3884. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3885. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3886. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3887. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3888. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3889. Doo::loadModel('receipt');
  3890. Doo::loadModel('receiptDetail');
  3891. Doo::loadModel('accountItem');
  3892. $accountItem=new accountItem();
  3893. $receipt=new receipt();
  3894. Doo::loadModel('enclosur');
  3895. Doo::loadModel('execute');
  3896. $execute=new execute();
  3897. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3898. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3899. // if(!empty($receiptDetail))
  3900. // return "/referReceipt/".$receiptDetail['rid'];
  3901. $aItem=$accountItem->find(array('asArray'=>true));
  3902. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3903. $ag=$tr=$ta=$ot=0;
  3904. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3905. foreach ($aItem as $key=>$value){
  3906. if ($value['category']==$this->AGENCY){
  3907. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3908. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3909. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3910. }
  3911. $ag++;
  3912. }
  3913. if($value['category']==$this->TRAVEL){
  3914. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3915. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3916. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3917. }
  3918. $tr++;
  3919. }
  3920. if($value['category']==$this->TRAIN){
  3921. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3922. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3923. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3924. }
  3925. $ta++;
  3926. }
  3927. if($value['category']==$this->OTHER){
  3928. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3929. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3930. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3931. }
  3932. $ot++;
  3933. }
  3934. }
  3935. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3936. //报销单
  3937. $receipt->accountItem=json_encode($accountJson);
  3938. $receipt->staff=$this->staff[0]['sid'];
  3939. $receipt->sum=number_format($sum, 2, '.', '');
  3940. $receipt->date=date("Y-m-d");
  3941. $receipt->cid=$cid;
  3942. $receipt->status=5;
  3943. //修改审批流程加入角色
  3944. $receipt->verify=$verify;
  3945. $receipt->executeCopy=$executeDetail['staff'];
  3946. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3947. $receipt->explanation=$explanation;
  3948. $rid=$receipt->insert();
  3949. //附件
  3950. if (!empty($enclosurName)){
  3951. $enclosurArray=explode('-', $enclosurName);
  3952. foreach ($enclosurArray as $value){
  3953. $enclosur=new enclosur();
  3954. $enclosur->name=$value;
  3955. $enclosur->rid=$rid;
  3956. $enclosur->insert();
  3957. }
  3958. //print_r($enclosurArray);die;
  3959. }
  3960. //报销详情
  3961. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3962. $receiptDetail=new receiptDetail();
  3963. $receiptDetail->staff=$this->staff[0]['sid'];
  3964. $receiptDetail->item=$value['name'];
  3965. $receiptDetail->itemCategory=$this->AGENCY;
  3966. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3967. $receiptDetail->date=date("Y-m-d");
  3968. $receiptDetail->cid=$cid;
  3969. $receiptDetail->rid=$rid;
  3970. $receiptDetail->status=4;
  3971. $receiptDetail->insert();
  3972. }
  3973. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3974. $receiptDetail=new receiptDetail();
  3975. $receiptDetail->staff=$this->staff[0]['sid'];
  3976. $receiptDetail->item=$value['name'];
  3977. $receiptDetail->itemCategory=$this->TRAVEL;
  3978. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3979. $receiptDetail->date=date("Y-m-d");
  3980. $receiptDetail->cid=$cid;
  3981. $receiptDetail->rid=$rid;
  3982. $receiptDetail->status=4;
  3983. $receiptDetail->insert();
  3984. }
  3985. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3986. $receiptDetail=new receiptDetail();
  3987. $receiptDetail->staff=$this->staff[0]['sid'];
  3988. $receiptDetail->item=$value['name'];
  3989. $receiptDetail->itemCategory=$this->TRAIN;
  3990. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3991. $receiptDetail->date=date("Y-m-d");
  3992. $receiptDetail->cid=$cid;
  3993. $receiptDetail->rid=$rid;
  3994. $receiptDetail->status=4;
  3995. $receiptDetail->insert();
  3996. }
  3997. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3998. $receiptDetail=new receiptDetail();
  3999. $receiptDetail->staff=$this->staff[0]['sid'];
  4000. $receiptDetail->item=$value['name'];
  4001. $receiptDetail->itemCategory=$this->OTHER;
  4002. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4003. $receiptDetail->date=date("Y-m-d");
  4004. $receiptDetail->cid=$cid;
  4005. $receiptDetail->rid=$rid;
  4006. $receiptDetail->status=4;
  4007. $receiptDetail->insert();
  4008. }
  4009. //return "/referReceipt/".$rid;
  4010. }
  4011. return "/saeaBorad";
  4012. }
  4013. function referReceipt(){
  4014. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4015. Doo::loadModel('receipt');
  4016. Doo::loadModel('verify');
  4017. $verify=new verify();
  4018. $receipt=new receipt();
  4019. Doo::loadModel('L_category');
  4020. $lCategory=new L_category();
  4021. Doo::loadModel("role");
  4022. $role=new role();
  4023. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  4024. if(empty($receiptDetail))
  4025. return "/addReceipt";
  4026. foreach ($receiptDetail as $key=>$value){
  4027. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  4028. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4029. $v=json_decode($veList['staff']);
  4030. array_push($v[0], $veList['description']);
  4031. foreach ($v as $n=>$m){
  4032. if ($m['1']=='ROLE'){
  4033. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4034. $v[$n][1]=$roleInfo['name'];
  4035. }
  4036. }
  4037. $receiptDetail[$key]['staff']=$v;
  4038. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4039. $receiptDetail[$key]['category']=$category['title'];
  4040. }
  4041. //print_r($receiptDetail);
  4042. $data['receiptDetail']=$receiptDetail;
  4043. $data['memu']="receipt";
  4044. $data['staff']=$this->staff;
  4045. $data['receiptMemu']='saeaCreate';
  4046. $data['verifyId']=$this->verifyId;
  4047. $data['executeId']=$this->executeId;
  4048. $this->render ( "/admin/saea_confirm", $data );
  4049. }
  4050. function editReceipt(){
  4051. //edit status 4
  4052. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4053. //echo $rid;
  4054. Doo::loadModel('accountItem');
  4055. Doo::loadModel('verify');
  4056. Doo::loadModel('receipt');
  4057. $receipt=new receipt();
  4058. $verify=new verify();
  4059. $accountItem=new accountItem();
  4060. Doo::loadModel('L_category');
  4061. $lCategory=new L_category();
  4062. Doo::loadModel("role");
  4063. $role=new role();
  4064. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  4065. if(empty($receiptDetail))
  4066. return "/saeaCreate";
  4067. $acItem=$accountItem->find(array('asArray'=>true));
  4068. $veList=$verify->find(array('asArray'=>true));
  4069. foreach ($veList as $key=>$value){
  4070. $v=json_decode($value['staff']);
  4071. $list=array();
  4072. foreach ($v as $n=>$m){
  4073. if ($m['1']=='ROLE'){
  4074. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4075. $v[$n][1]=$roleInfo['name'];
  4076. array_push($list, $roleInfo['name']);
  4077. }else{
  4078. array_push($list, $v[$n][1]);
  4079. }
  4080. }
  4081. $veList[$key]['staff']=implode('>', $list);
  4082. }
  4083. //配置编辑信息
  4084. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4085. foreach ($acItem as $key=>$value){
  4086. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4087. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4088. $acItem[$key]['price']=$v['price'];
  4089. }
  4090. }
  4091. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4092. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4093. $acItem[$key]['price']=$v['price'];
  4094. }
  4095. }
  4096. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4097. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4098. $acItem[$key]['price']=$v['price'];
  4099. }
  4100. }
  4101. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4102. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4103. $acItem[$key]['price']=$v['price'];
  4104. }
  4105. }
  4106. }
  4107. $data['category']=$lCategory->find(array('asArray'=>true));
  4108. $data['cSum']=$accountItemList['cSum'];
  4109. $data['sum']=$receiptDetail['sum'];
  4110. $data['receiptDetail']=$receiptDetail;
  4111. $data['veList']=$veList;
  4112. $data['acItem']=$acItem;
  4113. $data['memu']="receipt";
  4114. $data['staff']=$this->staff;
  4115. $data['receiptMemu']='saeaBorad';
  4116. $data['verify']=$receiptDetail['verify'];
  4117. $data['verifyId']=$this->verifyId;
  4118. $data['executeId']=$this->executeId;
  4119. $data['rid']=$rid;
  4120. $this->render ( "/admin/saea_edit", $data );
  4121. }
  4122. function updateReceipt(){
  4123. $agency=$this->get_args('agency');
  4124. $travel=$this->get_args('travel');
  4125. $train=$this->get_args('train');
  4126. $other=$this->get_args('other');
  4127. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4128. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4129. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4130. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4131. if(!empty($explanation)){
  4132. Doo::loadModel('receipt');
  4133. Doo::loadModel('receiptDetail');
  4134. Doo::loadModel('accountItem');
  4135. $accountItem=new accountItem();
  4136. $receipt=new receipt();
  4137. Doo::loadModel('execute');
  4138. $execute=new execute();
  4139. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4140. if(empty($receiptDetail))
  4141. return "/saeaBorad";
  4142. if ($receiptDetail['Rtype']==1)
  4143. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4144. else
  4145. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4146. $aItem=$accountItem->find(array('asArray'=>true));
  4147. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4148. $ag=$tr=$ta=$ot=0;
  4149. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4150. foreach ($aItem as $key=>$value){
  4151. if ($value['category']==$this->AGENCY){
  4152. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4153. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4154. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4155. }
  4156. $ag++;
  4157. }
  4158. if($value['category']==$this->TRAVEL){
  4159. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4160. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4161. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4162. }
  4163. $tr++;
  4164. }
  4165. if($value['category']==$this->TRAIN){
  4166. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4167. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4168. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4169. }
  4170. $ta++;
  4171. }
  4172. if($value['category']==$this->OTHER){
  4173. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4174. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4175. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4176. }
  4177. $ot++;
  4178. }
  4179. }
  4180. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4181. //报销单
  4182. $rid=$receipt->rid=$receiptDetail['rid'];
  4183. $receipt->accountItem=json_encode($accountJson);
  4184. $receipt->staff=$this->staff[0]['sid'];
  4185. $receipt->sum=number_format($sum, 2, '.', '');
  4186. $receipt->date=date("Y-m-d");
  4187. $receipt->cid=$cid;
  4188. if (($receiptDetail['status']!=4)){
  4189. if ($receiptDetail['Rtype']==1)
  4190. $receipt->status=7;
  4191. else
  4192. $receipt->status=5;
  4193. }
  4194. if ($receiptDetail!=4&&!empty($verify))
  4195. $receipt->verify=$verify;
  4196. $receipt->executeCopy=$executeDetail['staff'];
  4197. $receipt->explanation=$explanation;
  4198. $receipt->update();
  4199. $receiptDetail=new receiptDetail();
  4200. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4201. //报销详情
  4202. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4203. $receiptDetail=new receiptDetail();
  4204. $receiptDetail->staff=$this->staff[0]['sid'];
  4205. $receiptDetail->item=$value['name'];
  4206. $receiptDetail->itemCategory=$this->AGENCY;
  4207. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4208. $receiptDetail->date=date("Y-m-d");
  4209. $receiptDetail->cid=$cid;
  4210. $receiptDetail->rid=$rid;
  4211. $receiptDetail->status=4;
  4212. $receiptDetail->insert();
  4213. }
  4214. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4215. $receiptDetail=new receiptDetail();
  4216. $receiptDetail->staff=$this->staff[0]['sid'];
  4217. $receiptDetail->item=$value['name'];
  4218. $receiptDetail->itemCategory=$this->TRAVEL;
  4219. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4220. $receiptDetail->date=date("Y-m-d");
  4221. $receiptDetail->cid=$cid;
  4222. $receiptDetail->rid=$rid;
  4223. $receiptDetail->status=4;
  4224. $receiptDetail->insert();
  4225. }
  4226. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4227. $receiptDetail=new receiptDetail();
  4228. $receiptDetail->staff=$this->staff[0]['sid'];
  4229. $receiptDetail->item=$value['name'];
  4230. $receiptDetail->itemCategory=$this->TRAIN;
  4231. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4232. $receiptDetail->date=date("Y-m-d");
  4233. $receiptDetail->cid=$cid;
  4234. $receiptDetail->rid=$rid;
  4235. $receiptDetail->status=4;
  4236. $receiptDetail->insert();
  4237. }
  4238. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4239. $receiptDetail=new receiptDetail();
  4240. $receiptDetail->staff=$this->staff[0]['sid'];
  4241. $receiptDetail->item=$value['name'];
  4242. $receiptDetail->itemCategory=$this->OTHER;
  4243. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4244. $receiptDetail->date=date("Y-m-d");
  4245. $receiptDetail->cid=$cid;
  4246. $receiptDetail->rid=$rid;
  4247. $receiptDetail->status=4;
  4248. $receiptDetail->insert();
  4249. }
  4250. //return "/referReceipt/".$rid;
  4251. }
  4252. return "/saeaBorad";
  4253. }
  4254. function approvedReceipt(){
  4255. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4256. Doo::loadModel('receipt');
  4257. Doo::loadModel('receiptDetail');
  4258. $receipt=new receipt();
  4259. $receiptDetail=new receiptDetail();
  4260. Doo::loadModel('statistics');
  4261. Doo::loadModel('itemStatistics');
  4262. $statistics=new statistics();
  4263. $itemStatistics=new itemStatistics();
  4264. Doo::loadModel("verify");
  4265. $verify=new verify();
  4266. //审批状态的判定
  4267. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4268. if(empty($receiptDetailList))
  4269. return "/saeaBorad";
  4270. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4271. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4272. if (empty($receiptDetailList['nowStaff'])){
  4273. $nowStaff="";$nowStaffList=array();
  4274. if ($verifyDetail[0][1]=='ROLE'){
  4275. $vStaffString=json_decode($verifyDetail[0][3]);
  4276. foreach ($vStaffString as $key=>$value){
  4277. $staffK=explode("_", $value);
  4278. array_push($nowStaffList, $staffK[0]);
  4279. }
  4280. $nowStaff=implode(',', $nowStaffList);
  4281. }else{
  4282. $nowStaff=$verifyDetail[0][0];
  4283. }
  4284. $receipt->nowStaff=$nowStaff;
  4285. }
  4286. // echo $nowStaff;
  4287. // print_r($verifyDetail);die;
  4288. $receipt->rid=$receiptDetailList['rid'];
  4289. $receipt->date=date("Y-m-d");
  4290. $receipt->status=2;
  4291. $receipt->update();
  4292. $receiptDetail->status=2;
  4293. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4294. Doo::loadModel("receiptLog");
  4295. $receiptLog=new receiptLog();
  4296. Doo::loadModel("verify");
  4297. $verify=new verify();
  4298. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4299. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4300. $jd=json_decode($vr['staff']);$roleId=0;
  4301. foreach ($jd as $key=>$value){
  4302. if ($value[1]=='ROLE'){
  4303. $pos = strpos($value[3], $this->staff[0]['sid']);
  4304. if ($pos !== false) {
  4305. $roleId=$value[0];
  4306. }
  4307. }
  4308. }
  4309. //审批日志
  4310. //echo $roleId;die;
  4311. if (!empty($roleId)){
  4312. Doo::loadModel("role");
  4313. $role=new role();
  4314. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4315. $receiptLog->rolename=$roleInfo['name'];
  4316. }
  4317. $receiptLog->username=$this->staff[0]['username'];
  4318. $receiptLog->uid=$this->staff[0]['sid'];
  4319. $receiptLog->date=date("Y-m-d");
  4320. $receiptLog->opinion='提交审批';
  4321. $receiptLog->img=$this->staff[0]['avatar'];
  4322. $receiptLog->status=2;
  4323. $receiptLog->rid=$rid;
  4324. $receiptLog->insert();
  4325. //statistics item
  4326. $dateArray=explode("-", $receiptDetailList['date']);
  4327. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4328. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4329. //print_r($accountItem['cSum']['agencySum']);die;
  4330. // foreach ($accountItem['cSum'] as $key=>$value){
  4331. // if($key=="agencySum"){
  4332. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4333. // if(empty($iStatistics)){
  4334. // $itemStatistics->cid=$this->staff[0]['cid'];
  4335. // $itemStatistics->staff=$this->staff[0]['sid'];
  4336. // $itemStatistics->price=$value;
  4337. // $itemStatistics->itemCategory=$this->AGENCY;
  4338. // $itemStatistics->date=date("Y-m-d");
  4339. // $itemStatistics->insert();
  4340. // }else{
  4341. // if (!empty($value)){
  4342. // $itemStatistics->price=$value+$iStatistics['price'];
  4343. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4344. // }
  4345. // }
  4346. // }elseif($key=="travelSum"){
  4347. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4348. // if(empty($iStatistics)){
  4349. // $itemStatistics->cid=$this->staff[0]['cid'];
  4350. // $itemStatistics->staff=$this->staff[0]['sid'];
  4351. // $itemStatistics->price=$value;
  4352. // $itemStatistics->itemCategory=$this->TRAVEL;
  4353. // $itemStatistics->date=date("Y-m-d");
  4354. // $itemStatistics->insert();
  4355. // }else{
  4356. // if (!empty($value)){
  4357. // $itemStatistics->price=$value+$iStatistics['price'];
  4358. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4359. // }
  4360. // }
  4361. // }elseif($key=="trainSum"){
  4362. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4363. // if(empty($iStatistics)){
  4364. // $itemStatistics->cid=$this->staff[0]['cid'];
  4365. // $itemStatistics->staff=$this->staff[0]['sid'];
  4366. // $itemStatistics->price=$value;
  4367. // $itemStatistics->itemCategory=$this->TRAIN;
  4368. // $itemStatistics->date=date("Y-m-d");
  4369. // $itemStatistics->insert();
  4370. // }else{
  4371. // if (!empty($value)){
  4372. // $itemStatistics->price=$value+$iStatistics['price'];
  4373. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4374. // }
  4375. // }
  4376. // }elseif($key=="otherSum"){
  4377. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4378. // if(empty($iStatistics)){
  4379. // $itemStatistics->cid=$this->staff[0]['cid'];
  4380. // $itemStatistics->staff=$this->staff[0]['sid'];
  4381. // $itemStatistics->price=$value;
  4382. // $itemStatistics->itemCategory=$this->OTHER;
  4383. // $itemStatistics->date=date("Y-m-d");
  4384. // $itemStatistics->insert();
  4385. // }else{
  4386. // if (!empty($value)){
  4387. // $itemStatistics->price=$value+$iStatistics['price'];
  4388. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4389. // }
  4390. // }
  4391. // }
  4392. // }
  4393. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4394. if(empty($stat)){
  4395. $statistics->date=date("Y-m-d");
  4396. $statistics->cid=$this->staff[0]['cid'];
  4397. $statistics->staff=$this->staff[0]['sid'];
  4398. $statistics->agPrice=0;
  4399. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4400. $statistics->insert();
  4401. }else{
  4402. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4403. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4404. }
  4405. return "/expenses";
  4406. }
  4407. function approval(){
  4408. $status=isset($this->params['status'])?$this->params['status']:'';
  4409. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4410. $month=$this->get_args('month')?$this->get_args('month'):"";
  4411. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4412. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4413. if (empty($status))
  4414. $status=$this->get_args('status')?$this->get_args('status'):2;
  4415. $vidList=array();
  4416. $button=0;
  4417. Doo::loadModel('verify');
  4418. $verify=new verify();
  4419. Doo::loadModel('receipt');
  4420. $receipt=new receipt();
  4421. Doo::loadModel('staff');
  4422. $staff=new staff();
  4423. Doo::loadModel('L_category');
  4424. $Lcategory=new L_category();
  4425. //user verify ID
  4426. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4427. foreach ($verifyDetail as $key=>$value){
  4428. array_push($vidList, $value['vid']);
  4429. }
  4430. $vid=implode(",", $vidList);
  4431. if(empty($verifyDetail))
  4432. $vid=0;
  4433. /*
  4434. */
  4435. $dateCondition=" and Year(date) =".$year;
  4436. if(!empty($month))
  4437. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4438. $categoryList=$Lcategory->find(array('asArray'=>true));
  4439. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4440. $cateCondition="";$staffCondition="";$approvalCondition="";
  4441. if (!empty($cid))
  4442. $cateCondition=' and cid='.$cid;
  4443. if(!empty($sid)){
  4444. $staffCondition=' and staff='.$sid;
  4445. $cateCondition="";
  4446. }
  4447. // elseif($status==1){
  4448. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4449. // }
  4450. if($status==2){
  4451. //查找角色审批人
  4452. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4453. }
  4454. $ap="";
  4455. if($status==4){
  4456. $ap=4;$status=2;
  4457. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4458. }
  4459. if($status==5){
  4460. $status=4;$ap=5;
  4461. }
  4462. //echo $vid;
  4463. //get Receipt By verifyID status 2 .$approvalCondition
  4464. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4465. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4466. ,'desc'=>'rid','asArray'=>true));
  4467. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4468. $Locate=0;
  4469. if($ap==4)
  4470. $status=4;
  4471. elseif ($ap==5)
  4472. $status=5;
  4473. foreach ($receiptList as $key=>$value){
  4474. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4475. $receiptList[$key]['reviseDetail']=array();
  4476. if (!empty($value['reviseDetail']))
  4477. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4478. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4479. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4480. $receiptList[$key]['category']=$categoryDetil['title'];
  4481. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4482. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4483. $verifyStaff=json_decode($value['verifyStaff'],true);
  4484. foreach ($verifyList as $k=>$v){
  4485. //init verifyStaff
  4486. $verifyList[$k]['date']="";
  4487. $verifyList[$k]['opinion']="";
  4488. $verifyList[$k]['status']="";
  4489. if (empty($verifyStaff)){
  4490. $verifyList[$k]['date']="";
  4491. $verifyList[$k]['opinion']="";
  4492. if ($v[0]==$this->staff[0]['sid']){
  4493. $verifyList[$k]['status']=4;
  4494. $button=4;
  4495. }
  4496. }else{
  4497. $flag=true;
  4498. foreach ($verifyStaff as $m=>$u){
  4499. if ($v[0]==$m){
  4500. $verifyList[$k]['date']=$u['date'];
  4501. $verifyList[$k]['opinion']=$u['opinion'];
  4502. $verifyList[$k]['status']=$u['status'];
  4503. $flag=false;
  4504. break;
  4505. }
  4506. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4507. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4508. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4509. }
  4510. if($flag){//检测可编辑
  4511. if($v[0]==$this->staff[0]['sid']){
  4512. $verifyList[$k]['status']=4;$button=4;
  4513. }
  4514. }
  4515. }
  4516. }
  4517. $receiptList[$key]['verifyList']=$verifyList;
  4518. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4519. $receiptList[$key]['button']=$button;
  4520. }
  4521. //print_r($receiptList);die;
  4522. //$data['verifyDetail']=$verifyDetail;
  4523. $mothHtml="";
  4524. for($i=1;$i<=12;$i++){
  4525. if($month==$i)
  4526. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4527. else
  4528. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4529. }
  4530. $data['mothHtml']=$mothHtml;
  4531. $data['receiptList']=$receiptList;
  4532. $data['receiptApprovalCount']=count($receiptList);
  4533. $data['status']=$status;
  4534. $data['year']=$year;
  4535. $data['categoryList']=$categoryList;
  4536. $data['staffList']=$staffList;
  4537. $data['cid']=$cid;
  4538. $data['sid']=$sid;
  4539. $data['ap']=$ap;
  4540. $data['memu']="receipt";
  4541. $data['staff']=$this->staff;
  4542. $data['receiptMemu']='approval';
  4543. $data['verifyId']=$this->verifyId;
  4544. $data['executeId']=$this->executeId;
  4545. $this->render ( "/admin/saea_reportList", $data );
  4546. }
  4547. function approvalDetails(){
  4548. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4549. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4550. $month=$this->get_args('month')?$this->get_args('month'):"";
  4551. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4552. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4553. Doo::loadModel('verify');
  4554. $verify=new verify();
  4555. Doo::loadModel('receipt');
  4556. $receipt=new receipt();
  4557. Doo::loadModel('staff');
  4558. $staff=new staff();
  4559. Doo::loadModel('L_category');
  4560. $Lcategory=new L_category();
  4561. Doo::loadModel('enclosur');
  4562. $enclosur=new enclosur();
  4563. $vidList=array();
  4564. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4565. foreach ($verifyDetail as $key=>$value){
  4566. array_push($vidList, $value['vid']);
  4567. }
  4568. $vid=implode(",", $vidList);
  4569. if(empty($verifyDetail))
  4570. $vid=0;
  4571. $categoryList=$Lcategory->find(array('asArray'=>true));
  4572. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4573. $ap=0;
  4574. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4575. $Locate=0;$roleId=0;$button=0;
  4576. foreach ($receiptList as $key=>$value){
  4577. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4578. $receiptList[$key]['reviseDetail']=array();
  4579. if (!empty($value['reviseDetail']))
  4580. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4581. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4582. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4583. $receiptList[$key]['category']=$categoryDetil['title'];
  4584. //检测编辑状态
  4585. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4586. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4587. $verifyStaff=json_decode($value['verifyStaff'],true);
  4588. Doo::loadModel('role');
  4589. $role=new role();
  4590. //print_r($verifyList);
  4591. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4592. foreach ($verifyList as $k=>$v){
  4593. //init verifyStaff
  4594. if ($v[1]=='ROLE'){
  4595. if (!empty($verifyStaff)){
  4596. $endStaffArray=end($verifyStaff);
  4597. if ($v[0]==$endStaffArray['nextStaff']){
  4598. $roleId=$v[0];
  4599. }
  4600. }
  4601. $roleVerify=json_decode($v[3],true);
  4602. $roleKey=$k;$roleArray=array();
  4603. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4604. foreach ($roleVerify as $o=>$p){
  4605. $staffID=explode ('_',$p);
  4606. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4607. //print_r($staffID);
  4608. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4609. array_push($roleArray, $exp);
  4610. }
  4611. $roleArrayCopy[$v[0]]=$roleArray;
  4612. //$verifyList[$k]['roleArray']=$roleArray;
  4613. }
  4614. //print_r($roleArray);
  4615. $verifyList[$k]['date']="";
  4616. $verifyList[$k]['opinion']="";
  4617. $verifyList[$k]['status']="";
  4618. if (empty($verifyStaff)){
  4619. $verifyList[$k]['date']="";
  4620. $verifyList[$k]['opinion']="";
  4621. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4622. $verifyList[$k]['status']=4;
  4623. $button=4;$flag=false;
  4624. }
  4625. }else{
  4626. foreach ($verifyStaff as $m=>$u){
  4627. if ($v[0]==$m){
  4628. $verifyList[$k]['date']=$u['date'];
  4629. $verifyList[$k]['opinion']=$u['opinion'];
  4630. $verifyList[$k]['status']=$u['status'];
  4631. $flag=false;
  4632. break;
  4633. }
  4634. }
  4635. $endStaffArray=end($verifyStaff);
  4636. if (isset($endStaffArray['ROLE'])){
  4637. }else{
  4638. $endKey=key($verifyStaff);
  4639. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4640. $button=4;
  4641. $verifyList[$k]['status']=4;
  4642. }
  4643. }
  4644. }
  4645. }
  4646. $rolename['name']='';
  4647. if (!empty($roleId)){
  4648. Doo::loadModel('role');
  4649. $role=new role();
  4650. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4651. }
  4652. if (!empty($verifyStaff))
  4653. $endStaffArray=end($verifyStaff);
  4654. $KOP=false;
  4655. foreach ($roleArrayCopy as $P=>$A){
  4656. foreach ( $A as $MKI=>$AVL){
  4657. if (!empty($verifyStaff)){
  4658. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4659. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4660. $button=4;
  4661. $roleArrayCopy[$P][$MKI]['status']=4;
  4662. }
  4663. foreach ($verifyStaff as $m=>$u){
  4664. $AVLFK=$AVL[0].'_R';
  4665. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4666. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4667. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4668. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4669. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4670. break;
  4671. }
  4672. }
  4673. }else{
  4674. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4675. $button=4;
  4676. $roleArrayCopy[$P][$MKI]['status']=4;
  4677. }
  4678. }
  4679. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4680. $KOP=true;
  4681. }
  4682. }
  4683. foreach ($roleArrayCopy as $k=>$v){
  4684. foreach ($verifyList as $m=>$n){
  4685. if ($n[0]==$k){
  4686. array_splice($verifyList,$m,1,$v);
  4687. }
  4688. }
  4689. }
  4690. $receiptList[$key]['verifyList']=$verifyList;
  4691. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4692. $receiptList[$key]['button']=$button;
  4693. }
  4694. $mothHtml="";
  4695. for($i=1;$i<=12;$i++){
  4696. if($month==$i)
  4697. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4698. else
  4699. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4700. }
  4701. //获取审批日志
  4702. Doo::loadModel('receiptLog');
  4703. $receiptLog=new receiptLog();
  4704. $rlList=array();
  4705. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4706. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4707. if (!empty($rlInfo)){
  4708. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4709. }
  4710. $receiptList[0]['rlList']=$rlList;
  4711. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4712. $enclosurHtml='';
  4713. foreach ($enclosurList as $value){
  4714. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4715. }
  4716. $data['enclosurHtml']=$enclosurHtml;
  4717. $data['rolename']=$rolename['name'];
  4718. $data['datetij']=$tijdate['date'];
  4719. $data['mothHtml']=$mothHtml;
  4720. $data['receiptList']=$receiptList;
  4721. $data['receiptApprovalCount']=count($receiptList);
  4722. $data['year']=$year;
  4723. $data['categoryList']=$categoryList;
  4724. $data['staffList']=$staffList;
  4725. $data['cid']=$cid;
  4726. $data['sid']=$sid;
  4727. $data['status']=0;
  4728. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4729. $ap=4;
  4730. }else
  4731. $data['status']=$receiptList[0]['status'];
  4732. if ($receiptList[0]['status']==4){
  4733. $data['status']=5;
  4734. $ap=0;
  4735. }
  4736. $data['ap']=$ap;
  4737. $data['memu']="receipt";
  4738. $data['staff']=$this->staff;
  4739. $data['receiptMemu']='approval';
  4740. $data['verifyId']=$this->verifyId;
  4741. $data['executeId']=$this->executeId;
  4742. $this->render ( "/admin/saeaReportListReport", $data );
  4743. }
  4744. function approvalEdi(){
  4745. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4746. $status=isset($this->params['status'])?$this->params['status']:'';
  4747. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4748. $month=$this->get_args('month')?$this->get_args('month'):"";
  4749. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4750. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4751. if (empty($status))
  4752. $status=$this->get_args('status')?$this->get_args('status'):2;
  4753. $vidList=array();
  4754. $button=0;
  4755. Doo::loadModel('verify');
  4756. Doo::loadModel('receipt');
  4757. Doo::loadModel('staff');
  4758. $staff=new staff();
  4759. $receipt=new receipt();
  4760. $verify=new verify();
  4761. Doo::loadModel('L_category');
  4762. $Lcategory=new L_category();
  4763. Doo::loadModel('enclosur');
  4764. $enclosur=new enclosur();
  4765. //user verify ID
  4766. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4767. foreach ($verifyDetail as $key=>$value){
  4768. array_push($vidList, $value['vid']);
  4769. }
  4770. $vid=implode(",", $vidList);
  4771. if(empty($verifyDetail))
  4772. $vid=0;
  4773. $categoryList=$Lcategory->find(array('asArray'=>true));
  4774. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4775. $ap="";
  4776. if($status==4){
  4777. $ap=4;$status=2;
  4778. }
  4779. //get Receipt By verifyID status 2
  4780. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4781. $Locate=0;$roleId=0;
  4782. if($ap==4)
  4783. $status=4;
  4784. foreach ($receiptList as $key=>$value){
  4785. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4786. $receiptList[$key]['reviseDetail']=array();
  4787. if (!empty($value['reviseDetail']))
  4788. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4789. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4790. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4791. $receiptList[$key]['category']=$categoryDetil['title'];
  4792. //检测编辑状态
  4793. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4794. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4795. $verifyStaff=json_decode($value['verifyStaff'],true);
  4796. // print_r($verifyList);
  4797. //
  4798. // if (empty($verifyStaff)){
  4799. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4800. // $verifyList[0]['status']=4;$button=4;
  4801. // }
  4802. //
  4803. // }else{
  4804. //
  4805. // }
  4806. // die;
  4807. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4808. // echo array_search("green",$a);
  4809. //
  4810. Doo::loadModel('role');
  4811. $role=new role();
  4812. //print_r($verifyList);
  4813. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4814. foreach ($verifyList as $k=>$v){
  4815. //init verifyStaff
  4816. if ($v[1]=='ROLE'){
  4817. if (!empty($verifyStaff)){
  4818. $endStaffArray=end($verifyStaff);
  4819. if ($v[0]==$endStaffArray['nextStaff']){
  4820. $roleId=$v[0];
  4821. }
  4822. }
  4823. $roleVerify=json_decode($v[3],true);
  4824. $roleKey=$k;$roleArray=array();
  4825. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4826. foreach ($roleVerify as $o=>$p){
  4827. $staffID=explode ('_',$p);
  4828. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4829. //print_r($staffID);
  4830. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4831. array_push($roleArray, $exp);
  4832. }
  4833. $roleArrayCopy[$v[0]]=$roleArray;
  4834. //$verifyList[$k]['roleArray']=$roleArray;
  4835. }
  4836. //print_r($roleArray);
  4837. $verifyList[$k]['date']="";
  4838. $verifyList[$k]['opinion']="";
  4839. $verifyList[$k]['status']="";
  4840. if (empty($verifyStaff)){
  4841. $verifyList[$k]['date']="";
  4842. $verifyList[$k]['opinion']="";
  4843. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4844. $verifyList[$k]['status']=4;
  4845. $button=4;$flag=false;
  4846. }
  4847. }else{
  4848. foreach ($verifyStaff as $m=>$u){
  4849. if ($v[0]==$m){
  4850. $verifyList[$k]['date']=$u['date'];
  4851. $verifyList[$k]['opinion']=$u['opinion'];
  4852. $verifyList[$k]['status']=$u['status'];
  4853. $flag=false;
  4854. break;
  4855. }
  4856. }
  4857. $endStaffArray=end($verifyStaff);
  4858. if (isset($endStaffArray['ROLE'])){
  4859. }else{
  4860. $endKey=key($verifyStaff);
  4861. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4862. $button=4;
  4863. $verifyList[$k]['status']=4;
  4864. }
  4865. }
  4866. //print_r($endStaffArray);die;
  4867. // if (empty($verifyStaff)){
  4868. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4869. // $verifyList[$k]['status']=4;$button=4;
  4870. // }
  4871. //
  4872. // }else{
  4873. //
  4874. // }
  4875. // if($flag){//检测可编辑
  4876. // if($v[0]==$this->staff[0]['sid']){
  4877. // $verifyList[$k]['status']=4;$button=4;
  4878. // }
  4879. // }
  4880. }
  4881. }
  4882. $rolename['name']='';
  4883. if (!empty($roleId)){
  4884. Doo::loadModel('role');
  4885. $role=new role();
  4886. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4887. }
  4888. if (!empty($verifyStaff))
  4889. $endStaffArray=end($verifyStaff);
  4890. $KOP=false;
  4891. foreach ($roleArrayCopy as $P=>$A){
  4892. foreach ( $A as $MKI=>$AVL){
  4893. if (!empty($verifyStaff)){
  4894. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4895. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4896. $button=4;
  4897. $roleArrayCopy[$P][$MKI]['status']=4;
  4898. }
  4899. foreach ($verifyStaff as $m=>$u){
  4900. $AVLFK=$AVL[0].'_R';
  4901. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4902. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4903. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4904. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4905. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4906. break;
  4907. }
  4908. }
  4909. }else{
  4910. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4911. $button=4;
  4912. $roleArrayCopy[$P][$MKI]['status']=4;
  4913. }
  4914. }
  4915. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4916. $KOP=true;
  4917. }
  4918. }
  4919. // print_r($roleArrayCopy);
  4920. // echo $roleKey;
  4921. foreach ($roleArrayCopy as $k=>$v){
  4922. foreach ($verifyList as $m=>$n){
  4923. if ($n[0]==$k){
  4924. array_splice($verifyList,$m,1,$v);
  4925. }
  4926. }
  4927. }
  4928. // if ($KOP)
  4929. // array_splice($verifyList,$roleKey,1,$roleArray);
  4930. //print_r($verifyList);
  4931. $receiptList[$key]['verifyList']=$verifyList;
  4932. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4933. $receiptList[$key]['button']=$button;
  4934. }
  4935. //$data['verifyDetail']=$verifyDetail;
  4936. $mothHtml="";
  4937. for($i=1;$i<=12;$i++){
  4938. if($month==$i)
  4939. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4940. else
  4941. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4942. }
  4943. //获取审批日志
  4944. Doo::loadModel('receiptLog');
  4945. $receiptLog=new receiptLog();
  4946. $rlList=array();
  4947. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4948. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4949. if (!empty($rlInfo)){
  4950. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4951. }
  4952. $receiptList[0]['rlList']=$rlList;
  4953. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4954. $enclosurHtml='';
  4955. foreach ($enclosurList as $value){
  4956. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4957. }
  4958. $data['enclosurHtml']=$enclosurHtml;
  4959. $data['rolename']=$rolename['name'];
  4960. $data['datetij']=$tijdate['date'];
  4961. $data['mothHtml']=$mothHtml;
  4962. $data['receiptList']=$receiptList;
  4963. $data['receiptApprovalCount']=count($receiptList);
  4964. $data['status']=$status;
  4965. $data['year']=$year;
  4966. $data['categoryList']=$categoryList;
  4967. $data['staffList']=$staffList;
  4968. $data['cid']=$cid;
  4969. $data['sid']=$sid;
  4970. $data['ap']=$ap;
  4971. $data['memu']="receipt";
  4972. $data['staff']=$this->staff;
  4973. $data['receiptMemu']='approval';
  4974. $data['verifyId']=$this->verifyId;
  4975. $data['executeId']=$this->executeId;
  4976. $this->render ( "/admin/saeaReportListReport", $data );
  4977. }
  4978. function remittance(){
  4979. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4980. $month=$this->get_args('month')?$this->get_args('month'):"";
  4981. Doo::loadModel('receipt');
  4982. $receipt=new receipt();
  4983. Doo::loadModel('staff');
  4984. $staff=new staff();
  4985. $dateCondition=" and Year(pastDate) =".$year;
  4986. if(!empty($month))
  4987. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4988. //get Receipt By verifyID status 1
  4989. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4990. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4991. $dataList=array();
  4992. foreach ($dateList as $d=>$a){
  4993. $dataList[$a['pastDate']]=array();$daySum=0;
  4994. foreach ($receiptList as $key=>$value){
  4995. if($a['pastDate']==$value['pastDate']){
  4996. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4997. $list=array();$html="";
  4998. foreach ($oderList as $v){
  4999. array_push($list, $v['receiptOrder']);
  5000. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  5001. }
  5002. $receiptList[$key]['receiptOrder']=$html;
  5003. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  5004. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  5005. $receiptList[$key]['username']=$sinfo['username'];
  5006. $daySum+=$value['sum'];
  5007. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  5008. }
  5009. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  5010. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  5011. }
  5012. }
  5013. //print_r($dataList);
  5014. $data['dataList']=$dataList;
  5015. $mothHtml="";
  5016. for($i=1;$i<=12;$i++){
  5017. if($month==$i)
  5018. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  5019. else
  5020. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  5021. }
  5022. $data['year']=$year;
  5023. $data['mothHtml']=$mothHtml;
  5024. $data['memu']="receipt";
  5025. $data['staff']=$this->staff;
  5026. $data['receiptMemu']='approval';
  5027. $data['verifyId']=$this->verifyId;
  5028. $data['executeId']=$this->executeId;
  5029. $this->render ( "/admin/saeaReportListPay", $data );
  5030. }
  5031. function revocationAdjustment(){
  5032. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  5033. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  5034. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5035. //echo $price;die;
  5036. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  5037. Doo::loadModel('receipt');
  5038. $receipt=new receipt();
  5039. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5040. if (empty($receiptDetail['reviseDetail']))
  5041. return "/approval";
  5042. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5043. $RD=array();
  5044. foreach ($reviseDetail as $key=>$value){
  5045. if ($value['price']==$price&&$value['sid']==$sid)
  5046. continue;
  5047. array_push($RD, $value);
  5048. }
  5049. $reviseDetailString=json_encode($RD);
  5050. $receipt->reviseDetail=$reviseDetailString;
  5051. $receipt->sum=$receiptDetail['sum']-$price;
  5052. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  5053. $receipt->update(array('where'=>'rid='.$rid));
  5054. }
  5055. //approvalEdi/37
  5056. return "/approvalEdi/".$rid;
  5057. }
  5058. function updateApprovalReceipt(){
  5059. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5060. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  5061. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5062. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  5063. if(!empty($rid)){
  5064. Doo::loadModel("verify");
  5065. $verify=new verify();
  5066. Doo::loadModel("receiptDetail");
  5067. $receiptDetailObj=new receiptDetail();
  5068. Doo::loadModel("itemStatistics");
  5069. Doo::loadModel("statistics");
  5070. $statistics=new statistics();
  5071. $itemStatistics=new itemStatistics();
  5072. Doo::loadModel("receipt");
  5073. $receipt=new receipt();
  5074. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5075. if (empty($receiptDetail))
  5076. return "/approval";
  5077. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  5078. $verifyString=$verifyDetail['staff'];
  5079. $verifyDetail=json_decode($verifyDetail['staff'],true);
  5080. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  5081. if(empty($opinion)){
  5082. if ($status==3)
  5083. $opinion="终止";
  5084. else
  5085. $opinion="同意支付";
  5086. }
  5087. $nowStaff=0;$nowStaffList=array();
  5088. if(empty($verifyStaff)){
  5089. //还需加入是否已经进入角色审批
  5090. if ($verifyDetail[0][1]=='ROLE'){
  5091. $vStaffString=json_decode($verifyDetail[0][3]);
  5092. foreach ($vStaffString as $key=>$value){
  5093. $staffK=explode("_", $value);
  5094. if ($staffK[0]!=$this->staff[0]['sid'])
  5095. array_push($nowStaffList, $staffK[0]);
  5096. }
  5097. //print_r($verifyDetail);
  5098. //die;
  5099. if (!empty($nowStaffList)){
  5100. $nowStaff=implode(',', $nowStaffList);
  5101. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5102. }else{
  5103. $nowStaff=$verifyDetail[1][0];
  5104. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5105. }
  5106. }else{
  5107. if ($verifyDetail[1][1]=='ROLE'){
  5108. $vStaffString=json_decode($verifyDetail[1][3]);
  5109. //echo "dd";
  5110. foreach ($vStaffString as $key=>$value){
  5111. $staffK=explode("_", $value);
  5112. array_push($nowStaffList, $staffK[0]);
  5113. }
  5114. $nowStaff=implode(',', $nowStaffList);
  5115. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5116. }else{
  5117. $nowStaff=$verifyDetail[1][0];
  5118. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5119. }
  5120. }
  5121. if($status==3)
  5122. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5123. $vStaffString=json_encode($verifyStaff);
  5124. $receipt->nowStaff=$nowStaff;
  5125. $receipt->verifyStaff=$vStaffString;
  5126. }else{
  5127. $VS=end($verifyStaff);
  5128. //非角色审批
  5129. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5130. $nextStaff=0;$roleSTF=false;
  5131. foreach ($verifyDetail as $key=>$value){
  5132. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5133. if (isset($verifyDetail[$key+1])){
  5134. $nextStaff=$verifyDetail[$key+1][0];
  5135. if ($verifyDetail[$key+1][1]=='ROLE')
  5136. $roleSTF=true;
  5137. }
  5138. break;
  5139. }
  5140. }
  5141. if (!$roleSTF){
  5142. $nowStaff=$nextStaff;
  5143. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5144. }else{
  5145. //获取角色下的所有用户ID
  5146. $nowStaffList=array();
  5147. foreach ($verifyDetail as $vfk){
  5148. if ($vfk[1]=='ROLE'){
  5149. $vStaffString=json_decode($vfk[3]);
  5150. foreach ($vStaffString as $key=>$value){
  5151. $staffK=explode("_", $value);
  5152. array_push($nowStaffList, $staffK[0]);
  5153. }
  5154. }
  5155. }
  5156. $nowStaff=implode(',', $nowStaffList);
  5157. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5158. }
  5159. if($status==3){
  5160. $verifyStaff['final']=$status;
  5161. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5162. }
  5163. $vStaffString=json_encode($verifyStaff);
  5164. $receipt->nowStaff=$nowStaff;
  5165. $receipt->verifyStaff=$vStaffString;
  5166. }
  5167. //角色审批
  5168. if (isset($VS['ROLE'])){
  5169. //找出角色人 当前审批角色组
  5170. $verifyJSStaff=array();$nowStaffList2=array();
  5171. foreach ($verifyDetail as $key=>$value){
  5172. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5173. $verifyJSStaff=json_decode($value[3]);
  5174. foreach ($verifyJSStaff as $m){
  5175. $staffK=explode("_", $m);
  5176. array_push($nowStaffList2, $staffK[0]);
  5177. }
  5178. // print_r($nowStaffList2);
  5179. }
  5180. }
  5181. $RoleVerifyStaff=array();
  5182. foreach ($verifyStaff as $key=>$value){
  5183. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5184. foreach ($nowStaffList2 as $m) {
  5185. if ($key==$m."_R")
  5186. $RoleVerifyStaff[$key]=$value;
  5187. }
  5188. }
  5189. }
  5190. // print_r($verifyStaff);
  5191. // print_r($nowStaffList2);
  5192. // print_r($RoleVerifyStaff);
  5193. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5194. //print_r($verifyJSStaff);
  5195. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5196. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5197. //下一个审批人ID
  5198. $nextStaff=0;$falg=false;
  5199. foreach ($verifyDetail as $key=>$value){
  5200. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5201. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5202. $falg=true;
  5203. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5204. foreach ($vStaffString as $v){
  5205. $staffK=explode("_", $v);
  5206. array_push($nowStaffList, $staffK[0]);
  5207. }
  5208. $nowStaff=implode(',', $nowStaffList);
  5209. $nextStaff=$verifyDetail[$key+1][0];
  5210. }elseif(isset($verifyDetail[$key+1])){
  5211. $nextStaff=$verifyDetail[$key+1][0];
  5212. $nowStaff=$nextStaff;
  5213. }else
  5214. $nowStaff='';
  5215. break;
  5216. }
  5217. }
  5218. if ($falg)
  5219. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5220. else
  5221. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5222. // print_r($verifyStaff);
  5223. // echo $nowStaff;die;
  5224. }else{ //进入下一个角色或者审批人
  5225. /*
  5226. */
  5227. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5228. //
  5229. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5230. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5231. // print_r($verifyStaff);
  5232. // die;
  5233. }
  5234. if($status==3){
  5235. $verifyStaff['final']=$status;
  5236. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5237. }
  5238. $vStaffString=json_encode($verifyStaff);
  5239. $receipt->verifyStaff=$vStaffString;
  5240. $receipt->nowStaff=$nowStaff;
  5241. //die;
  5242. //}
  5243. // print_r($verifyStaff);
  5244. // die;
  5245. }
  5246. //print_r($verifyStaff);die;
  5247. }
  5248. //print_r($verifyDetail);
  5249. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5250. foreach ($verifyDetail as $k=>$v){
  5251. if ($v[1]=='ROLE'){
  5252. $roleId=$v[0];
  5253. $roleVerify=json_decode($v[3],true);
  5254. $roleKey=$k;$roleArray=array();
  5255. foreach ($roleVerify as $o=>$p){
  5256. $staffID=explode ('_',$p);
  5257. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5258. array_push($roleArray, $exp);
  5259. }
  5260. $verifyDetailCopy[$v[0]]=$roleArray;
  5261. }
  5262. }
  5263. //print_r($verifyDetail);
  5264. foreach ($verifyDetailCopy as $k=>$v){
  5265. foreach ($verifyDetail as $m=>$n){
  5266. if ($n[0]==$k){
  5267. array_splice($verifyDetail,$m,1,$v);
  5268. }
  5269. }
  5270. }
  5271. // die;
  5272. // if (!empty($roleArray))
  5273. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5274. // echo $roleId;
  5275. // print_r($verifyStaff);
  5276. // print_r($verifyDetail);
  5277. // die;
  5278. Doo::loadModel("receiptLog");
  5279. $receiptLog=new receiptLog();
  5280. //审批日志
  5281. if (!isset($verifyStaff['final'])){
  5282. if (!empty($roleId)){
  5283. Doo::loadModel("role");
  5284. $role=new role();
  5285. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5286. $receiptLog->rolename=$roleInfo['name'];
  5287. }
  5288. $receiptLog->username=$this->staff[0]['username'];
  5289. $receiptLog->uid=$this->staff[0]['sid'];
  5290. $receiptLog->date=date("Y-m-d");
  5291. $receiptLog->opinion=$opinion;
  5292. $receiptLog->img=$this->staff[0]['avatar'];
  5293. $receiptLog->status=1;
  5294. $receiptLog->rid=$rid;
  5295. $receiptLog->insert();
  5296. }
  5297. if (isset($verifyStaff['final'])){//rDetail
  5298. $receipt->verifyBreakup=$verifyString;
  5299. $receipt->status=3;
  5300. $receiptDetailObj->status=3;
  5301. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5302. if (!empty($roleId)){
  5303. Doo::loadModel("role");
  5304. $role=new role();
  5305. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5306. $receiptLog->rolename=$roleInfo['name'];
  5307. }
  5308. $receiptLog->username=$this->staff[0]['username'];
  5309. $receiptLog->uid=$this->staff[0]['sid'];
  5310. $receiptLog->date=date("Y-m-d");
  5311. $receiptLog->opinion=$opinion;
  5312. $receiptLog->img=$this->staff[0]['avatar'];
  5313. $receiptLog->status=3;
  5314. $receiptLog->rid=$rid;
  5315. $receiptLog->insert();
  5316. //微信企业号通知
  5317. $this->setWXMsg($rid,3);
  5318. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5319. $receipt->status=1;$reviseSum=0;
  5320. $receipt->verifyBreakup=$verifyString;
  5321. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5322. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5323. foreach ($reviseDetail as $key=>$value){
  5324. $receiptDetailObj=new receiptDetail();
  5325. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5326. $receiptDetailObj->item=$value['description'];
  5327. $receiptDetailObj->itemCategory="报销金额调整";
  5328. $receiptDetailObj->price=$value['price'];
  5329. $receiptDetailObj->date=$receiptDetail['date'];
  5330. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5331. $receiptDetailObj->rid=$rid;
  5332. $receiptDetailObj->status=1;
  5333. $receiptDetailObj->insert();
  5334. $reviseSum+=$value['price'];
  5335. }
  5336. $itemStatistics=new itemStatistics();
  5337. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5338. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5339. $itemStatistics->price=$reviseSum;
  5340. $itemStatistics->itemCategory="报销金额调整";
  5341. $itemStatistics->date=$receiptDetail['date'];
  5342. $itemStatistics->insert();
  5343. }
  5344. $receiptDetailObj=new receiptDetail();
  5345. $receiptDetailObj->status=1;
  5346. $receiptDetailObj->pastDate=date("Y-m-d");
  5347. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5348. $dateArray=explode("-", $receiptDetail['date']);
  5349. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5350. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5351. if(empty($stat)){
  5352. $statistics->date=$receiptDetail['date'];
  5353. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5354. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5355. $statistics->agPrice=$receiptDetail['sum'];
  5356. $statistics->rePrice=$reviseSum;
  5357. $statistics->insert();
  5358. }else{
  5359. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5360. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5361. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5362. }
  5363. $dateArray=explode("-", $receiptDetail['date']);
  5364. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5365. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5366. foreach ($accountItem['cSum'] as $key=>$value){
  5367. if($key=="agencySum"){
  5368. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5369. if(empty($iStatistics)){
  5370. $itemStatistics->cid=$receiptDetail['cid'];;
  5371. $itemStatistics->staff=$receiptDetail['staff'];
  5372. $itemStatistics->price=$value;
  5373. $itemStatistics->itemCategory=$this->AGENCY;
  5374. $itemStatistics->date=$receiptDetail['date'];
  5375. $itemStatistics->insert();
  5376. }else{
  5377. if (!empty($value)){
  5378. $itemStatistics->price=$value+$iStatistics['price'];
  5379. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5380. }
  5381. }
  5382. }elseif($key=="travelSum"){
  5383. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5384. if(empty($iStatistics)){
  5385. $itemStatistics->cid=$receiptDetail['cid'];
  5386. $itemStatistics->staff=$receiptDetail['staff'];
  5387. $itemStatistics->price=$value;
  5388. $itemStatistics->itemCategory=$this->TRAVEL;
  5389. $itemStatistics->date=$receiptDetail['date'];
  5390. $itemStatistics->insert();
  5391. }else{
  5392. if (!empty($value)){
  5393. $itemStatistics->price=$value+$iStatistics['price'];
  5394. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5395. }
  5396. }
  5397. }elseif($key=="trainSum"){
  5398. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5399. if(empty($iStatistics)){
  5400. $itemStatistics->cid=$receiptDetail['cid'];
  5401. $itemStatistics->staff=$receiptDetail['staff'];
  5402. $itemStatistics->price=$value;
  5403. $itemStatistics->itemCategory=$this->TRAIN;
  5404. $itemStatistics->date=$receiptDetail['date'];
  5405. $itemStatistics->insert();
  5406. }else{
  5407. if (!empty($value)){
  5408. $itemStatistics->price=$value+$iStatistics['price'];
  5409. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5410. }
  5411. }
  5412. }elseif($key=="otherSum"){
  5413. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5414. if(empty($iStatistics)){
  5415. $itemStatistics->cid=$receiptDetail['cid'];
  5416. $itemStatistics->staff=$receiptDetail['staff'];
  5417. $itemStatistics->price=$value;
  5418. $itemStatistics->itemCategory=$this->OTHER;
  5419. $itemStatistics->date=$receiptDetail['date'];
  5420. $itemStatistics->insert();
  5421. }else{
  5422. if (!empty($value)){
  5423. $itemStatistics->price=$value+$iStatistics['price'];
  5424. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5425. }
  5426. }
  5427. }
  5428. }
  5429. $receipt->pastDate=date("Y-m-d");
  5430. //微信企业号通知
  5431. $this->setWXMsg($rid,1);
  5432. }
  5433. $receipt->update(array('where'=>' rid = '.$rid));
  5434. return "/approvalExpenses/2";
  5435. }
  5436. }
  5437. function expensesRetreats(){
  5438. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5439. if (!empty($rid)){
  5440. //操作记录
  5441. Doo::loadModel("receipt");
  5442. $receipt=new receipt();
  5443. Doo::loadModel("receiptLog");
  5444. $receiptLog=new receiptLog();
  5445. Doo::loadModel("verify");
  5446. $verify=new verify();
  5447. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5448. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5449. $jd=json_decode($vr['staff']);$roleId=0;
  5450. foreach ($jd as $key=>$value){
  5451. if ($value[1]=='ROLE'){
  5452. $pos = strpos($value[3], $this->staff[0]['sid']);
  5453. if ($pos !== false) {
  5454. $roleId=$value[0];
  5455. }
  5456. }
  5457. }
  5458. //审批日志
  5459. //echo $roleId;die;
  5460. if (!empty($roleId)){
  5461. Doo::loadModel("role");
  5462. $role=new role();
  5463. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5464. $receiptLog->rolename=$roleInfo['name'];
  5465. }
  5466. $receiptLog->username=$this->staff[0]['username'];
  5467. $receiptLog->uid=$this->staff[0]['sid'];
  5468. $receiptLog->date=date("Y-m-d");
  5469. $receiptLog->opinion='撤回';
  5470. $receiptLog->img=$this->staff[0]['avatar'];
  5471. $receiptLog->status=4;
  5472. $receiptLog->rid=$rid;
  5473. $receiptLog->insert();
  5474. $receipt->status=4;
  5475. $receipt->update(array('where'=>'rid='.$rid));
  5476. //微信企业号通知
  5477. $this->setWXMsg($rid,2);
  5478. }
  5479. //echo "ddd";
  5480. return '/approvalExpenses';
  5481. }
  5482. function updateCheReceipt(){
  5483. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5484. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5485. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5486. if (!empty($rid)){
  5487. //操作记录
  5488. Doo::loadModel("receipt");
  5489. $receipt=new receipt();
  5490. Doo::loadModel("receiptLog");
  5491. $receiptLog=new receiptLog();
  5492. Doo::loadModel("verify");
  5493. $verify=new verify();
  5494. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5495. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5496. $jd=json_decode($vr['staff']);$roleId=0;
  5497. foreach ($jd as $key=>$value){
  5498. if ($value[1]=='ROLE'){
  5499. $pos = strpos($value[3], $this->staff[0]['sid']);
  5500. if ($pos !== false) {
  5501. $roleId=$value[0];
  5502. }
  5503. }
  5504. }
  5505. //审批日志
  5506. //echo $roleId;die;
  5507. if (!empty($roleId)){
  5508. Doo::loadModel("role");
  5509. $role=new role();
  5510. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5511. $receiptLog->rolename=$roleInfo['name'];
  5512. }
  5513. $receiptLog->username=$this->staff[0]['username'];
  5514. $receiptLog->uid=$this->staff[0]['sid'];
  5515. $receiptLog->date=date("Y-m-d");
  5516. $receiptLog->opinion=$opinion;
  5517. $receiptLog->img=$this->staff[0]['avatar'];
  5518. $receiptLog->status=4;
  5519. $receiptLog->rid=$rid;
  5520. $receiptLog->insert();
  5521. $receipt->status=4;
  5522. $receipt->update(array('where'=>'rid='.$rid));
  5523. //微信企业号通知
  5524. $this->setWXMsg($rid,2);
  5525. echo json_encode ( array (
  5526. 'status' => 1
  5527. ) );die;
  5528. }
  5529. echo json_encode ( array (
  5530. 'status' => 2
  5531. ) );die;
  5532. //echo "ddd";
  5533. //return '/saeaBorad';
  5534. }
  5535. function revisePrice(){
  5536. $description=$this->get_args('description')?$this->get_args('description'):"";
  5537. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5538. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5539. //echo $price;die;
  5540. if (!empty($rid)){
  5541. Doo::loadModel("receipt");
  5542. $receipt=new receipt();
  5543. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5544. if (empty($receiptDetail))
  5545. return "/approval";
  5546. $reviseDetail=array();
  5547. if (empty($receiptDetail['reviseDetail'])){
  5548. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5549. $reviseDetailString=json_encode($reviseDetail);
  5550. $receipt->reviseDetail=$reviseDetailString;
  5551. $receipt->revisePrice=$price;
  5552. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5553. }else{
  5554. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5555. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5556. $reviseDetailString=json_encode($reviseDetail);
  5557. $receipt->reviseDetail=$reviseDetailString;
  5558. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5559. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5560. }
  5561. $receipt->update(array('where'=>'rid='.$rid));
  5562. }
  5563. return '/approvalEdi/'.$rid;
  5564. }
  5565. function personalCollect(){
  5566. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5567. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5568. $this->showCache($path);
  5569. Doo::loadModel("receiptDetail");
  5570. Doo::loadModel("itemStatistics");
  5571. Doo::loadModel('statistics');
  5572. $statistics=new statistics();
  5573. $itemStatistics=new itemStatistics();
  5574. $receiptDetail=new receiptDetail();
  5575. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5576. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5577. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5578. //create collect html
  5579. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5580. $adjustment=array();
  5581. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5582. array_push($collectArray['日常相关费用'], $collectHtml);
  5583. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5584. array_push($collectArray['差旅相关费用'], $collectHtml);
  5585. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5586. array_push($collectArray['培训班费用'], $collectHtml);
  5587. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5588. array_push($collectArray['其他'], $collectHtml);
  5589. $data['collectArray']=$collectArray;
  5590. //statistics html
  5591. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5592. if(empty($stList))
  5593. $stList=array('rePrice'=>0,'agPrice'=>0);
  5594. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5595. //Adjustment price html
  5596. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5597. array_push($adjustment, $collectHtml);
  5598. $data['adjustment']=$adjustment;
  5599. //total price html
  5600. $collectHtml="";$total=0;
  5601. for ($i=1;$i<=12;$i++){
  5602. $sumPrice=0;
  5603. foreach ($receiptCollectList as $key=>$value){
  5604. if($value['month']==$i){
  5605. $sumPrice+=$value['price'];
  5606. }
  5607. }
  5608. if ($sumPrice==0)
  5609. $collectHtml.='<td class="taR">-</td>';
  5610. else
  5611. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5612. $total+=$sumPrice;
  5613. }
  5614. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5615. $data['totalPrice']=$collectHtml;
  5616. $data['year']=$year;
  5617. $data['totalYear']=$total;
  5618. $data['memu']="receipt";
  5619. $data['staff']=$this->staff;
  5620. $data['receiptMemu']='personalCollect';
  5621. $data['verifyId']=$this->verifyId;
  5622. $data['executeId']=$this->executeId;
  5623. //year staff status 2,4
  5624. if($year<date("Y")){
  5625. Doo::loadModel('receipt');
  5626. $receipt=new receipt();
  5627. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5628. if(empty($receiptList)){
  5629. ob_start();
  5630. $this->render ( "/admin/saea_slist_collect", $data );
  5631. $this->cacheFile($path);die;
  5632. }
  5633. }
  5634. $this->render ( "/admin/saea_slist_collect", $data );
  5635. }
  5636. function personalCollectDetail(){
  5637. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5638. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5639. $this->showCache($path);
  5640. Doo::loadModel("receiptDetail");
  5641. Doo::loadModel("itemStatistics");
  5642. Doo::loadModel('statistics');
  5643. Doo::loadModel('accountItem');
  5644. $accountItem=new accountItem();
  5645. $statistics=new statistics();
  5646. $itemStatistics=new itemStatistics();
  5647. $receiptDetail=new receiptDetail();
  5648. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5649. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5650. $accountList=$accountItem->find(array('asArray'=>true));
  5651. //create CollectDetail HTML
  5652. $collectHtml=array();
  5653. foreach ($accountList as $key=>$value){
  5654. $html="";$asum=0;
  5655. for ($i=1;$i<=12;$i++){
  5656. $falg=true;
  5657. foreach ($receiptCollectList as $v) {
  5658. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5659. $asum+=$v['price'];
  5660. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5661. }
  5662. }
  5663. if($falg)
  5664. $html.='<td class="taR">-</td>';
  5665. }
  5666. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5667. $collectHtml[$value['category']][$value['name']]=$html;
  5668. }
  5669. $data['collectHtml']=$collectHtml;
  5670. //create Adjustment price html
  5671. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5672. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5673. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5674. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5675. array_push($collectArray['日常相关费用'], $collectHtml);
  5676. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5677. array_push($collectArray['差旅相关费用'], $collectHtml);
  5678. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5679. array_push($collectArray['培训班费用'], $collectHtml);
  5680. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5681. array_push($collectArray['其他'], $collectHtml);
  5682. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5683. array_push($adjustment, $collectHtml);
  5684. //total price html
  5685. $collectHtml="";$total=0;
  5686. for ($i=1;$i<=12;$i++){
  5687. $sumPrice=0;
  5688. foreach ($receiptCollectList as $key=>$value){
  5689. if($value['month']==$i){
  5690. $sumPrice+=$value['price'];
  5691. }
  5692. }
  5693. if ($sumPrice==0)
  5694. $collectHtml.='<td class="taR">-</td>';
  5695. else
  5696. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5697. $total+=$sumPrice;
  5698. }
  5699. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5700. //statistics html
  5701. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5702. if(empty($stList))
  5703. $stList=array('rePrice'=>0,'agPrice'=>0);
  5704. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5705. $data['collectArray']=$collectArray;
  5706. $data['adjustment']=$adjustment;
  5707. $data['totalPrice']=$collectHtml;
  5708. $data['totalYear']=$total;
  5709. $data['year']=$year;
  5710. $data['memu']="receipt";
  5711. $data['staff']=$this->staff;
  5712. $data['receiptMemu']='personalCollect';
  5713. $data['verifyId']=$this->verifyId;
  5714. $data['executeId']=$this->executeId;
  5715. //year staff status 2,4
  5716. if($year<date("Y")){
  5717. Doo::loadModel('receipt');
  5718. $receipt=new receipt();
  5719. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5720. if(empty($receiptList)){
  5721. ob_start();
  5722. $this->render ( "/admin/saeaCollectArticles", $data );
  5723. $this->cacheFile($path);die;
  5724. }
  5725. }
  5726. $this->render ( "/admin/saeaCollectArticles", $data );
  5727. }
  5728. function companyCategoryCollect(){
  5729. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5730. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5731. $this->showCache($path);
  5732. Doo::loadModel('L_category');
  5733. Doo::loadModel('itemStatistics');
  5734. Doo::loadModel('statistics');
  5735. $statistics=new statistics();
  5736. $Lcategory=new L_category();
  5737. $itemStatistics=new itemStatistics();
  5738. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5739. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5740. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5741. //ceatre companyCollectHtml
  5742. foreach ($LcategoryList as $value){
  5743. $html="";$asum=0;
  5744. for ($i=1;$i<=12;$i++){
  5745. $falg=true;
  5746. foreach ($itemStatisticsList as $v){
  5747. if($value['cid']==$v['cid']&&$i==$v['month']){
  5748. $asum+=$v['price'];
  5749. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5750. }
  5751. }
  5752. if($falg)
  5753. $html.='<td class="taR">-</td>';
  5754. }
  5755. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5756. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5757. }
  5758. $data['companyHtml']=$collectHtml;
  5759. //total price html
  5760. $collectHtml="";$total=0;
  5761. for ($i=1;$i<=12;$i++){
  5762. $sumPrice=0;
  5763. foreach ($itemStatisticsList as $key=>$value){
  5764. if($value['month']==$i){
  5765. $sumPrice+=$value['price'];
  5766. }
  5767. }
  5768. if ($sumPrice==0)
  5769. $collectHtml.='<td class="taR">-</td>';
  5770. else
  5771. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5772. $total+=$sumPrice;
  5773. }
  5774. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5775. $data['companyTotalHtml']=$collectHtml;
  5776. $data['total']=$total;
  5777. //statistics html
  5778. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5779. if(empty($stList))
  5780. $stList=array('rePrice'=>0,'agPrice'=>0);
  5781. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5782. $data['year']=$year;
  5783. $data['memu']="receipt";
  5784. $data['staff']=$this->staff;
  5785. $data['receiptMemu']='companyCategoryCollect';
  5786. $data['verifyId']=$this->verifyId;
  5787. $data['executeId']=$this->executeId;
  5788. //year staff status 2,4
  5789. if($year<date("Y")){
  5790. Doo::loadModel('receipt');
  5791. $receipt=new receipt();
  5792. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5793. if(empty($receiptList)){
  5794. ob_start();
  5795. $this->render ( "/admin/saeaCompanyCollect", $data );
  5796. $this->cacheFile($path);die;
  5797. }
  5798. }
  5799. $this->render ( "/admin/saeaCompanyCollect", $data );
  5800. }
  5801. function categoryCollectDetail(){
  5802. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5803. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5804. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5805. $this->showCache($path);
  5806. Doo::loadModel('statistics');
  5807. $statistics=new statistics();
  5808. Doo::loadModel("receiptDetail");
  5809. $receiptDetail=new receiptDetail();
  5810. Doo::loadModel('L_category');
  5811. $Lcategory=new L_category();
  5812. Doo::loadModel('accountItem');
  5813. $accountItem=new accountItem();
  5814. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5815. if ($cid==0){
  5816. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5817. if ($cid==0)
  5818. $cid=$LcategoryList[0]['cid'];
  5819. }
  5820. $data['LcategoryList']=$LcategoryList;
  5821. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5822. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5823. $accountList=$accountItem->find(array('asArray'=>true));
  5824. //create CollectDetail HTML
  5825. $collectHtml=array();
  5826. foreach ($accountList as $key=>$value){
  5827. $html="";$asum=0;
  5828. for ($i=1;$i<=12;$i++){
  5829. $falg=true;
  5830. foreach ($receiptCollectList as $v) {
  5831. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5832. $asum+=$v['price'];
  5833. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5834. }
  5835. }
  5836. if($falg)
  5837. $html.='<td class="taR">-</td>';
  5838. }
  5839. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5840. $collectHtml[$value['category']][$value['name']]=$html;
  5841. }
  5842. $data['collectHtml']=$collectHtml;
  5843. //create Adjustment price html
  5844. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5845. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5846. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5847. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5848. array_push($collectArray['日常相关费用'], $collectHtml);
  5849. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5850. array_push($collectArray['差旅相关费用'], $collectHtml);
  5851. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5852. array_push($collectArray['培训班费用'], $collectHtml);
  5853. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5854. array_push($collectArray['其他'], $collectHtml);
  5855. $data['collectArray']=$collectArray;
  5856. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5857. array_push($adjustment, $collectHtml);
  5858. $data['adjustment']=$adjustment;
  5859. //total price html
  5860. $collectHtml="";$total=0;
  5861. for ($i=1;$i<=12;$i++){
  5862. $sumPrice=0;
  5863. foreach ($receiptCollectList as $key=>$value){
  5864. if($value['month']==$i){
  5865. $sumPrice+=$value['price'];
  5866. }
  5867. }
  5868. if ($sumPrice==0)
  5869. $collectHtml.='<td class="taR">-</td>';
  5870. else
  5871. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5872. $total+=$sumPrice;
  5873. }
  5874. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5875. //statistics html
  5876. $stList=$statistics->statisticsByCid($year,$cid);
  5877. if(empty($stList))
  5878. $stList=array('rePrice'=>0,'agPrice'=>0);
  5879. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5880. $data['totalYear']=$total;
  5881. $data['year']=$year;
  5882. $data['cid']=$cid;
  5883. $data['memu']="receipt";
  5884. $data['staff']=$this->staff;
  5885. $data['receiptMemu']='companyCategoryCollect';
  5886. $data['verifyId']=$this->verifyId;
  5887. $data['executeId']=$this->executeId;
  5888. //year staff status 2,4
  5889. if($year<date("Y")){
  5890. Doo::loadModel('receipt');
  5891. $receipt=new receipt();
  5892. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5893. if(empty($receiptList)){
  5894. ob_start();
  5895. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5896. $this->cacheFile($path);die;
  5897. }
  5898. }
  5899. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5900. }
  5901. function staffCollect(){
  5902. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5903. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5904. //$this->showCache($path);
  5905. Doo::loadModel('statistics');
  5906. $statistics=new statistics();
  5907. Doo::loadModel("receiptDetail");
  5908. $receiptDetail=new receiptDetail();
  5909. Doo::loadModel('L_category');
  5910. $Lcategory=new L_category();
  5911. Doo::loadModel('accountItem');
  5912. $accountItem=new accountItem();
  5913. Doo::loadModel('staff');
  5914. $staff=new staff();
  5915. Doo::loadModel('itemStatistics');
  5916. $itemStatistics=new itemStatistics();
  5917. /*
  5918. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5919. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5920. if(empty($stList))
  5921. $stList=array('rePrice'=>0,'agPrice'=>0);
  5922. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5923. */
  5924. //statistics html
  5925. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5926. if(empty($stList))
  5927. $stList=array('rePrice'=>0,'agPrice'=>0);
  5928. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5929. //---
  5930. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5931. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5932. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5933. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5934. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5935. //print_r($itemStatisticsList);die;
  5936. //ceatre companyCollectHtml
  5937. foreach ($categoryList as $vlu){
  5938. $count=$vlu['count']+1;
  5939. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5940. $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;
  5941. foreach ($staffList as $value){
  5942. if ($vlu['cid']==$value['cid']){
  5943. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5944. $asum=0;
  5945. for ($i=1;$i<=12;$i++){
  5946. $falg=true;
  5947. foreach ($itemStatisticsList as $v){
  5948. if($value['sid']==$v['staff']&&$i==$v['month']){
  5949. if ($v['month']==1)
  5950. $m1+=$v['price'];
  5951. if ($v['month']==2)
  5952. $m2+=$v['price'];
  5953. if ($v['month']==3)
  5954. $m3+=$v['price'];
  5955. if ($v['month']==4)
  5956. $m4+=$v['price'];
  5957. if ($v['month']==5)
  5958. $m5+=$v['price'];
  5959. if ($v['month']==6)
  5960. $m6+=$v['price'];
  5961. if ($v['month']==7)
  5962. $m7+=$v['price'];
  5963. if ($v['month']==8)
  5964. $m8+=$v['price'];
  5965. if ($v['month']==9)
  5966. $m9+=$v['price'];
  5967. if ($v['month']==10)
  5968. $m10+=$v['price'];
  5969. if ($v['month']==11)
  5970. $m11+=$v['price'];
  5971. if ($v['month']==12)
  5972. $m12+=$v['price'];
  5973. $asum+=$v['price'];
  5974. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5975. }
  5976. }
  5977. if($falg)
  5978. $html.='<td class="taR">-</td>';
  5979. }
  5980. $m13+=$asum;
  5981. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5982. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5983. $html="";
  5984. }
  5985. }
  5986. $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>
  5987. <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>
  5988. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5989. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5990. }
  5991. $data['companyHtml']=$collectHtml;
  5992. //total price html
  5993. $collectHtml="";$total=0;
  5994. for ($i=1;$i<=12;$i++){
  5995. $sumPrice=0;
  5996. foreach ($itemStatisticsList as $key=>$value){
  5997. if($value['month']==$i){
  5998. $sumPrice+=$value['price'];
  5999. }
  6000. }
  6001. if ($sumPrice==0)
  6002. $collectHtml.='<td class="taR">-</td>';
  6003. else
  6004. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  6005. $total+=$sumPrice;
  6006. }
  6007. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  6008. $data['companyTotalHtml']=$collectHtml;
  6009. $data['total']=$total;
  6010. $data['year']=$year;
  6011. $data['memu']="receipt";
  6012. $data['staff']=$this->staff;
  6013. $data['receiptMemu']='companyCategoryCollect';
  6014. $data['verifyId']=$this->verifyId;
  6015. $data['executeId']=$this->executeId;
  6016. if ($year<=date("Y")){
  6017. Doo::loadModel('receipt');
  6018. $receipt=new receipt();
  6019. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  6020. if(empty($receiptList)){ //generated files
  6021. ob_start();
  6022. $this->render ( "/admin/saeaStaffCollectB", $data );
  6023. $this->cacheFile($path);die;
  6024. }
  6025. }
  6026. $this->render ( "/admin/saeaStaffCollectB", $data );
  6027. }
  6028. function staffCollectBak(){
  6029. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6030. $month=$this->get_args('month')?$this->get_args('month'):1;
  6031. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  6032. $this->showCache($path);
  6033. Doo::loadModel('statistics');
  6034. $statistics=new statistics();
  6035. Doo::loadModel("receiptDetail");
  6036. $receiptDetail=new receiptDetail();
  6037. Doo::loadModel('L_category');
  6038. $Lcategory=new L_category();
  6039. Doo::loadModel('accountItem');
  6040. $accountItem=new accountItem();
  6041. Doo::loadModel('staff');
  6042. $staff=new staff();
  6043. Doo::loadModel('itemStatistics');
  6044. $itemStatistics=new itemStatistics();
  6045. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6046. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  6047. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6048. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  6049. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  6050. $staffList=$staff->find(array('asArray'=>true));
  6051. $htmlArray=array();
  6052. foreach ($LcategoryList as $value){
  6053. $htmlArray[$value['title']]=array();
  6054. foreach ($staffList as $v){
  6055. if($value['cid']==$v['cid']){
  6056. $html="";$falg=true;$staffSumPrice=0;
  6057. foreach ($itemStatisticsList as $a){
  6058. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  6059. if(empty($a['price'])){
  6060. $html.='<td class="taR">-</td>';$falg=false;break;
  6061. }else{
  6062. $staffSumPrice+=$a['price'];
  6063. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6064. }
  6065. }
  6066. }
  6067. if ($falg){
  6068. $html.='<td class="taR">-</td>';$falg=true;
  6069. }
  6070. $falg=true;
  6071. foreach ($itemStatisticsList as $a){
  6072. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  6073. if(empty($a['price'])){
  6074. $html.='<td class="taR">-</td>';$falg=false;break;
  6075. }else{
  6076. $staffSumPrice+=$a['price'];
  6077. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6078. }
  6079. }
  6080. }
  6081. if ($falg){
  6082. $html.='<td class="taR">-</td>';$falg=true;
  6083. }
  6084. $falg=true;
  6085. foreach ($itemStatisticsList as $a){
  6086. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  6087. if(empty($a['price'])){
  6088. $html.='<td class="taR">-</td>';$falg=false;break;
  6089. }else{
  6090. $staffSumPrice+=$a['price'];
  6091. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6092. }
  6093. }
  6094. }
  6095. if ($falg){
  6096. $html.='<td class="taR">-</td>';$falg=true;
  6097. }
  6098. $falg=true;
  6099. foreach ($itemStatisticsList as $a){
  6100. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6101. if(!empty($a['price'])){
  6102. $staffSumPrice+=$a['price'];
  6103. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6104. }else{
  6105. $html.='<td class="taR">-</td>';$falg=false;break;
  6106. }
  6107. }
  6108. }
  6109. if ($falg){
  6110. $html.='<td class="taR">-</td>';$falg=true;
  6111. }
  6112. $falg=true;
  6113. foreach ($itemStatisticsList as $a){
  6114. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6115. if(!empty($a['price'])){
  6116. $staffSumPrice+=$a['price'];
  6117. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6118. }else{
  6119. $html.='<td class="taR">-</td>';$falg=false;break;
  6120. }
  6121. }
  6122. }
  6123. if ($falg){
  6124. $html.='<td class="taR">-</td>';$falg=true;
  6125. }
  6126. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6127. $htmlArray[$value['title']][$v['username']]=$html;
  6128. }
  6129. }
  6130. /*-- ---*/
  6131. //合计费用
  6132. $cateHtml="";$catePrice=0;$cateFalg=true;
  6133. foreach ($itemCategoryList as $l){
  6134. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6135. if(empty($l['price'])){
  6136. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6137. }else{
  6138. $catePrice+=$l['price'];
  6139. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6140. }
  6141. }
  6142. }
  6143. if ($cateFalg){
  6144. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6145. }
  6146. $cateFalg=true;
  6147. foreach ($itemCategoryList as $l){
  6148. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6149. if(empty($l['price'])){
  6150. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6151. }else{
  6152. $catePrice+=$l['price'];
  6153. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6154. }
  6155. }
  6156. }
  6157. if ($cateFalg){
  6158. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6159. }
  6160. $cateFalg=true;
  6161. foreach ($itemCategoryList as $l){
  6162. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6163. if(empty($l['price'])){
  6164. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6165. }else{
  6166. $catePrice+=$l['price'];
  6167. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6168. }
  6169. }
  6170. }
  6171. if ($cateFalg){
  6172. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6173. }
  6174. $cateFalg=true;
  6175. foreach ($itemCategoryList as $l){
  6176. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6177. if(empty($l['price'])){
  6178. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6179. }else{
  6180. $catePrice+=$l['price'];
  6181. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6182. }
  6183. }
  6184. }
  6185. if ($cateFalg){
  6186. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6187. }
  6188. $cateFalg=true;
  6189. foreach ($itemCategoryList as $l){
  6190. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6191. if(empty($l['price'])){
  6192. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6193. }else{
  6194. $catePrice+=$l['price'];
  6195. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6196. }
  6197. }
  6198. }
  6199. if ($cateFalg){
  6200. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6201. }
  6202. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6203. $htmlArray[$value['title']]['合计']=$cateHtml;
  6204. /*-- ---*/
  6205. }
  6206. //print_r($htmlArray);die;
  6207. $data['htmlArray']=$htmlArray;
  6208. //statistics html
  6209. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6210. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6211. if(empty($stList))
  6212. $stList=array('rePrice'=>0,'agPrice'=>0);
  6213. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6214. $monthHtml="";
  6215. for ($i=1;$i<=12;$i++){
  6216. if ($i==$month)
  6217. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6218. else
  6219. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6220. }
  6221. $data['monthHtml']=$monthHtml;
  6222. $data['year']=$year;
  6223. $data['month']=$month;
  6224. $data['memu']="receipt";
  6225. $data['staff']=$this->staff;
  6226. $data['receiptMemu']='companyCategoryCollect';
  6227. $data['verifyId']=$this->verifyId;
  6228. $data['executeId']=$this->executeId;
  6229. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6230. Doo::loadModel('receipt');
  6231. $receipt=new receipt();
  6232. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6233. if(empty($receiptList)){ //generated files
  6234. ob_start();
  6235. $this->render ( "/admin/saeaStaffCollect", $data );
  6236. $this->cacheFile($path);die;
  6237. }
  6238. }
  6239. $this->render ( "/admin/saeaStaffCollect", $data );
  6240. }
  6241. function lyt(){
  6242. Doo::loadModel("receiptDetail");
  6243. $receiptDetail=new receiptDetail();
  6244. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6245. foreach ($receiptCollectList as $key=>$value){
  6246. $receiptDetail=new receiptDetail();
  6247. $receiptDetail->pastDate=$value['date'];
  6248. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6249. }
  6250. }
  6251. function staffCollectMonthDetail(){
  6252. $year=$this->get_args('year')?$this->get_args('year'):"";
  6253. $month=$this->get_args('month')?$this->get_args('month'):"";
  6254. if(!$year)
  6255. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6256. if(!$month)
  6257. $month=isset($this->params['month'])?$this->params['month']:1;
  6258. Doo::loadModel('staff');
  6259. $staff=new staff();
  6260. Doo::loadModel("receiptDetail");
  6261. $receiptDetail=new receiptDetail();
  6262. Doo::loadModel('accountItem');
  6263. $accountItem=new accountItem();
  6264. Doo::loadModel('statistics');
  6265. $statistics=new statistics();
  6266. Doo::loadModel('L_category');
  6267. $lCategory=new L_category();
  6268. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6269. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6270. $list=array();
  6271. foreach ($categoryList as $vlu){
  6272. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6273. $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;
  6274. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6275. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6276. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6277. $s1=0;
  6278. $m1=0;
  6279. foreach ($staffList as $value){
  6280. if ($vlu['cid']==$value['cid']){
  6281. //pastDate
  6282. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6283. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6284. // if ($value['sid']==42){
  6285. // print_r($receiptCollectList);die;
  6286. // }
  6287. if(!empty($receiptCollectList)){
  6288. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6289. $html="";
  6290. $psum=0;
  6291. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6292. foreach ($item as $va){
  6293. $falg=true;
  6294. foreach ($receiptCollectList as $v){
  6295. if($v['itemCategory']=='日常相关费用'){
  6296. if($v['item']==$va){
  6297. if ($va=='市内交通费')
  6298. $r1+=$v['price'];
  6299. if ($va=='市内出租费')
  6300. $r2+=$v['price'];
  6301. if ($va=='办事处房租')
  6302. $r3+=$v['price'];
  6303. if ($va=='电话费')
  6304. $r4+=$v['price'];
  6305. if ($va=='水费')
  6306. $r5+=$v['price'];
  6307. if ($va=='电费')
  6308. $r6+=$v['price'];
  6309. if ($va=='办公费用')
  6310. $r7+=$v['price'];
  6311. if ($va=='邮寄费')
  6312. $r8+=$v['price'];
  6313. if ($va=='其他费用')
  6314. $r9+=$v['price'];
  6315. if ($va=='车辆费用')
  6316. $r10+=$v['price'];
  6317. if ($va=='广告费')
  6318. $r11+=$v['price'];
  6319. if ($va=='团队建设费')
  6320. $r13+=$v['price'];
  6321. if ($va=='物业管理费')
  6322. $r14+=$v['price'];
  6323. if ($va=='宽带费')
  6324. $r15+=$v['price'];
  6325. $psum+=$v['price'];
  6326. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6327. }
  6328. }
  6329. }
  6330. if($falg)
  6331. $html.='<td class="taR">-</td>';
  6332. }
  6333. $r12+=$psum;
  6334. if(!empty($psum))
  6335. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6336. else
  6337. $psum='<td class="colGreen taR">-</td>';
  6338. $receiptL['日常相关费用']=$psum.$html;
  6339. /*-----------------------------------*/
  6340. $html="";
  6341. $psum=0;
  6342. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6343. foreach ($item as $va){
  6344. $falg=true;
  6345. foreach ($receiptCollectList as $v){
  6346. if($v['itemCategory']=='差旅相关费用'){
  6347. if($v['item']==$va){
  6348. if ($va=='往来交通费')
  6349. $c1+=$v['price'];
  6350. if ($va=='市内交通费')
  6351. $c2+=$v['price'];
  6352. if ($va=='出差住宿费')
  6353. $c3+=$v['price'];
  6354. if ($va=='出差补助')
  6355. $c4+=$v['price'];
  6356. if ($va=='其他费用')
  6357. $c5+=$v['price'];
  6358. $psum+=$v['price'];
  6359. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6360. }
  6361. }
  6362. }
  6363. if($falg)
  6364. $html.='<td class="taR">-</td>';
  6365. }
  6366. $c6+=$psum;
  6367. if(!empty($psum))
  6368. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6369. else
  6370. $psum='<td class="colGreen taR">-</td>';
  6371. $receiptL['差旅相关费用']=$psum.$html;
  6372. /*-------------------------------------*/
  6373. $html="";
  6374. $psum=0;
  6375. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6376. foreach ($item as $va){
  6377. $falg=true;
  6378. foreach ($receiptCollectList as $v){
  6379. if($v['itemCategory']=='培训班费用'){
  6380. if($v['item']==$va){
  6381. if ($va=='场租费')
  6382. $p1+=$v['price'];
  6383. if ($va=='薪酬')
  6384. $p2+=$v['price'];
  6385. if ($va=='住宿费')
  6386. $p3+=$v['price'];
  6387. if ($va=='交通费')
  6388. $p4+=$v['price'];
  6389. if ($va=='餐饮费')
  6390. $p5+=$v['price'];
  6391. if ($va=='办公费')
  6392. $p6+=$v['price'];
  6393. if ($va=='公关费')
  6394. $p7+=$v['price'];
  6395. if ($va=='其他')
  6396. $p8+=$v['price'];
  6397. $psum+=$v['price'];
  6398. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6399. }
  6400. }
  6401. }
  6402. if($falg)
  6403. $html.='<td class="taR">-</td>';
  6404. }
  6405. $p9+=$psum;
  6406. if(!empty($psum))
  6407. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6408. else
  6409. $psum='<td class="colGreen taR">-</td>';
  6410. $receiptL['培训班费用']=$psum.$html;
  6411. /*-------------------------------------*/
  6412. $html="";
  6413. $psum=0;
  6414. $item=array('公关费','广告费','借款','可自加费用');
  6415. foreach ($item as $va){
  6416. $falg=true;
  6417. foreach ($receiptCollectList as $v){
  6418. if($v['itemCategory']=='其他'){
  6419. // if ($value['sid']==42){
  6420. //
  6421. // echo var_dump($v['item']);
  6422. // echo var_dump($va);
  6423. // echo var_dump($v['item']==" ".$va);
  6424. // echo $v['item']."==".$va."/<br/>";
  6425. // //print_r( $receiptCollectList);//echo $va;
  6426. // }
  6427. if(trim($v['item'])==$va){
  6428. if ($va=='公关费')
  6429. $t1+=$v['price'];
  6430. if ($va=='广告费'){
  6431. $t2+=$v['price'];
  6432. }
  6433. if ($va=='借款')
  6434. $t3+=$v['price'];
  6435. if ($va=='可自加费用')
  6436. $t4+=$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. $t5+=$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. foreach ($receiptCollectList as $v){
  6455. if($v['itemCategory']=='报销金额调整'){
  6456. if (!empty($v['price'])){
  6457. $psum+=$v['price'];
  6458. }
  6459. }
  6460. }
  6461. $s1+=$psum;
  6462. if(!empty($psum))
  6463. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6464. else
  6465. $psum='<td class="taR colOrange">-</td>';
  6466. $receiptL['报销金额调整']=$psum.$html;
  6467. }else{
  6468. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6469. <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>
  6470. <td class="taR">-</td><td class="taR">-</td>';
  6471. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6472. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6473. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6474. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6475. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6476. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6477. }
  6478. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6479. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6480. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6481. if(!empty($monthStaffPrice[0]['price'])){
  6482. $m1+=$monthStaffPrice[0]['price'];
  6483. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6484. }else
  6485. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6486. $list[$value['username']]=$receiptL;
  6487. }
  6488. }
  6489. $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>
  6490. <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>
  6491. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6492. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6493. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6494. $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>
  6495. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6496. $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>';
  6497. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6498. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6499. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6500. }
  6501. $data['list']=$list;
  6502. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6503. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6504. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6505. //statistics html
  6506. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6507. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6508. if(empty($stList))
  6509. $stList=array('rePrice'=>0,'agPrice'=>0);
  6510. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6511. $monthHtml="";
  6512. for ($i=1;$i<=12;$i++){
  6513. if ($i==$month)
  6514. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6515. else
  6516. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6517. }
  6518. $data['monthHtml']=$monthHtml;
  6519. $data['year']=$year;
  6520. $data['month']=$month;
  6521. $data['memu']="receipt";
  6522. $data['staff']=$this->staff;
  6523. $data['receiptMemu']='companyCategoryCollect';
  6524. $data['verifyId']=$this->verifyId;
  6525. $data['executeId']=$this->executeId;
  6526. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6527. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6528. }
  6529. function staffCollectMonthDetail2(){
  6530. $year=$this->get_args('year')?$this->get_args('year'):"";
  6531. $month=$this->get_args('month')?$this->get_args('month'):"";
  6532. if(!$year)
  6533. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6534. if(!$month)
  6535. $month=isset($this->params['month'])?$this->params['month']:1;
  6536. Doo::loadModel('staff');
  6537. $staff=new staff();
  6538. Doo::loadModel("receiptDetail");
  6539. $receiptDetail=new receiptDetail();
  6540. Doo::loadModel('accountItem');
  6541. $accountItem=new accountItem();
  6542. Doo::loadModel('statistics');
  6543. $statistics=new statistics();
  6544. Doo::loadModel('L_category');
  6545. $lCategory=new L_category();
  6546. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6547. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6548. $list=array();
  6549. foreach ($categoryList as $vlu){
  6550. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6551. $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;
  6552. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6553. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6554. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6555. $s1=0;
  6556. $m1=0;
  6557. foreach ($staffList as $value){
  6558. if ($vlu['cid']==$value['cid']){
  6559. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6560. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6561. if(!empty($receiptCollectList)){
  6562. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6563. $html="";
  6564. $psum=0;
  6565. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6566. foreach ($item as $va){
  6567. $falg=true;
  6568. foreach ($receiptCollectList as $v){
  6569. if($v['itemCategory']=='日常相关费用'){
  6570. if($v['item']==$va){
  6571. if ($va=='市内交通费')
  6572. $r1+=$v['price'];
  6573. if ($va=='市内出租费')
  6574. $r2+=$v['price'];
  6575. if ($va=='办事处房租')
  6576. $r3+=$v['price'];
  6577. if ($va=='电话费')
  6578. $r4+=$v['price'];
  6579. if ($va=='水费')
  6580. $r5+=$v['price'];
  6581. if ($va=='电费')
  6582. $r6+=$v['price'];
  6583. if ($va=='办公费用')
  6584. $r7+=$v['price'];
  6585. if ($va=='邮寄费')
  6586. $r8+=$v['price'];
  6587. if ($va=='其他费用')
  6588. $r9+=$v['price'];
  6589. if ($va=='车辆费用')
  6590. $r10+=$v['price'];
  6591. if ($va=='广告费')
  6592. $r11+=$v['price'];
  6593. if ($va=='团队建设费')
  6594. $r13+=$v['price'];
  6595. if ($va=='物业管理费')
  6596. $r14+=$v['price'];
  6597. if ($va=='宽带费')
  6598. $r15+=$v['price'];
  6599. $psum+=$v['price'];
  6600. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6601. }
  6602. }
  6603. }
  6604. if($falg)
  6605. $html.='<td class="taR">-</td>';
  6606. }
  6607. $r12+=$psum;
  6608. if(!empty($psum))
  6609. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6610. else
  6611. $psum='<td class="colGreen taR">-</td>';
  6612. $receiptL['日常相关费用']=$psum.$html;
  6613. /*-----------------------------------*/
  6614. $html="";
  6615. $psum=0;
  6616. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6617. foreach ($item as $va){
  6618. $falg=true;
  6619. foreach ($receiptCollectList as $v){
  6620. if($v['itemCategory']=='差旅相关费用'){
  6621. if($v['item']==$va){
  6622. if ($va=='往来交通费')
  6623. $c1+=$v['price'];
  6624. if ($va=='市内交通费')
  6625. $c2+=$v['price'];
  6626. if ($va=='出差住宿费')
  6627. $c3+=$v['price'];
  6628. if ($va=='出差补助')
  6629. $c4+=$v['price'];
  6630. if ($va=='其他费用')
  6631. $c5+=$v['price'];
  6632. $psum+=$v['price'];
  6633. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6634. }
  6635. }
  6636. }
  6637. if($falg)
  6638. $html.='<td class="taR">-</td>';
  6639. }
  6640. $c6+=$psum;
  6641. if(!empty($psum))
  6642. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6643. else
  6644. $psum='<td class="colGreen taR">-</td>';
  6645. $receiptL['差旅相关费用']=$psum.$html;
  6646. /*-------------------------------------*/
  6647. $html="";
  6648. $psum=0;
  6649. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6650. foreach ($item as $va){
  6651. $falg=true;
  6652. foreach ($receiptCollectList as $v){
  6653. if($v['itemCategory']=='培训班费用'){
  6654. if($v['item']==$va){
  6655. if ($va=='场租费')
  6656. $p1+=$v['price'];
  6657. if ($va=='薪酬')
  6658. $p2+=$v['price'];
  6659. if ($va=='住宿费')
  6660. $p3+=$v['price'];
  6661. if ($va=='交通费')
  6662. $p4+=$v['price'];
  6663. if ($va=='餐饮费')
  6664. $p5+=$v['price'];
  6665. if ($va=='办公费')
  6666. $p6+=$v['price'];
  6667. if ($va=='公关费')
  6668. $p7+=$v['price'];
  6669. if ($va=='其他')
  6670. $p8+=$v['price'];
  6671. $psum+=$v['price'];
  6672. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6673. }
  6674. }
  6675. }
  6676. if($falg)
  6677. $html.='<td class="taR">-</td>';
  6678. }
  6679. $p9+=$psum;
  6680. if(!empty($psum))
  6681. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6682. else
  6683. $psum='<td class="colGreen taR">-</td>';
  6684. $receiptL['培训班费用']=$psum.$html;
  6685. /*-------------------------------------*/
  6686. $html="";
  6687. $psum=0;
  6688. $item=array('公关费','广告费','借款','可自加费用');
  6689. foreach ($item as $va){
  6690. $falg=true;
  6691. foreach ($receiptCollectList as $v){
  6692. if($v['itemCategory']=='其他'){
  6693. if($v['item']==$va){
  6694. if ($va=='公关费')
  6695. $t1+=$v['price'];
  6696. if ($va=='广告费')
  6697. $t2+=$v['price'];
  6698. if ($va=='借款')
  6699. $t3+=$v['price'];
  6700. if ($va=='可自加费用')
  6701. $t4+=$v['price'];
  6702. $psum+=$v['price'];
  6703. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6704. }
  6705. }
  6706. }
  6707. if($falg)
  6708. $html.='<td class="taR">-</td>';
  6709. }
  6710. $t5+=$psum;
  6711. if(!empty($psum))
  6712. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6713. else
  6714. $psum='<td class="colGreen taR">-</td>';
  6715. $receiptL['其他']=$psum.$html;
  6716. /*-------------------------------------*/
  6717. $html="";
  6718. $psum=0;
  6719. foreach ($receiptCollectList as $v){
  6720. if($v['itemCategory']=='报销金额调整'){
  6721. if (!empty($v['price'])){
  6722. $psum+=$v['price'];
  6723. }
  6724. }
  6725. }
  6726. $s1+=$psum;
  6727. if(!empty($psum))
  6728. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6729. else
  6730. $psum='<td class="taR colOrange">-</td>';
  6731. $receiptL['报销金额调整']=$psum.$html;
  6732. }else{
  6733. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6734. <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>';
  6735. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6736. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6737. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6738. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6739. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6740. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6741. }
  6742. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6743. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6744. if(!empty($monthStaffPrice[0]['price'])){
  6745. $m1+=$monthStaffPrice[0]['price'];
  6746. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6747. }else
  6748. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6749. $list[$value['username']]=$receiptL;
  6750. }
  6751. }
  6752. $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>
  6753. <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>
  6754. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6755. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6756. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6757. $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>
  6758. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6759. $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>';
  6760. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6761. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6762. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6763. }
  6764. $data['list']=$list;
  6765. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6766. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6767. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6768. //statistics html
  6769. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6770. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6771. if(empty($stList))
  6772. $stList=array('rePrice'=>0,'agPrice'=>0);
  6773. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6774. $monthHtml="";
  6775. for ($i=1;$i<=12;$i++){
  6776. if ($i==$month)
  6777. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6778. else
  6779. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6780. }
  6781. $data['monthHtml']=$monthHtml;
  6782. $data['year']=$year;
  6783. $data['month']=$month;
  6784. $data['memu']="receipt";
  6785. $data['staff']=$this->staff;
  6786. $data['receiptMemu']='companyCategoryCollect';
  6787. $data['verifyId']=$this->verifyId;
  6788. $data['executeId']=$this->executeId;
  6789. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6790. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6791. }
  6792. function companyMonthCollectDetail(){
  6793. $year=$this->get_args('year')?$this->get_args('year'):"";
  6794. $month=$this->get_args('month')?$this->get_args('month'):"";
  6795. if(!$year)
  6796. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6797. if(!$month)
  6798. $month=isset($this->params['month'])?$this->params['month']:1;
  6799. Doo::loadModel('staff');
  6800. $staff=new staff();
  6801. Doo::loadModel("receiptDetail");
  6802. $receiptDetail=new receiptDetail();
  6803. Doo::loadModel('accountItem');
  6804. $accountItem=new accountItem();
  6805. Doo::loadModel('statistics');
  6806. $statistics=new statistics();
  6807. Doo::loadModel('L_category');
  6808. $lCategory=new L_category();
  6809. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6810. $categoryList=$lCategory->find(array('asArray'=>true));
  6811. $list=array();
  6812. foreach ($categoryList as $value){
  6813. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6814. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6815. if(!empty($receiptCollectList)){
  6816. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6817. $html="";
  6818. $psum=0;
  6819. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6820. foreach ($item as $va){
  6821. $falg=true;
  6822. foreach ($receiptCollectList as $v){
  6823. if($v['itemCategory']=='日常相关费用'){
  6824. if($v['item']==$va){
  6825. $psum+=$v['price'];
  6826. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6827. }
  6828. }
  6829. }
  6830. if($falg)
  6831. $html.='<td class="taR">-</td>';
  6832. }
  6833. if(!empty($psum))
  6834. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6835. else
  6836. $psum='<td class="colGreen taR">-</td>';
  6837. $receiptL['日常相关费用']=$psum.$html;
  6838. /*-----------------------------------*/
  6839. $html="";
  6840. $psum=0;
  6841. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6842. foreach ($item as $va){
  6843. $falg=true;
  6844. foreach ($receiptCollectList as $v){
  6845. if($v['itemCategory']=='差旅相关费用'){
  6846. if($v['item']==$va){
  6847. $psum+=$v['price'];
  6848. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6849. }
  6850. }
  6851. }
  6852. if($falg)
  6853. $html.='<td class="taR">-</td>';
  6854. }
  6855. if(!empty($psum))
  6856. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6857. else
  6858. $psum='<td class="colGreen taR">-</td>';
  6859. $receiptL['差旅相关费用']=$psum.$html;
  6860. /*-------------------------------------*/
  6861. $html="";
  6862. $psum=0;
  6863. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6864. foreach ($item as $va){
  6865. $falg=true;
  6866. foreach ($receiptCollectList as $v){
  6867. if($v['itemCategory']=='培训班费用'){
  6868. if($v['item']==$va){
  6869. $psum+=$v['price'];
  6870. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6871. }
  6872. }
  6873. }
  6874. if($falg)
  6875. $html.='<td class="taR">-</td>';
  6876. }
  6877. if(!empty($psum))
  6878. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6879. else
  6880. $psum='<td class="colGreen taR">-</td>';
  6881. $receiptL['培训班费用']=$psum.$html;
  6882. /*-------------------------------------*/
  6883. $html="";
  6884. $psum=0;
  6885. $item=array('公关费','广告费','借款','可自加费用');
  6886. foreach ($item as $va){
  6887. $falg=true;
  6888. foreach ($receiptCollectList as $v){
  6889. if($v['itemCategory']=='其他'){
  6890. if($v['item']==$va){
  6891. $psum+=$v['price'];
  6892. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6893. }
  6894. }
  6895. }
  6896. if($falg)
  6897. $html.='<td class="taR">-</td>';
  6898. }
  6899. if(!empty($psum))
  6900. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6901. else
  6902. $psum='<td class="colGreen taR">-</td>';
  6903. $receiptL['其他']=$psum.$html;
  6904. /*-------------------------------------*/
  6905. $html="";
  6906. $psum=0;
  6907. foreach ($receiptCollectList as $v){
  6908. if($v['itemCategory']=='报销金额调整'){
  6909. if (!empty($v['price']))
  6910. $psum+=$v['price'];
  6911. }
  6912. }
  6913. if(!empty($psum))
  6914. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6915. else
  6916. $psum='<td class="taR colOrange">-</td>';
  6917. $receiptL['报销金额调整']=$psum.$html;
  6918. }else{
  6919. $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>
  6920. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6921. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6922. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6923. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6924. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6925. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6926. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6927. }
  6928. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6929. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6930. if(!empty($monthStaffPrice[0]['price']))
  6931. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6932. else
  6933. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6934. $list[$value['title']]=$receiptL;
  6935. }
  6936. $data['list']=$list;
  6937. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6938. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6939. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6940. //print_r($data['monthPriceHtml']);
  6941. // foreach ($data['monthPriceHtml'] as $value){
  6942. // echo $value;
  6943. // }
  6944. // die;
  6945. //statistics html
  6946. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6947. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6948. if(empty($stList))
  6949. $stList=array('rePrice'=>0,'agPrice'=>0);
  6950. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6951. $monthHtml="";
  6952. for ($i=1;$i<=12;$i++){
  6953. if ($i==$month)
  6954. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6955. else
  6956. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6957. }
  6958. $data['monthHtml']=$monthHtml;
  6959. $data['year']=$year;
  6960. $data['month']=$month;
  6961. $data['memu']="receipt";
  6962. $data['staff']=$this->staff;
  6963. $data['receiptMemu']='companyCategoryCollect';
  6964. $data['verifyId']=$this->verifyId;
  6965. $data['executeId']=$this->executeId;
  6966. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6967. }
  6968. function staffCollectDetail(){
  6969. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6970. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6971. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6972. if(!$staffname){
  6973. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6974. $staffname= urldecode($staffname);
  6975. }
  6976. Doo::loadModel('staff');
  6977. $staff=new staff();
  6978. Doo::loadModel("receiptDetail");
  6979. $receiptDetail=new receiptDetail();
  6980. Doo::loadModel('accountItem');
  6981. $accountItem=new accountItem();
  6982. Doo::loadModel('statistics');
  6983. $statistics=new statistics();
  6984. Doo::loadModel('L_category');
  6985. $lCategory=new L_category();
  6986. $staffList=$staff->find(array('asArray'=>true));
  6987. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6988. foreach ($staffList as $value){
  6989. if ($value['username']==$staffname&&$value['username']!='admin'){
  6990. $stTitle=$value['category'].'-'.$value['username'];
  6991. $staffId=$value['sid'];
  6992. $cid=$value['cid'];
  6993. $ocid=$value['cid'];
  6994. if (!empty($value['othercid']))
  6995. $cid=$value['cid'].','.$value['othercid'];
  6996. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6997. }elseif ($value['username']!='admin')
  6998. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6999. }
  7000. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  7001. if(empty($pcid))
  7002. $pcid=$ocid;
  7003. $data['ocid']=$pcid;
  7004. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  7005. $this->showCache($path);
  7006. //
  7007. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  7008. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  7009. $accountList=$accountItem->find(array('asArray'=>true));
  7010. //create CollectDetail HTML
  7011. $collectHtml=array();
  7012. foreach ($accountList as $key=>$value){
  7013. $html="";$asum=0;
  7014. for ($i=1;$i<=12;$i++){
  7015. $falg=true;
  7016. foreach ($receiptCollectList as $v) {
  7017. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  7018. $asum+=$v['price'];
  7019. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  7020. }
  7021. }
  7022. if($falg)
  7023. $html.='<td class="taR">-</td>';
  7024. }
  7025. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  7026. $collectHtml[$value['category']][$value['name']]=$html;
  7027. }
  7028. $data['collectHtml']=$collectHtml;
  7029. //create Adjustment price html
  7030. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  7031. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  7032. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7033. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  7034. array_push($collectArray['日常相关费用'], $collectHtml);
  7035. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  7036. array_push($collectArray['差旅相关费用'], $collectHtml);
  7037. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  7038. array_push($collectArray['培训班费用'], $collectHtml);
  7039. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  7040. array_push($collectArray['其他'], $collectHtml);
  7041. $data['collectArray']=$collectArray;
  7042. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  7043. array_push($adjustment, $collectHtml);
  7044. $data['adjustment']=$adjustment;
  7045. //total price html
  7046. $collectHtml="";$total=0;
  7047. for ($i=1;$i<=12;$i++){
  7048. $sumPrice=0;
  7049. foreach ($receiptCollectList as $key=>$value){
  7050. if($value['month']==$i){
  7051. $sumPrice+=$value['price'];
  7052. }
  7053. }
  7054. if ($sumPrice==0)
  7055. $collectHtml.='<td class="taR">-</td>';
  7056. else
  7057. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  7058. $total+=$sumPrice;
  7059. }
  7060. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  7061. //statistics html
  7062. $stList=$statistics->statisticsByYear($year,$staffId);
  7063. if(empty($stList))
  7064. $stList=array('rePrice'=>0,'agPrice'=>0);
  7065. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  7066. $data['totalPrice']=$collectHtml;
  7067. $data['totalYear']=$total;
  7068. $data['stHtml']=$stHtml;
  7069. $data['year']=$year;
  7070. $data['stTitle']=$stTitle;
  7071. $data['memu']="receipt";
  7072. $data['staff']=$this->staff;
  7073. $data['receiptMemu']='companyCategoryCollect';
  7074. $data['verifyId']=$this->verifyId;
  7075. $data['executeId']=$this->executeId;
  7076. if ($year<date("Y")){
  7077. Doo::loadModel('receipt');
  7078. $receipt=new receipt();
  7079. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  7080. if(empty($receiptList)){ //generated files
  7081. ob_start();
  7082. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7083. $this->cacheFile($path);die;
  7084. }
  7085. }
  7086. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7087. }
  7088. function BUGFLAG(){
  7089. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  7090. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  7091. $month=$this->get_args('month')?$this->get_args('month'):"";
  7092. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  7093. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  7094. if (empty($status))
  7095. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  7096. $page_size=12;
  7097. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7098. $vidList=array();
  7099. $button=0;
  7100. Doo::loadModel('verify');
  7101. $verify=new verify();
  7102. Doo::loadModel('receipt');
  7103. $receipt=new receipt();
  7104. Doo::loadModel('staff');
  7105. $staff=new staff();
  7106. Doo::loadModel('L_category');
  7107. $Lcategory=new L_category();
  7108. $dateCondition=" and Year(date) =".$year;
  7109. if(!empty($month))
  7110. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  7111. $categoryList=$Lcategory->find(array('asArray'=>true));
  7112. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7113. $cateCondition="";$staffCondition="";$approvalCondition="";
  7114. if (!empty($cid))
  7115. $cateCondition=' and cid='.$cid;
  7116. if(!empty($sid)){
  7117. $staffCondition=' and staff='.$sid;
  7118. $cateCondition="";
  7119. }
  7120. $approvalCondition=" and status=".$status;
  7121. if($status==2){
  7122. //查找角色审批人
  7123. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7124. }
  7125. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7126. $approvalCondition=' and status=2 ';
  7127. }
  7128. if($status==1){
  7129. $approvalCondition=' and (status='.$status.' or status=6) ';
  7130. }
  7131. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7132. $pageinfo['page']=array('previous'=>'');
  7133. if ($status==0){
  7134. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7135. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7136. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7137. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7138. }else
  7139. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7140. ,'desc'=>'rid','asArray'=>true));
  7141. $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
  7142. ,'desc'=>'rid','asArray'=>true));
  7143. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7144. //print_r($pageinfo);
  7145. $Locate=0;
  7146. foreach ($receiptList as $key=>$value){
  7147. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7148. $receiptList[$key]['reviseDetail']=array();
  7149. if (!empty($value['reviseDetail']))
  7150. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7151. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7152. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7153. $receiptList[$key]['category']=$categoryDetil['title'];
  7154. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7155. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7156. $verifyStaff=json_decode($value['verifyStaff'],true);
  7157. foreach ($verifyList as $k=>$v){
  7158. //init verifyStaff
  7159. $verifyList[$k]['date']="";
  7160. $verifyList[$k]['opinion']="";
  7161. $verifyList[$k]['status']="";
  7162. if (empty($verifyStaff)){
  7163. $verifyList[$k]['date']="";
  7164. $verifyList[$k]['opinion']="";
  7165. if ($v[0]==$this->staff[0]['sid']){
  7166. $verifyList[$k]['status']=4;
  7167. $button=4;
  7168. }
  7169. }else{
  7170. $flag=true;
  7171. foreach ($verifyStaff as $m=>$u){
  7172. if ($v[0]==$m){
  7173. $verifyList[$k]['date']=$u['date'];
  7174. $verifyList[$k]['opinion']=$u['opinion'];
  7175. $verifyList[$k]['status']=$u['status'];
  7176. $flag=false;
  7177. break;
  7178. }
  7179. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7180. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7181. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7182. }
  7183. if($flag){//检测可编辑
  7184. if($v[0]==$this->staff[0]['sid']){
  7185. $verifyList[$k]['status']=4;$button=4;
  7186. }
  7187. }
  7188. }
  7189. }
  7190. $receiptList[$key]['verifyList']=$verifyList;
  7191. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7192. $receiptList[$key]['button']=$button;
  7193. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7194. }
  7195. //print_r($receiptList);die;
  7196. //$data['verifyDetail']=$verifyDetail;
  7197. $mothHtml="";
  7198. for($i=1;$i<=12;$i++){
  7199. if($month==$i)
  7200. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7201. else
  7202. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7203. }
  7204. $data['mothHtml']=$mothHtml;
  7205. $data['page']=$pageinfo;
  7206. $data['receiptList']=$receiptList;
  7207. $data['receiptApprovalCount']=count($rLRes);
  7208. $data['status']=$status;
  7209. $data['year']=$year;
  7210. $data['categoryList']=$categoryList;
  7211. $data['staffList']=$staffList;
  7212. $data['cid']=$cid;
  7213. $data['sid']=$sid;
  7214. //print_r($receiptList);
  7215. $data['memu']="receipt";
  7216. $data['staff']=$this->staff;
  7217. $data['receiptMemu']='approvalExpenses';
  7218. $data['verifyId']=$this->verifyId;
  7219. $data['executeId']=$this->executeId;
  7220. $this->render ( "/admin/FALG", $data );
  7221. }
  7222. function ajaxGetReceiptOrder(){
  7223. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7224. if (!empty($receiptOrder)){
  7225. Doo::loadModel('receipt');
  7226. $receipt=new receipt();
  7227. Doo::loadModel ( 'staff' );
  7228. $staff = new staff ();
  7229. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7230. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7231. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7232. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7233. </tbody></table><table class="table table table-bordered"><tbody>';
  7234. foreach ($verifyStaff as $key=>$value){
  7235. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7236. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7237. }
  7238. $html.='</tbody></table></div></div>';
  7239. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7240. }
  7241. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7242. }
  7243. function _getMonthCollectDetail($receiptCollectList){
  7244. if(!empty($receiptCollectList)){
  7245. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7246. $html="";
  7247. $psum=0;
  7248. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7249. foreach ($item as $value){
  7250. $falg=true;
  7251. foreach ($receiptCollectList as $v){
  7252. if($v['itemCategory']=='日常相关费用'){
  7253. if($v['item']==$value){
  7254. $psum+=$v['price'];
  7255. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7256. }
  7257. }
  7258. }
  7259. if($falg)
  7260. $html.='<td class="taR">-</td>';
  7261. }
  7262. if(!empty($psum))
  7263. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7264. else
  7265. $psum='<td class="colGreen taR">-</td>';
  7266. $receiptL['日常相关费用']=$psum.$html;
  7267. /*-----------------------------------*/
  7268. $html="";
  7269. $psum=0;
  7270. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7271. foreach ($item as $value){
  7272. $falg=true;
  7273. foreach ($receiptCollectList as $v){
  7274. if($v['itemCategory']=='差旅相关费用'){
  7275. if($v['item']==$value){
  7276. $psum+=$v['price'];
  7277. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7278. }
  7279. }
  7280. }
  7281. if($falg)
  7282. $html.='<td class="taR">-</td>';
  7283. }
  7284. if(!empty($psum))
  7285. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7286. else
  7287. $psum='<td class="colGreen taR">-</td>';
  7288. $receiptL['差旅相关费用']=$psum.$html;
  7289. /*-------------------------------------*/
  7290. $html="";
  7291. $psum=0;
  7292. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7293. foreach ($item as $value){
  7294. $falg=true;
  7295. foreach ($receiptCollectList as $v){
  7296. if($v['itemCategory']=='培训班费用'){
  7297. if($v['item']==$value){
  7298. $psum+=$v['price'];
  7299. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7300. }
  7301. }
  7302. }
  7303. if($falg)
  7304. $html.='<td class="taR">-</td>';
  7305. }
  7306. if(!empty($psum))
  7307. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7308. else
  7309. $psum='<td class="colGreen taR">-</td>';
  7310. $receiptL['培训班费用']=$psum.$html;
  7311. /*-------------------------------------*/
  7312. $html="";
  7313. $psum=0;
  7314. $item=array('公关费','广告费','借款','可自加费用');
  7315. foreach ($item as $value){
  7316. $falg=true;
  7317. foreach ($receiptCollectList as $v){
  7318. if($v['itemCategory']=='其他'){
  7319. if($v['item']==$value){
  7320. $psum+=$v['price'];
  7321. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7322. }
  7323. }
  7324. }
  7325. if($falg)
  7326. $html.='<td class="taR">-</td>';
  7327. }
  7328. if(!empty($psum))
  7329. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7330. else
  7331. $psum='<td class="colGreen taR">-</td>';
  7332. $receiptL['其他']=$psum.$html;
  7333. /*-------------------------------------*/
  7334. $html="";
  7335. $psum=0;
  7336. foreach ($receiptCollectList as $v){
  7337. if($v['itemCategory']=='报销金额调整'){
  7338. if (!empty($v['price']))
  7339. $psum+=$v['price'];
  7340. }
  7341. }
  7342. if(!empty($psum))
  7343. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7344. else
  7345. $psum='<td class="taR colOrange">-</td>';
  7346. $receiptL['报销金额调整']=$psum.$html;
  7347. }else{
  7348. $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>
  7349. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7350. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7351. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7352. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7353. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7354. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7355. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7356. }
  7357. return $receiptL;
  7358. }
  7359. function eMail(){
  7360. Doo::loadModel('staff');
  7361. $staff=new staff();
  7362. Doo::loadModel('receipt');
  7363. $receipt=new receipt();
  7364. Doo::loadModel('L_category');
  7365. $Lcategory=new L_category();
  7366. Doo::loadModel("verify");
  7367. $verify=new verify();
  7368. $staffList=$staff->find(array('asArray'=>true));
  7369. foreach ($staffList as $key=>$value){
  7370. if($value['username']!='admin'){
  7371. //提交人
  7372. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7373. if(!empty($receiptList)){
  7374. $html='<br><div><style></style>
  7375. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7376. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7377. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7378. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7379. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7380. <tbody><tr>
  7381. <td style="padding: 0 40px;" align="left">
  7382. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7383. </td></tr><tr>
  7384. <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>
  7385. </tr>
  7386. </tbody> </table></td> </tr> <tr><td>
  7387. <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">
  7388. <tbody> <tr><td>
  7389. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7390. 以下报销单完成了审批,等着收款吧:</p>
  7391. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7392. foreach ($receiptList as $k=>$v){
  7393. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7394. $html.='
  7395. <tr>
  7396. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7397. <td align="left">
  7398. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7399. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7400. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7401. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7402. </tr>';
  7403. }
  7404. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7405. <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>
  7406. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7407. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7408. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7409. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7410. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7411. $receipt=new receipt();
  7412. $receipt->notice=1;
  7413. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7414. }
  7415. }
  7416. //审批人
  7417. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7418. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7419. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7420. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7421. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7422. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7423. <tbody><tr><td style="padding: 0 40px;" align="left">
  7424. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7425. </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>
  7426. </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">
  7427. <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>
  7428. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7429. foreach ($verifyList as $k=>$v){
  7430. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7431. foreach ($receiptList as $r=>$l){
  7432. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7433. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7434. $html.='
  7435. <tr>
  7436. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7437. <td align="left">
  7438. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7439. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7440. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7441. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7442. </tr>';
  7443. }
  7444. }
  7445. $html.='
  7446. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7447. <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>
  7448. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7449. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7450. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7451. // $receipt=new receipt();
  7452. // $receipt->notice=1;
  7453. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7454. }
  7455. }
  7456. }
  7457. }
  7458. function setWXMsg($rid,$type){
  7459. Doo::loadModel("receipt");
  7460. $receipt=new receipt();
  7461. $receiptDetail = $receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  7462. if(!empty($receiptDetail)){
  7463. Doo::loadModel('staff');
  7464. $staff = new staff();
  7465. $staffmsg = $staff->getStaffBySid($receiptDetail['staff']);
  7466. if(!empty($staffmsg['wxid'])){
  7467. require_once (SITE_PATH . '/protected/class/client.php');
  7468. $client = new client ('http://m.cld.smartcost.com.cn/');
  7469. $user = $staffmsg['wxid'];
  7470. $receiptName = '';
  7471. $msg = '';
  7472. switch($receiptDetail['Rtype']){
  7473. case 0:$receiptName = '报销';break;
  7474. case 1:$receiptName = '借款';break;
  7475. case 2:$receiptName = '对公汇款';break;
  7476. }
  7477. switch($type){
  7478. case 1:$msg = '太好了,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已同意支付。';break;
  7479. case 2:$msg = '注意,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被撤回,请及时处理。';break;
  7480. case 3:$msg = '很遗憾,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被终止。';break;
  7481. }
  7482. $result = $client->SendMsg($user,$msg,'text');
  7483. }
  7484. }
  7485. }
  7486. // Email发送函数
  7487. function SMail($toemail, $subject, $contents) {
  7488. Doo::loadClass('class.phpmailer');
  7489. $mail = new PHPMailer();
  7490. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7491. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7492. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7493. $mail->Password = "cDO1GjtY1seH"; //密码
  7494. $mail->CharSet = "UTF8";
  7495. $mail->SMTPAuth = true;
  7496. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7497. $mail->Mailer = "smtp";
  7498. $mail->Port = 25;
  7499. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7500. $mail->MsgHTML($contents);
  7501. $mail->AddAddress($toemail);
  7502. $mail->CharSet = "UTF-8";
  7503. return $mail->Send();
  7504. }
  7505. function swfupload(){
  7506. $POST_MAX_SIZE = ini_get('post_max_size');
  7507. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7508. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7509. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7510. header("HTTP/1.1 500 Internal Server Error");
  7511. echo "POST exceeded maximum allowed size.";
  7512. exit(0);
  7513. }
  7514. // Settings
  7515. $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)
  7516. $upload_name = "Filedata";
  7517. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7518. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7519. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7520. // Other variables
  7521. $MAX_FILENAME_LENGTH = 260;
  7522. $file_name = "";
  7523. $file_extension = "";
  7524. $uploadErrors = array(
  7525. 0=>"文件上传成功",
  7526. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7527. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7528. 3=>"上传的文件仅为部分文件",
  7529. 4=>"没有文件上传",
  7530. 6=>"缺少临时文件夹"
  7531. );
  7532. $nk= time();
  7533. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7534. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7535. echo "文件无法保存.";
  7536. exit(0);
  7537. }
  7538. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7539. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7540. exit(0);
  7541. }
  7542. function _GetFileEXT($filename) {
  7543. $pics = explode ( '.', $filename );
  7544. $num = count ( $pics );
  7545. return $pics [$num - 1];
  7546. }
  7547. /**
  7548. * 获取get或者POST值
  7549. * @param string $name 属性名称
  7550. * @return fixed 值
  7551. */
  7552. function get_args($name) {
  7553. if (isset ( $_GET [$name] )) {
  7554. if (is_array ( $_GET [$name] ))
  7555. return $_GET [$name];
  7556. else
  7557. return addslashes ( $_GET [$name] );
  7558. } elseif (isset ( $_POST [$name] )) {
  7559. if (is_array ( $_POST [$name] ))
  7560. return $_POST [$name];
  7561. else
  7562. return addslashes ( $_POST [$name] );
  7563. } else
  7564. return false;
  7565. }
  7566. function num_to_rmb($num){
  7567. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7568. $c2 = "分角元拾佰仟万拾佰仟亿";
  7569. //精确到分后面就不要了,所以只留两个小数位
  7570. $num = round($num, 2);
  7571. //将数字转化为整数
  7572. $num = $num * 100;
  7573. if (strlen($num) > 10) {
  7574. return "金额太大,请检查";
  7575. }
  7576. $i = 0;
  7577. $c = "";
  7578. while (1) {
  7579. if ($i == 0) {
  7580. //获取最后一位数字
  7581. $n = substr($num, strlen($num)-1, 1);
  7582. } else {
  7583. $n = $num % 10;
  7584. }
  7585. //每次将最后一位数字转化为中文
  7586. $p1 = substr($c1, 3 * $n, 3);
  7587. $p2 = substr($c2, 3 * $i, 3);
  7588. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7589. $c = $p1 . $p2 . $c;
  7590. } else {
  7591. $c = $p1 . $c;
  7592. }
  7593. $i = $i + 1;
  7594. //去掉数字最后一位了
  7595. $num = $num / 10;
  7596. $num = (int)$num;
  7597. //结束循环
  7598. if ($num == 0) {
  7599. break;
  7600. }
  7601. }
  7602. $j = 0;
  7603. $slen = strlen($c);
  7604. while ($j < $slen) {
  7605. //utf8一个汉字相当3个字符
  7606. $m = substr($c, $j, 6);
  7607. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7608. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7609. $left = substr($c, 0, $j);
  7610. $right = substr($c, $j + 3);
  7611. $c = $left . $right;
  7612. $j = $j-3;
  7613. $slen = $slen-3;
  7614. }
  7615. $j = $j + 3;
  7616. }
  7617. //这个是为了去掉类似23.0中最后一个“零”字
  7618. if (substr($c, strlen($c)-3, 3) == '零') {
  7619. $c = substr($c, 0, strlen($c)-3);
  7620. }
  7621. //将处理的汉字加上“整”
  7622. if (empty($c)) {
  7623. return "零元整";
  7624. }else{
  7625. return $c . "整";
  7626. }
  7627. }
  7628. /**
  7629. * 获得分页数据
  7630. * @param unknown_type $table
  7631. * @param unknown_type $condition
  7632. * @param unknown_type $on_page
  7633. * @param unknown_type $page_size
  7634. */
  7635. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7636. $page_c = "";
  7637. $page ['previous'] = $this->get_previous ( $on_page );
  7638. $page ['on_page'] = $on_page;
  7639. $total_count = $this->get_table_count ( $table, $condition );
  7640. $total = intval ( $total_count / $page_size );
  7641. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7642. $page ['total_data'] = $total_count;
  7643. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7644. $i = 1;
  7645. $page_max = 1;
  7646. $page_width=3;
  7647. if ($on_page >= $page_width) {
  7648. $page_max = intval ( $on_page / $page_width ) + 1;
  7649. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7650. }
  7651. for(; $i <= $page ['total_page']; $i ++) {
  7652. if ($i == $on_page)
  7653. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7654. else
  7655. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7656. if ($i == ($page_width * $page_max))
  7657. break;
  7658. }
  7659. $page ['page'] = $page_c;
  7660. $page ['lower'] = (-- $on_page) * $page_size;
  7661. return $page;
  7662. }
  7663. /**
  7664. * 获取总页数
  7665. * @param unknown_type $table
  7666. * @param unknown_type $condition
  7667. */
  7668. public function get_table_count($table = "", $condition = "") {
  7669. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7670. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7671. //echo $sql;die;
  7672. $query = Doo::db ()->query ( $sql );
  7673. $result = $query->fetch ();
  7674. return $result ['count'];
  7675. }
  7676. /**
  7677. * 获取上一页
  7678. * @param unknown_type $on_page
  7679. */
  7680. function get_previous($on_page = 1) {
  7681. return $on_page != 0 ? $on_page - 1 : $on_page;
  7682. }
  7683. }
  7684. ?>